Compare commits
7 commits
Author | SHA1 | Date | |
---|---|---|---|
50177d96b8 | |||
146b177ca9 | |||
84b5595490 | |||
2ab67a8138 | |||
517a083694 | |||
fd2e6ae699 | |||
c669ad98f1 |
5 changed files with 53 additions and 49 deletions
|
@ -1,11 +1,12 @@
|
||||||
# SConstruct
|
# SConstruct
|
||||||
# vim: set ft=python:
|
# vim: set ft=python:
|
||||||
#
|
|
||||||
# Toplevel Scons build script. This should be mostly complete and generic enough
|
|
||||||
# for most builds.
|
|
||||||
#
|
|
||||||
# Eryn Wells <eryn@erynwells.me>
|
# Eryn Wells <eryn@erynwells.me>
|
||||||
|
|
||||||
|
'''
|
||||||
|
Toplevel Scons build script. This should be mostly complete and generic enough
|
||||||
|
for most builds.
|
||||||
|
'''
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
setup_logging()
|
setup_logging()
|
||||||
|
|
|
@ -1,30 +0,0 @@
|
||||||
# paths.py
|
|
||||||
# Eryn Wells <eryn@erynwells.me>
|
|
||||||
|
|
||||||
import os
|
|
||||||
import os.path
|
|
||||||
|
|
||||||
|
|
||||||
def is_executable(path):
|
|
||||||
return os.path.exists(path) and os.access(path, os.X_OK)
|
|
||||||
|
|
||||||
|
|
||||||
def which(program):
|
|
||||||
'''
|
|
||||||
Look for `program` in system path and return the full path to that binary if
|
|
||||||
it is found. Otherwise, return `None`.
|
|
||||||
'''
|
|
||||||
path, name = os.path.split(program)
|
|
||||||
if path:
|
|
||||||
if is_executable(program):
|
|
||||||
return program
|
|
||||||
else:
|
|
||||||
pathext = [''] + os.environ.get('PATHEXT', '').split(os.pathsep)
|
|
||||||
for path in os.environ.get('PATH', '').split(os.pathsep):
|
|
||||||
exe = os.path.join(path, program)
|
|
||||||
for ext in pathext:
|
|
||||||
candidate = exe + ext
|
|
||||||
if is_executable(candidate):
|
|
||||||
return candidate
|
|
||||||
return None
|
|
||||||
|
|
|
@ -3,12 +3,9 @@
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import SCons.Environment
|
import SCons.Environment
|
||||||
import SCons.Errors
|
import SCons.Errors
|
||||||
|
|
||||||
import paths
|
|
||||||
|
|
||||||
|
|
||||||
def setup_logging(level=logging.DEBUG):
|
def setup_logging(level=logging.DEBUG):
|
||||||
'''Configure global logging for the SCons system.'''
|
'''Configure global logging for the SCons system.'''
|
||||||
|
@ -105,6 +102,9 @@ class Environment(SCons.Environment.Environment):
|
||||||
if colorful and sys.stdout.isatty():
|
if colorful and sys.stdout.isatty():
|
||||||
if 'clang' in self['CC'] or 'clang' in self['CXX']:
|
if 'clang' in self['CC'] or 'clang' in self['CXX']:
|
||||||
self.AppendUnique(CCFLAGS=['-fcolor-diagnostics'])
|
self.AppendUnique(CCFLAGS=['-fcolor-diagnostics'])
|
||||||
|
elif 'gcc' in self['CC'] or 'g++' in self['CXX']:
|
||||||
|
# TODO: Also set a GCC_COLORS variable in the system environment?
|
||||||
|
self.AppendUnique(CCFLAGS=['-fdiagnostics-color=always'])
|
||||||
|
|
||||||
# Pretty printing
|
# Pretty printing
|
||||||
self.SetDefault(ARCOMSTR=Environment._comstr('Archiving', succinct))
|
self.SetDefault(ARCOMSTR=Environment._comstr('Archiving', succinct))
|
||||||
|
@ -135,8 +135,6 @@ class Environment(SCons.Environment.Environment):
|
||||||
|
|
||||||
def process_src(self):
|
def process_src(self):
|
||||||
out_dir = self.build_root.Dir('src')
|
out_dir = self.build_root.Dir('src')
|
||||||
# TODO: Do the thing.
|
|
||||||
# do_sconscript(env, env.source_root, src_out_dir)
|
|
||||||
self.SConscript(self.src_root.File('SConscript'),
|
self.SConscript(self.src_root.File('SConscript'),
|
||||||
variant_dir=out_dir)
|
variant_dir=out_dir)
|
||||||
self.Append(CPPPATH=[self.src_root])
|
self.Append(CPPPATH=[self.src_root])
|
||||||
|
@ -184,7 +182,7 @@ class Environment(SCons.Environment.Environment):
|
||||||
def _append_custom_tools(self, kwargs):
|
def _append_custom_tools(self, kwargs):
|
||||||
'''Add custom tools to the `kwargs`.'''
|
'''Add custom tools to the `kwargs`.'''
|
||||||
tools = kwargs.setdefault('tools', ['default'])
|
tools = kwargs.setdefault('tools', ['default'])
|
||||||
for tool in ['lib', 'test', 'program', 'sconscript']:
|
for tool in ['lib', 'test', 'program', 'sconscript', 'swiftc']:
|
||||||
if tool in tools:
|
if tool in tools:
|
||||||
continue
|
continue
|
||||||
tools.append(tool)
|
tools.append(tool)
|
||||||
|
|
|
@ -9,18 +9,20 @@ import SCons.Script
|
||||||
|
|
||||||
def _do_sconscript(env):
|
def _do_sconscript(env):
|
||||||
original_sconscript = env.SConscript
|
original_sconscript = env.SConscript
|
||||||
|
|
||||||
def sconscript(env, sconscript, clone=False, *args, **kwargs):
|
def sconscript(env, sconscript, clone=False, *args, **kwargs):
|
||||||
exports = {'Library': env.Library,
|
exports = {
|
||||||
'StaticLibrary': env.StaticLibrary,
|
'Library': env.Library,
|
||||||
'SharedLibrary': env.SharedLibrary,
|
'Object': env.Object,
|
||||||
'Program': env.Program}
|
'SharedObject': env.SharedObject,
|
||||||
|
'StaticLibrary': env.StaticLibrary,
|
||||||
|
'SharedLibrary': env.SharedLibrary,
|
||||||
|
'Program': env.Program,
|
||||||
|
'env': env.Clone() if clone else env,
|
||||||
|
}
|
||||||
SCons.Script._SConscript.GlobalDict.update(exports)
|
SCons.Script._SConscript.GlobalDict.update(exports)
|
||||||
env.log('Reading {}'.format(sconscript))
|
env.log('Reading {}'.format(sconscript))
|
||||||
return original_sconscript(sconscript,
|
return original_sconscript(sconscript, {}, *args, **kwargs)
|
||||||
{'env': env.Clone() if clone else env},
|
|
||||||
*args,
|
|
||||||
**kwargs)
|
|
||||||
|
|
||||||
return sconscript
|
return sconscript
|
||||||
|
|
||||||
|
|
33
site_scons/site_tools/swiftc.py
Normal file
33
site_scons/site_tools/swiftc.py
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
# swiftc.py
|
||||||
|
# vim: set ft=python:
|
||||||
|
# Eryn Wells <eryn@erynwells.me>
|
||||||
|
|
||||||
|
'''
|
||||||
|
SCons plugin for building Swift files with swiftc.
|
||||||
|
'''
|
||||||
|
|
||||||
|
import SCons.Action
|
||||||
|
import SCons.Tool
|
||||||
|
import SCons.Util
|
||||||
|
|
||||||
|
SwiftSuffix = '.swift'
|
||||||
|
SwiftAction = SCons.Action.Action("$SWIFTCCOM", "$SWIFTCCOMSTR")
|
||||||
|
|
||||||
|
compilers = ['swiftc']
|
||||||
|
|
||||||
|
def generate(env):
|
||||||
|
static_obj, shared_obj = SCons.Tool.createObjBuilders(env)
|
||||||
|
static_obj.add_action(SwiftSuffix, SwiftAction)
|
||||||
|
static_obj.add_emitter(SwiftSuffix, SCons.Defaults.SharedObjectEmitter)
|
||||||
|
shared_obj.add_action(SwiftSuffix, SwiftAction)
|
||||||
|
shared_obj.add_emitter(SwiftSuffix, SCons.Defaults.SharedObjectEmitter)
|
||||||
|
|
||||||
|
if 'SWIFTC' not in env:
|
||||||
|
compiler = env.Detect(compilers)
|
||||||
|
env['SWIFTC'] = compiler if compiler else compilers[0]
|
||||||
|
env['SWIFTFLAGS'] = SCons.Util.CLVar('')
|
||||||
|
env['SWIFTCCOM'] = '$SWIFTC -o $TARGET -c $SWIFTFLAGS $SOURCES'
|
||||||
|
env['SWIFTFILESUFFIX'] = SwiftSuffix
|
||||||
|
|
||||||
|
def exists(env):
|
||||||
|
return env.Detect(compilers)
|
Loading…
Add table
Add a link
Reference in a new issue