Commit graph

208 commits

Author SHA1 Message Date
Joe Onorato
8ad2b88c8d Add new soong module debug info json.
Enabled by setting GENERATE_SOONG_DEBUG=true

Test: GENERATE_SOONG_DEBUG=true m nothing ; soongdbg ...
Change-Id: If70c7d91cc59a5a7642e453c85278e8022693ac7
2024-02-03 14:37:02 -08:00
Cole Faust
7add62142d Enforce that providers are not changed
When setProvider() is called, hash the provider and store the hash in
the module. Then after the build is done, hash all the providers again
and compare the hashes. It's an error if they don't match.

Also add a flag to control it in case this check gets slow as we convert
more things to providers. However right now it's fast (unnoticable
in terms of whole seconds) so just have the flag always enabled.

Bug: 322069292
Test: m nothing
Change-Id: Ie4e806a6a9f20542ffcc7439eef376d3fb6a98ca
2024-01-30 15:18:24 -08:00
Cole Faust
ef75beb068 Add implicit inputs to primary builder actions
This is needed so primary builder actions can directly depend on their
glob result files.

Bug: 318434287
Test: rm -rf out && m nothing && m nothing
Change-Id: I5c67ee53c9f18f81c79c0fe13b3338eacaccdbc0
2024-01-02 16:58:49 -08:00
Colin Cross
ed49204e85 Use generics for providers API
Using generics for the providers API allows a type to be associated
with a ProviderKey, resulting in a type-safe API without that doesn't
require runtime type assertions by every caller.

Unfortunately, Go does not allow generic types in methods, only in
functions [1].  This prevents a type-safe API on ModuleContext, and
requires moving the API to be functions that take a ModuleContext as
a parameter.

[1] https://go.googlesource.com/proposal/+/refs/heads/master/design/43651-type-parameters.md#no-parameterized-methods)

Bug: 316410648
Test: provider_test.go
Change-Id: Ide91de9f2a2a7d075b05e287c7cc86b395db0edb
2023-12-14 16:59:16 -08:00
Aditya Choudhary
a992d06f60 Create src file provider in build/blueprint
Change-Id: I7091effe7791c1f3ea57e775b37cd72f4ee13d03
2023-12-05 07:14:29 +00:00
Colin Cross
95bec3331c Use strings instead of simpleNinjaStrings where possible
Storing every string without ninja variable references through
simpleNinjaString costs 24 bytes and a heap allocation.  16 bytes
is used for the ninjaString.str string, 8 bytes for the
ninjaString.variables *[]variableReference.  An additional 8 bytes
is used for the resulting pointer into the heap.

The vast majority of calls to simpleNinjaString originate in
blueprint.parseBuildParams, which converts all of the parameters
passed to ctx.Build into ninjaStrings.  All together this was
allocating 1.575 GB of *ninjaString objects.

Add a parseNinjaOrSimpleStrings function that converts input strings
into ninjaStrings if they have ninja variable references, but also
returns a slice of plain strings for input strings without any ninja
variable references.  That still results in 1.39 GB of allocations just
for the output string slice, so also add an optimization that reuses
the input string slice as the output slice if all of the strings had
no variable references.

Plumb the resulting strings through everywhere that the []*ninjaStrings
were used.

This reduces the total memory allocations inside
blueprint.parseBuildParams in my AOSP aosp_cf_x86_64_phone-userdebug
build from 3.337 GB to 1.786 GB.

Test: ninja_strings_test.go
Change-Id: I51bc138a2a6b1cc7383c7df0a483ccb067ffa02b
2023-11-01 15:15:15 -07:00
Colin Cross
0065131f50 Always generate rules for blueprint tests
Generate the rules to build and run the blueprint tests whether or
not running the tests during bootstrap is enabled, and only add them
as validation dependencies if running the tests is enabled.  Export
the outputs of the tests as a phony target for checkbuild to depend on.

Bug: 269296618
Test: m nothing
Test: aninja -t path checkbuild out/host/linux-x86/bin/go/soong-java/test/test.passed
Change-Id: I09cd20d802bed5a659f3f36e87128d4281dfcfb0
2023-10-24 11:05:56 -07:00
Spandan Das
6a3475adf5 Add a testdata property in goPackage and goBinary
Some go tests depend on testData, but do not declare it explicitly. In
preparation for the stricter sandboxing constratints imposed by Bazel,
introduce this property.

This will be a no-op in Soong for now. But bp2build will convert it into
`data` property of go_test

Test: go build ./blueprint/bootstrap
Bug: 288491147
Change-Id: I0e1e7941db1efe6f1488936d9bae7e8d295b88ba
2023-06-23 00:15:44 +00:00
Spandan Das
4e84d6b010 Export goPackage and goBinary from bootstrap package
These two module types will be special-cased in bp2build. To enable this
special-casing, export from the package alongwith getter methods to
access its properties.

Test: go build ./bootstrap

Change-Id: I9ef7ac4b6331fec99713296f8f78f614f3536847
2023-06-22 23:50:02 +00:00
Treehugger Robot
f99595ba0d Merge "Helper function to register go module types in tests" 2023-06-21 20:07:28 +00:00
Lukacs T. Berki
2cd5fe6206 Make RunBlueprint() return an error, if need be.
This is so that it doesn't need to abruptly call os.Exit(), denying
callers the opportunity to do cleanups.

Bug: 244730498
Test: Presubmits.
Change-Id: Ifd191d3bbbf2fdea2ca49e4fb552e5d1c557b80f
2023-06-20 09:44:50 +00:00
Spandan Das
c5db2df213 Helper function to register go module types in tests
These two module types will be special-cased in bp2build generation
logic in build/soong. To write bp2build tests, create a helper function
to register these two module types

Test: go build ./bootstrap
Change-Id: If6abd8c8911a525bf6841b199d8ce204941d7bcb
2023-06-14 17:44:07 +00:00
LaMont Jones
12ccb17d4e context: Allow running some singletons in parallel.
Many of the singletons are trivial and can be run in parallel, improving
the performance during analysis.

Bug: 281536768
Test: manual, presubmit
Change-Id: Ia63e4bc42a68e65dfa800e770982fa5826355fad
2023-05-19 19:03:08 +00:00
Kevin Dagostino
ad7bcc7b50 Enable parallelCompile since golang is now >= 1.9
Test: m nothing
Change-Id: I38cdd83ca9b17263155433abb65fb4f97b5ec70b
2023-03-03 21:57:29 +00:00
Usta Shrestha
ce85ecb176 cosmetic: readability
Test: run `m nothing` and `m nothing --empty_ninja_file`
Bug: NA
Change-Id: I6fd81667ea2d636139ae38bc36315f8710b72c25
2023-02-23 02:27:26 +00:00
Chris Parsons
58a29728ea Close ninja file descriptor
With this close() missing, especially with large ninja files, soong paid
the runtime cost at arbitrary times during the rest of its execution (or
during process cleanup).

Test: Manual runs of `m nothing` and verifying timing metrics
Change-Id: Ibdfbf7371cfc4c58c485e76f96b8e9b9ad900972
2023-02-08 23:33:56 -05:00
Treehugger Robot
a405cf7f6a Merge changes I516c984b,I2b3354de
* changes:
  comment on how glob files are written
  cosmetic: use map[_]struct{}  for set semantics
2022-12-21 15:44:42 +00:00
Usta Shrestha
f0e02237da comment on how glob files are written
Bug: NA
Test: NA
Change-Id: I516c984b62d07ca7f188b2faef1466c5720b3b22
2022-12-21 01:04:19 -05:00
Sasha Smundak
08343b7a89 bootstrap.Args should contain only relevant command line arguments
Soong/Bazel-specific arguments are now kept in Soong.

Test: treehugger
Change-Id: If37bc6ea60b58173baa981bb5c85bfc90102005c
2022-12-14 10:27:31 -08:00
Spandan Das
c3887c2bbb Merge "Conditional inclusion of blueprint modules" 2022-12-05 23:50:23 +00:00
Spandan Das
ed4af01be6 Conditional inclusion of blueprint modules
This introduces a new `blueprint_package_includes` module type. If
present, other blueprint modules in that file will be analyzed
if and only if the requested include tags are met

example syntax:
```
Android.bp
blueprint_packgage_includes {
  match_all: ["tag1", "tag2", ...],
}

other_module1 {...}
other_module2 {...}
```
other_module1 and other_module2 will not be analyzed unless
tag1,tag2, ... are set

This also adds a new object of type `IncludeTags` to the Context object,
which is a container for these string keys.

Test: In build/blueprint, go test ./
Test: TH

Change-Id: I79de0d7da3224a5b2025c27a5137f39d00c7382e
2022-12-02 01:46:28 +00:00
MarkDacek
99f7962b35 Add bazel-force-enabled-modules.
Test: m nothing
Change-Id: I97d8fcb304f0d039fd7bbd3ea3d01966ae25471f
2022-12-01 20:15:33 +00:00
Colin Cross
1b457a5e10 Add VariableFuncContext argument to VariableFuncs
Add a VariableFuncContext argument to VariableFuncs that implements
GlobWithDeps.  This will allow Soong to use optimized glob dependencies
in VariableFuncs.

Bug: 257079828
Test: no dependencies on directories in build.ninja.d
Change-Id: Iee5fc9c9ae3087662a5d1a3d7323a87462299205
2022-11-04 18:21:31 +00:00
Lukacs T. Berki
0acaefea0d Add order-only inputs for primary builder.
Test: Presubmits.
Change-Id: Iefe729f6874c1154c94d10563fb2fac3dc03049a
2022-10-27 08:05:27 +00:00
MarkDacek
c5e959b244 Add staging mode to soong build.
This is to build bazel targets that are nearing readiness for prod mode.

Bug: 254265047
Test: m nothing
Test: m nothing --bazel-mode-dev
Test: m nothing --bazel-mode-staging
Change-Id: Ie8336ec4ad70c0c9bd6d74f3b0a278c85fd5df2d
2022-10-18 20:35:45 +00:00
usta
71ce3eae12 cosmetic: fail fast on empty module list
also minor refactoring to limit var scopes

Test: m nothing and ensure ninja files are generated
Bug: N/A
Change-Id: If7bdede4e54687955896b03ab11ef771855d2225
2022-09-20 05:15:24 +00:00
usta
83ede83a31 cleanup: remove deprecated module ioutil
Test: m nothing and check bootstrap.ninja and build.ninja file
Bug: N/A
Change-Id: I8c2f2d8cb452955921b2287ec2c621909ebde5e4
2022-09-20 05:13:27 +00:00
Chris Parsons
a034bea7e9 Add bazelmode and bazelmodedev as command args
Test: See attached topic CLs
Change-Id: I7a6290702f6cd721ef5f67e885b3dfc4b98edeb0
2022-08-19 11:35:54 -04:00
Chris Parsons
91f638f692 Support pre-build-action hook in blueprint
This allows for a bazel-invocation hook in mixed builds, which allows
for mixed builds to take place in only a single pass, greatly improving
its performance and complexity.

Test: Conjunction with build/soong CL
Change-Id: If89fb56830b4eb06d3263d6ca6da7b285e7ba315
2022-05-10 13:46:40 -04:00
Chris Parsons
18ebb2318a Add event handling to blueprint for metrics
In conjunction with soong/build changes, this materialized runtime
metrics for various soong_build events.

Test: Manually verified materialized protos for bp2build, mixed builds,
and legacy build.

Change-Id: Ia92403605e3063028dbf6a1ded8449c190b9e63e
2022-03-25 13:15:17 -04:00
Usta Shrestha
62823dcf01 use iota for "enum"
Test: m nothing
Bug: N/A
Change-Id: I9d59796cbf1dc3dc8e1e9fc536b50c1dea3a5f61
2022-01-18 16:51:12 -05:00
Lukacs T. Berki
a67610a75f Allow soong_ui to set env vars for soong_build .
This is used to make GODEBUG=asyncpreemptoff=1 only be set in debug mode
so that production is not affected.

Test: Presubmits.
Change-Id: Idb15ad20bb74ba3f896699715e3208c1287a5e82
2022-01-05 10:29:48 +01:00
Lukács T. Berki
1a1ec4b59c Merge "Set GODEBUG=asyncpreemptoff=1 for soong_build." 2022-01-05 09:06:19 +00:00
Lukacs T. Berki
3dab5143bd Allow specifying the pool for soong_build calls.
Test: Presubmits.
Change-Id: Iff0edf595b1868ccdda4ea6391c1057e0f86cd9b
2022-01-04 14:49:54 +01:00
Lukacs T. Berki
635fc35a09 Set GODEBUG=asyncpreemptoff=1 for soong_build.
This makes debugging with Delve much faster, sometimes by an order of
magnitude because Delve does not have to deal with the many SIGURG
signals that are used to stop preempted goroutines this way.

This could in theory result in a performance loss, but running
`rm -f out/soong/build.ninja; time m nothing` five times demonstrated no
change in the execution time.

Test: Presubmits + performance testing as described above.
Change-Id: I438564bcaf70d2a50147cf54cdfac6dcfe925ce5
2022-01-04 12:37:24 +01:00
Jingwen Chen
8e7786a0fd Forward descriptions to primary build invocations.
Test: m nothing bp2build json-module-graph queryview soong_docs
Change-Id: Ic64238dc10a90c923cf5559d1bbbc51fd0922e31
2021-12-06 13:30:18 +00:00
Lukacs T. Berki
6fbc68d41d Move bpglob to outside of the Ninja action graph.
It's in reality built by Microfactory quite early in the build which
takes care of incrementality in bpglob itself.

Test: Presubmits.
Change-Id: I066a6e85f48e9cfec4efd46cb1f615c68b806080
2021-11-10 12:37:55 +01:00
Trevor Radcliffe
0bf636f3ef Merge "Change bpdoc to separate entries with the same type" 2021-11-05 16:11:23 +00:00
Lukacs T. Berki
f12f1d7d1e Remove the -v argument from bpglob.
Now that we have bootstrapEpoch, it's not necessary anymore.

Test: Presubmits.
Change-Id: If36cf3c8f71c1023003f408b4e799bbbdba6fa27
2021-11-04 11:48:43 +01:00
Trevor Radcliffe
d14f342fa6 Change bpdoc to separate entries with the same type
Presently, entries in the Soong reference docs that
share the same type are condensed into a single entry.
This is very unintuitive, so this change removes that
functionality.

Fixes: 204441523
Test: bpdoc_test.go
Test: build and compare Soong docs
Change-Id: Ic03891a8a7a29b5f7ee58c01b2fa05a0c27e0a2b
2021-11-02 15:59:48 +00:00
Colin Cross
37d151ff95 Move bpglob out of ToolDir
ToolDir is going to become unstable when switching between KatiEnabled
and Soong-only builds while the duplication between out/soong/host and
out/host is resolved.  bpglob gets executed very early during bootstrap,
before the primary builder has run to update the paths to match the
current configuration.  Move it into SoongOutDir() so that its path
is more stable.

The copy of bpglob in ToolDir is still used when bpglob is used by the
primary builder through bootstrap.GlobFile.

Bug: 204136549
Test: m nothing
Change-Id: Ida51997b6408d7c265f3ba343278e5e2968467d3
2021-11-01 22:54:02 -07:00
Spandan Das
1109cd96b7 bpdocs for struct types created using reflection
struct types defined using reflection have empty PkgPaths(), due to
which they were not added to the generated bpdocs. This CL allows
us to generate bpdocs for such struct types.

For each field in the struct, the algorithm checks the following and
creates a PropertyStruct object accordingly
1. If field is a primitive type (Base condition)
2. If field is another exported struct (Base condition)
3. If field is another struct created using reflection (Recurse)

Test: m soong_docs
Test: java_sdk_library_import before
https://ci.android.com/builds/submitted/7710820/linux/latest/view/java.html#java_sdk_library_import
and after
https://spandandas.users.x20web.corp.google.com/docs/java.html#java_sdk_library_import
Bug: 172797653

Change-Id: I0349e405fd290d427fa0b38a109b4212aace50c6
2021-09-20 22:33:05 +00:00
Lukacs T. Berki
d9d298c760 Remove UseValidationsForGoTests.
Whenever it was called, it returned true.

Test: Presubmits.
Change-Id: Iabe5a99b8363771d06b200d4641d9ce477ba5b6e
2021-09-08 15:32:52 +02:00
Lukacs T. Berki
5d5ed5fc6b Remove PrimaryBuilderExtraFlags and cull Args.
PrimaryBuilderExtra flags was only used from soong_ui and has nothing to
do with Blueprint files or modules and Args contained a lot of members
that were likewise only used for plumbing withing soong_ui or for
command line processing for soong_build.

Test: Presubmits.
Change-Id: Ibf009e446b4044309a331592a88a4aa86b4801e3
2021-09-08 09:35:56 +02:00
Lukacs T. Berki
70d6564d7d Prefix file names with ctx.SrcDir() in docgen.
This is because docgen will be called from the bootstrap Ninja file with
cwd == /.

Side cleanup: remove an unused template.

Test: Presubmits.
Change-Id: Ia5ff10247becbabc7a76c21f4ed05d654a7b20c3
2021-09-08 09:34:56 +02:00
Lukacs T. Berki
a9768e1ad7 Pass StopBefore as an argument to RunBlueprint.
Its value is a function of the call site, so it doesn't make a lot of
sense to plumb it through the configuration.

Test: Presubmits.
Change-Id: I5081650818664f283ebc5dc04daef90c26759353
2021-09-07 18:12:29 +02:00
Lukacs T. Berki
f99e89c147 Remove ConfigRemoveAbandonedFilesUnder.
It was not implemented by anyone.

Test: Presubmits.
Change-Id: I8b98620c0ef9c1f242fe7fc0a7d810f2af15d042
2021-09-06 11:35:28 +02:00
Lukacs T. Berki
9b435b8089 Make cmdline args consistent with what they do.
Test: Presubmits.
Change-Id: I6d5f827e06526a121f915aae57c6f086ba44f21d
2021-09-02 13:29:10 +02:00
Lukacs T. Berki
d782b504e0 Remove the bootstrap.Config class.
It was confusing because there are two concepts with the same name:
thebootstrapping config special-cased in the bootstrap modules /
singletons and the "global" config.

This change folds the first into the second.

A further next step would be to split the Go parts and the Ninja parts
(subninjas + primary builder invocation) apart, but at some point, I
should stop gold-plating this.

Test: Presubmits.
Change-Id: Id341dee664a9d2527535f4f9980e5f0d10139eef
2021-09-02 09:58:45 +02:00
Lukacs T. Berki
ceb3c43f65 Simplify bootstrapping:
- Remove the bootstrap_go_binary module type in favor of
blueprint_go_binary
- Make it so that all the binaries used during bootstrapping are in the
host tool directory so that the bootstrap and main Ninja files are
consistent

Test: Presubmits.

Change-Id: I00744fec0474fbea89db6c0c0338856453138564
2021-09-01 11:55:00 +02:00