Commit graph

59 commits

Author SHA1 Message Date
Cole Faust
b378c18ddf Simplify commandString
Use the same logic for both go and non-go actions. This also has a
slight performance improvement for go actions by allocating the slice
in advance instead of using append()

Test: Presubmits
Change-Id: I92b60c547d8470816a67ac1ef6e334fd5f547701
2023-10-24 10:24:05 -07:00
usta
04525ba886 Remove unused aquery structs
See aosp/I5962b27fe31f7103d2af6cef159f11747cff3ed9
where proto classes were used directly making
these structs unused.

Test: go test soong tests
Test: m nothing
Change-Id: Ib452aaa4ce069d882888fc2556ebf3bf7a94c2ca
2023-10-16 22:51:24 -04:00
usta
c45478190f Skip @bazel_tools// labels from ninja
Since these bazel labels are removed from depsets anyways,
there is little reason to convert they to ninja build statements

Test: m nothing (with bazel af426041)
Bug: 301638491
Change-Id: Ie920477231d147d0b5b7dbcd1c59ed9985a80abb
2023-09-28 16:03:15 +00:00
usta
a79afd7efa Include label in aquery error
When an Action fails to convert to a Ninja build statement,
include the bazel label in the error message.

Test: NA
Bug: 301638491
Change-Id: I592978c5e530043769b0232fdd200ad13b72c39b
2023-09-22 17:31:32 -04:00
Cole Faust
bdee8f91f3 Don't allow tree artifacts in mixed builds
Tree artifacts aren't fully correct in incremental builds with ninja,
so add a check that we don't write rules using them.

Bug: 293609369
Test: m nothing
Change-Id: I2e49cb6ec24124baf00adb0860f3c1f1f80178bb
2023-09-07 14:28:51 -07:00
Cole Faust
20f2030e29 Use aquery results to determine if a file should be executable
Now that aquery includes this information.

Also added rm -f $out to some rules, because since they write files
by shell redirection, if the file existed before and was executable,
they wouldn't make the file non-executable and visa versa.

Fixes: 297366783
Test: m bazel_sandwich
Change-Id: Ie5b6c4275b162601f51deaec9912eea4be16988d
2023-08-31 11:00:25 -07:00
Cole Faust
bc65a3fea8 Revert^2 "Initial implementation of the bazel sandwich"
c13fad8181

Change-Id: I478562c8fd89e62983feb5b52b62aad851d40f00
2023-08-01 10:27:57 -07:00
Jooyung Han
09195f4ffd Merge "Revert "Initial implementation of the bazel sandwich"" into main 2023-08-01 06:50:25 +00:00
Jooyung Han
c13fad8181 Revert "Initial implementation of the bazel sandwich"
Revert submission 2651299-bazel_sandwich

Reason for revert: b/293883239, checking if this breaks the build.

Reverted changes: /q/submissionid:2651299-bazel_sandwich

Change-Id: I5f1d4bb13d21e6599f5c353dcaba2375f5ec234d
2023-08-01 05:15:17 +00:00
Treehugger Robot
61a27f80cd Merge "Initial implementation of the bazel sandwich" into main 2023-07-31 23:00:55 +00:00
Cole Faust
a20d947329 Initial implementation of the bazel sandwich
The "bazel sandwich" is a mechanism for bazel to depend on make/soong
outputs. The name comes from the fact that bazel is now at the top
and bottom of the build graph. This is intended to allow us to work
on converting the partition builds to bazel while not all of the
dependencies of the partition have been converted.

It works by adding the bazel_sandwich_import_file rule, which emits a
dangling symlink that starts with bazel_sandwich:, and includes
information that the aquery handler in soong reads. The aquery handler
rewrites the symlink so that it points to a file generated by
make/soong, and adds a ninja dependency from the symlink to the file
it's targeting.

This allows us to depend on make-built files from bazel, but notably
it doesn't allow us to depend on analysis-time information from make.
This shouldn't be a problem for the partitions, but limits the use of
the bazel sandwich to similar, less complicated types of builds.

go/roboleaf-bazel-sandwich

Bug: 265127181
Test: m bazel_sandwich
Change-Id: Ic41bae7be0b55f251d04a6a95f846c50ce897adc
2023-07-31 11:53:41 -07:00
Spandan Das
2d93ebba11 Add GoStdlib mnemonic for special handling of ''
This mnemonic has '' args, which would become literal empty when
combined by strings.Join. To prevent this, add it to the
special-handling function.

Bug: 284483729
Test: N/A
Change-Id: Ibd3c3ebc55284882e7336487319070b9710076d3
2023-07-28 03:07:28 +00:00
Cole Faust
1c535124d5 Merge "Revert "Add workaround for a file with an mtime in the future"" into main 2023-07-22 04:01:59 +00:00
Romain Jobredeaux
e3989a114d Revert "Add workaround for a file with an mtime in the future"
This reverts commit e9ae480a82.

Reason for revert: Should no longer be needed after https://android-review.git.corp.google.com/q/topic:%22use_vendored_java_rules%22

Change-Id: Ic3abed3c27fe4669df811b993d87ae5450c79d7e
2023-07-19 20:58:27 +00:00
Spandan Das
958ca02582 Merge changes from topic "build_go_source_mixed_builds" into main
* changes:
  Delete aliases to prebuilts
  Add functionality to sandbox mixed build actions
2023-07-19 17:21:25 +00:00
Cole Faust
e9ae480a82 Add workaround for a file with an mtime in the future
Bug: 291828210
Test: `m` repeatedly, and see ninja say there's no work to do on the second run
Change-Id: I0e1e5a82ebd25e9eec5daea90eb72db0ac085f34
2023-07-18 19:36:41 -07:00
Spandan Das
af4ccaaf41 Add functionality to sandbox mixed build actions
The use case for this is for building rules_go's root builder which runs
into issues when built in a directory that contains a symlink to
prebuilts/go

The implementation will involve two changes of working dir
- `sbox` to change the working directory to
__SBOX_SANDBOX_DIR__
- the generated manifest will change the working
directory to mixed build execution root relative to that

Implemenation details
1. Create a unique intermediate path by hashing the outputs of a buildAction.
   "out/bazel/output/execroot/__main__/" was deliberately not chosen as
   the outpuDir for the sandbox because ruleBuilder would wipe it.
   `sbox` will generate the files in __SBOX_SANDBOX_DIR__ and then place
   the files in this intermediate directory.
2. After the files have been generated in (1), copy them to
   out/bazel/output/execroot/__main__/...
3. For bazel depsets that are inputs of an action, copy the direct
   artifacts into the sandbox instead of the phony target
4. Make sandboxing an opt-in. Currently we will only use it for
   `GoToolchainBinaryBuild`

In the current implementation, (3) will increase the size of the ninja
file. With sboxing turned on for only GoToolchainBinaryBuild, this will
increase the size of the ninja file by around 1.3% on aosp's cf

Test: m com.android.neuralnetworks (will build soong_zip from source
using rules_go)
Test: OUT_DIR=out.other m com.android.neuralnetworks
Bug: 289102849

Change-Id: I7addda9af583ba0ff306e50c1dfa16ed16c29799
2023-07-14 00:43:52 +00:00
Cole Faust
950689a9c2 Handle RepoMappingManifest actions
These are essentially FileWrite actions, like SourceSymlinkManifest.

However, currently aquery appears to give non-deterministic results
for the file content. Emit an empty file for now to avoid the
non-determinism.

Fixes: 288292933
Bug: 287539324
Test: Presubmits
Change-Id: Ieaf8aff0d58d2d69087e4e34dc99074a015e700c
2023-07-06 09:44:14 -07:00
Spandan Das
da724863da Respect '' received from aquery
GoCompilePkg action's aquery results contains ''. e.g (the interesting
ones)
```
/bin/bulder ... -embedroot '' -gcflags '' -asmflags ''
```

strings.Join would cause it to appear as a whitespace and cause issues.
(in ninja without this CL)
```
/bin/builder ... -embedroot  -gcflags  -asmflags
```

Convert the empty literal to '' before strings.Join

To limit inadvertent side-effects, this limits it to GoCompilePkg mnemonic

Test: TH
Change-Id: I67161c194dabac6f857ff49b85d4b2471970a9b2
2023-06-23 04:25:32 +00: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
Liz Kammer
00629db646 Use aquery proto directly
This prevents unnecessary copies of data from the query by using a
pointer to the proto or its contents

Test: go test soong tests
Test: m nothing
Change-Id: I5962b27fe31f7103d2af6cef159f11747cff3ed9
2023-02-15 11:29:47 -05:00
Liz Kammer
f15a0797c0 Only create a command line replacer once
Test: CI
Change-Id: Ibb9b822aea808c936fedc4c8fea7b7d787b101d5
2023-02-14 11:10:20 -05: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
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
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
d27e28c2a7 Revert "Use proto output instead of jsonproto output for aquery"
This reverts commit 6fe8721e12.

Reason for revert: Broke aosp_kernel-build-tools/linux

Change-Id: I502ec4c275cbc56e1024a42fadf68b308750939d
2022-10-27 05:18:40 +00:00
Jason Wu
6fe8721e12 Use proto output instead of jsonproto output for aquery
Test: use m --bazel-mode-dev and mixed_droid.sh
Bug: 233798334
Change-Id: Ib945359d3d05e6f51afe70432ec380e4e584175b
2022-10-26 17:07:48 -04:00
Colin Cross
d079e0b270 Reformat build/soong for go 1.19
Test: none
Change-Id: I132368f0fcbdb5ea088b5b84dbe4ccfdd9e94cad
2022-08-17 10:43:13 -07:00
Sasha Smundak
fe9a5b833d Implement mixed builds for apex modules, take 2.
* Add ApexCqueryInfo to obtain apex artifacts used by the makefile
  generator and downstream modules
* Refactor code common to GenerateAndroidBuildActions and ProcessBazelQueryResponse
* Implement android.MixedBuildBuildable for modules
* Enable mixed build for apex modules with payload_type:"image"

The first take 6a2b7c40b was setting compressed APEX suffix incorrectly, and
was reverted in 8a3c91494.

Fixes: 239925080 239695521 232085015
Test: treehugger
Change-Id: I1720f8db3c7cc773183d25a815d9b7eeaf7c73ad
2022-07-28 14:43:50 -07:00
Martin Stjernholm
8a3c914942 Revert "Implement mixed builds for apex modules."
Revert submission 2147387-mixed_builds

Reason for revert: Breaks zipapex build on git_master-art-host
Bug: 239925080
Reverted Changes:
I9f1e03e5e:Implement mixed builds for apex modules.
I13d9a0270:Add container and bundle encription key pairs to t...

Change-Id: I0eaad4dd81cac16d634f4c9cec18137a38e30d47
2022-07-26 09:35:39 +00:00
Sasha Smundak
6a2b7c40b3 Implement mixed builds for apex modules.
* Add ApexCqueryInfo to obtain apex artifacts used by the makefile
  generator and downstream modules
* Refactor code common to GenerateAndroidBuildActions and ProcessBazelQueryResponse
* Implement android.MixedBuildBuildable for modules
* Enable mixed build for apex modules with payload_type:"image"

Bug: 232085015
Test: treehugger
Change-Id: I9f1e03e5e7a5b5dde35a5db10c253069543ac973
2022-07-18 13:34:36 -07:00
Sasha Smundak
c180dbd4c7 Handle SymlinkTree action, ignore PythonZipper action.
Introduce bazelBuildRunfiles to build runfiles symlink tree, allowing to
ignore a bogus PythonZipper action.

Bug: 232085015
Test: treehugger
Change-Id: I81267f523d8237fddbc7d65955cdd08ea6369046
2022-07-06 11:30:40 -07:00
Sasha Smundak
1da064c1e6 Handle WriteFile and SourceSymlinkManifest actions.
Plus minor editorial changes.

Bug: 232085015
Test: treehugger
Change-Id: I966e9d6d306382dbb8eac6f8a495a2f152c7a22e
2022-07-06 11:30:40 -07:00
Usta Shrestha
ef92225a67 null build upon repeated mixed build
no implicit deps on bazel-tools

Test: USE_BAZEL_ANALYSIS=1 ../bazel/ci/incremental_mixed_build.sh
Bug: b/216194240
Change-Id: Ibbd87c6a6cc2fddf21fba37a6bb4e72adc209576
2022-06-28 15:37:12 -04:00
Usta Shrestha
16ac13506e cosmetic changes
Test: m nothing
Bug: N/A
Change-Id: Ia74a09a6ee42560562e2e1a15e972860e77a5724
2022-06-22 11:02:43 -04:00
Yu Liu
57c1edc4d9 Merge "Support cc code coverage for mixed build" 2022-06-13 18:57:50 +00:00
Yu Liu
8d82ac58b4 Support cc code coverage for mixed build
Bug: 231322627
Test: Manual tests and unit tests
Change-Id: I786042af0d612192c54c3572f63a86a47174a242
2022-06-06 12:29:25 -07:00
Usta Shrestha
2ccdb42098 minor dead code: unused format string
Using URL base64 encoding
(without padding, i.e. with trailing '=' or '==')
hash string width is 256/6 = 43 characters.

file size virtually unchanged,
  out/soong/build.ninja:  7,188,669,041 => 7,186,999,370 ie 1.6M

Bug: N/A
Test: manually verified (e.g. ran `m nothing` successfully)
Change-Id: I166d613e1fd857555da9611d420d6691806571c7
2022-06-02 11:37:20 -04:00
Usta Shrestha
6298cc5e67 cosmetics: readability
Note go.mod file changes go version to 1.18 (for generics)
You might need to refresh/reload your IDE (e.g. IntelliJ)

Bug: N/A
Test: manually verified (e.g. ran `m nothing` successfully)
Change-Id: I2a6dadd673fd170961d1fd1e1756f7581e9a1091
2022-05-31 21:39:06 +00:00
Usta Shrestha
c23724905b cosmetic: name receiver consistently
see go/go-style/decisions#receiver-names

Bug: N/A
Test: N/A
Change-Id: Ifee42ff66cdb4db024a82ebd03cdee1c6d4fb5f7
2022-05-27 10:59:02 -04:00
Trevor Radcliffe
ef9c900ec3 Generate genlex rules from bp2build for cc targets
This change will cause bp2build to generate genlex targets any
time a .l or .ll file is present in the srcs for a cc target and
add those genlex targets to the srcs attribute of the original
target.

Bug: 207408632
Test: unit tests
Change-Id: I1bce82c9d3c3d458eae1cef547ffae3d6e975134
2022-05-24 14:42:51 +00:00
MarkDacek
7564127cf2 Grammar nit.
Test: N/A

Change-Id: Ied10037b662cd49573680d392cddd11b628618ff
2022-05-13 20:44:07 +00:00
Chris Parsons
0bfb1c0556 Deterministic aquery details in mixed builds
This change constitutes a number of fixes which cause mixed builds to
have deterministic ninja file output:

1. Depsets are identified based on a hash of their contents instead of
   an arbitrary ID integer from Bazel
2. Depset definitions in the ninja file are sorted by the above hashes
3. BuildStatements (action information from Bazel's aquery) are sorted
   by their contents

Test: Ran `USE_BAZEL_ANALYSIS=1 m nothing` three times and verified the
md5sum of out/soong/build.ninja was identical all three runs.
Test: mixed_droid

Change-Id: Iffdf6cc62c31d76fbbfa78726827497516171f4f
2022-05-13 13:45:56 -04:00
Chris Parsons
1a7aca075b Preserve depset structure from bazel aquery
Each depset now corresponds to a phony rule which depends on other
depsets or on full paths; thus, bazel's depset structure is preserved in
the form of phony rules of name bazel_depset_{id}.

Previously, flattening and recopying large lists of file path strings
was quite inefficient. This was particularly evident as we enumerated
hundreds of clang headers for each cc compile action.

This reduces soong_build analysis time by about 30% for mixed builds.
It also reduces ninja file size by ~750MB.

Fixes: 229405615
Test: Unit tests, manually verified metrics, mixed_droid CI

Change-Id: I78df152ac1488ae0c6807afdde4b4ad5e6d26287
2022-04-28 12:44:28 -04:00
Liz Kammer
c31929962b Quote aquery commands.
Bazel run shell actions begin `bin/bash -c <command>`, without escaping,
the command can be treated as an argument to `bin/bash`.

Test: build/bazel/mixed_droid.sh
Change-Id: I423cb393da2e6ac97448ec77b2596f12670dfd31
2021-11-16 17:31:05 -05:00
Wei Li
455ba83a94 Fix the output handling of Bazel aquery for py_binary targets so soong's python_binary_host modules can be converted to py_binary and built with Bazel dependent targets in mixed build.
Test: USE_BAZEL_ANALYSIS=1 m genfunctosyscallnrs
Test: USE_BAZEL_ANALYSIS=1 m func_to_syscall_nrs
Test: USE_BAZEL_ANALYSIS=1 m libseccomp_policy
Bug: 201094425
Bug: 197135289
Bug: 204949078
Change-Id: If98630830d687ca814d6ae09c1e610f2c3a371b1
2021-11-16 20:49:28 +00:00
Liz Kammer
c773778bfe Make bazel action symlinks absolute paths
hardlinks are incompatible with sandboxing
relative links are incopatible with Soong's use of `cp -d`

Test: build/bazel/ci/mixed_libc.sh
Change-Id: I8c776cda6a27c680c51466d9a7af1b499f2f566d
2021-11-04 12:42:52 -04:00
Rupert Shuttleworth
ffc4cc41a3 Revert "Fix python_binary_host module in mixed build."
Revert submission 1861755-fix_python_binary_host_in_mixed_build

Reason for revert: Broke Bazel CI, please see https://android-build.googleplex.com/builds/submitted/7879108/mixed_droid-clean/latest/view/logs/build_error.log and https://android-build.googleplex.com/builds/submitted/7879108/mixed_droid-incremental/latest/view/logs/build_error.log
Reverted Changes:
Ica457ee71:Add platform needed by python_binary_host.
Ibc8b99a92:Fix python_binary_host module in mixed build.

Change-Id: I3d6c4f6edee2d00bdc78efd5cee64f4c915baeaa
2021-11-03 09:07:26 +00:00
Wei Li
664a4fd0af Fix python_binary_host module in mixed build.
Test: USE_BAZEL_ANALYSIS=1 m genfunctosyscallnrs
Test: USE_BAZEL_ANALYSIS=1 m func_to_syscall_nrs
Test: USE_BAZEL_ANALYSIS=1 m libseccomp_policy
Bug: 201094425, 197135289

Change-Id: Ibc8b99a92149410c8a879b7a4facf6c8961a7b9f
2021-11-02 17:04:38 +00:00
Chris Parsons
d80b3c8218 Use hardlinks for Bazel's symlink actions
This prevents failures resulting from using `cp -d` on symlinks.

Test: USE_BAZEL_ANAYSIS=1 m adbd
Change-Id: Ic1756ffe407df81b0e99f99c50bee6af4ecf7796
2021-10-14 15:24:05 -04:00