From de697f0b6589696b78d06d0cdcbce1c7ef36c546 Mon Sep 17 00:00:00 2001 From: Julian-o Date: Fri, 1 Sep 2023 14:03:49 +1000 Subject: [PATCH] Mainly path updates --- buildozer/commandline.py | 54 ++++++++++++++++++----------------- buildozer/pathatlas.py | 2 +- buildozer/target.py | 13 ++++++--- buildozer/targets/android.py | 55 ++++++++++++++++++------------------ 4 files changed, 66 insertions(+), 58 deletions(-) diff --git a/buildozer/commandline.py b/buildozer/commandline.py index 63608faa9..bf1159148 100644 --- a/buildozer/commandline.py +++ b/buildozer/commandline.py @@ -72,7 +72,7 @@ def run(args): elif arg in ("-p", "--profile"): profile = args.pop(0) - config = _load_spec() + config = _load_spec(profile) if not log_level_set_by_command_line: _set_log_level_from_config(config) @@ -97,7 +97,7 @@ def run(args): # Generic commands don't need a target. if command in GENERIC_COMMANDS: - action = GENERIC_COMMANDS[command][2] + action = GENERIC_COMMANDS[command][1] action(config, paths, args) return @@ -111,7 +111,7 @@ def run(args): # We have a target. if not args: - logger.error('Missing target command') + logger.error("Missing target command") _usage() exit(1) @@ -119,7 +119,7 @@ def run(args): config=config, paths=paths, target_cls=available_targets[command], - args=args[1:], + args=args, ) @@ -148,7 +148,10 @@ def _run_target_command(config, paths, target_cls, args): # on the line should be passed to the command (even if they don't start # with "--") - valid_command_names = set(target_cls.get_custom_commands() + GENERIC_COMMANDS) + valid_command_names = ( + set(command[0] for command in target_cls.get_custom_commands()) + | GENERIC_COMMANDS.keys() + ) # Commands that have been parsed. complete_commands = [] @@ -158,20 +161,20 @@ def _run_target_command(config, paths, target_cls, args): while args: arg = args.pop(0) - if arg == '--': + if arg == "--": if partial_command: # Rest of arguments are part of the current command. partial_command += args break else: - logger.error('-- arguments passed without a command') + logger.error("-- arguments passed without a command") _usage() exit(1) - if not arg.startswith('--'): + if not arg.startswith("--"): # New command starting. if arg.lower() not in valid_command_names: - logger.error('Unrecognised command: {}'.format(arg)) + logger.error("Unrecognised command: {}".format(arg)) _usage() exit(1) @@ -183,7 +186,7 @@ def _run_target_command(config, paths, target_cls, args): partial_command.append(arg.lower()) else: if not partial_command: - logger.error('Argument passed without a command') + logger.error("Argument passed without a command") _usage() exit(1) partial_command.append(arg) @@ -191,7 +194,7 @@ def _run_target_command(config, paths, target_cls, args): complete_commands.append(partial_command) if not complete_commands: - logger.error('No command for target provided') + logger.error("No command for target provided") _usage() exit(1) @@ -327,18 +330,18 @@ def _targets(): return result -def _usage(): +def _usage(*_): print("Usage:") - print(" buildozer [--profile ] [--verbose] ...") + print(" buildozer [--profile ] [--verbose] [opts]") print( - " buildozer [--profile ] [--verbose] [target] ..." + " buildozer [--profile ] [--verbose] [opts]" ) print(" buildozer --version") print("") print("Global commands:") for name in sorted(GENERIC_COMMANDS.keys()): - print(" {0:<18} {1}".format(name, GENERIC_COMMANDS[name][0])) + print(" {0:<14} {1}".format(name, GENERIC_COMMANDS[name][0])) print("") print("Available targets:") @@ -355,19 +358,18 @@ def _usage(): doc = "" except Exception as e: doc = "" + str(e) - print(" {0:<18} {1}".format(target_name, doc)) - print("") + print(" {0:<14} {1}".format(target_name, doc)) if available_targets: print("") print("Target commands:") - print(" clean Clean the target environment") - print(" update Update the target dependencies") - print(" debug Build the application in debug mode") - print(" release Build the application in release mode") - print(" deploy Deploy the application on the device") - print(" run Run the application on the device") - print(" serve Serve the bin directory via SimpleHTTPServer") + print(" clean Clean the target environment") + print(" update Update the target dependencies") + print(" debug Build the application in debug mode") + print(" release Build the application in release mode") + print(" deploy Deploy the application on the device") + print(" run Run the application on the device") + print(" serve Serve the bin directory via SimpleHTTPServer") for target_name, target_cls in available_targets: commands = target_cls.get_custom_commands() @@ -379,9 +381,9 @@ def _usage(): if not doc: continue doc = textwrap.fill( - textwrap.dedent(doc).strip(), 59, subsequent_indent=" " * 21 + textwrap.dedent(doc).strip(), 59, subsequent_indent=" " * 17 ) - print(" {0:<18} {1}".format(command, doc)) + print(" {0:<14} {1}".format(command, doc)) print("") diff --git a/buildozer/pathatlas.py b/buildozer/pathatlas.py index af333e284..68b50cd64 100644 --- a/buildozer/pathatlas.py +++ b/buildozer/pathatlas.py @@ -69,5 +69,5 @@ def __init__(self, generic_paths, target_name): ) self.global_packages_path = ( - generic_paths.global_platform_path / target_name / "packages" + self.global_platform_path / target_name / "packages" ) diff --git a/buildozer/target.py b/buildozer/target.py index 1cb4ef037..19c2f522d 100644 --- a/buildozer/target.py +++ b/buildozer/target.py @@ -4,6 +4,7 @@ import buildozer.buildops as buildops from buildozer.logger import Logger +from buildozer.buildsupport import TargetedBuildSupporter def no_config(f): @@ -17,13 +18,17 @@ class Target: standard_cmds = ('distclean', 'update', 'debug', 'release', 'deploy', 'run', 'serve') - def __init__(self, buildsupporter): + def __init__(self, buildsupporter: TargetedBuildSupporter): self.buildsupporter = buildsupporter self.build_mode = 'debug' self.artifact_format = 'apk' self.platform_update = False self.logger = Logger() + self.generic_paths = buildsupporter.paths + self.target_paths = buildsupporter.target_paths + + def check_requirements(self): pass @@ -199,7 +204,7 @@ def path_or_git_url(self, repo, owner='kivy', branch='master', path = config.getdefault('app', '{}_dir'.format(key), None) if path is not None: - path = join(self.buildsupporter.root_dir, path) + path = join(self.generic_paths.root_dir, path) url = None branch = None else: @@ -223,7 +228,7 @@ def install_or_update_repo(self, repo, **kwargs): :Returns: fully qualified path to updated git repo """ - install_dir = join(self.buildsupporter.platform_dir, repo) + install_dir = join(self.target_paths.platform_dir, repo) custom_dir, clone_url, clone_branch = self.path_or_git_url(repo, **kwargs) if not buildops.file_exists(install_dir): if custom_dir: @@ -232,7 +237,7 @@ def install_or_update_repo(self, repo, **kwargs): else: buildops.cmd( ["git", "clone", "--branch", clone_branch, clone_url], - cwd=self.buildsupporter.platform_dir, + cwd=self.target_paths.platform_dir, env=self.buildsupporter.environ) elif self.platform_update: if custom_dir: diff --git a/buildozer/targets/android.py b/buildozer/targets/android.py index 31224a9a1..88aaf9e8a 100644 --- a/buildozer/targets/android.py +++ b/buildozer/targets/android.py @@ -84,7 +84,7 @@ def __init__(self, *args, **kwargs): self._archs = self.buildsupporter.config.getlist( 'app', 'android.archs', DEFAULT_ARCHS) self._build_dir = join( - self.buildsupporter.paths.platform_path, 'build-{}'.format(self.archs_snake)) + self.target_paths.platform_path, 'build-{}'.format(self.archs_snake)) executable = sys.executable or 'python' self._p4a_cmd = [executable, "-m", "pythonforandroid.toolchain"] self._p4a_bootstrap = self.buildsupporter.config.getdefault( @@ -144,7 +144,7 @@ def p4a_dir(self): """The directory where python-for-android is/will be installed.""" # Default p4a dir - p4a_dir = join(self.buildsupporter.paths.platform_path, self.p4a_directory_name) + p4a_dir = join(self.target_paths.platform_path, self.p4a_directory_name) # Possibly overridden by user setting system_p4a_dir = self.buildsupporter.config.getdefault('app', 'p4a.source_dir') @@ -224,7 +224,7 @@ def android_sdk_dir(self): 'app', 'android.sdk_path', '')) if directory: return realpath(directory) - return join(self.buildsupporter.paths.global_platform_path, + return join(self.target_paths.global_platform_path, 'android-sdk') @property @@ -235,7 +235,7 @@ def android_ndk_dir(self): return realpath(directory) version = self.buildsupporter.config.getdefault('app', 'android.ndk', self.android_ndk_version) - return join(self.buildsupporter.paths.global_platform_path, + return join(self.target_paths.global_platform_path, 'android-ndk-r{0}'.format(version)) @property @@ -246,7 +246,7 @@ def apache_ant_dir(self): return realpath(directory) version = self.buildsupporter.config.getdefault('app', 'android.ant', APACHE_ANT_VERSION) - return join(self.buildsupporter.paths.global_platform_path, + return join(self.target_paths.global_platform_path, 'apache-ant-{0}'.format(version)) @property @@ -458,17 +458,17 @@ def _install_android_ndk(self): buildops.download(url, archive, - cwd=self.buildsupporter.paths.global_platform_path) + cwd=self.target_paths.global_platform_path) self.logger.info('Unpacking Android NDK') buildops.file_extract( archive, - cwd=self.buildsupporter.global_platform_path, + cwd=self.target_paths.global_platform_path, env=self.buildsupporter.environ) buildops.rename( unpacked, ndk_dir, - cwd=self.buildsupporter.global_platform_path) + cwd=self.target_paths.global_platform_path) self.logger.info('Android NDK installation done.') return ndk_dir @@ -652,7 +652,7 @@ def install_platform(self): raise BuildozerException() self.buildsupporter.environ.update({ - 'PACKAGES_PATH': self.buildsupporter.paths.global_packages_path, + 'PACKAGES_PATH': self.target_paths.global_packages_path, 'ANDROIDSDK': self.android_sdk_dir, 'ANDROIDNDK': self.android_ndk_dir, 'ANDROIDAPI': self.android_api, @@ -715,7 +715,7 @@ def _install_p4a(self): p4a_url, self.p4a_directory_name, ], - cwd=self.buildsupporter.paths.platform_path, + cwd=self.target_paths.platform_path, env=self.buildsupporter.environ ) elif self.platform_update: @@ -1018,7 +1018,7 @@ def cmd_run(self, *args): "-a", entrypoint, ], - cwd=self.buildsupporter.paths.global_platform_path, + cwd=self.target_paths.global_platform_path, env=self.buildsupporter.environ ) self.buildsupporter.environ.pop('ANDROID_SERIAL', None) @@ -1075,7 +1075,7 @@ def build_package(self): dist_dir = self.get_dist_dir(dist_name) config = self.buildsupporter.config package = self._get_package() - version = self.buildsupporter.get_version() + version = self.buildsupporter.get_app_version() # add extra libs/armeabi files in dist/default/libs/armeabi # (same for armeabi-v7a, arm64-v8a, x86, mips) @@ -1095,7 +1095,7 @@ def build_package(self): self.logger.debug('Search and copy libs for {}'.format(lib_dir)) for fn in buildops.file_matches(patterns): buildops.file_copy( - join(self.buildsupporter.root_dir, fn), + join(self.generic_paths.root_path, fn), join(dist_dir, 'libs', lib_dir, basename(fn))) # update the project.properties libraries references @@ -1113,7 +1113,7 @@ def build_package(self): self.android_minapi)), ("--ndk-api", config.getdefault('app', 'android.minapi', self.android_minapi)), - ("--private", self.buildsupporter.app_dir), + ("--private", self.target_paths.app_dir), ] # add permissions @@ -1129,7 +1129,7 @@ def build_package(self): # add res_xml xmlfiles = config.getlist('app', 'android.res_xml', []) for xmlfile in xmlfiles: - build_cmd += [("--res_xml", join(self.buildsupporter.paths.root_path, + build_cmd += [("--res_xml", join(self.generic_paths.root_path, xmlfile))] # android.entrypoint @@ -1165,7 +1165,7 @@ def build_package(self): # add extra Java jar files add_jars = config.getlist('app', 'android.add_jars', []) for pattern in add_jars: - pattern = join(self.buildsupporter.paths.root_path, pattern) + pattern = join(self.generic_paths.root_path, pattern) matches = glob(expanduser(pattern.strip())) if matches: for jar in matches: @@ -1182,23 +1182,23 @@ def build_package(self): # add presplash, lottie animation or static presplash = config.getdefault('app', 'android.presplash_lottie', '') if presplash: - build_cmd += [("--presplash-lottie", join(self.buildsupporter.paths.root_path, + build_cmd += [("--presplash-lottie", join(self.generic_paths.root_path, presplash))] else: presplash = config.getdefault('app', 'presplash.filename', '') if presplash: - build_cmd += [("--presplash", join(self.buildsupporter.paths.root_path, + build_cmd += [("--presplash", join(self.generic_paths.root_path, presplash))] # add icon icon = config.getdefault('app', 'icon.filename', '') if icon: - build_cmd += [("--icon", join(self.buildsupporter.paths.root_path, icon))] + build_cmd += [("--icon", join(self.generic_paths.root_path, icon))] icon_fg = config.getdefault('app', 'icon.adaptive_foreground.filename', '') icon_bg = config.getdefault('app', 'icon.adaptive_background.filename', '') if icon_fg and icon_bg: - build_cmd += [("--icon-fg", join(self.buildsupporter.paths.root_path, icon_fg))] - build_cmd += [("--icon-bg", join(self.buildsupporter.paths.root_path, icon_bg))] + build_cmd += [("--icon-fg", join(self.generic_paths.root_path, icon_fg))] + build_cmd += [("--icon-bg", join(self.generic_paths.root_path, icon_bg))] # OUYA Console support ouya_category = config.getdefault('app', 'android.ouya.category', @@ -1212,7 +1212,7 @@ def build_package(self): ouya_icon = config.getdefault('app', 'android.ouya.icon.filename', '') build_cmd += [("--ouya-category", ouya_category)] - build_cmd += [("--ouya-icon", join(self.buildsupporter.paths.root_path, + build_cmd += [("--ouya-icon", join(self.generic_paths.root_path, ouya_icon))] if config.getdefault('app', 'p4a.bootstrap', 'sdl2') != 'service_only': @@ -1242,7 +1242,7 @@ def build_package(self): intent_filters = config.getdefault( 'app', 'android.manifest.intent_filters', '') if intent_filters: - build_cmd += [("--intent-filters", join(self.buildsupporter.paths.root_path, + build_cmd += [("--intent-filters", join(self.generic_paths.root_path, intent_filters))] # activity launch mode @@ -1270,7 +1270,7 @@ def build_package(self): # android.backup_rules backup_rules = config.getdefault('app', 'android.backup_rules', '') if backup_rules: - build_cmd += [("--backup-rules", join(self.buildsupporter.paths.root_path, + build_cmd += [("--backup-rules", join(self.generic_paths.root_path, backup_rules))] # build only in debug right now. @@ -1286,6 +1286,7 @@ def build_package(self): self.execute_build_package(build_cmd) try: + # ToDo: Hook is never defined. This will always fail. self.buildsupporter.hook("android_pre_build_apk") self.execute_build_package(build_cmd) self.buildsupporter.hook("android_post_build_apk") @@ -1466,7 +1467,7 @@ def cmd_deploy(self, *args): self.logger.info('Deploy on {}'.format(serial)) buildops.cmd( [self.adb_executable, *self.adb_args, "install", "-r", full_apk], - cwd=self.buildsupporter.paths.global_platform_path, + cwd=self.target_paths.global_platform_path, env=self.buildsupporter.environ ) self.buildsupporter.environ.pop('ANDROID_SERIAL', None) @@ -1492,7 +1493,7 @@ def _get_pid(self): return pid.strip() return False - def cmd_logcat(self, *args): + def cmd_logcat(self, *_): '''Show the log from the device ''' self.check_requirements() @@ -1516,7 +1517,7 @@ def cmd_logcat(self, *args): buildops.cmd( [self.adb_executable, *self.adb_args, "logcat", filters, *extra_args], - cwd=self.buildsupporter.paths.global_platform_path, + cwd=self.target_paths.global_platform_path, show_output=True, run_condition=self._get_pid if pid else None, break_on_error=False,