Reputation: 3495
When I rebuild my app the executable built previously is not removed, and in case on compilation error my script continues execution and executes the executable file, which in fact was not updated. How can I i.e. remove the executable before the build process takes place? I want to do this in compilation action:
exe myapp :
#here I want to remove the executable file
sources
libraries
;
Upvotes: 1
Views: 596
Reputation: 6869
Not sure if there is an easier way, but this will work:
# cleanexe.jam
import project ;
import targets ;
import generators ;
import type ;
type.register CLEAN_EXE : clean-exe ;
rule clean-exe ( source : requirements * : target-name ? )
{
target-name ?= $(source:D=:S=).cleanexe ;
return [ targets.create-typed-target CLEAN_EXE : [ project.current ] : $(target-name) : $(source) : $(requirements) ] ;
}
generators.register-standard cleanexe.clean-on-failure : EXE : CLEAN_EXE ;
rule clean-on-failure ( target : source : requirements * )
{
RMOLD $(source) ;
}
And then in your jamfile you can do:
# jamfile
exe myapp :
sources
libraries
;
import cleanexe : clean-exe ;
clean-exe myapp ;
Alternatively you might consider checking b2's (bjam's) exit code and if failed skip the rest of the script as appropriate.
Upvotes: 1