简体   繁体   中英

How to save and return exit code in makefile target

I have a make target that looks something like this:

.PHONY: run-my-test
run-my-test: all
    run_test_suite.sh --all --log-to-file
    post_process_logs.sh

If a test case fails, the exit code of run_test_suite.sh will cause Make to not continue with running post_process_logs.sh . This is a problem, because i want to get the processed logs even for failed tests. How should i update my target to do this?

I've thought of saving the exit code somehow and perhaps exit with it in the end of the target definition. Or do I split the calls up into separate targets?

I can add that I'm pretty much forced to do this from Make because of how our build system works. And I would prefer not having to add more targets as the make files tend to be cluttered with these as it is.

If you want the build to fail after running post_process_logs.sh , put both commands in the same entry.

.PHONY: run-my-test
run-my-test: all
        run_test_suite.sh --all --log-to-file; \
        e=$$?; \
        post_process_logs.sh; \
        exit $$e

The exit status of run_test_suite.sh is saved in the shell variable e , which is used as the argument to exit after post_process_logs.sh to set the exit status of the overall command.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM