Skip to content

Commit

Permalink
Custom recipes implementation via arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
misl6 committed Apr 11, 2020
1 parent 22dc109 commit c0300ef
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@ src/ios/ios.c
*.DS_Store*
*-ios/
__pycache__
custom_recipes
27 changes: 23 additions & 4 deletions toolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,8 @@ def __init__(self):
num_cores = None
self.num_cores = num_cores if num_cores else 4 # default to 4 if we can't detect

self.custom_recipes_paths = []

ensure_dir(self.root_dir)
ensure_dir(self.build_dir)
ensure_dir(self.cache_dir)
Expand Down Expand Up @@ -1006,10 +1008,19 @@ def get_recipe(cls, name, ctx):
recipe = mod.recipe
recipe.recipe_dir = join(ctx.root_dir, "recipes", name)
except ImportError:
logger.info("Looking for recipe '{}' in custom_recipes folder (if present)".format(name))
mod = importlib.import_module("custom_recipes.{}".format(name))
recipe = mod.recipe
recipe.recipe_dir = join(ctx.root_dir, "custom_recipes", name)
logger.info("Looking for recipe '{}' in custom recipes paths (if provided)".format(name))
for custom_recipe_path in ctx.custom_recipes_paths:
if custom_recipe_path.split('/')[-1] == name:
spec = importlib.util.spec_from_file_location(name,
join(custom_recipe_path, '__init__.py' ))
mod = importlib.util.module_from_spec(spec)
spec.loader.exec_module(mod)
recipe = mod.recipe
recipe.recipe_dir = custom_recipe_path
logger.info("Custom recipe '{}' found in folder {}".format(name, custom_recipe_path))
break
else:
raise
recipe.init_after_import(ctx)

if version:
Expand Down Expand Up @@ -1299,6 +1310,8 @@ def build(self):
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")
parser.add_argument("--add-custom-recipe", action="append", default=[],
help="Path to custom recipe")
args = parser.parse_args(sys.argv[2:])

if args.arch:
Expand All @@ -1325,6 +1338,12 @@ def build(self):
logger.info("Using pigz to decompress gzip data")
if ctx.use_pbzip2:
logger.info("Using pbzip2 to decompress bzip2 data")
for custom_recipe_path in args.add_custom_recipe:
if exists(custom_recipe_path):
logger.info(f"Adding {custom_recipe_path} to custom recipes paths")
ctx.custom_recipes_paths.append(custom_recipe_path)
else:
logger.error(f"{custom_recipe_path} isn't a valid path")
build_recipes(args.recipe, ctx)

def recipes(self):
Expand Down

0 comments on commit c0300ef

Please sign in to comment.