Created
March 7, 2011 04:35
-
-
Save mmoss/858080 to your computer and use it in GitHub Desktop.
SCons darwin build helpers based on scripts found here: https://github.com/hortont424/particles
This file contains 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
import ExtGlob | |
import AppBundle | |
import CompileXIB | |
import UnitTest | |
from SCons.Environment import * | |
def initTools(env): | |
ExtGlob.TOOL_EXT_GLOB(env) | |
UnitTest.TOOL_UNIT_TEST(env) | |
CompileXIB.TOOL_COMPILE_XIB(env) | |
AppBundle.TOOL_APP_BUNDLE(env) | |
return env |
This file contains 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
#!/usr/bin/env python | |
from os.path import * | |
from SCons.Builder import * | |
from SCons.Script.SConscript import SConsEnvironment | |
def TOOL_APP_BUNDLE(env): | |
if env['PLATFORM'] != 'darwin': | |
return | |
if 'APP_BUNDLE' in env['TOOLS']: | |
return | |
env.Append(TOOLS = 'APP_BUNDLE') | |
env['APPDIRSUFFIX'] = '.app' | |
def AppBundle(env, app, info_plist="Info.plist", creator='APPL', | |
resources=[], frameworks=[]): | |
if SCons.Util.is_List(app): | |
app = app[0] | |
if SCons.Util.is_String(app): | |
app = env.subst(app) | |
appbase = basename(app) | |
else: | |
appbase = basename(str(app)) | |
bundledir = env.subst(appbase + '$APPDIRSUFFIX') | |
contentsdir = join(bundledir, "Contents") | |
resourcesdir = join(contentsdir, "Resources") | |
frameworksdir = join(contentsdir, "Frameworks") | |
env.SideEffect(bundledir, app) | |
# Install various required files to the .app/Contents | |
inst = env.Install(join(contentsdir, "MacOS"), app) | |
inf = env.InstallAs(join(contentsdir, "Info.plist"), info_plist) | |
# env.WriteVal(target=join(contentsdir, "PkgInfo"), | |
# source=SCons.Node.Python.Value("APPL" + creator)) | |
# Install all resources to .app/Contents/Resources | |
for r in resources: | |
# Compile XIBs, copy the resultant NIB instead | |
if r.endswith(".xib"): | |
r = env.NIB(r)[0] | |
env.Install(resourcesdir, r) | |
# Install included frameworks to .app/Contents/Frameworks | |
for r in frameworks: | |
env.Install(frameworksdir, r) | |
return [SCons.Node.FS.default_fs.Dir(bundledir)] | |
SConsEnvironment.AppBundle = AppBundle |
This file contains 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
#!/usr/bin/env python | |
import os | |
from SCons.Action import * | |
from SCons.Builder import * | |
def TOOL_COMPILE_XIB(env): | |
if 'COMPILE_XIB' in env['TOOLS']: | |
return | |
else: | |
env.Append(TOOLS = 'COMPILE_XIB') | |
def compile_xib(target, source, env): | |
args = "--errors --output-format human-readable-text" | |
for plugin in env["IBPLUGINSPATH"]: | |
args += " --plugin-dir %s" % plugin | |
os.system("ibtool %s --compile %s %s" % (args, target[0], source[0])) | |
env['BUILDERS']['CompileXIB'] = Builder( | |
action = Action(compile_xib, "$IBTOOLCOMSTR"), | |
suffix = ".nib", | |
src_suffix = ".xib") |
This file contains 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
#!/usr/bin/env python | |
import os, os.path, sys, fnmatch, shutil, SCons.Script | |
from SCons.Script import Dir, File, Split, Glob | |
from SCons.Script.SConscript import SConsEnvironment | |
def TOOL_EXT_GLOB(env): | |
if 'TOOL_EXT_GLOB' in env['TOOLS']: | |
return | |
env.Append(TOOLS = 'TOOL_EXT_GLOB') | |
def ExtGlob(env, dir, patterns): | |
found = [] | |
for pattern in Split(patterns): | |
found = Glob(os.path.join(dir, pattern)) + found | |
for i in range(5): | |
pattern = os.path.join('*', pattern) | |
found = Glob(os.path.join(dir, pattern)) + found | |
return found | |
SConsEnvironment.ExtGlob = ExtGlob | |
This file contains 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
#!/usr/bin/env python | |
from os.path import * | |
from SCons.Action import * | |
from SCons.Script.SConscript import SConsEnvironment | |
def TOOL_UNIT_TEST(env): | |
env.Append(TOOLS = 'UNIT_TEST') | |
def UnitTest(env, target, source=[], resources=[], **kwargs): | |
test = env.Program(target, source = source, **kwargs) | |
run_tests = env.Alias('run_tests', test, test[0].abspath) | |
env.Depends(run_tests, env.Install(env.File(target[0]).dir, resources)) | |
env.AlwaysBuild(run_tests) | |
return run_tests | |
SConsEnvironment.UnitTest = UnitTest |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment