Skip to content

Commit

Permalink
Add custom_recipes (#417)
Browse files Browse the repository at this point in the history
  • Loading branch information
misl6 committed May 24, 2020
1 parent df56328 commit 0998ea8
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions kivy_ios/toolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ 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 @@ -963,9 +964,24 @@ def get_recipe(cls, name, ctx):
if name in cls.recipes:
recipe = cls.recipes[name]
else:
mod = importlib.import_module("kivy_ios.recipes.{}".format(name))
recipe = mod.recipe
recipe.recipe_dir = join(ctx.root_dir, "recipes", name)
try:
mod = importlib.import_module("kivy_ios.recipes.{}".format(name))
recipe = mod.recipe
recipe.recipe_dir = join(ctx.root_dir, "recipes", name)
except ImportError:
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 @@ -1294,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 @@ -1320,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 0998ea8

Please sign in to comment.