Run cquery using an expression
Passing multiple targets to cquery causes an error. Paste:
https://paste.googleplex.com/5320993747763200. Fix this by creating an
algebraic union expression.
As a trivial example, instead of the following
```
c = //bionic/libc/libc.contribution //bionic/libm/libm.contribution
build/bazel/bin/bazel --config=android --config=api_bp2build cquery $c
```
Run it as
```
c = //bionic/libc/libc.contribution union //bionic/libm/libm.contribution
build/bazel/bin/bazel --config=android --config=api_bp2build cquery $c
```
Also skip bp2build in the cquery call, since we just ran bp2build to
build the metadata files. This should be a no-op anyways, but doing that
check takes some time (~2s).
Test: multitree_build locally
Change-Id: Ie551a40f210d07ac6f0f9895bd66f0408fc1b8cd
diff --git a/inner_build/inner_build_soong.py b/inner_build/inner_build_soong.py
index 6d97ca5..d886d22 100755
--- a/inner_build/inner_build_soong.py
+++ b/inner_build/inner_build_soong.py
@@ -174,16 +174,21 @@
targets=contribution_targets,
capture_output=False, # log everything to terminal
)
- print(f"Running Bazel cquery on api_domain_contribution targets "
+ print("Running Bazel cquery on api_domain_contribution targets "
f"in tree rooted at {self.inner_tree}")
proc = self._run_bazel_cmd(
subcmd="cquery",
- targets=contribution_targets,
+ # cquery raises an error if multiple targets are provided.
+ # Create a union expression instead.
+ targets=[" union ".join(contribution_targets)],
subcmd_options=[
"--output=files",
],
capture_output=True, # parse cquery result from stdout
- )
+ # we just ran bp2build. We can run it in again,
+ # but this adds time.
+ run_bp2build=False,
+ )
# The cquery response contains a blank line at the end.
# Remove this before creating the filepaths array.
filepaths = proc.stdout.decode().rstrip().split("\n")
@@ -223,11 +228,13 @@
subcmd: str,
targets: List[str],
subcmd_options: Tuple[str] = (),
+ run_bp2build=True,
**kwargs) -> subprocess.CompletedProcess:
"""Runs Bazel subcmd with Multi-tree specific configuration"""
# TODO (b/244766775): Replace the two discrete cmds once the new
# b-equivalent entrypoint is available.
- self._run_bp2build_cmd()
+ if run_bp2build:
+ self._run_bp2build_cmd()
output_user_root = self._output_user_root()
cmd = [
# Android's Bazel-entrypoint. Contains configs like the JDK to use.