Skip to content

Commit

Permalink
pw_build: Upstream build script fix
Browse files Browse the repository at this point in the history
Remove project_root() calls when importing this file to be compatible
with sphinx running under bazel.

Change-Id: I66f41d08650d2f1ab6d076720a7555f275e4435c
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/261972
Reviewed-by: Kayce Basques <[email protected]>
Docs-Not-Needed: Anthony DiGirolamo <[email protected]>
Presubmit-Verified: CQ Bot Account <[email protected]>
Commit-Queue: Kayce Basques <[email protected]>
Lint: Lint 🤖 <[email protected]>
  • Loading branch information
AnthonyDiGirolamo authored and CQ Bot Account committed Jan 22, 2025
1 parent 57c1c31 commit 1e7179c
Showing 1 changed file with 26 additions and 14 deletions.
40 changes: 26 additions & 14 deletions pw_build/py/pw_build/pigweed_upstream_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,6 @@

_LOG = logging.getLogger('pw_build')

_PW_ENV = pw_cli.env.pigweed_environment()
_REPO_ROOT = pw_cli.env.project_root()
_PACKAGE_ROOT = _PW_ENV.PW_PACKAGE_ROOT
if not _PACKAGE_ROOT:
_PACKAGE_ROOT = _REPO_ROOT / 'environment/packages'


def gn_recipe() -> BuildRecipe:
"""Return the default_gn recipe."""
Expand Down Expand Up @@ -111,10 +105,10 @@ def bazel_recipe() -> BuildRecipe:
)


def cmake_recipe() -> BuildRecipe:
def cmake_recipe(repo_root: Path, package_root: Path) -> BuildRecipe:
"""Construct the default_cmake recipe."""
toolchain_path = (
_REPO_ROOT / 'pw_toolchain' / 'host_clang' / 'toolchain.cmake'
repo_root / 'pw_toolchain' / 'host_clang' / 'toolchain.cmake'
)

cmake_generate_command = [
Expand All @@ -123,18 +117,18 @@ def cmake_recipe() -> BuildRecipe:
'--debug-output',
'-DCMAKE_MESSAGE_LOG_LEVEL=WARNING',
'-S',
str(_REPO_ROOT),
str(repo_root),
'-B',
# NOTE: Not an f-string. BuildRecipe will replace with the out dir.
'{build_dir}',
'-G',
'Ninja',
f'-DCMAKE_TOOLCHAIN_FILE={toolchain_path}',
'-DCMAKE_EXPORT_COMPILE_COMMANDS=1',
f'-Ddir_pw_third_party_nanopb={_PACKAGE_ROOT / "nanopb"}',
f'-Ddir_pw_third_party_nanopb={package_root / "nanopb"}',
'-Dpw_third_party_nanopb_ADD_SUBDIRECTORY=ON',
f'-Ddir_pw_third_party_emboss={_PACKAGE_ROOT / "emboss"}',
f'-Ddir_pw_third_party_boringssl={_PACKAGE_ROOT / "boringssl"}',
f'-Ddir_pw_third_party_emboss={package_root / "emboss"}',
f'-Ddir_pw_third_party_boringssl={package_root / "boringssl"}',
]

if shutil.which('ccache'):
Expand Down Expand Up @@ -165,6 +159,15 @@ def cmake_recipe() -> BuildRecipe:
)


def _get_repo_and_package_root() -> tuple[Path, Path]:
pw_env = pw_cli.env.pigweed_environment()
repo_root = pw_cli.env.project_root()
package_root = pw_env.PW_PACKAGE_ROOT
if not package_root:
package_root = repo_root / 'environment/packages'
return (repo_root, package_root)


def pigweed_upstream_main() -> int:
"""Entry point for Pigweed upstream ``pw build`` command.
Expand All @@ -186,13 +189,14 @@ def pigweed_upstream_main() -> int:
pw build --step gn_combined_build_check --step gn_python_*
pw build -C out/gn --watch
"""
repo_root, package_root = _get_repo_and_package_root()

return main(
presubmit_programs=pw_presubmit.pigweed_presubmit.PROGRAMS,
build_recipes=[
gn_recipe(),
bazel_recipe(),
cmake_recipe(),
cmake_recipe(repo_root, package_root),
],
default_root_logfile=Path('out/build.txt'),
)
Expand All @@ -204,7 +208,15 @@ def _build_argument_parser() -> argparse.ArgumentParser:
[
gn_recipe(),
bazel_recipe(),
cmake_recipe(),
# Empty cmake recipe for argparse validation by display_name.
# This is needed because project_root can only be determined with
# bazel run and the sphinx docs build runs this function for
# argparse documentation.
BuildRecipe(
build_dir=Path('out/cmake'),
title='default_cmake',
steps=[],
),
],
)

Expand Down

0 comments on commit 1e7179c

Please sign in to comment.