Commit graph

162 commits

Author SHA1 Message Date
Treehugger Robot
7a9626c655 Merge "Make buildroot.cquery determinisitc" 2023-04-12 21:04:52 +00:00
Cole Faust
8181f4b916 Replace json_encode with json.encode
Now that the json module is available in the cquery starlark execution
enviornment.

Bug: 245315355
Test: m nothing
Change-Id: Ie7c314e2f4e2ef4257bd84abc1add01ddb668f0b
2023-03-19 14:24:23 -07:00
Vinh Tran
cbee4e3f2e Remove --extra_toolchains flag from aquery runner
When specifying --extra_toolchains=//prebuilts/clang/host/linux-x86:all, there is no control over the sort order of toolchains, which can result in a more generic toolchain being used rather than the most specific (and correct) toolchain.

Apparently, this flag is causing Bazel to drop some flags from CppCompile actions. This causes mixed-build's outputs different from Soong build. The mixed-build also generates different from Bazel build because we don't use the flag when using `b` to build the targets.

Test: Inspect differences in CppCompile actions from Soong's Bazel aquery handler and b aquery
Bug: 273995121
Change-Id: Id9e32c0cd12ab8577cd5b223ca9e19c982f3ae1f
2023-03-17 15:34:37 -04:00
Jingwen Chen
2d37b641c5 Populate apexBundle#filesInfo using bazel info.
This CL adds a few things:

1) Populate the filesInfo struct with cquery'd information from an
apex's ApexMkInfo provider. This filesInfo is then used in
apex/androidmk.go to generate Make modules (soong_cc_rust_prebuilt.mk),
which are then used in packaging to generate zip files of symbols in $PRODUCT_OUT.
2) Make a list of dicts of primitives JSON-encodable.
3) Tests.

Bug: 271423316
Bug: 271423062
Test: presubmits
Change-Id: Iaa34f51044de310510e580d9cf1fe60bbef801c1
2023-03-16 18:09:27 +00:00
Chris Parsons
38851d86aa Make buildroot.cquery determinisitc
Test: determinism_test.sh
Change-Id: Ia80dc425a781247f518ace8a5d11b49cd1ae60ce
2023-03-15 00:19:55 -04:00
Chris Parsons
9402ca881c Add a persistent bazel server between builds
This feature is toggled on with USE_PERSISTENT_BAZEL, which is off by
default. Those that opt-in will have a bazel server running between
builds (with a 3hr default TTL) which will greatly improve analysis on
subsequent builds. (As Bazel maintains a cache of analysis results).

Bug: 266983462
Test: Manual `m nothing` runs (timing with and without the feature)
Test: New integration test
Test: Presubmits
Change-Id: I3af4948baa0c490e9b87c48ffdbe9f67732586c7
2023-03-01 23:30:19 -05:00
Yu Liu
bfb2362cde Only apply apex transition to DCLA libs for now.
Bug: 270339610
Test: mixed_droid.sh
Change-Id: I6a8b7fdefeb504a25256e92647de9b487d5b65a3
2023-02-22 10:43:46 -08:00
Yu Liu
e43124023c Support DCLA
Bug: 240424572
Test: Manual tests:
1. m --dev-mode-staging com.android.adbd com.android.media.swcodec.
2. verify the DCLA libs from the two apexes have the same size and
   sha1sum, and also match the libs in bazel-out.
3. empty the DCLA libs list in allowlist.go and repeat step 1
4. repeat step 2 and verify the opposite result
5. build git_master: mainline_modules_bundles-userdebug in ABTD
   with the cl, then follow go/build-sideload-dcla-locally to
   download the adbd and swcodec aab files, run the DCLA trimming
   workflow locally, and verify the symlinks in the two trimmed
   apexes are identical and also match the lib path in the DCLA
   apex that was created by the workflow.

Change-Id: Ib2f8a29126a54829c0e10eba17b256a79930fd70
2023-02-21 10:12:47 -08:00
Liz Kammer
a4655a96c0 Handle aquery build statements in a goroutine
Creation of build statements is largely parallelizable because each
action is independent apart from updates/reads to
depsetHashToArtifactPathsCache. Locally resulted in build statements
taking ~.45 seconds on staging mode to ~.02 seconds

Test: CI
Change-Id: Iab00c8394a9eab17353f71230885ff0870e17f24
2023-02-15 11:29:49 -05:00
Treehugger Robot
80936bd15f Merge "Collect more metrics for aquery handling" 2023-02-14 19:25:53 +00:00
Liz Kammer
690fbac200 Collect more metrics for aquery handling
Test: go test soong tests
Test: m nothing & verify metrics
Change-Id: Id19e004d90dfbaa1b1706c607d5250bf845c0f3b
2023-02-14 11:10:19 -05:00
Sam Delmerico
e56fd9467d Merge "pass TIDY_EXTERNAL_VENDOR envvar to Bazel" 2023-02-13 19:02:29 +00:00
Sam Delmerico
700b4d3e1a pass TIDY_EXTERNAL_VENDOR envvar to Bazel
Bug: 268668248
Test: verify that Bazel tidy actions don't have a large diff from Soong tidy actions:
  (add -v to Ninja invocation in ui/build/ninja.go [and disable fifo file])
  WITH_TIDY=1 DISABLE_ARTIFACT_PATH_REQUIREMENTS=true m com.android.adbd 2>&1 | tee soong_build-tidy.adbd &&
  WITH_TIDY=1 DISABLE_ARTIFACT_PATH_REQUIREMENTS=true m com.android.adbd --bazel-mode-staging 2>&1 | tee mixed_build-tidy.adbd &&
  grep -Po "prebuilts/clang/host/linux-x86/clang-r475365b/bin/clang-tidy.sh \K\S+" soong_build-tidy.adbd | sort -u > soong-clang-tidy.adbd &&
  grep -Po "prebuilts/clang/host/linux-x86/clang-r475365b/bin/clang-tidy.sh \K\S+" mixed_build-tidy.adbd | sort -u > mixed-clang-tidy.adbd &&
  vimdiff soong_build-tidy.adbd mixed_build-tidy.adbd
Change-Id: I22804d6d92ed56d9727eaf430318df0b041712a8
2023-02-10 16:46:33 -05:00
Sam Delmerico
db23e22835 Merge "export allowlist of environment variables to Bazel" 2023-02-07 19:25:39 +00:00
Christopher Parsons
a9242e32d5 Merge "Only write soong_injection files if changed" 2023-02-06 22:23:54 +00:00
Sam Delmerico
cb3c52c766 export allowlist of environment variables to Bazel
Previously, Bazel was invoked during mixed builds with a stripped down
environment. This CL adds an allowlist of environment variables that are
passed to Bazel.

Test: WITH_TIDY=1 DISABLE_ARTIFACT_PATH_REQUIREMENTS=true mss tidy-packages-modules-NeuralNetworks --bazel-mode-dev
Change-Id: I23147bec59f6522953cf623e7bcaa0f1f99a75a3
2023-02-06 14:34:43 -05:00
Chris Parsons
3a8d0fbede Only write soong_injection files if changed
This also fixes determinism of these files (by ensuring that bazel
requests and their configurations are sorted, as these are used in the
soong_injection file output)

Bug: 266983462
Test: Manually verified soong_injection files are the same among
multiple runs
Test: Unit test
Test: m nothing

Change-Id: I1568930549cff0bc5676825434cc448d16ebdd4e
2023-02-03 18:29:02 -05:00
Usta Shrestha
13fd5aead7 prune out empty bazel depsets
Instead of using a sentinel file that was created under bazel_workspace
prune them out. The sentinel file was being created under bazel_workspace,
which would be deleted and thus rendered useless from the perspective of
not retriggering a build.

Test: `touch Android.bp` then `NINJA_ARGS="-d explain" m --bazel-mode-staging adbd_test`
Bug: 265155778
Change-Id: If5d8f0ea7f3b8828fda0646faafd1a621f0cb27c
2023-01-30 11:37:04 -05:00
Sam Delmerico
ce39f83538 add error handling to cquery in MockBazelContext
Change-Id: Ia01072b6528caff2f3ceaca67cdba8b900924fe5
2023-01-24 10:39:07 -05:00
Sasha Smundak
39a301c963 Clean up mixed builds module names filtering
* Remove `Bp2buildCcLibraryStaticOnlyList` it is never set
* Remove the rest of the sutff related to it
* Streamline MixedBuildsEnabled
* Rename BazelContext.BazelAllowlisted to BazelContext.NameFilter
  to reflect its action
* Rename bazelContext to mixedBuildBazelContext
* Fix minor warnings from Go static analyzer

Test: treehugger
Change-Id: Ie245c992f94bbfd5c7c23dd06917026200a28263
2023-01-12 00:32:45 +00:00
Cole Faust
b85d1a15cc Bp2build support for multiple product configs
Create a
build/bazel/product_config/generated/products/<product_name>/BUILD
file that contains the platform definitions needed for
a particular product. Currently we just create it for the
current lunch target, but the idea is that eventually when
all product config is in starlark, all the products will
have their platform definitions in the tree at once.

Bug: 249685973
Test: Presubmits
Change-Id: I08c82ff28dcf62f09d3b1d2e3186a6b961e12f6e
2023-01-05 12:49:14 -08:00
Paul Duffin
58f7784e95 Merge "Stop changes to BAZEL_METRICS_DIR regenerating ninja file" 2023-01-05 18:02:10 +00:00
Paul Duffin
184366a18f Stop changes to BAZEL_METRICS_DIR regenerating ninja file
Bug: 262738679
Test: BAZEL_METRICS_DIR=dir1 m nothing
      BAZEL_METRICS_DIR=dir2 m nothing
      # Make sure that the second does not regenerate the ninja file.
Change-Id: If30f13eee5d27d902c894af04af38078f437b6df
2023-01-04 10:55:20 +00:00
Cole Faust
a734749148 Use WriteFileRule instead of custom echo commands
These instances could use WriteFileRule instead of
making their own shell code to write a file.

Test: Presubmits
Change-Id: I9c809b2164a68b4ce1c22fbbd0d7497240110b39
2023-01-03 14:42:23 -08:00
Colin Cross
62e4fe15dc Merge changes I47b8fdd9,Ifbd121ab
* changes:
  Return linux as host OS from getConfigString when using musl
  Use //build/bazel/platforms/os:linux_glibc for osLinux
2022-12-21 19:33:14 +00:00
Colin Cross
046fcea830 Return linux as host OS from getConfigString when using musl
linux_musl is an alternative host OS, return "linux" from
getConfigString when it is being used.

Bug: 259266326
Test: build/bazel/ci/mixed_libc.sh
Test: USE_HOST_MUSL=true build/bazel/ci/mixed_libc.sh
Change-Id: I47b8fdd93b36345f82dd4e8455edb4c579f805e9
2022-12-20 15:32:18 -08:00
Treehugger Robot
597894279d Merge "mixed builds: add cc_test bazel handler, and add adbd_test to staging allowlist." 2022-12-20 03:12:53 +00:00
Cole Faust
705968d043 Allow exporting bazel mixed build allowlists to simple text files
So that they the allowlists can be read from build_mainline_modules_bundles.sh.

Bug: 262302253
Test: m out/soong/bazel_prod_mixed_builds_enabled_list.txt out/soong/bazel_staging_mixed_builds_enabled_list.txt && cat out/soong/bazel_prod_mixed_builds_enabled_list.txt && echo && cat out/soong/bazel_staging_mixed_builds_enabled_list.txt
Change-Id: Id5f89ebb651a52dc5368681a20d6183703e05bd4
2022-12-15 15:40:36 -08:00
Jingwen Chen
3952a9039e mixed builds: add cc_test bazel handler, and add adbd_test to staging allowlist.
This will allow the test_suites_{arm64, x86_64} CI targets on
git_master-bazel to build adbd_test with bazel in `m`.

This is currently implemented similar to the cc_binary handler to
hydrate the output path field.

The tradefed config is still currently handled by Soong in
testBinary#install, which is called from both ProcessBazelQueryResponse
and GenerateAndroidBuildActions. We'll move the tradefed config path to
a mixed builds handler when it's ready on the cc_test bazel rule side.

Tested with `atest` with cuttlefish. Since `atest` doesn't have a way to pass
--bazel-mode-staging to its internal call to Soong, so I manually tested
this by adding adbt_test to the prod allowlist, and confirmed that the
installed adbd_test is the same binary as the one in bazel-out.

Test: $ showcommands adbd_test | grep bazel-out | tail -n1

```
/bin/bash -c "rm -f
out/target/product/vsoc_x86_64/data/nativetest64/adbd_test/adbd_test &&
cp -f -d
out/bazel/output/execroot/__main__/bazel-out/android_x86_64_silvermont-opt-ST-59d4124ca041/bin/packages/modules/adb/adbd_test
out/target/product/vsoc_x86_64/data/nativetest64/adbd_test/adbd_test"
```

Test: Add adbd_test to prod allowlist and run 'lunch aosp_cf_x86_64_phone-userdebug; atest adbd_test', all tests pass.
Bug: 258426425
Bug: 261692372
Change-Id: I6be329f39d607af8daa1dc772b23e8dd0247418c
2022-12-15 08:01:44 +00:00
Colin Cross
d5c7ddb4df Workaround bazel command too long
Write long bazel commands returned by aquery to a shell script
before executing them to work around command line length limits.

Bug: 261536423
Test: USE_HOST_MUSL=true build/bazel/ci/mixed_libc.sh
Change-Id: Id98a07800df82d1538e6b16b733488a1b9943bf3
2022-12-13 12:40:03 -08:00
Sasha Smundak
dc87f2db0e Streamline NewBazeContext code
Test: treehugger
Change-Id: I707636fef70d35dcb29796d3faed2168bf5adb15
2022-12-06 20:29:28 -08:00
MarkDacek
d06db5dd5b Add command line flag for extra bazel-built modules
Test: m libcore --bazel-mode-staging --bazel-force-enabled-modules=libcore and find out/bazel/ -name libcore*

Change-Id: I065696d06ce07e05300a41e133867a6e7a891b5e
2022-12-02 21:16:11 +00:00
Sasha Smundak
0e87b186cb Print error code when bazel invocation fails
Also, fix compiler warnings about deprecated ioutil.WriteFile/ReadFile
and about redundant variables

Test: treehugger
Change-Id: Iaf8f89b0e991dae8c5da403d4a1ec3a270f1ae29
2022-12-01 13:37:48 -08:00
Treehugger Robot
efc1bc7f2f Merge "Improve mixed builds error messages" 2022-11-28 22:06:21 +00:00
Cole Faust
97d1527dd2 Improve mixed builds error messages
When a target does not have a certain provider we need,
currently we just fail at the dictionary lookup. Change
it so that we fail with a message that tells us what
target had the issue.

Bug: 260131489
Test: Presubmits
Change-Id: I99fd018835c14eba0d4db54ba2769b2da1b278f6
2022-11-22 14:38:24 -08:00
usta
fdb3e34df7 volatile-status.txt to be translated to an order-only dep in build.ninja
Bug: b/260092986
Test: 1. `out/soong/build.ninja` has `bazel-out/volatile-status.txt` as order-only dep 2. `touch Android.bp && m --bazel-mode-staging aapt2` updates bazel-out/volatile-status.txt but aapt2 is not rebuilt

Change-Id: I1fa23437fea14e0d25b68d75010e964dff34766d
2022-11-22 17:12:30 -05:00
Sasha Smundak
4975c82666 Provide Bazel timing breakdown for the mixed builds
Instead of single event in the build metrics
```
| soong_build.mixed_build.bazel          | 1:17.1 |
```
it will now show:
```
| soong_build.mixed_build.bazel          | 1:17.1 |
| soong_build.mixed_build.bazel.cquery   |   51.9 |
| soong_build.mixed_build.bazel.aquery   |   23.1 |
| soong_build.mixed_build.bazel.symlinks |    2.1 |
```

Test: treehugger
Change-Id: I84a7dda6e3122860da9aaa98bfa6afe33d392dcf
2022-11-16 18:44:08 -08:00
Wei Li
cbd181c8e8 Fix the following issues in bazel_handler:
1) Convert coverage path wildcard to regex values for --instrumentation_filter to Bazel.
2) Handle the error properly when aquery commmand returns error.

Bug: 258397103
Test: CIs
Change-Id: Ie7485c2c45f2eb0e1ca0dc60478aae04ab151b61
2022-11-16 08:59:23 -08:00
Liz Kammer
dbb9fe8e92 Merge "Increase testing of request_type" 2022-11-10 13:30:58 +00:00
Treehugger Robot
01dd619766 Merge changes from topic "clang-tidy-mixed-builds"
* changes:
  add tidy files to mixed builds
  add --norun_validations to bazel build action
2022-11-10 01:00:15 +00:00
Liz Kammer
1b7ed9bcbc Increase testing of request_type
Test: go test soong tests
Change-Id: Iacb773a91a4cc097320f06ea1d1669c5923f8076
2022-11-09 11:22:11 -05:00
Chris Parsons
66fc74509f Refactor "staging dep on prod" allowlist dep
This allows branch-specific plugins to more easily add modules to
staging or prod mode allowlists (they need not separately ensure that
staging mode is a superset of prod mode)

Bug: 254447469
Test: TH
Test: Verified that adding tzdata modules via plugin (not part of
this CL) causes many outputs under bazel-out directories

Change-Id: I5d543e262a42cce324c59e3f9880b57ca209c13c
2022-11-08 05:54:19 +00:00
Jingwen Chen
1214001184 Merge "Call rm -rf in mixed build build statement preamble." 2022-11-07 23:03:43 +00:00
Sam Delmerico
658a4da53b add --norun_validations to bazel build action
Validation actions were being run before the build environment was set
up and causing build errors. Turn off validation actions in this phase
because they will be run later in the Ninja invocation.

Bug: 195029134
Test: build/bazel/ci/mixed_libc.sh
Test: verify that Ninja build file contains commands to generate tidy
  files that are generated by these validation actions
Test: delete a tidy file in mixed builds mode, and verify that it is
  rebuilt
Change-Id: I371572d5662913c5637e39c8894eeb6ee53d00ac
2022-11-07 15:58:19 -05:00
Liz Kammer
0e255ef6e6 Add apex_test for mixed builds
Test: go test soong tests
Change-Id: I33327e1fe7d6a4bbf32890d9fbd5453c28a9c5b1
2022-11-07 11:11:37 -05:00
Jingwen Chen
f3b1ec39eb Call rm -rf in mixed build build statement preamble.
https://android-review.git.corp.google.com/q/topic:bazel_using_txt added
a tree artifact output for an action. This CL adds "-r" to the rm calls
to support deleting the old tree artifact outputs.

Test: presubmits
Fixes: 257956807
Change-Id: Ia44b1bef4f8031fe75a239fb162972e8827e3c19
2022-11-07 15:10:04 +00:00
Liz Kammer
be6a712767 Rename ApexCqueryInfo to ApexInfo
cquery is redundant given this is in the cquery package.

Test: go test soong tests
Change-Id: Ib38794b712f548129eec964b8fd85bf8401a5f86
2022-11-04 16:24:37 -04:00
Jason Wu
1cb6739c01 Merge "Rollforward "Use proto output instead of jsonproto output for aquery""" 2022-10-28 14:47:52 +00:00
Jason Wu
118fd2b443 Rollforward "Use proto output instead of jsonproto output for aquery""
Test: use m --bazel-mode-dev and mixed_droid.sh
Bug: 233798334

This reverts commit d27e28c2a7.

Change-Id: Ifd37ac449979330529dd25c92a5eca2f5a80827e
2022-10-27 18:41:50 +00:00
Jason Wu
ab17626ba6 Merge "Revert "Use proto output instead of jsonproto output for aquery"" 2022-10-27 05:24:40 +00:00