Last active
August 23, 2016 07:08
-
-
Save nrclark/9e6072bdeea1d156d8a9e98f1a6d9e99 to your computer and use it in GitHub Desktop.
Sample SConstruct file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# vi: set ft=python: | |
import os | |
# Run scons three times: | |
# Run 1. Create new 'dummy_file' and 'file.tcl' | |
# Run 2. Build 'file.xpr' | |
# Run 3. Rebuild 'file.tcl' from 'file.xpr' (doesn't trigger currently) | |
generate_new_tcl = Builder(action='echo "dummy file" > $TARGET') | |
ROT13_CMD = "tr '[A-Za-z]' '[N-ZA-Mn-za-m]'" | |
xpr2tcl = Builder(action="cat $SOURCE | %s > $TARGET" % ROT13_CMD) | |
tcl2xpr = Builder(action="cat $SOURCE | %s > $TARGET" % ROT13_CMD) | |
env = Environment() | |
env.Append(BUILDERS={'xpr2tcl': xpr2tcl}) | |
env.Append(BUILDERS={'tcl2xpr': tcl2xpr}) | |
env.Append(BUILDERS={'generate_new_tcl': generate_new_tcl}) | |
dummy_file = env.generate_new_tcl(["dummy_file"], []) | |
Default(dummy_file) | |
def up_to_date(node): | |
""" Returns True if a file node is up-to-date/fresh, and False | |
otherwise. """ | |
# From empirical tests, it appears that node.is_up_to_date() must be | |
# called once before the result can actually be used in further calls. | |
node.is_up_to_date() | |
if node.has_builder() == False: | |
return True | |
elif node.always_build: | |
return False | |
return node.is_up_to_date() | |
if not os.path.isfile("file.tcl") and not os.path.isfile("file.xpr"): | |
# This clause is picked up on a clean run of the script. It creates | |
# sample source files. | |
tcl_file = env.generate_new_tcl(["file.tcl"], []) | |
Default(tcl_file) | |
else: | |
# This clause is picked up on subsequent runs. | |
xpr_file = env.tcl2xpr(["file.xpr"], ["file.tcl", "dummy_file"]) | |
if not up_to_date(xpr_file[0]): | |
Default(xpr_file) | |
else: | |
tcl_file = env.xpr2tcl(["file.tcl"], ["file.xpr"]) | |
Ignore(xpr_file, "file.tcl") | |
Default(tcl_file) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment