summaryrefslogtreecommitdiff
path: root/bootstrap.py
diff options
context:
space:
mode:
authorDirk Baechle <dl9obn@darc.de>2013-05-04 02:26:07 +0200
committerDirk Baechle <dl9obn@darc.de>2013-05-04 02:26:07 +0200
commit8e70741f93305f5b28bd3f77954f615aa0fcf840 (patch)
treeb536cbdd6f472955473f77766d68d31e76b719c0 /bootstrap.py
parent889700ab75d4ead62253dcdd12391662caf8b36b (diff)
downloadscons-8e70741f93305f5b28bd3f77954f615aa0fcf840.tar.gz
- patched setup.py and several MANIFEST files, such that the docbook-xsl
folder and all additional documentation sources get packaged properly - added basic support for wildcards and recursive globbing in MANIFEST files - added missing JPG/SVG files
Diffstat (limited to 'bootstrap.py')
-rwxr-xr-xbootstrap.py262
1 files changed, 158 insertions, 104 deletions
diff --git a/bootstrap.py b/bootstrap.py
index 0d1a3fc5..78a85b5f 100755
--- a/bootstrap.py
+++ b/bootstrap.py
@@ -25,6 +25,7 @@
import os
import os.path
import sys
+import glob
import subprocess
__doc__ = """bootstrap.py
@@ -71,112 +72,165 @@ the following SCons options:
"eaten" by the bootstrap.py script.
"""
-script_dir = os.path.abspath(os.path.dirname(__file__))
-
-bootstrap_dir = os.path.join(script_dir, 'bootstrap')
-
-pass_through_args = []
-update_only = None
-
-requires_an_argument = 'bootstrap.py: %s requires an argument\n'
-
-def must_copy(dst, src):
- if not os.path.exists(dst):
- return 1
- return open(dst, 'rb').read() != open(src, 'rb').read()
-
-search = [script_dir]
-
-# Note: We don't use the getopt module to process the command-line
-# arguments because we'd have to teach it about all of the SCons options.
-
-command_line_args = sys.argv[1:]
-
-while command_line_args:
- arg = command_line_args.pop(0)
-
- if arg == '--bootstrap_dir':
- try:
- bootstrap_dir = command_line_args.pop(0)
- except IndexError:
- sys.stderr.write(requires_an_argument % arg)
- sys.exit(1)
- elif arg[:16] == '--bootstrap_dir=':
- bootstrap_dir = arg[16:]
-
- elif arg == '--bootstrap_force':
- def must_copy(dst, src):
+def parseManifestLines(basedir, lines):
+ """ Scans the single lines of a MANIFEST file,
+ and returns the list of source files.
+ Has basic support for recursive globs '**',
+ filename wildcards of the form '*.xml' and
+ comment lines, starting with a '#'.
+ """
+ sources = []
+ oldwd = os.path.abspath(os.getcwd())
+ basewd = os.path.abspath(basedir)
+ os.chdir(basedir)
+ for l in lines:
+ if l.startswith('#'):
+ # Skip comments
+ continue
+ l = l.rstrip('\n')
+ if l.endswith('**'):
+ # Glob all files recursively
+ globwd, tail = os.path.split(l)
+ if globwd:
+ os.chdir(globwd)
+ for path, dirs, files in os.walk('.'):
+ for f in files:
+ if globwd:
+ fpath = os.path.join(globwd, path, f)
+ else:
+ fpath = os.path.join(path, f)
+ sources.append(os.path.normpath(fpath))
+ if globwd:
+ os.chdir(basewd)
+ elif '*' in l:
+ # Glob file pattern
+ globwd, tail = os.path.split(l)
+ if globwd:
+ os.chdir(globwd)
+ files = glob.glob(tail)
+ for f in files:
+ fpath = os.path.join(globwd, f)
+ sources.append(os.path.normpath(fpath))
+ os.chdir(basewd)
+ else:
+ sources.extend(glob.glob(tail))
+ else:
+ sources.append(l)
+ os.chdir(oldwd)
+
+ return sources
+
+def main():
+ script_dir = os.path.abspath(os.path.dirname(__file__))
+
+ bootstrap_dir = os.path.join(script_dir, 'bootstrap')
+
+ pass_through_args = []
+ update_only = None
+
+ requires_an_argument = 'bootstrap.py: %s requires an argument\n'
+
+ search = [script_dir]
+
+ def find(file, search=search):
+ for dir in search:
+ f = os.path.join(dir, file)
+ if os.path.exists(f):
+ return os.path.normpath(f)
+ sys.stderr.write("could not find `%s' in search path:\n" % file)
+ sys.stderr.write("\t" + "\n\t".join(search) + "\n")
+ sys.exit(2)
+
+ def must_copy(dst, src):
+ if not os.path.exists(dst):
return 1
-
- elif arg == '--bootstrap_src':
- try:
- search.insert(0, command_line_args.pop(0))
- except IndexError:
- sys.stderr.write(requires_an_argument % arg)
- sys.exit(1)
- elif arg[:16] == '--bootstrap_src=':
- search.insert(0, arg[16:])
-
- elif arg == '--bootstrap_update':
- update_only = 1
-
- elif arg in ('-C', '--directory'):
- try:
- dir = command_line_args.pop(0)
- except IndexError:
- sys.stderr.write(requires_an_argument % arg)
- sys.exit(1)
+ return open(dst, 'rb').read() != open(src, 'rb').read()
+
+ # Note: We don't use the getopt module to process the command-line
+ # arguments because we'd have to teach it about all of the SCons options.
+
+ command_line_args = sys.argv[1:]
+
+ while command_line_args:
+ arg = command_line_args.pop(0)
+
+ if arg == '--bootstrap_dir':
+ try:
+ bootstrap_dir = command_line_args.pop(0)
+ except IndexError:
+ sys.stderr.write(requires_an_argument % arg)
+ sys.exit(1)
+ elif arg[:16] == '--bootstrap_dir=':
+ bootstrap_dir = arg[16:]
+
+ elif arg == '--bootstrap_force':
+ def must_copy(dst, src):
+ return 1
+
+ elif arg == '--bootstrap_src':
+ try:
+ search.insert(0, command_line_args.pop(0))
+ except IndexError:
+ sys.stderr.write(requires_an_argument % arg)
+ sys.exit(1)
+ elif arg[:16] == '--bootstrap_src=':
+ search.insert(0, arg[16:])
+
+ elif arg == '--bootstrap_update':
+ update_only = 1
+
+ elif arg in ('-C', '--directory'):
+ try:
+ dir = command_line_args.pop(0)
+ except IndexError:
+ sys.stderr.write(requires_an_argument % arg)
+ sys.exit(1)
+ else:
+ os.chdir(dir)
+ elif arg[:2] == '-C':
+ os.chdir(arg[2:])
+ elif arg[:12] == '--directory=':
+ os.chdir(arg[12:])
+
else:
- os.chdir(dir)
- elif arg[:2] == '-C':
- os.chdir(arg[2:])
- elif arg[:12] == '--directory=':
- os.chdir(arg[12:])
-
- else:
- pass_through_args.append(arg)
-
-def find(file, search=search):
- for dir in search:
- f = os.path.join(dir, file)
- if os.path.exists(f):
- return os.path.normpath(f)
- sys.stderr.write("could not find `%s' in search path:\n" % file)
- sys.stderr.write("\t" + "\n\t".join(search) + "\n")
- sys.exit(2)
-
-scons_py = os.path.join('src', 'script', 'scons.py')
-src_engine = os.path.join('src', 'engine')
-MANIFEST_in = find(os.path.join(src_engine, 'MANIFEST.in'))
-
-files = [ scons_py ] + [os.path.join(src_engine, x[:-1])
- for x in open(MANIFEST_in).readlines()]
-
-for file in files:
- src = find(file)
- dst = os.path.join(bootstrap_dir, file)
- if must_copy(dst, src):
- dir = os.path.split(dst)[0]
- if not os.path.isdir(dir):
- os.makedirs(dir)
- try: os.unlink(dst)
- except: pass
- open(dst, 'wb').write( open(src, 'rb').read() )
-
-if update_only:
- sys.exit(0)
-
-args = [
- sys.executable,
- os.path.join(bootstrap_dir, scons_py)
- ] + pass_through_args
-
-sys.stdout.write(" ".join(args) + '\n')
-sys.stdout.flush()
-
-os.environ['SCONS_LIB_DIR'] = os.path.join(bootstrap_dir, src_engine)
-
-sys.exit(subprocess.Popen(args, env=os.environ).wait())
+ pass_through_args.append(arg)
+
+
+ scons_py = os.path.join('src', 'script', 'scons.py')
+ src_engine = os.path.join('src', 'engine')
+ MANIFEST_in = find(os.path.join(src_engine, 'MANIFEST.in'))
+
+ files = [ scons_py ] + [os.path.join(src_engine, x)
+ for x in parseManifestLines(src_engine, open(MANIFEST_in).readlines())]
+
+ for file in files:
+ src = find(file)
+ dst = os.path.join(bootstrap_dir, file)
+ if must_copy(dst, src):
+ dir = os.path.split(dst)[0]
+ if not os.path.isdir(dir):
+ os.makedirs(dir)
+ try: os.unlink(dst)
+ except: pass
+ open(dst, 'wb').write( open(src, 'rb').read() )
+
+ if update_only:
+ sys.exit(0)
+
+ args = [
+ sys.executable,
+ os.path.join(bootstrap_dir, scons_py)
+ ] + pass_through_args
+
+ sys.stdout.write(" ".join(args) + '\n')
+ sys.stdout.flush()
+
+ os.environ['SCONS_LIB_DIR'] = os.path.join(bootstrap_dir, src_engine)
+
+ sys.exit(subprocess.Popen(args, env=os.environ).wait())
+
+if __name__ == "__main__":
+ main()
# Local Variables:
# tab-width:4