Merge pull request #249 from kived/concurrent-build

add concurrent make, xcodebuild, gzip/bzip2
This commit is contained in:
Mathieu Virbel 2017-05-19 13:52:11 +02:00 committed by GitHub
commit 54b9a0dad6
13 changed files with 60 additions and 18 deletions

View file

@ -85,7 +85,7 @@ class FFMpegRecipe(Recipe):
"config.asm") "config.asm")
""" """
shprint(sh.make, "clean", _env=build_env) shprint(sh.make, "clean", _env=build_env)
shprint(sh.make, "-j4", _env=build_env) shprint(sh.make, self.ctx.concurrent_make, _env=build_env)
shprint(sh.make, "install") shprint(sh.make, "install")

View file

@ -28,7 +28,7 @@ class FreetypeRecipe(Recipe):
"--enable-static=yes", "--enable-static=yes",
"--enable-shared=no") "--enable-shared=no")
shprint(sh.make, "clean") shprint(sh.make, "clean")
shprint(sh.make) shprint(sh.make, self.ctx.concurrent_make)
recipe = FreetypeRecipe() recipe = FreetypeRecipe()

View file

@ -34,7 +34,7 @@ class LibffiRecipe(Recipe):
self.set_marker("patched") self.set_marker("patched")
def build_arch(self, arch): def build_arch(self, arch):
shprint(sh.xcodebuild, shprint(sh.xcodebuild, self.ctx.concurrent_xcodebuild,
"ONLY_ACTIVE_ARCH=NO", "ONLY_ACTIVE_ARCH=NO",
"ARCHS={}".format(arch.arch), "ARCHS={}".format(arch.arch),
"-sdk", "macosx", "-sdk", "macosx",

View file

@ -73,7 +73,7 @@ class HostpythonRecipe(Recipe):
"--disable-toolbox-glue", "--disable-toolbox-glue",
"--without-gcc", "--without-gcc",
_env=build_env) _env=build_env)
shprint(sh.make, "-C", self.build_dir, "-j4", "python", "Parser/pgen", shprint(sh.make, "-C", self.build_dir, self.ctx.concurrent_make, "python", "Parser/pgen",
_env=build_env) _env=build_env)
shutil.move("python", "hostpython") shutil.move("python", "hostpython")
shutil.move("Parser/pgen", "Parser/hostpgen") shutil.move("Parser/pgen", "Parser/hostpgen")
@ -88,7 +88,7 @@ class HostpythonRecipe(Recipe):
shprint(sh.ln, "-s", shprint(sh.ln, "-s",
join(build_dir, "hostpython"), join(build_dir, "hostpython"),
join(build_dir, "Python")) join(build_dir, "Python"))
shprint(sh.make, shprint(sh.make, self.ctx.concurrent_make,
"-C", build_dir, "-C", build_dir,
"bininstall", "inclinstall", "bininstall", "inclinstall",
_env=build_env) _env=build_env)

View file

@ -23,7 +23,7 @@ class LibffiRecipe(Recipe):
self.set_marker("patched") self.set_marker("patched")
def build_arch(self, arch): def build_arch(self, arch):
shprint(sh.xcodebuild, shprint(sh.xcodebuild, self.ctx.concurrent_xcodebuild,
"ONLY_ACTIVE_ARCH=NO", "ONLY_ACTIVE_ARCH=NO",
"ARCHS={}".format(arch.arch), "ARCHS={}".format(arch.arch),
"-sdk", arch.sdk, "-sdk", arch.sdk,

View file

@ -29,7 +29,7 @@ class JpegRecipe(Recipe):
"--host={}".format(arch.triple), "--host={}".format(arch.triple),
"--disable-shared") "--disable-shared")
shprint(sh.make, "clean") shprint(sh.make, "clean")
shprint(sh.make) shprint(sh.make, self.ctx.concurrent_make)
recipe = JpegRecipe() recipe = JpegRecipe()

View file

@ -21,6 +21,6 @@ class PngRecipe(Recipe):
"--host={}".format(arch.triple), "--host={}".format(arch.triple),
"--disable-shared") "--disable-shared")
shprint(sh.make, "clean") shprint(sh.make, "clean")
shprint(sh.make, _env=build_env) shprint(sh.make, self.ctx.concurrent_make, _env=build_env)
recipe = PngRecipe() recipe = PngRecipe()

View file

@ -43,6 +43,6 @@ class OpensslRecipe(Recipe):
sh.sed("-ie", "s!^CFLAG=!CFLAG={} !".format(build_env['CFLAGS']), sh.sed("-ie", "s!^CFLAG=!CFLAG={} !".format(build_env['CFLAGS']),
"Makefile") "Makefile")
shprint(sh.make, "clean") shprint(sh.make, "clean")
shprint(sh.make, "-j4", "build_libs") shprint(sh.make, self.ctx.concurrent_make, "build_libs")
recipe = OpensslRecipe() recipe = OpensslRecipe()

View file

@ -58,7 +58,7 @@ class PythonRecipe(Recipe):
self.apply_patch("ctypes_duplicate.patch") self.apply_patch("ctypes_duplicate.patch")
self.apply_patch("ctypes_duplicate_longdouble.patch") self.apply_patch("ctypes_duplicate_longdouble.patch")
shprint(sh.make, "-j4", shprint(sh.make, self.ctx.concurrent_make,
"CROSS_COMPILE_TARGET=yes", "CROSS_COMPILE_TARGET=yes",
"HOSTPYTHON={}".format(self.ctx.hostpython), "HOSTPYTHON={}".format(self.ctx.hostpython),
"HOSTPGEN={}".format(self.ctx.hostpgen)) "HOSTPGEN={}".format(self.ctx.hostpgen))
@ -68,7 +68,7 @@ class PythonRecipe(Recipe):
build_env = arch.get_env() build_env = arch.get_env()
build_dir = self.get_build_dir(arch.arch) build_dir = self.get_build_dir(arch.arch)
build_env["PATH"] = os.environ["PATH"] build_env["PATH"] = os.environ["PATH"]
shprint(sh.make, shprint(sh.make, self.ctx.concurrent_make,
"-C", build_dir, "-C", build_dir,
"install", "install",
"CROSS_COMPILE_TARGET=yes", "CROSS_COMPILE_TARGET=yes",

View file

@ -20,7 +20,7 @@ class LibSDL2Recipe(Recipe):
def build_arch(self, arch): def build_arch(self, arch):
env = arch.get_env() env = arch.get_env()
shprint(sh.xcodebuild, shprint(sh.xcodebuild, self.ctx.concurrent_xcodebuild,
"ONLY_ACTIVE_ARCH=NO", "ONLY_ACTIVE_ARCH=NO",
"ARCHS={}".format(arch.arch), "ARCHS={}".format(arch.arch),
"CC={}".format(env['CC']), "CC={}".format(env['CC']),

View file

@ -12,7 +12,7 @@ class LibSDL2ImageRecipe(Recipe):
pbx_frameworks = ["CoreGraphics", "MobileCoreServices"] pbx_frameworks = ["CoreGraphics", "MobileCoreServices"]
def build_arch(self, arch): def build_arch(self, arch):
shprint(sh.xcodebuild, shprint(sh.xcodebuild, self.ctx.concurrent_xcodebuild,
"ONLY_ACTIVE_ARCH=NO", "ONLY_ACTIVE_ARCH=NO",
"ARCHS={}".format(arch.arch), "ARCHS={}".format(arch.arch),
"HEADER_SEARCH_PATHS={}".format( "HEADER_SEARCH_PATHS={}".format(

View file

@ -12,7 +12,7 @@ class LibSDL2MixerRecipe(Recipe):
pbx_libraries = ["libc++"] pbx_libraries = ["libc++"]
def build_arch(self, arch): def build_arch(self, arch):
shprint(sh.xcodebuild, shprint(sh.xcodebuild, self.ctx.concurrent_xcodebuild,
"ONLY_ACTIVE_ARCH=NO", "ONLY_ACTIVE_ARCH=NO",
"ARCHS={}".format(arch.arch), "ARCHS={}".format(arch.arch),
"HEADER_SEARCH_PATHS=$HEADER_SEARCH_PATHS {}".format(" ".join(arch.include_dirs)), "HEADER_SEARCH_PATHS=$HEADER_SEARCH_PATHS {}".format(" ".join(arch.include_dirs)),

View file

@ -355,6 +355,15 @@ class Context(object):
if not ok: if not ok:
sys.exit(1) sys.exit(1)
self.use_pigz = sh.which('pigz')
self.use_pbzip2 = sh.which('pbzip2')
try:
num_cores = int(sh.sysctl('-n', 'hw.ncpu'))
except Exception:
num_cores = None
self.num_cores = num_cores if num_cores else 4 # default to 4 if we can't detect
ensure_dir(self.root_dir) ensure_dir(self.root_dir)
ensure_dir(self.build_dir) ensure_dir(self.build_dir)
ensure_dir(self.cache_dir) ensure_dir(self.cache_dir)
@ -373,6 +382,14 @@ class Context(object):
# set the state # set the state
self.state = JsonStore(join(self.dist_dir, "state.db")) self.state = JsonStore(join(self.dist_dir, "state.db"))
@property
def concurrent_make(self):
return "-j{}".format(self.num_cores)
@property
def concurrent_xcodebuild(self):
return "IDEBuildOperationMaxNumberOfConcurrentCompileTasks={}".format(self.num_cores)
class Recipe(object): class Recipe(object):
version = None version = None
@ -425,16 +442,24 @@ class Recipe(object):
return return
print("Extract {} into {}".format(filename, cwd)) print("Extract {} into {}".format(filename, cwd))
if filename.endswith(".tgz") or filename.endswith(".tar.gz"): if filename.endswith(".tgz") or filename.endswith(".tar.gz"):
shprint(sh.tar, "-C", cwd, "-xvzf", filename) if self.ctx.use_pigz:
comp = '--use-compress-program={}'.format(self.ctx.use_pigz)
else:
comp = '-z'
shprint(sh.tar, "-C", cwd, "-xv", comp, "-f", filename)
elif filename.endswith(".tbz2") or filename.endswith(".tar.bz2"): elif filename.endswith(".tbz2") or filename.endswith(".tar.bz2"):
shprint(sh.tar, "-C", cwd, "-xvjf", filename) if self.ctx.use_pbzip2:
comp = '--use-compress-program={}'.format(self.ctx.use_pbzip2)
else:
comp = '-j'
shprint(sh.tar, "-C", cwd, "-xv", comp, "-f", filename)
elif filename.endswith(".zip"): elif filename.endswith(".zip"):
shprint(sh.unzip, "-d", cwd, filename) shprint(sh.unzip, "-d", cwd, filename)
else: else:
print("Error: cannot extract, unreconized extension for {}".format( print("Error: cannot extract, unrecognized extension for {}".format(
filename)) filename))
raise Exception() raise Exception()
@ -1088,14 +1113,20 @@ Xcode:
getattr(self, args.command)() getattr(self, args.command)()
def build(self): def build(self):
ctx = Context()
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description="Build the toolchain") description="Build the toolchain")
parser.add_argument("recipe", nargs="+", help="Recipe to compile") parser.add_argument("recipe", nargs="+", help="Recipe to compile")
parser.add_argument("--arch", action="append", parser.add_argument("--arch", action="append",
help="Restrict compilation to this arch") help="Restrict compilation to this arch")
parser.add_argument("--concurrency", type=int, default=ctx.num_cores,
help="number of concurrent build processes (where supported)")
parser.add_argument("--no-pigz", action="store_true", default=not bool(ctx.use_pigz),
help="do not use pigz for gzip decompression")
parser.add_argument("--no-pbzip2", action="store_true", default=not bool(ctx.use_pbzip2),
help="do not use pbzip2 for bzip2 decompression")
args = parser.parse_args(sys.argv[2:]) args = parser.parse_args(sys.argv[2:])
ctx = Context()
if args.arch: if args.arch:
if len(args.arch) == 1: if len(args.arch) == 1:
archs = args.arch[0].split() archs = args.arch[0].split()
@ -1109,6 +1140,17 @@ Xcode:
continue continue
ctx.archs = [arch for arch in ctx.archs if arch.arch in archs] ctx.archs = [arch for arch in ctx.archs if arch.arch in archs]
print("Architectures restricted to: {}".format(archs)) print("Architectures restricted to: {}".format(archs))
ctx.num_cores = args.concurrency
if args.no_pigz:
ctx.use_pigz = False
if args.no_pbzip2:
ctx.use_pbzip2 = False
ctx.use_pigz = ctx.use_pbzip2
print("Building with {} processes, where supported".format(ctx.num_cores))
if ctx.use_pigz:
print("Using pigz to decompress gzip data")
if ctx.use_pbzip2:
print("Using pbzip2 to decompress bzip2 data")
build_recipes(args.recipe, ctx) build_recipes(args.recipe, ctx)
def recipes(self): def recipes(self):