diff options
author | Tobias Markmann <tm@ayena.de> | 2015-05-19 08:47:04 (GMT) |
---|---|---|
committer | Kevin Smith <kevin.smith@isode.com> | 2015-05-19 10:33:54 (GMT) |
commit | ed23f4578d6a5776b77e743ad54802d55f54f7e1 (patch) | |
tree | 36bd0737bf6a9890577baa796858d1ce75b62537 /BuildTools/SCons/Tools | |
parent | e86a46545e23ad824d7013c3c57bd83a52ade9af (diff) | |
download | swift-ed23f4578d6a5776b77e743ad54802d55f54f7e1.zip swift-ed23f4578d6a5776b77e743ad54802d55f54f7e1.tar.bz2 |
Consolidate Python and SCons files to tab based indentation
Test-Information:
Verified that SCons still runs on OS X.
Change-Id: I7e9b97f90ee5581a691a959b6f2c999d93e0be53
Diffstat (limited to 'BuildTools/SCons/Tools')
-rw-r--r-- | BuildTools/SCons/Tools/AppBundle.py | 102 | ||||
-rw-r--r-- | BuildTools/SCons/Tools/BuildVersion.py | 10 | ||||
-rw-r--r-- | BuildTools/SCons/Tools/DoxyGen.py | 38 | ||||
-rw-r--r-- | BuildTools/SCons/Tools/Flags.py | 16 | ||||
-rw-r--r-- | BuildTools/SCons/Tools/Nib.py | 14 | ||||
-rw-r--r-- | BuildTools/SCons/Tools/ReplacePragmaOnce.py | 36 | ||||
-rw-r--r-- | BuildTools/SCons/Tools/SLOCCount.py | 22 | ||||
-rw-r--r-- | BuildTools/SCons/Tools/WindowsBundle.py | 222 | ||||
-rw-r--r-- | BuildTools/SCons/Tools/WriteVal.py | 16 | ||||
-rw-r--r-- | BuildTools/SCons/Tools/textfile.py | 218 |
10 files changed, 347 insertions, 347 deletions
diff --git a/BuildTools/SCons/Tools/AppBundle.py b/BuildTools/SCons/Tools/AppBundle.py index 6a343f6..f1072f5 100644 --- a/BuildTools/SCons/Tools/AppBundle.py +++ b/BuildTools/SCons/Tools/AppBundle.py @@ -1,64 +1,64 @@ import SCons.Util, os.path def generate(env) : - def createAppBundle(env, bundle, version = "1.0", resources = [], frameworks = [], info = {}, handlesXMPPURIs = False) : - bundleDir = bundle + ".app" - bundleContentsDir = bundleDir + "/Contents" - resourcesDir = bundleContentsDir + "/Resources" - frameworksDir = bundleContentsDir + "/Frameworks" - env.Install(bundleContentsDir + "/MacOS", bundle) - env.WriteVal(bundleContentsDir + "/PkgInfo", env.Value("APPL\77\77\77\77")) + def createAppBundle(env, bundle, version = "1.0", resources = [], frameworks = [], info = {}, handlesXMPPURIs = False) : + bundleDir = bundle + ".app" + bundleContentsDir = bundleDir + "/Contents" + resourcesDir = bundleContentsDir + "/Resources" + frameworksDir = bundleContentsDir + "/Frameworks" + env.Install(bundleContentsDir + "/MacOS", bundle) + env.WriteVal(bundleContentsDir + "/PkgInfo", env.Value("APPL\77\77\77\77")) - infoDict = { - "CFBundleDevelopmentRegion" : "English", - "CFBundleExecutable" : bundle, - "CFBundleIdentifier" : "im.swift." + bundle, - "CFBundleInfoDictionaryVersion" : "6.0", - "CFBundleName" : bundle, - "CFBundlePackageType" : "APPL", - "CFBundleSignature": "\77\77\77\77", - "CFBundleVersion" : version, - "CFBundleIconFile" : bundle, - "NSPrincipalClass" : "NSApplication", - "NSHumanReadableCopyright" : unichr(0xA9) + " 2010 Swift Development Team.\nAll Rights Reserved." - } - infoDict.update(info) - - plist = """<?xml version="1.0" encoding="UTF-8"?> - <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> - <plist version="1.0"> - <dict> - """ - for key, value in infoDict.items() : - plist += "<key>" + key + "</key>\n" - plist += "<string>" + value.encode("utf-8") + "</string>\n" - if handlesXMPPURIs : - plist += """<key>CFBundleURLTypes</key> + infoDict = { + "CFBundleDevelopmentRegion" : "English", + "CFBundleExecutable" : bundle, + "CFBundleIdentifier" : "im.swift." + bundle, + "CFBundleInfoDictionaryVersion" : "6.0", + "CFBundleName" : bundle, + "CFBundlePackageType" : "APPL", + "CFBundleSignature": "\77\77\77\77", + "CFBundleVersion" : version, + "CFBundleIconFile" : bundle, + "NSPrincipalClass" : "NSApplication", + "NSHumanReadableCopyright" : unichr(0xA9) + " 2010 Swift Development Team.\nAll Rights Reserved." + } + infoDict.update(info) + + plist = """<?xml version="1.0" encoding="UTF-8"?> + <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> + <plist version="1.0"> + <dict> + """ + for key, value in infoDict.items() : + plist += "<key>" + key + "</key>\n" + plist += "<string>" + value.encode("utf-8") + "</string>\n" + if handlesXMPPURIs : + plist += """<key>CFBundleURLTypes</key> <array> - <dict> - <key>CFBundleURLName</key> - <string>XMPP URL</string> - <key>CFBundleURLSchemes</key> - <array> - <string>xmpp</string> - </array> - </dict> + <dict> + <key>CFBundleURLName</key> + <string>XMPP URL</string> + <key>CFBundleURLSchemes</key> + <array> + <string>xmpp</string> + </array> + </dict> </array>\n""" - plist += """</dict> - </plist> - """ - env.WriteVal(bundleContentsDir + "/Info.plist", env.Value(plist)) + plist += """</dict> + </plist> + """ + env.WriteVal(bundleContentsDir + "/Info.plist", env.Value(plist)) - for (target, resource) in resources.items() : - env.Install(os.path.join(resourcesDir, target), resource) + for (target, resource) in resources.items() : + env.Install(os.path.join(resourcesDir, target), resource) - for framework in frameworks : - env.Install(frameworksDir, framework) + for framework in frameworks : + env.Install(frameworksDir, framework) - return env.Dir(bundleDir) + return env.Dir(bundleDir) - env.AddMethod(createAppBundle, "AppBundle") + env.AddMethod(createAppBundle, "AppBundle") def exists(env) : - return env["PLATFORM"] == "darwin" + return env["PLATFORM"] == "darwin" diff --git a/BuildTools/SCons/Tools/BuildVersion.py b/BuildTools/SCons/Tools/BuildVersion.py index 41e6d8d..b15448a 100644 --- a/BuildTools/SCons/Tools/BuildVersion.py +++ b/BuildTools/SCons/Tools/BuildVersion.py @@ -3,16 +3,16 @@ import SCons.Util import Version def generate(env) : - def createBuildVersion(env, target, project) : - buildVersion = """#pragma once + def createBuildVersion(env, target, project) : + buildVersion = """#pragma once static const char* buildVersion = \"%(buildVersion)s\";\n #define SWIFT_VERSION_STRING \"%(buildVersion)s\";\n """ % { "buildVersion" : Version.getBuildVersion(env.Dir("#").abspath, project) } - env.WriteVal(target, env.Value(buildVersion)) + env.WriteVal(target, env.Value(buildVersion)) - env.AddMethod(createBuildVersion, "BuildVersion") + env.AddMethod(createBuildVersion, "BuildVersion") def exists(env) : - return true + return true diff --git a/BuildTools/SCons/Tools/DoxyGen.py b/BuildTools/SCons/Tools/DoxyGen.py index 3fc53c4..79af1c9 100644 --- a/BuildTools/SCons/Tools/DoxyGen.py +++ b/BuildTools/SCons/Tools/DoxyGen.py @@ -1,26 +1,26 @@ import SCons.Util, os def generate(env) : - def modify_targets(target, source, env) : - target = [env.File("html/index.html")] - return target, source + def modify_targets(target, source, env) : + target = [env.File("html/index.html")] + return target, source - def generate_actions(source, target, env, for_signature) : - if env.WhereIs("$DOXYGEN") and env.WhereIs("$DOT") : - return [SCons.Action.Action("$DOXYGEN $SOURCE", cmdstr = "$DOXYCOMSTR")] - else : - return [] + def generate_actions(source, target, env, for_signature) : + if env.WhereIs("$DOXYGEN") and env.WhereIs("$DOT") : + return [SCons.Action.Action("$DOXYGEN $SOURCE", cmdstr = "$DOXYCOMSTR")] + else : + return [] - env["DOXYGEN"] = "doxygen" - # FIXME: For some reason, things go incredibly slow (at least on OS X) - # when not doing this. Some environment flag is having an effect on - # this; find out which - env["ENV"] = os.environ - env["DOT"] = "dot" - env["BUILDERS"]["DoxyGen"] = SCons.Builder.Builder( - emitter = modify_targets, - generator = generate_actions, - single_source = True) + env["DOXYGEN"] = "doxygen" + # FIXME: For some reason, things go incredibly slow (at least on OS X) + # when not doing this. Some environment flag is having an effect on + # this; find out which + env["ENV"] = os.environ + env["DOT"] = "dot" + env["BUILDERS"]["DoxyGen"] = SCons.Builder.Builder( + emitter = modify_targets, + generator = generate_actions, + single_source = True) def exists(env) : - return True + return True diff --git a/BuildTools/SCons/Tools/Flags.py b/BuildTools/SCons/Tools/Flags.py index c130faf..0768181 100644 --- a/BuildTools/SCons/Tools/Flags.py +++ b/BuildTools/SCons/Tools/Flags.py @@ -1,13 +1,13 @@ import SCons.Util def generate(env) : - def useFlags(env, flags) : - for flag in flags : - if flag in env : - env[flag] = env[flag] + flags[flag] - else : - env[flag] = flags[flag] - env.AddMethod(useFlags, "UseFlags") + def useFlags(env, flags) : + for flag in flags : + if flag in env : + env[flag] = env[flag] + flags[flag] + else : + env[flag] = flags[flag] + env.AddMethod(useFlags, "UseFlags") def exists(env) : - return True + return True diff --git a/BuildTools/SCons/Tools/Nib.py b/BuildTools/SCons/Tools/Nib.py index ccfd884..91eb064 100644 --- a/BuildTools/SCons/Tools/Nib.py +++ b/BuildTools/SCons/Tools/Nib.py @@ -1,12 +1,12 @@ import SCons.Util def generate(env) : - env["IBTOOL"] = "ibtool" - env["BUILDERS"]["Nib"] = SCons.Builder.Builder( - action = SCons.Action.Action("$IBTOOL --errors --warnings --notices --output-format human-readable-text --compile $TARGET $SOURCE", cmdstr = "$NIBCOMSTR"), - suffix = ".nib", - src_suffix = ".xib", - single_source = True) + env["IBTOOL"] = "ibtool" + env["BUILDERS"]["Nib"] = SCons.Builder.Builder( + action = SCons.Action.Action("$IBTOOL --errors --warnings --notices --output-format human-readable-text --compile $TARGET $SOURCE", cmdstr = "$NIBCOMSTR"), + suffix = ".nib", + src_suffix = ".xib", + single_source = True) def exists(env) : - return env["PLATFORM"] == "darwin" + return env["PLATFORM"] == "darwin" diff --git a/BuildTools/SCons/Tools/ReplacePragmaOnce.py b/BuildTools/SCons/Tools/ReplacePragmaOnce.py index 466c31e..3df0f41 100644 --- a/BuildTools/SCons/Tools/ReplacePragmaOnce.py +++ b/BuildTools/SCons/Tools/ReplacePragmaOnce.py @@ -1,25 +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:] + 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() + 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) + env["BUILDERS"]["ReplacePragmaOnce"] = SCons.Builder.Builder( + action = SCons.Action.Action(replacePragmaOnce, cmdstr = "$GENCOMSTR"), + single_source = True) def exists(env) : - return True + return True diff --git a/BuildTools/SCons/Tools/SLOCCount.py b/BuildTools/SCons/Tools/SLOCCount.py index abf4a3c..682a797 100644 --- a/BuildTools/SCons/Tools/SLOCCount.py +++ b/BuildTools/SCons/Tools/SLOCCount.py @@ -1,17 +1,17 @@ import SCons.Util, os.path, os def generate(env) : - def createSLOCCount(env, source) : - myenv = env.Clone() - myenv["ENV"]["HOME"] = os.environ["HOME"] - source = myenv.Dir(source) - target = myenv.File("#/" + source.path + ".sloccount") - # FIXME: There's probably a better way to force building the .sc - if os.path.exists(target.abspath) : - os.unlink(target.abspath) - return myenv.Command(target, source, [SCons.Action.Action("sloccount --duplicates --wide --details " + source.path + " | grep -v qrc_ > $TARGET", cmdstr = "$GENCOMSTR")]) + def createSLOCCount(env, source) : + myenv = env.Clone() + myenv["ENV"]["HOME"] = os.environ["HOME"] + source = myenv.Dir(source) + target = myenv.File("#/" + source.path + ".sloccount") + # FIXME: There's probably a better way to force building the .sc + if os.path.exists(target.abspath) : + os.unlink(target.abspath) + return myenv.Command(target, source, [SCons.Action.Action("sloccount --duplicates --wide --details " + source.path + " | grep -v qrc_ > $TARGET", cmdstr = "$GENCOMSTR")]) - env.AddMethod(createSLOCCount, "SLOCCount") + env.AddMethod(createSLOCCount, "SLOCCount") def exists(env) : - return True + return True diff --git a/BuildTools/SCons/Tools/WindowsBundle.py b/BuildTools/SCons/Tools/WindowsBundle.py index 744d5c8..5afb56e 100644 --- a/BuildTools/SCons/Tools/WindowsBundle.py +++ b/BuildTools/SCons/Tools/WindowsBundle.py @@ -4,119 +4,119 @@ import re import shutil def which(program_name): - if hasattr(shutil, "which"): - return shutil.which(program_name) - else: - path = os.getenv('PATH') - for p in path.split(os.path.pathsep): - p = os.path.join(p,program_name) - if os.path.exists(p) and os.access(p,os.X_OK): - return p + if hasattr(shutil, "which"): + return shutil.which(program_name) + else: + path = os.getenv('PATH') + for p in path.split(os.path.pathsep): + p = os.path.join(p,program_name) + if os.path.exists(p) and os.access(p,os.X_OK): + return p def generate(env) : - def captureWinDeployQtMapping(release = True): - p = False - - qt_bin_folder = "" - if "QTDIR" in env: - qt_bin_folder = env["QTDIR"] + "\\bin;" - - environ = {"PATH": qt_bin_folder + os.getenv("PATH"), "TEMP": os.getenv("TEMP"), "TMP": os.getenv("TMP")} - - if release: - p = subprocess.Popen(['windeployqt', '--release', '--dry-run', '--list', 'mapping', 'Swift.exe'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=environ) - else: - p = subprocess.Popen(['windeployqt', '--debug', '--dry-run', '--list', 'mapping', 'Swift.exe'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=environ) - - if p: - stdout, stderr = p.communicate() - - mappings = [] - - p = re.compile(ur'"([^\"]*)" "([^\"]*)"') - - matches = re.findall(p, stdout) - for match in matches: - mappings.append(match) - return mappings - else: - return False - - def createWindowsBundleManual(env, bundle, resources = {}, qtplugins = {}, qtlibs = [], qtversion = '4') : - all_files = [] - all_files += env.Install(bundle, bundle + ".exe") - for lib in qtlibs : - all_files += env.Install(bundle, os.path.join(env["QTDIR"], "bin", lib + ".dll")) - plugins_suffix = '4' - if qtversion == '5' : - plugins_suffix = '' - for plugin_type in qtplugins: - all_files += env.Install(os.path.join(bundle, plugin_type), [os.path.join(env["QTDIR"], "plugins", plugin_type, "q" + plugin + plugins_suffix + ".dll") for plugin in qtplugins[plugin_type]]) - for dir, resourceFiles in resources.items() : - for resource in resourceFiles : - e = env.Entry(resource) - if e.isdir() : - for subresource in env.Glob(str(e) + "/*") : - all_files += env.Install(os.path.join(bundle, dir, e.name), subresource) - else : - all_files += env.Install(os.path.join(bundle, dir), resource) - return all_files - - # This version of uses windeployqt tool - def createWindowsBundleWithWinDeployQt(env, bundle, resources = {}, qtplugins = {}, qtlibs = [], qtversion = '4') : - assert(qtversion == '5') - all_files = [] - - # add swift executable - all_files += env.Install(bundle, bundle + ".exe") - - # adding resources (swift sounds/images/translations) - for dir, resourceFiles in resources.items() : - for resource in resourceFiles : - e = env.Entry(resource) - if e.isdir() : - for subresource in env.Glob(str(e) + "/*") : - all_files += env.Install(os.path.join(bundle, dir, e.name), subresource) - else : - all_files += env.Install(os.path.join(bundle, dir), resource) - - qtmappings = captureWinDeployQtMapping() - assert(qtmappings) - - # handle core DLLs - qt_corelib_regex = re.compile(ur".*bin.*\\(.*)\.dll") - - for qtlib in qtlibs: - if qtlib.startswith("Qt5"): - (src_path, target_path) = next(((src_path, target_path) for (src_path, target_path) in qtmappings if qt_corelib_regex.match(src_path) and qt_corelib_regex.match(src_path).group(1) == qtlib), (None, None)) - if src_path != None: - all_files += env.Install(bundle, src_path) - - # handle core dependencies - for (src_path, target_path) in qtmappings: - if qt_corelib_regex.match(src_path) and not qt_corelib_regex.match(src_path).group(1).startswith("Qt5"): - all_files += env.Install(bundle, src_path) - - # handle plugins - qt_plugin_regex = re.compile(ur".*plugins.*\\(.*)\\(.*)\.dll") - for (src_path, target_path) in qtmappings: - if qt_plugin_regex.match(src_path): - plugin_folder, filename = qt_plugin_regex.match(src_path).groups() - try: - if filename[1:] in qtplugins[plugin_folder]: - all_files += env.Install(os.path.join(bundle, plugin_folder), src_path) - except: - pass - return all_files - - def createWindowsBundle(env, bundle, resources = {}, qtplugins = {}, qtlibs = [], qtversion = '4'): - if which("windeployqt.exe"): - return createWindowsBundleWithWinDeployQt(env, bundle, resources, qtplugins, qtlibs, qtversion) - else: - return createWindowsBundleManual(env, bundle, resources, qtplugins, qtlibs, qtversion) - - env.AddMethod(createWindowsBundle, "WindowsBundle") + def captureWinDeployQtMapping(release = True): + p = False + + qt_bin_folder = "" + if "QTDIR" in env: + qt_bin_folder = env["QTDIR"] + "\\bin;" + + environ = {"PATH": qt_bin_folder + os.getenv("PATH"), "TEMP": os.getenv("TEMP"), "TMP": os.getenv("TMP")} + + if release: + p = subprocess.Popen(['windeployqt', '--release', '--dry-run', '--list', 'mapping', 'Swift.exe'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=environ) + else: + p = subprocess.Popen(['windeployqt', '--debug', '--dry-run', '--list', 'mapping', 'Swift.exe'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=environ) + + if p: + stdout, stderr = p.communicate() + + mappings = [] + + p = re.compile(ur'"([^\"]*)" "([^\"]*)"') + + matches = re.findall(p, stdout) + for match in matches: + mappings.append(match) + return mappings + else: + return False + + def createWindowsBundleManual(env, bundle, resources = {}, qtplugins = {}, qtlibs = [], qtversion = '4') : + all_files = [] + all_files += env.Install(bundle, bundle + ".exe") + for lib in qtlibs : + all_files += env.Install(bundle, os.path.join(env["QTDIR"], "bin", lib + ".dll")) + plugins_suffix = '4' + if qtversion == '5' : + plugins_suffix = '' + for plugin_type in qtplugins: + all_files += env.Install(os.path.join(bundle, plugin_type), [os.path.join(env["QTDIR"], "plugins", plugin_type, "q" + plugin + plugins_suffix + ".dll") for plugin in qtplugins[plugin_type]]) + for dir, resourceFiles in resources.items() : + for resource in resourceFiles : + e = env.Entry(resource) + if e.isdir() : + for subresource in env.Glob(str(e) + "/*") : + all_files += env.Install(os.path.join(bundle, dir, e.name), subresource) + else : + all_files += env.Install(os.path.join(bundle, dir), resource) + return all_files + + # This version of uses windeployqt tool + def createWindowsBundleWithWinDeployQt(env, bundle, resources = {}, qtplugins = {}, qtlibs = [], qtversion = '4') : + assert(qtversion == '5') + all_files = [] + + # add swift executable + all_files += env.Install(bundle, bundle + ".exe") + + # adding resources (swift sounds/images/translations) + for dir, resourceFiles in resources.items() : + for resource in resourceFiles : + e = env.Entry(resource) + if e.isdir() : + for subresource in env.Glob(str(e) + "/*") : + all_files += env.Install(os.path.join(bundle, dir, e.name), subresource) + else : + all_files += env.Install(os.path.join(bundle, dir), resource) + + qtmappings = captureWinDeployQtMapping() + assert(qtmappings) + + # handle core DLLs + qt_corelib_regex = re.compile(ur".*bin.*\\(.*)\.dll") + + for qtlib in qtlibs: + if qtlib.startswith("Qt5"): + (src_path, target_path) = next(((src_path, target_path) for (src_path, target_path) in qtmappings if qt_corelib_regex.match(src_path) and qt_corelib_regex.match(src_path).group(1) == qtlib), (None, None)) + if src_path != None: + all_files += env.Install(bundle, src_path) + + # handle core dependencies + for (src_path, target_path) in qtmappings: + if qt_corelib_regex.match(src_path) and not qt_corelib_regex.match(src_path).group(1).startswith("Qt5"): + all_files += env.Install(bundle, src_path) + + # handle plugins + qt_plugin_regex = re.compile(ur".*plugins.*\\(.*)\\(.*)\.dll") + for (src_path, target_path) in qtmappings: + if qt_plugin_regex.match(src_path): + plugin_folder, filename = qt_plugin_regex.match(src_path).groups() + try: + if filename[1:] in qtplugins[plugin_folder]: + all_files += env.Install(os.path.join(bundle, plugin_folder), src_path) + except: + pass + return all_files + + def createWindowsBundle(env, bundle, resources = {}, qtplugins = {}, qtlibs = [], qtversion = '4'): + if which("windeployqt.exe"): + return createWindowsBundleWithWinDeployQt(env, bundle, resources, qtplugins, qtlibs, qtversion) + else: + return createWindowsBundleManual(env, bundle, resources, qtplugins, qtlibs, qtversion) + + env.AddMethod(createWindowsBundle, "WindowsBundle") def exists(env) : - return env["PLATFORM"] == "win32" + return env["PLATFORM"] == "win32" diff --git a/BuildTools/SCons/Tools/WriteVal.py b/BuildTools/SCons/Tools/WriteVal.py index 0a1e1ad..4e8d3bb 100644 --- a/BuildTools/SCons/Tools/WriteVal.py +++ b/BuildTools/SCons/Tools/WriteVal.py @@ -1,15 +1,15 @@ import SCons.Util def generate(env) : - def replacePragmaOnce(env, target, source) : - f = open(str(target[0]), 'wb') - f.write(source[0].get_contents()) - f.close() + 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(replacePragmaOnce, cmdstr = "$GENCOMSTR"), - single_source = True) + env["BUILDERS"]["WriteVal"] = SCons.Builder.Builder( + action = SCons.Action.Action(replacePragmaOnce, cmdstr = "$GENCOMSTR"), + single_source = True) def exists(env) : - return True + return True diff --git a/BuildTools/SCons/Tools/textfile.py b/BuildTools/SCons/Tools/textfile.py index 89f8963..b290125 100644 --- a/BuildTools/SCons/Tools/textfile.py +++ b/BuildTools/SCons/Tools/textfile.py @@ -25,23 +25,23 @@ __doc__ = """ Textfile/Substfile builder for SCons. - Create file 'target' which typically is a textfile. The 'source' - may be any combination of strings, Nodes, or lists of same. A - 'linesep' will be put between any part written and defaults to - os.linesep. - - The only difference between the Textfile builder and the Substfile - builder is that strings are converted to Value() nodes for the - former and File() nodes for the latter. To insert files in the - former or strings in the latter, wrap them in a File() or Value(), - respectively. - - The values of SUBST_DICT first have any construction variables - expanded (its keys are not expanded). If a value of SUBST_DICT is - a python callable function, it is called and the result is expanded - as the value. Values are substituted in a "random" order; if any - substitution could be further expanded by another subsitition, it - is unpredictible whether the expansion will occur. + Create file 'target' which typically is a textfile. The 'source' + may be any combination of strings, Nodes, or lists of same. A + 'linesep' will be put between any part written and defaults to + os.linesep. + + The only difference between the Textfile builder and the Substfile + builder is that strings are converted to Value() nodes for the + former and File() nodes for the latter. To insert files in the + former or strings in the latter, wrap them in a File() or Value(), + respectively. + + The values of SUBST_DICT first have any construction variables + expanded (its keys are not expanded). If a value of SUBST_DICT is + a python callable function, it is called and the result is expanded + as the value. Values are substituted in a "random" order; if any + substitution could be further expanded by another subsitition, it + is unpredictible whether the expansion will occur. """ __revision__ = "src/engine/SCons/Tool/textfile.py 5357 2011/09/09 21:31:03 bdeegan" @@ -56,117 +56,117 @@ from SCons.Node.Python import Value from SCons.Util import is_String, is_Sequence, is_Dict def _do_subst(node, subs): - """ - Fetch the node contents and replace all instances of the keys with - their values. For example, if subs is - {'%VERSION%': '1.2345', '%BASE%': 'MyProg', '%prefix%': '/bin'}, - then all instances of %VERSION% in the file will be replaced with - 1.2345 and so forth. - """ - contents = node.get_text_contents() - if not subs: return contents - for (k,v) in subs: - contents = re.sub(k, v, contents) - return contents + """ + Fetch the node contents and replace all instances of the keys with + their values. For example, if subs is + {'%VERSION%': '1.2345', '%BASE%': 'MyProg', '%prefix%': '/bin'}, + then all instances of %VERSION% in the file will be replaced with + 1.2345 and so forth. + """ + contents = node.get_text_contents() + if not subs: return contents + for (k,v) in subs: + contents = re.sub(k, v, contents) + return contents def _action(target, source, env): - # prepare the line separator - linesep = env['LINESEPARATOR'] - if linesep is None: - linesep = os.linesep - elif is_String(linesep): - pass - elif isinstance(linesep, Value): - linesep = linesep.get_text_contents() - else: - raise SCons.Errors.UserError( - 'unexpected type/class for LINESEPARATOR: %s' - % repr(linesep), None) - - # create a dictionary to use for the substitutions - if 'SUBST_DICT' not in env: - subs = None # no substitutions - else: - d = env['SUBST_DICT'] - if is_Dict(d): - d = list(d.items()) - elif is_Sequence(d): - pass - else: - raise SCons.Errors.UserError('SUBST_DICT must be dict or sequence') - subs = [] - for (k,v) in d: - if callable(v): - v = v() - if is_String(v): - v = env.subst(v) - else: - v = str(v) - subs.append((k,v)) - - # write the file - try: - fd = open(target[0].get_path(), "wb") - except (OSError,IOError), e: - raise SCons.Errors.UserError("Can't write target file %s" % target[0]) - # separate lines by 'linesep' only if linesep is not empty - lsep = None - for s in source: - if lsep: fd.write(lsep) - fd.write(_do_subst(s, subs)) - lsep = linesep - fd.close() + # prepare the line separator + linesep = env['LINESEPARATOR'] + if linesep is None: + linesep = os.linesep + elif is_String(linesep): + pass + elif isinstance(linesep, Value): + linesep = linesep.get_text_contents() + else: + raise SCons.Errors.UserError( + 'unexpected type/class for LINESEPARATOR: %s' + % repr(linesep), None) + + # create a dictionary to use for the substitutions + if 'SUBST_DICT' not in env: + subs = None # no substitutions + else: + d = env['SUBST_DICT'] + if is_Dict(d): + d = list(d.items()) + elif is_Sequence(d): + pass + else: + raise SCons.Errors.UserError('SUBST_DICT must be dict or sequence') + subs = [] + for (k,v) in d: + if callable(v): + v = v() + if is_String(v): + v = env.subst(v) + else: + v = str(v) + subs.append((k,v)) + + # write the file + try: + fd = open(target[0].get_path(), "wb") + except (OSError,IOError), e: + raise SCons.Errors.UserError("Can't write target file %s" % target[0]) + # separate lines by 'linesep' only if linesep is not empty + lsep = None + for s in source: + if lsep: fd.write(lsep) + fd.write(_do_subst(s, subs)) + lsep = linesep + fd.close() def _strfunc(target, source, env): - return "Creating '%s'" % target[0] + return "Creating '%s'" % target[0] def _convert_list_R(newlist, sources): - for elem in sources: - if is_Sequence(elem): - _convert_list_R(newlist, elem) - elif isinstance(elem, Node): - newlist.append(elem) - else: - newlist.append(Value(elem)) + for elem in sources: + if is_Sequence(elem): + _convert_list_R(newlist, elem) + elif isinstance(elem, Node): + newlist.append(elem) + else: + newlist.append(Value(elem)) def _convert_list(target, source, env): - if len(target) != 1: - raise SCons.Errors.UserError("Only one target file allowed") - newlist = [] - _convert_list_R(newlist, source) - return target, newlist + if len(target) != 1: + raise SCons.Errors.UserError("Only one target file allowed") + newlist = [] + _convert_list_R(newlist, source) + return target, newlist _common_varlist = ['SUBST_DICT', 'LINESEPARATOR'] _text_varlist = _common_varlist + ['TEXTFILEPREFIX', 'TEXTFILESUFFIX'] _text_builder = SCons.Builder.Builder( - action = SCons.Action.Action(_action, _strfunc, varlist = _text_varlist), - source_factory = Value, - emitter = _convert_list, - prefix = '$TEXTFILEPREFIX', - suffix = '$TEXTFILESUFFIX', - ) + action = SCons.Action.Action(_action, _strfunc, varlist = _text_varlist), + source_factory = Value, + emitter = _convert_list, + prefix = '$TEXTFILEPREFIX', + suffix = '$TEXTFILESUFFIX', + ) _subst_varlist = _common_varlist + ['SUBSTFILEPREFIX', 'TEXTFILESUFFIX'] _subst_builder = SCons.Builder.Builder( - action = SCons.Action.Action(_action, _strfunc, varlist = _subst_varlist), - source_factory = SCons.Node.FS.File, - emitter = _convert_list, - prefix = '$SUBSTFILEPREFIX', - suffix = '$SUBSTFILESUFFIX', - src_suffix = ['.in'], - ) + action = SCons.Action.Action(_action, _strfunc, varlist = _subst_varlist), + source_factory = SCons.Node.FS.File, + emitter = _convert_list, + prefix = '$SUBSTFILEPREFIX', + suffix = '$SUBSTFILESUFFIX', + src_suffix = ['.in'], + ) def generate(env): - env['LINESEPARATOR'] = os.linesep - env['BUILDERS']['MyTextfile'] = _text_builder - env['TEXTFILEPREFIX'] = '' - env['TEXTFILESUFFIX'] = '.txt' - env['BUILDERS']['MySubstfile'] = _subst_builder - env['SUBSTFILEPREFIX'] = '' - env['SUBSTFILESUFFIX'] = '' + env['LINESEPARATOR'] = os.linesep + env['BUILDERS']['MyTextfile'] = _text_builder + env['TEXTFILEPREFIX'] = '' + env['TEXTFILESUFFIX'] = '.txt' + env['BUILDERS']['MySubstfile'] = _subst_builder + env['SUBSTFILEPREFIX'] = '' + env['SUBSTFILESUFFIX'] = '' def exists(env): - return 1 + return 1 # Local Variables: # tab-width:4 |