Vendor dependencies

Let's see how I like this workflow.
This commit is contained in:
John Doty 2022-12-19 08:27:18 -08:00
parent 34d1830413
commit 9c435dc440
7500 changed files with 1665121 additions and 99 deletions

View file

@ -0,0 +1,37 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under both the MIT license found in the
# LICENSE-MIT file in the root directory of this source tree and the Apache
# License, Version 2.0 found in the LICENSE-APACHE file in the root directory
# of this source tree.
def inject_test_run_info(ctx: "context", test_info: ExternalRunnerTestInfo.type) -> ["provider"]:
# Access this here so we get failures in CI if we forget to inject it
# anywhere, regardless of whether an `env` is used.
inject_test_env = ctx.attrs._inject_test_env[RunInfo]
if (not test_info.env) or _exclude_test_env_from_run_info(ctx):
return [test_info, RunInfo(args = test_info.command)]
cell_root = ctx.label.cell_root
env_file = ctx.actions.write_json(
"test_env.json",
{
k: _maybe_relativize_path(test_info, cell_root, cmd_args(v, delimiter = " "))
for (k, v) in test_info.env.items()
},
with_inputs = True,
)
return [test_info, RunInfo(args = [inject_test_env, env_file, "--", test_info.command])]
def _maybe_relativize_path(test_info: ExternalRunnerTestInfo.type, cell_root: "cell_root", arg: "cmd_args") -> "cmd_args":
if test_info.run_from_project_root:
return arg
return arg.relative_to(cell_root)
def _exclude_test_env_from_run_info(ctx: "context"):
# Antlir assumes that $(exe ...) is a single, relative path, so if we make
# it multiple commands here, it'll break.
return "antlir_inner_test" in ctx.attrs.labels

View file

@ -0,0 +1,7 @@
prelude = native
prelude.python_bootstrap_binary(
name = "inject_test_env",
main = "inject_test_env.py",
visibility = ["PUBLIC"],
)

View file

@ -0,0 +1,32 @@
#!/usr/bin/env python3
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under both the MIT license found in the
# LICENSE-MIT file in the root directory of this source tree and the Apache
# License, Version 2.0 found in the LICENSE-APACHE file in the root directory
# of this source tree.
import argparse
import json
import os
def main():
parser = argparse.ArgumentParser()
parser.add_argument(
"env_file", help="A JSON file containing the environment to inject"
)
parser.add_argument("executable")
parser.add_argument("args", nargs="*")
args = parser.parse_args()
with open(args.env_file) as env_file:
env_from_file = json.load(env_file)
env = {**os.environ, **env_from_file}
os.execve(args.executable, [args.executable, *args.args], env)
if __name__ == "__main__":
main()