toolchain: use environ to select a directory to copy instead of an url to download (like KIVY_DIR=~/code/kivy) + add --arch for build to restrict the architectures to build (it will enforce any caching.)
This commit is contained in:
parent
34c812dbda
commit
490fe0d153
1 changed files with 46 additions and 9 deletions
55
toolchain.py
55
toolchain.py
|
@ -39,11 +39,12 @@ def cache_execution(f):
|
||||||
def _cache_execution(self, *args, **kwargs):
|
def _cache_execution(self, *args, **kwargs):
|
||||||
state = self.ctx.state
|
state = self.ctx.state
|
||||||
key = "{}.{}".format(self.name, f.__name__)
|
key = "{}.{}".format(self.name, f.__name__)
|
||||||
|
force = kwargs.pop("force", False)
|
||||||
if args:
|
if args:
|
||||||
for arg in args:
|
for arg in args:
|
||||||
key += ".{}".format(arg)
|
key += ".{}".format(arg)
|
||||||
key_time = "{}.at".format(key)
|
key_time = "{}.at".format(key)
|
||||||
if key in state:
|
if key in state and not force:
|
||||||
print("# (ignored) {} {}".format(f.__name__.capitalize(), self.name))
|
print("# (ignored) {} {}".format(f.__name__.capitalize(), self.name))
|
||||||
return
|
return
|
||||||
print("{} {}".format(f.__name__.capitalize(), self.name))
|
print("{} {}".format(f.__name__.capitalize(), self.name))
|
||||||
|
@ -507,17 +508,38 @@ class Recipe(object):
|
||||||
return value
|
return value
|
||||||
|
|
||||||
def execute(self):
|
def execute(self):
|
||||||
|
if self.custom_dir:
|
||||||
|
self.ctx.state.remove_all(self.name)
|
||||||
self.download()
|
self.download()
|
||||||
self.extract()
|
self.extract()
|
||||||
self.build_all()
|
self.build_all()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def custom_dir(self):
|
||||||
|
"""Check if there is a variable name to specify a custom version /
|
||||||
|
directory to use instead of the current url.
|
||||||
|
"""
|
||||||
|
d = environ.get("{}_DIR".format(self.name.upper()))
|
||||||
|
if not d:
|
||||||
|
return
|
||||||
|
if not exists(d):
|
||||||
|
return
|
||||||
|
return d
|
||||||
|
|
||||||
@cache_execution
|
@cache_execution
|
||||||
def download(self):
|
def download(self):
|
||||||
fn = self.archive_fn
|
|
||||||
if not exists(fn):
|
|
||||||
self.download_file(self.url.format(version=self.version), fn)
|
|
||||||
key = "{}.archive_root".format(self.name)
|
key = "{}.archive_root".format(self.name)
|
||||||
self.ctx.state[key] = self.get_archive_rootdir(self.archive_fn)
|
if self.custom_dir:
|
||||||
|
self.ctx.state[key] = basename(self.custom_dir)
|
||||||
|
else:
|
||||||
|
src_dir = join(self.recipe_dir, self.url)
|
||||||
|
if exists(src_dir):
|
||||||
|
self.ctx.state[key] = basename(src_dir)
|
||||||
|
return
|
||||||
|
fn = self.archive_fn
|
||||||
|
if not exists(fn):
|
||||||
|
self.download_file(self.url.format(version=self.version), fn)
|
||||||
|
self.ctx.state[key] = self.get_archive_rootdir(self.archive_fn)
|
||||||
|
|
||||||
@cache_execution
|
@cache_execution
|
||||||
def extract(self):
|
def extract(self):
|
||||||
|
@ -528,10 +550,20 @@ class Recipe(object):
|
||||||
|
|
||||||
def extract_arch(self, arch):
|
def extract_arch(self, arch):
|
||||||
build_dir = join(self.ctx.build_dir, self.name, arch)
|
build_dir = join(self.ctx.build_dir, self.name, arch)
|
||||||
if exists(join(build_dir, self.archive_root)):
|
dest_dir = join(build_dir, self.archive_root)
|
||||||
return
|
if self.custom_dir:
|
||||||
ensure_dir(build_dir)
|
if exists(dest_dir):
|
||||||
self.extract_file(self.archive_fn, build_dir)
|
shutil.rmtree(dest_dir)
|
||||||
|
shutil.copytree(self.custom_dir, dest_dir)
|
||||||
|
else:
|
||||||
|
if exists(dest_dir):
|
||||||
|
return
|
||||||
|
src_dir = join(self.recipe_dir, self.url)
|
||||||
|
if exists(src_dir):
|
||||||
|
shutil.copytree(src_dir, dest_dir)
|
||||||
|
return
|
||||||
|
ensure_dir(build_dir)
|
||||||
|
self.extract_file(self.archive_fn, build_dir)
|
||||||
|
|
||||||
@cache_execution
|
@cache_execution
|
||||||
def build(self, arch):
|
def build(self, arch):
|
||||||
|
@ -732,9 +764,14 @@ Available commands:
|
||||||
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", help="Restrict compilation to this arch")
|
||||||
args = parser.parse_args(sys.argv[2:])
|
args = parser.parse_args(sys.argv[2:])
|
||||||
|
|
||||||
ctx = Context()
|
ctx = Context()
|
||||||
|
if args.arch:
|
||||||
|
archs = args.arch.split()
|
||||||
|
ctx.archs = [arch for arch in ctx.archs if arch.arch in archs]
|
||||||
|
print("Architectures restricted to: {}".format(archs))
|
||||||
build_recipes(args.recipe, ctx)
|
build_recipes(args.recipe, ctx)
|
||||||
|
|
||||||
def recipes(self):
|
def recipes(self):
|
||||||
|
|
Loading…
Add table
Reference in a new issue