Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion fboss/lib/asic_config_v2/run-helper.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
#!/bin/bash
python3 fboss/lib/oss/run-helper.py --target fboss-asic-config-gen "$@"
python3 fboss/lib/oss/run-helper.py \
--target fboss-asic-config-gen.GEN_PY_EXE \
--extra-cmake-defines='{"RANGE_V3_TESTS": "OFF"}' \
"$@"
51 changes: 35 additions & 16 deletions fboss/lib/oss/run-helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,36 @@
"""

import argparse
import json
import os
import subprocess
import sys
from pathlib import Path
from typing import List, Tuple


def get_command_line_args() -> Tuple[str, List[str]]:
def get_command_line_args() -> tuple[str, dict[str, str], list[str]]:
parser = argparse.ArgumentParser(
description="OSS FBOSS build and run helper script."
)
parser.add_argument("--target", type=str, required=True, help="Target to build")
parser.add_argument(
"--extra-cmake-defines",
type=str,
default="{}",
help=("JSON object of additional cmake defines"),
)
args, unknown_args = parser.parse_known_args()

return args.target, unknown_args
extra_defines = json.loads(args.extra_cmake_defines)
if not isinstance(extra_defines, dict):
print("--extra-cmake-defines must be a JSON object", file=sys.stderr)
sys.exit(1)

return args.target, extra_defines, unknown_args


def main() -> None:
target, command_line_args = get_command_line_args()
target, extra_cmake_defines, command_line_args = get_command_line_args()

run_path = os.getcwd()
parents = Path(__file__).parents
Expand All @@ -40,14 +51,14 @@ def main() -> None:
"Please run the script from the root of the FBOSS repository",
file=sys.stderr,
)
exit(1)
sys.exit(1)
expected_path = parents[3].absolute().as_posix()
if run_path != expected_path:
error_string = f"""Please executed the script from the root of the FBOSS repository
Expected run path: {expected_path}
Current run path: {run_path}"""
print(error_string, file=sys.stderr)
exit(1)
sys.exit(1)

get_deps_paths = [
expected_path + "/opensource/fbcode_builder/getdeps.py",
Expand All @@ -60,7 +71,7 @@ def main() -> None:
get_deps_path = maybe_path
if get_deps_path is None:
print("Could not find getdeps.py", file=sys.stderr)
exit(1)
sys.exit(1)
else:
print(get_deps_path)

Expand All @@ -70,41 +81,49 @@ def main() -> None:
if is_facebook_machine:
get_deps_path = f"{proxy_env_vars} {get_deps_path}"

cmake_defines = {"CMAKE_BUILD_TYPE": "MinSizeRel", "CMAKE_CXX_STANDARD": "20"}
cmake_defines.update(extra_cmake_defines)
cmake_defines_json = json.dumps(cmake_defines)

print(f"Starting build for {target}")
subprocess.run(
f"""{get_deps_path} build """
+ '--allow-system-packages --num-jobs 32 --extra-cmake-defines=\'{"CMAKE_BUILD_TYPE": "MinSizeRel", "CMAKE_CXX_STANDARD": "20"}\' --cmake-target'
+ f"--allow-system-packages --num-jobs 32 --extra-cmake-defines='{cmake_defines_json}' --cmake-target"
+ f" {target} fboss",
check=False,
shell=True,
)

print(f"Completed build for {target}")

show_build_dir_proc = subprocess.run(
f"""{get_deps_path} show-build-dir fboss""",
check=False,
shell=True,
capture_output=True,
text=True,
)

fboss_oss_target = (
show_build_dir_proc.stdout.rstrip()
+ f"/{target}"
+ " "
+ " ".join(command_line_args)
)
build_dir = show_build_dir_proc.stdout.rstrip()
target_basename = target.removesuffix(".GEN_PY_EXE")
output_path = f"{build_dir}/{target_basename}"

# Thrift python output is a directory; everything else is a native executable
python_prefix = "python3 " if os.path.isdir(output_path) else ""
fboss_oss_target = f"{python_prefix}{output_path} {' '.join(command_line_args)}"

result = subprocess.run(
fboss_oss_target,
check=False,
shell=True,
)

if result.returncode != 0:
print(f"Failed to run target {target}", file=sys.stderr)
exit(1)
sys.exit(1)

print("Configs have been written to specified output directory")
exit(0)
sys.exit(0)


if __name__ == "__main__":
Expand Down
Loading