diff options
author | Remko Tronçon <git@el-tramo.be> | 2012-07-15 08:56:48 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2012-07-15 09:38:40 (GMT) |
commit | 8853ae3063bc9d3fb5b023352dd0fb4fb6cc277b (patch) | |
tree | 86261f1621615c340791839a434ae6162ee9baaa /BuildTools | |
parent | b3f5d140e336e042724f2e37796d8ba50570d88c (diff) | |
download | swift-8853ae3063bc9d3fb5b023352dd0fb4fb6cc277b.zip swift-8853ae3063bc9d3fb5b023352dd0fb4fb6cc277b.tar.bz2 |
Provide replace_pragma_once flag.
Diffstat (limited to 'BuildTools')
-rw-r--r-- | BuildTools/SCons/SConscript.boot | 2 | ||||
-rw-r--r-- | BuildTools/SCons/SConstruct | 28 | ||||
-rw-r--r-- | BuildTools/SCons/Tools/ReplacePragmaOnce.py | 25 | ||||
-rw-r--r-- | BuildTools/SCons/Tools/WriteVal.py | 5 |
4 files changed, 55 insertions, 5 deletions
diff --git a/BuildTools/SCons/SConscript.boot b/BuildTools/SCons/SConscript.boot index c246bf6..1cfa962 100644 --- a/BuildTools/SCons/SConscript.boot +++ b/BuildTools/SCons/SConscript.boot @@ -62,7 +62,7 @@ vars.Add(BoolVariable("set_iterator_debug_level", "Set _ITERATOR_DEBUG_LEVEL=0", # Set up default build & configure environment ################################################################################ -env = Environment(CPPPATH = ["#"], ENV = { +env = Environment(ENV = { 'PATH' : os.environ['PATH'], 'LD_LIBRARY_PATH' : os.environ.get("LD_LIBRARY_PATH", ""), }, variables = vars) diff --git a/BuildTools/SCons/SConstruct b/BuildTools/SCons/SConstruct index 5640877..cd7a25a 100644 --- a/BuildTools/SCons/SConstruct +++ b/BuildTools/SCons/SConstruct @@ -71,8 +71,6 @@ def checkObjCHeader(context, header) : # Platform configuration ################################################################################ -env.Append(CPPPATH = [root]) - if ARGUMENTS.get("force-configure", 0) : SCons.SConf.SetCacheMode("force") @@ -493,6 +491,31 @@ if env.Dir("#/.git").exists() : if not env.GetOption("clean") : env.Install("#/.git/hooks", Glob("#/BuildTools/Git/Hooks/*")) + +################################################################################ +# Replace #pragma once with proper guards on platforms that require it +################################################################################ + +if ARGUMENTS.get("replace_pragma_once", False) : + env.Tool("ReplacePragmaOnce", toolpath = ["#/BuildTools/SCons/Tools"]) + + def relpath(path, start) : + i = len(os.path.commonprefix([path, start])) + return path[i+1:] + + for actual_root, dirs, files in os.walk(root) : + if "3rdParty" in actual_root : + continue + for file in files : + if not file.endswith(".h") : + continue + include = relpath(os.path.join(actual_root, file), root) + env.ReplacePragmaOnce("#/include/" + include, "#/" + include) + env.Append(CPPPATH = ["#/include"]) +else : + env.Append(CPPPATH = [root]) + + ################################################################################ # Project files ################################################################################ @@ -528,6 +551,7 @@ if ARGUMENTS.get("sloccount", False) : for project in env["PROJECTS"] : env.SLOCCount("#/" + project) + ################################################################################ # Print summary ################################################################################ diff --git a/BuildTools/SCons/Tools/ReplacePragmaOnce.py b/BuildTools/SCons/Tools/ReplacePragmaOnce.py new file mode 100644 index 0000000..466c31e --- /dev/null +++ b/BuildTools/SCons/Tools/ReplacePragmaOnce.py @@ -0,0 +1,25 @@ +import SCons.Util, os.path + +def generate(env) : + root = env.Dir("#").abspath + def relpath(path, start) : + i = len(os.path.commonprefix([path, start])) + return path[i+1:] + + def replacePragmaOnce(env, target, source) : + guard = relpath(source[0].abspath, root).replace("/", "_").replace(".", "_").upper() + data = source[0].get_contents() + f = open(str(target[0]), 'wb') + if "#pragma once" in data : + f.write(data.replace("#pragma once", "#ifndef %(guard)s\n#define %(guard)s" % {"guard": guard})) + f.write("\n#endif\n") + else : + f.write(data) + f.close() + + env["BUILDERS"]["ReplacePragmaOnce"] = SCons.Builder.Builder( + action = SCons.Action.Action(replacePragmaOnce, cmdstr = "$GENCOMSTR"), + single_source = True) + +def exists(env) : + return True diff --git a/BuildTools/SCons/Tools/WriteVal.py b/BuildTools/SCons/Tools/WriteVal.py index e39ad82..0a1e1ad 100644 --- a/BuildTools/SCons/Tools/WriteVal.py +++ b/BuildTools/SCons/Tools/WriteVal.py @@ -1,14 +1,15 @@ import SCons.Util def generate(env) : - def writeVal(env, target, source) : + def replacePragmaOnce(env, target, source) : f = open(str(target[0]), 'wb') f.write(source[0].get_contents()) f.close() env["BUILDERS"]["WriteVal"] = SCons.Builder.Builder( - action = SCons.Action.Action(writeVal, cmdstr = "$GENCOMSTR"), + action = SCons.Action.Action(replacePragmaOnce, cmdstr = "$GENCOMSTR"), single_source = True) def exists(env) : return True + |