def configure_gradlew(config, job, taskdesc): run = job["run"] worker = taskdesc["worker"] = job["worker"] fetches_dir = path.join(run["workdir"], worker["env"]["MOZ_FETCHES_DIR"]) worker.setdefault("env", {}).update({ "ANDROID_SDK_ROOT": path.join(fetches_dir, "android-sdk-linux"), }) run["command"] = _extract_gradlew_command(run, fetches_dir) _inject_secrets_scopes(run, taskdesc) _set_run_task_attributes(job) configure_taskdesc_for_run(config, job, taskdesc, job["worker"]["implementation"])
def _extract_gradlew_command(run, fetches_dir): pre_gradle_commands = run.pop("pre-gradlew", []) pre_gradle_commands += [ _generate_dummy_secret_command(secret) for secret in run.pop("dummy-secrets", []) ] pre_gradle_commands += [ _generate_secret_command(secret) for secret in run.get("secrets", []) ] maven_dependencies_dir = path.join(fetches_dir, "android-gradle-dependencies") gradle_repos_args = [ "-P{repo_name}Repo=file://{dir}/{repo_name}".format( dir=maven_dependencies_dir, repo_name=repo_name) for repo_name in ("google", "jcenter") ] gradle_command = ["./gradlew"] + gradle_repos_args + [ "listRepositories" ] + run.pop("gradlew") post_gradle_commands = run.pop("post-gradlew", []) commands = pre_gradle_commands + [gradle_command] + post_gradle_commands shell_quoted_commands = [ " ".join(map(shell_quote, command)) for command in commands ] return " && ".join(shell_quoted_commands)
def configure_gradlew(config, job, taskdesc): run = job["run"] worker = taskdesc["worker"] = job["worker"] worker.setdefault("env", {}).update({ "ANDROID_SDK_ROOT": path.join(run["workdir"], worker["env"]["MOZ_FETCHES_DIR"], "android-sdk-linux") }) # defer to the run_task implementation run["command"] = _extract_command(run) secrets = run.pop("secrets", []) scopes = taskdesc.setdefault("scopes", []) new_secret_scopes = [ "secrets:get:{}".format(secret["name"]) for secret in secrets ] new_secret_scopes = list( set(new_secret_scopes)) # Scopes must not have any duplicates scopes.extend(new_secret_scopes) run["cwd"] = "{checkout}" run["using"] = "run-task" configure_taskdesc_for_run(config, job, taskdesc, job["worker"]["implementation"])
def hash_paths(base_path, patterns): """ Give a list of path patterns, return a digest of the contents of all the corresponding files, similarly to git tree objects or mercurial manifests. Each file is hashed. The list of all hashes and file paths is then itself hashed to produce the result. """ h = hashlib.sha256() found = set() for pattern in patterns: files = _find_files(base_path) matches = [path for path in files if mozpath.match(path, pattern)] if matches: found.update(matches) else: raise Exception("%s did not match anything" % pattern) for path in sorted(found): h.update("{} {}\n".format( hash_path(mozpath.abspath(mozpath.join(base_path, path))), mozpath.normsep(path), ).encode("utf-8")) return h.hexdigest()
def common_setup(config, job, taskdesc, command): run = job["run"] if run["checkout"]: repo_configs = config.repo_configs if len(repo_configs) > 1 and run["checkout"] is True: raise Exception( "Must explicitly sepcify checkouts with multiple repos.") elif run["checkout"] is not True: repo_configs = { repo: attr.evolve(repo_configs[repo], **config) for (repo, config) in run["checkout"].items() } vcs_path = support_vcs_checkout( config, job, taskdesc, repo_configs=repo_configs, sparse=bool(run["sparse-profile"]), ) vcs_path = taskdesc["worker"]["env"]["VCS_PATH"] for repo_config in repo_configs.values(): checkout_path = path.join(vcs_path, repo_config.path) command.append(f"--{repo_config.prefix}-checkout={checkout_path}") if run["sparse-profile"]: command.append( "--{}-sparse-profile=build/sparse-profiles/{}".format( repo_config.prefix, run["sparse-profile"], )) if "cwd" in run: run["cwd"] = path.normpath(run["cwd"].format(checkout=vcs_path)) elif "cwd" in run and "{checkout}" in run["cwd"]: raise Exception( "Found `{{checkout}}` interpolation in `cwd` for task {name} " "but the task doesn't have a checkout: {cwd}".format( cwd=run["cwd"], name=job.get("name", job.get("label")))) if "cwd" in run: command.extend(("--task-cwd", run["cwd"])) taskdesc["worker"].setdefault("env", {})["MOZ_SCM_LEVEL"] = config.params["level"]
def _extract_gradlew_command(run, fetches_dir): pre_gradle_commands = run.pop("pre-gradlew", []) pre_gradle_commands += [ _generate_dummy_secret_command(secret) for secret in run.pop("dummy-secrets", []) ] pre_gradle_commands += [ _generate_secret_command(secret) for secret in run.get("secrets", []) ] maven_dependencies_dir = path.join(fetches_dir, "android-gradle-dependencies") gradle_repos_args = [ "-P{repo_name}Repo=file://{dir}/{repo_name}".format( dir=maven_dependencies_dir, repo_name=repo_name) for repo_name in ("google", "jcenter") ] gradle_command = ["./gradlew"] + gradle_repos_args + run.pop("gradlew") post_gradle_commands = run.pop("post-gradlew", []) commands = pre_gradle_commands + [gradle_command] + post_gradle_commands return _convert_commands_to_string(commands)