John Graham-Cumming wrote a book about GNU Make much of the book originated from his blog posts on GNU Make, which are still available and are useful. Its pages that discuss special targets and errors in recipes are especially relevant to this article. This informs make not to delete them even if there is an error in the recipe.īeing easy to read and well written, Innolitics recommends the GNU Make Manual if you want to learn more about make. DELETE_ON_ERROR, but to list these “precious” targets as prerequisites of the. DELETE_ON_ERROR if you want to keep the target files even after an error occurs (e.g., imagine a target takes weeks to compute). ![]() (See this excellent tutorial about writing portable makefiles.) GNU make is quite pervasive, but you may not want to rely on it if you build on multiple platforms. DELETE_ON_ERROR is that it’s a GNU make extension. DELETE_ON_ERROR solves, it’s reasonable to ask if there are situations when you wouldn’t want to include it in your makefiles. This is almost always what you want make to do, but it is not historical practice so for compatibility, you must explicitly request it.Īfter considering the problems. The GNU Make Manual says this about deleting target files after a recipe error: DELETE_ON_ERROR ensures you don’t need to manually clean targets constructed from flaky recipes. Once it’s back online, you would need to manually delete languages.csv before make would run the recipe again. If the server is unavailable, languages.csv will be invalid. It avoids the need to manually clean invalid targets while not forcing you to maintain your scripts as prerequisites.įinally, imagine that extract_languages.py makes an HTTP request to a web server. DELETE_ON_ERROR is a practical alternative. However, maintaining script dependencies can be challenging (extract_languages.py may depend on many other python files). Doing so protects you in this situation while also ensuring that make rebuilds your targets if your scripts are updated. The ideal solution is to include your scripts as prerequisites. Therefore, once you do you’ll need to manually delete languages.csv to have make build it again. ![]() Since that isn’t a prerequisite, make won’t recognize that languages.csv is out of date even if you fix the bug. Now imagine there is a bug in extract_languages.py. Problem 2: defects in missing dependencies □ DELETE_ON_ERROR prevents this from occurring. If an empty languages.csv didn’t cause problems downstream, make would successfully complete, possibly without the developer realizing the build targets are invalid. ![]() It’s easy to imagine a developer-especially one not familiar with the project-rerunning make without fixing the error. However, imagine this rule is part of a complex makefile which was run in parallel. Thus languages.csv will be empty, although make considers it up to date.įixing the syntax error in projects.json increments its last modified time and informs make that it needs to rebuild languages.csv. You run our example makefile and extract_languages.py has a non-zero exit status-but not before the shell’s output redirection truncates language.csv and updates its last modified time. Imagine that you introduce a syntax error while updating projects.json. Problem 1: rerunning Make with invalid targets □ DELETE_ON_ERROR special target, then make deletes the target file if a recipe has an error. This behavior is often confusing and may lead to malformed build artifacts. Thus, next time make runs it won’t update the target file. If the target file was altered prior to exiting, then its last modified time will indicate that it’s up to date-even though it’s likely corrupt or incomplete. Make executes each recipe line in a new shell, one by one, and quits if an invocation exits with a non-zero status. ![]() If a prerequisite is newer than the target (or doesn’t exist), then make runs the recipe. Make processes a rule when it compares the last modification time of the target to that of its prerequisites. DELETE_ON_ERROR is the target of a rule, even though it has no prerequisites and no recipe. Python extract_languages.py projects.json > languages.csvĪ trailing colon signals that. DELETE_ON_ERROR : languages.csv : projects.json
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |