Commit graph

2803 commits

Author SHA1 Message Date
Colin Cross
dbf18bec98 Optimize deduplicateOrderOnlyDeps
keyForPhonyCandidate was using sha256, which is a crypto hash and
unnecessarily expensive for this use case.  hash/maphash would be
much faster because it implements WriteString and so doesn't cause
an extra allocation to copy to a byte slice for every write, but it
insists on randomizing the seed, which makes it unsuitable for writing
to the build.ninja file.  Use hash/fnv instead, and use unsafe to
write strings to the hash to avoid the extra allocation.

Also replace the manually rolled parallelism with the existing
parallelVisit, which will reuse goroutines and limit the parallelism
to a useful value.

The hash could collide, and using a 64-bit hash makes that more
likely, so also check the full contents to make sure they are really
equal.

Cuts 1 second off Soong analysis time.

Test: SOONG_PROFILE_MEM=/tmp/mem.pprof m nothing
Change-Id: I4d1292cb158cfc5823a0f4d8b4aeac1d0b10230e
2024-02-02 15:57:26 -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
Colin Cross
1b3fe6bd2c Merge changes from topic "transition-mutator-config" into main
* changes:
  Add Config() to TransitionMutator contexts
  Fix OutgoingTransitionContext to match the description of TransitionMutators
2024-01-24 20:03:46 +00:00
Colin Cross
9c2f78f6c4 Add Config() to TransitionMutator contexts
Test: builds
Change-Id: Iadcea3081d8537220d54b4eeb1ba3691105e1d82
2024-01-22 17:18:45 -08:00
Colin Cross
33bec91aec Fix OutgoingTransitionContext to match the description of TransitionMutators
The description of TransitionMutators says that "the outgoing transition
should not take the properties of the dependency into account, only those
of the module that depends on it. For this reason, the dependency is not
even passed into it as an argument."  However, OutgoingTransitionContext
was returing the dependency from ctx.Module(), not the parent.  This
didn't matter for the only existing TransitionMutator, as it only used
the module to get a constant value.

Test: sanitize_test.go
Change-Id: I1ce5b3144787f57be4d50e95f0c923da9b2b079f
2024-01-22 17:18:40 -08:00
Cole Faust
079c92fb04 Merge "Remove SymlinkOutputs" into main 2024-01-19 19:38:55 +00:00
Cole Faust
828e6b4f20 Remove SymlinkOutputs
symlink_outputs was added so bazel could run ninja files, but we
abanoned that approach in roboleaf, and then roboleaf was cancelled
entirely. Remove this feature so we're more compatible with upstream
ninja / n2.

Bug: 160568334
Test: Presubmits
Change-Id: Ie3afd084c5574444dddac77cba1866e82ff2ca19
2024-01-18 12:41:16 -08:00
Colin Cross
e70495ba9a Fix data race in a parallel singletons calling VisitAllModules
Force a resort of the module groups before running singletons
so that two singletons running in parallel don't cause a data
race when they trigger a resort in VisitAllModules.

Test: go test -race ./...
Change-Id: Iec041cec08c33c56787aadbde6a1b2b619815142
2024-01-18 12:28:49 -08:00
Colin Cross
6bc984abca Move name memoization out of variables
memoizeFullName was added to variables, rules and pools as an
optimization to prevent recomputing the full name repeatedly,
but the storage of variables, rules and pools are generally global
and not tied to the Context.  When running multiple tests in
parallel there will be multiple Context objects all trying to
update the memoized names on the global variables, causing a data
race.

Package names were previously memoized via a pkgNames map stored
on the Context.  Expand pkgNames to a nameTracker object that
contains maps for packages, variables, rules and pools, and replace
calls to fullName with calls through nameTracker.

Test: context_test.go
Change-Id: I15040b85a6d1dab9ab3cff44f227b22985acee18
2024-01-18 12:28:49 -08:00
Zi Wang
2f0f395cc9 Merge "Remove unnecessary used names before reporting" into main 2024-01-04 23:35:05 +00:00
Zi Wang
e5913c17e9 Remove unnecessary used names before reporting
When property a.b.c is not used, (also there is no a.* or a.b.* used)
"a", "a.b" and "a.b.c" are all in unusedNames.
removeUnnecessaryUnusedNames only keeps the last "a.b.c" as the
real unused name.

Test: TestNonExistentPropertyInSoongConfigModule, unpack_test.go and CI

Bug: 171232169
Change-Id: I861fa6933e558b07694ee5ff40ef549117d115ff
2024-01-04 12:24:39 -08:00
Cole Faust
6733423618 Merge "Add implicit inputs to primary builder actions" into main 2024-01-03 06:14:23 +00: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
Treehugger Robot
321aad0a8c Merge "Optimize returning the zero value from provider APIs" into main 2024-01-02 20:17:29 +00:00
Treehugger Robot
e1d71ae428 Merge "Fix TestExternalShellEscaping and TestExternalShellEscapeIncludingSpaces on darwin" into main 2023-12-18 19:50:44 +00:00
Colin Cross
0bb75189da Fix TestExternalShellEscaping and TestExternalShellEscapeIncludingSpaces on darwin
TestExternalShellEscaping and TestExternalShellEscapeIncludingSpaces
use "echo -n", which fails on darwin.  These tests weren't running on
darwin because they were only run in Soong, which always limits to
only short tests.  The test are now run in aosp-build-tools, which
doesn't limit to short tests.

Remove the unsupported -n argument from echo and trim the added newline
instead.

Test: TestExternalShellEscaping and TestExternalShellEscapeIncludingSpaces
Change-Id: I3d8ff1c0db0af386e1dc13cb6c2dabe561c1c89e
2023-12-15 16:30:59 -08:00
Colin Cross
8514b5c26d Optimize returning the zero value from provider APIs
Now that nothing calls *Context.*Provider directly, make the blueprint
methods return a nil any interface instead of the zero value that was
constructed via reflection.  The type-safe wrappers will return a
zero value that can be constructed without any reflection or copying.

Bug: 316410648
Test: provider_test.go
Change-Id: I0abde5bacab9964a83f03c1644b51295a6c34d0b
2023-12-14 16:59:19 -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
516ef4f48e Create src file provider in build/blueprint am: a992d06f60
Original change: https://android-review.googlesource.com/c/platform/build/blueprint/+/2854653

Change-Id: Idf8f6435270d1afbaef6759d99be34b843975235
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-12-06 08:11:01 +00:00
Aditya Choudhary
a992d06f60 Create src file provider in build/blueprint
Change-Id: I7091effe7791c1f3ea57e775b37cd72f4ee13d03
2023-12-05 07:14:29 +00:00
Jooyung Han
da4c2df54f Add a new util to clear a property am: 02d2b9e4cc
Original change: https://android-review.googlesource.com/c/platform/build/blueprint/+/2854407

Change-Id: I5151b8df9fc158ff8ff0ca3dcc70bf4c43d7fd73
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-12-05 05:57:01 +00:00
Jooyung Han
02d2b9e4cc Add a new util to clear a property
proptools.Clear(ptr) clears a property with its zero value.

Bug: 313806237
Test: m blueprint_tests
Change-Id: Ib78f9f88a9b0a8b04e1ab6c5e545b55ba4269e5d
2023-12-04 11:01:23 +09:00
Colin Cross
21118230c9 Fix TestCloneProperties for go 1.21 am: 50fe8e79e5
Original change: https://android-review.googlesource.com/c/platform/build/blueprint/+/2824190

Change-Id: If679bf544928acff32a8684bcc58e60108632359
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-11-09 18:57:43 +00:00
Colin Cross
50fe8e79e5 Fix TestCloneProperties for go 1.21
Go 1.21 does a better job using the same empty allocation for empty
structs, allow cloned properties to point to the original when it
is an empty struct.

Bug: 309895579
Test: TestCloneProperties
Change-Id: I064f2316a8a8017a109968671ac305dbbe3246af
2023-11-08 22:07:58 -08:00
Treehugger Robot
90d740b3cb Merge "Remove pre singletons" into main am: 228915b2f1
Original change: https://android-review.googlesource.com/c/platform/build/blueprint/+/2814612

Change-Id: I94b057984594b70f513cb314c21924c9a2be0748
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-11-02 18:20:14 +00:00
Treehugger Robot
228915b2f1 Merge "Remove pre singletons" into main 2023-11-02 18:04:52 +00:00
Colin Cross
94bbe04b4c Optimize NinjaEscapeList to avoid allocating an output slice am: 42b2e906ef
Original change: https://android-review.googlesource.com/c/platform/build/blueprint/+/2813841

Change-Id: I7645618790ff32fe76ff066b7a4173996ebf0ec3
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-11-02 17:49:09 +00:00
Colin Cross
539f19d1a8 Use strings instead of simpleNinjaStrings where possible am: 95bec3331c
Original change: https://android-review.googlesource.com/c/platform/build/blueprint/+/2813840

Change-Id: I729a500def4b5f8cfe51e8a2461df90a9ea90c80
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-11-02 17:48:13 +00:00
Cole Faust
41cbc49a25 Remove pre singletons
They're no longer used.

Test: m nothing --no-skip-soong-tests
Change-Id: I6481381a2ac6bca4211c88173dd4275261123e86
2023-11-01 15:26:17 -07:00
Colin Cross
42b2e906ef Optimize NinjaEscapeList to avoid allocating an output slice
NinjaEscapeList is called on every input or output of a rule, and
most of the time does not escape anything.  Optimize it by returning
the input slice when nothing was escaped.  This avoids 1.336 GB of
allocations in my AOSP aosp_cf_x86_64_phone-userdebug build.

Test: TestNinjaEscapeList
Change-Id: I33b9e7b77b33d10401d1ec3546caa6794c567b16
2023-11-01 15:15:16 -07: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
f55930a589 Remove unnecessary locking in fs am: 098c09334f
Original change: https://android-review.googlesource.com/c/platform/build/blueprint/+/2806056

Change-Id: I6703d363e4127f7fde773bf77793f7b531c4d731
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-11-01 18:21:45 +00:00
Colin Cross
098c09334f Remove unnecessary locking in fs
osFs.acquire and osFs.release are surprisingly expensive, using a
combined 345.7s of runtime in an AOSP aosp_cf_x86_64_phone-userdebug
build.  They are used to ensure we don't use too many simultaneous
open files, but many of the functions they are called from don't
actually open a file.  Remove them from all the stat-based functions
(Exists, IsDir, IsSymlink, Lstat, Stat), and from ReadLink.  After
this change the time spent in acquire and release is effectively
zero.

Test: SOONG_PROFILE_CPU=/tmp/cpu.pprof m nothing
Change-Id: Ie5e22e33c61794354821f05ab79ceb4efc3b276c
2023-10-31 20:24:35 +00:00
Colin Cross
6cfb101d57 Always generate rules for blueprint tests am: 0065131f50
Original change: https://android-review.googlesource.com/c/platform/build/blueprint/+/2802154

Change-Id: I13bfc46c8d6d2e5a44d756de6fc499f48db1a5f9
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-10-24 22:38:52 +00: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
Rashid Zaman
103c1e5b8c bpfmt: Process all blueprint files when a directory is specified am: a29ee638ea am: c72a75269d am: 177f5bfe6f am: fedab1373c
Original change: https://android-review.googlesource.com/c/platform/build/blueprint/+/2694306

Change-Id: Icfbfc2c60bf5722547d6d33c89fc3b6af5985788
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-08-23 02:41:07 +00:00
Rashid Zaman
fedab1373c bpfmt: Process all blueprint files when a directory is specified am: a29ee638ea am: c72a75269d am: 177f5bfe6f
Original change: https://android-review.googlesource.com/c/platform/build/blueprint/+/2694306

Change-Id: I3a4151f2c2c9f76d0908b561b9d2d84fe2a8024b
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-08-23 01:36:03 +00:00
Rashid Zaman
177f5bfe6f bpfmt: Process all blueprint files when a directory is specified am: a29ee638ea am: c72a75269d
Original change: https://android-review.googlesource.com/c/platform/build/blueprint/+/2694306

Change-Id: Ie7ae46ac64d8511ffbd97cb7831eb8492fce6af4
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-08-23 00:21:44 +00:00
Rashid Zaman
c72a75269d bpfmt: Process all blueprint files when a directory is specified am: a29ee638ea
Original change: https://android-review.googlesource.com/c/platform/build/blueprint/+/2694306

Change-Id: I7ca72d73c24d2221176998d3d4b08b51d167887a
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-08-22 21:51:17 +00:00
Rashid Zaman
a29ee638ea bpfmt: Process all blueprint files when a directory is specified
Currently when a directory path is specified bpfmt only processes files
named "Blueprints" so change this to also process files with a `.bp`
suffix.

Test: Manual + bpfmt -d frameworks/base/services shows differences

Change-Id: I5a6356f387892934ee8e83362db13cda6156ed51
Signed-off-by: Rashid Zaman <rashidz@meta.com>
2023-08-04 01:01:55 -07:00
Xin Li
eccef716c8 [automerger skipped] Empty Merge Android U (ab/10368041) am: da4de251ac -s ours am: f6d2187281 -s ours am: 8ed083d352 -s ours
am skip reason: Merged-In Ia1adf67a8c85303f1c3f3ea9d6c1565041eaa1a5 with SHA-1 3f24bff0b4 is already in history

Original change: https://googleplex-android-review.googlesource.com/c/platform/build/blueprint/+/24087656

Change-Id: I0d35269bc70f4a281e824fbcd12174c0cdd722f9
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-07-15 05:13:34 +00:00
Xin Li
8ed083d352 [automerger skipped] Empty Merge Android U (ab/10368041) am: da4de251ac -s ours am: f6d2187281 -s ours
am skip reason: Merged-In Ia1adf67a8c85303f1c3f3ea9d6c1565041eaa1a5 with SHA-1 3f24bff0b4 is already in history

Original change: https://googleplex-android-review.googlesource.com/c/platform/build/blueprint/+/24087656

Change-Id: I9dc53d4ee17a53cd00772086ba1f768346246eb0
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-07-15 04:30:06 +00:00
Xin Li
f6d2187281 [automerger skipped] Empty Merge Android U (ab/10368041) am: da4de251ac -s ours
am skip reason: Merged-In Ia1adf67a8c85303f1c3f3ea9d6c1565041eaa1a5 with SHA-1 3f24bff0b4 is already in history

Original change: https://googleplex-android-review.googlesource.com/c/platform/build/blueprint/+/24087656

Change-Id: Ibfa5e043232b200092b7fd1877563f832f20d9bb
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-07-15 03:22:24 +00:00
Xin Li
da4de251ac Empty Merge Android U (ab/10368041)
Bug: 291102124
Merged-In: Ia1adf67a8c85303f1c3f3ea9d6c1565041eaa1a5
Change-Id: I2c12f5bb76746ab889eff1db829d6d586bd64ace
2023-07-14 16:53:21 -07:00
LaMont Jones
87e2c0c0a0 Wrap singleton ninjaString Eval calls am: 7c2ebdef75 am: fa016e5910 am: adc079478c am: 83b2794179 am: ec448f4ec5
Original change: https://android-review.googlesource.com/c/platform/build/blueprint/+/2654105

Change-Id: I64326736d5ea454efd45170d1ea0d1ffbaf0615d
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-07-12 19:58:23 +00:00
LaMont Jones
ec448f4ec5 Wrap singleton ninjaString Eval calls am: 7c2ebdef75 am: fa016e5910 am: adc079478c am: 83b2794179
Original change: https://android-review.googlesource.com/c/platform/build/blueprint/+/2654105

Change-Id: Id353ea7b4dc1751d82a61c7f07fc94d384e873d9
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-07-12 19:14:39 +00:00
LaMont Jones
83b2794179 Wrap singleton ninjaString Eval calls am: 7c2ebdef75 am: fa016e5910 am: adc079478c
Original change: https://android-review.googlesource.com/c/platform/build/blueprint/+/2654105

Change-Id: Iad71e5d008fcb4cb975af8a27d88c3e72e320208
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-07-12 18:27:08 +00:00
LaMont Jones
adc079478c Wrap singleton ninjaString Eval calls am: 7c2ebdef75 am: fa016e5910
Original change: https://android-review.googlesource.com/c/platform/build/blueprint/+/2654105

Change-Id: I14994b03e59a038748dc08b1edc37145bb1831f2
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-07-12 17:42:21 +00:00
LaMont Jones
fa016e5910 Wrap singleton ninjaString Eval calls am: 7c2ebdef75
Original change: https://android-review.googlesource.com/c/platform/build/blueprint/+/2654105

Change-Id: I1b40f1aa57d06cee6cacabc1779a7449789986fd
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-07-12 16:57:01 +00:00
LaMont Jones
7c2ebdef75 Wrap singleton ninjaString Eval calls
This avoids a concurrent map read and write error in parallel
singletons.

Bug: 290795374
Test: manual, treehugger
Change-Id: I7f89909a98c4f530da92a3d2cc01ca8eaeddbfa0
2023-07-11 19:58:01 +00:00