Commit graph

796 commits

Author SHA1 Message Date
colincross
22343ff42c
Merge pull request #342 from colincross/optimize_updateDependencies
Optimize updateDependencies
2021-01-22 16:22:41 -08:00
colincross
2a29698186
Merge pull request #343 from colincross/optimize_ninja_writer
Optimize ninja writer
2021-01-22 16:22:22 -08:00
Colin Cross
7ff2e8d2a4 Optimize updateDependencies
Avoid reallocating module.forwardDeps and module.reverseDeps every
time through updateDependencies by resetting the slices without
reducing their capacity.  Accumulate dependencies to visit directly
into module.forwardDeps.  Use a loop instead of a map to check
for duplicates, average number of dependencies is measured to be
9.5, although there are a few outliers with up to 2108.

Reduces mean soong_build execution time on internal master from 87s
to 82.7s (5%).

Test: context_test.go
Change-Id: I58fcd5514e494bafa965443461851b21b7bce382
2021-01-22 10:22:21 -08:00
Colin Cross
8a40148408 Write build definitions directly to output writer
buildDef.WriteTo was calling valueList to convert all the build
parameter ninjaStrings into strings, which uses ValueWithEscaper
to build a strings.Builder.  This results in building a string
only to immediately copy it into the output writer's buffer.

Instead, pass an io.StringWriter to ValueWithEscaper so it can
build the string directly into the output writer's buffer.  This
requires converting ninjaWriterWithWrap into an io.StringWriter.

Test: ninja_writer_test.go
Change-Id: I02e1cf8259306267b9d2d0ebe8c81e13dd443725
2021-01-21 22:02:30 -08:00
Colin Cross
92054a49d2 Memoize full names of variables, pools and rules
Variables, pools and rules each computed their full names every time
they were referenced, which required string concatenations.  Since
every one is guaranteed to be accessed at least twice, once when the
definition is written into the ninja file and once for each reference,
precompute the full name.  For local variables that can be done
during initialization, but for global variables add a pass to
PrepareBuildActions to compute the name for each live variable using
the final package names.

Test: ninja_writer_test.go
Change-Id: I2264b05e0409e36651db2fb5d463c16c698d4d5e
2021-01-21 22:02:30 -08:00
Colin Cross
00890dd8f6 Optimize arg parsing in buildDef.WriteTo
Arguments to build definitions were copied from the input map to an
map with the name and value expanded, then to a list of names for
sorting, and then written, which required iterating over a map three
times.  Expand the name and value into a list of name value pairs,
and then do the rest of the operations on the list instead.

Test: ninja_writer_test.go
Change-Id: Id8ff644dafbaa3b4812747c60dc28cce22e21dbe
2021-01-21 22:02:30 -08:00
Colin Cross
c8b9e55289 Increase ninja file writer buffer
Increase the ninja file writer buffer from the default 4k to 16MB.

Test: m checkbuild
Change-Id: Ieb2c82218517b98469ef93f1ea4dd04b5651f7d1
2021-01-21 22:02:30 -08:00
Colin Cross
0335e0900d Use io.StringWriter in ninjaWriter
ninjaWriter repeatedly called io.WriteString() on its writer, which
does a type assertion every time.  Replace its io.Writer with an
io.StringWriter and call WriteString on it directly.

Test: ninja_writer_test.go
Change-Id: Ie073d996a319190242bf6a00af07a13a60d078b5
2021-01-21 22:02:30 -08:00
colincross
bcd5686660
Merge pull request #341 from colincross/optimize_glob
Return a copy of glob lists
2021-01-21 18:27:49 -08:00
Colin Cross
a64ca94c0d Return a copy of glob lists
Callers to glob methods may do in-place modifications on the returned
list of globs, return a copy instead of the cached value.

Test: m nothing && m nothing
Change-Id: Ic9140d1e1900e8724ba0a484f27786e5c15dea90
2021-01-21 13:47:59 -08:00
colincross
2b2b9f28f2
Merge pull request #340 from colincross/optimize_glob
Use info.IsDir() instead of info.Mode()&os.ModeDir != 0
2021-01-20 13:52:33 -08:00
Colin Cross
4604a81721 Use info.IsDir() instead of info.Mode()&os.ModeDir != 0
Use the info.IsDir() shortcut.

Test: glob_test.go
Change-Id: Ibba8bbc6af295e3d86321b0c070a84c2b7008dd9
2021-01-20 13:47:37 -08:00
colincross
49a8b95d4e
Merge pull request #339 from colincross/optimize_glob
Remove redundant stat/lstat calls from glob
2021-01-20 13:34:51 -08:00
Colin Cross
e535c97cc9 Remove redundant stat/lstat calls from glob
Glob was calling IsSymlink and IsDir on each visited directory entry,
which resulted in an lstat and then a stat call on each.

Instead, use lstat when not following symlinks and use stat when
following symlinks, then use the result to check if the entry is a
directory.

Test: glob_test.go
Change-Id: I83d769e2de64ce8221e952e5204d365aeaf47687
2021-01-20 11:01:41 -08:00
colincross
94a5c01693
Merge pull request #337 from colincross/map_assign
Fix silently ignoring values assigned to map properties
2021-01-19 10:35:33 -08:00
Colin Cross
3adb240964 Fix silently ignoring values assigned to map properties
Values assigned to map properties were silently ignored instead of
reported as an error.  Add a check when recursing into structs that
the value is a map.

Fixes: 177706602
Test: m nothing
Test: TestUnpackErrors
Change-Id: Ic56aeb1b9da6d5c86b6d98adae7bddb60c450404
2021-01-15 22:21:28 -08:00
Colin Cross
f6ef155884 Use UnpackError for incorrect property type errors
Returning a fmt.Errorf error causes Blueprint to identify the error
as an "internal error", return an UnpackError instead.

Bug: 177706602
Test: TestUnpackErrors
Change-Id: I19fba134ad778d08d5a4d90a0335bdf8cbea6a20
2021-01-15 22:21:28 -08:00
Colin Cross
461d95061e Improve unpack testing
Add more tests, give the tests names, run them as subtests, and add
benchmarks.

Test: unpack_test.go
Change-Id: Iff22538ce44ed503d5d088cfb55673448db998f1
2021-01-15 22:21:28 -08:00
Jooyung Han
53e92a0de6
bpmodify: support numerical sort (#332)
bpmodify sorts touched list respecting numbers embedded in strings. For
example, "foo-2" comes before "foo-10".

Test: bpmodify_test.go
Change-Id: If2fe9bc871a463a47dd3c0b52982b34c9fde05f0

Co-authored-by: Jooyung Han <jooyung@google.com>
2020-12-14 11:30:48 -08:00
colincross
cfa2e91dc4
Actually pause mutators when adding dependencies (#335)
In the coordination between #316 and #318 the calls to mctx.pause()
were forgotten, causing dependencies returned by the Add*Dependency
calls to be in an undefined state.  Add the missing calls to
mctx.pause().

Change-Id: I648ad269449777363801785059b13b866424d4b5
2020-12-14 11:23:23 -08:00
Liz Kammer
9ae14f12f9
Invalidate module group cache if deps are modified (#334)
* Invalidate module group cache if deps are modified

PreSingletons run after the blueprints have been parsed and can run
VisitAllModules; however, this seeds the cache of sorted modules which
may change after mutators have run. 

This causes recomputation of the cache if any deps have been
modified since the last time it was run.

Change-Id: I79fc822dd630f84790f309ba4e6024588a8fe28e
2020-11-30 16:30:45 -07:00
colincross
16754d14e2
Fix github builds for deprecated set-env and add-path commands (#333)
actions/setup-go@v2.0.3 seems to cause issues with
https://github.blog/changelog/2020-10-01-github-actions-deprecating-set-env-and-add-path-commands/

Change the precise versions to major versions to get updates.

Also fix the "Install ninja" action to use $GITHUB_PATH.

Change-Id: Ia3ec693e405a2530350736e7856ad758af3fb027
2020-11-23 16:52:58 -08:00
Martin Stjernholm
0f1637b19b
Improve formatting of some error messages. (#327)
In particular the formatting of dependencies with variants which lacked
braces that caused them to float together with the dependency names.

Also add some context to the ReplaceDependenciesIf panic message.

Test: m
Change-Id: Ibd03690317ca53f3ecbdd95033404d89d849b4dd
2020-11-16 12:15:36 -08:00
colincross
660bb7a3e5
Merge pull request #330 from colincross/glob
Remove unnecessary depFile parameter from GlobFile
2020-11-10 12:34:10 -08:00
Colin Cross
7ceeeaf364 Remove unnecessary depFile parameter from GlobFile
GlobRule uses $out.d for the dep file, it doesn't need an extra
parameter.

Test: glob_test.go
Change-Id: Ie753a119c3602c325450909f0240f6eeef9ef243
2020-11-10 12:24:17 -08:00
c-parsons
bcdfcceeb2
Create early-exit hook StopBeforeWriteNinja
This allows exiting bootstrap directly before writing ninja files.
This facilitates shorter runtime on integrations which do processing
which do not require ninja file output.

Test: Manually verified on Soong integration use case which involves
running bootstrap twice in a single program; stopping before ninja
output reduces runtime by ~20s, or ~11%.
2020-11-05 16:26:08 -05:00
Chris Parsons
5e834261a9 Create early-exit hook StopBeforeWriteNinja
This allows exiting bootstrap directly before writing ninja files.
This facilitates shorter runtime on integrations which do processing
which do not require ninja file output.

Test: Manually verified on Soong integration use case which involves
  running bootstrap twice in a single program; stopping before ninja
  output reduces runtime by ~20s, or ~11%.
2020-11-05 11:17:32 -05:00
Liz Kammer
764a771917
Identify the type of the list for bpdocs (#326)
* Identify the type of the list for bpdocs

Test: go test bpdoc tests
Test: m soong_docs
Change-Id: I6a4a916e1f72b3fc702da90c32a2eddca70b3bac
2020-11-04 17:20:11 -08:00
Liz Kammer
ed35255eca
Merge pull request #322 from jin/symlink_outputs
Add support for symlink_outputs to Blueprint
2020-10-19 08:52:08 -07:00
Jingwen Chen
fd8af0b082 Add support for symlink_outputs to Blueprint 2020-10-08 09:49:57 +00:00
colincross
25128bedbc
Merge pull request #325 from jin/codeowners
Add CODEOWNERS: @google/blueprint
2020-10-06 21:05:50 -07:00
Jingwen Chen
8a43c1bb1e Add CODEOWNERS: @google/blueprint 2020-10-07 11:57:54 +08:00
Liz Kammer
f20c9c3938
Merge pull request #324 from lizkammer/fix
Correct bug in generating anonymous nested props
2020-10-05 17:08:52 -05:00
Liz Kammer
2068e08a2c Correct bug in generating anonymous nested props
Some anonymous nested properties are missing from property structs,
since setting the property to anonymous is to allow future filtering,
there is no issue if we cannot find the struct.

test: go bpdoc tests
test: m soong_docs
2020-10-05 14:55:16 -07:00
Liz Kammer
a10477e361
Merge pull request #323 from lizkammer/bpdocs
Add docs for nested and embedded structs
2020-10-05 13:15:33 -05:00
Liz Kammer
5c9fe3834d Add docs for nested and embedded structs
Test: m soong_docs
Test: go bpdoc tests
Change-Id: I99f15405e1a7d4a819f6fb20fda22372afe253e1
2020-09-25 13:20:23 -07:00
colincross
8a747a0864
Merge pull request #309 from colincross/providers
Add Providers to Blueprint
2020-09-23 10:27:40 -07:00
Colin Cross
2da8492b9d Add Providers to Blueprint
Providers are a new concept for Blueprint, based on providers in Bazel:
https://docs.bazel.build/versions/master/skylark/rules.html#providers

Providers aim to simplify the interaction between modules by replacing
type asserting to arbitrary interfaces with requesting optional data
objects from modules.  This will also move Blueprint closer to supporting
incremental analysis by serializing the providers and only rerunning
the analysis phase on modules whose inputs have changed.

Change-Id: I39f5f78b372412a7dbf151ceccb3f917f6c874bf
2020-09-22 18:20:18 -07:00
colincross
66fa73dd6e
Merge pull request #316 from skvadrik/add-dep-ret-mod
Return dependency modules from dependency-adding methods.
2020-09-22 10:59:46 -07:00
colincross
ca601ee4fb
Merge pull request #318 from colincross/pause_parallel_visit
Support pausing parallelVisit
2020-09-22 10:58:03 -07:00
Ulya Trafimovich
9577bbc922 Return dependency modules from dependency-adding methods.
The motivaion for this change is to allow writing code that uses the
newly added dependency module in the same mutator pass, for example to
add more dependencies. Like this:

  for _, m := range ctx.AddVariationDependencies(nil, tag, deps...) {
      if someModuleProperty(m); ok {
          ctx.AddVariationDependencies(nil, tag, otherDep)
      }
  }

Note that there is no guarantee that the returned module has already
been processed by the current mutator.

The patch does not add runtime overhead on findng dependency modules,
as this has already been done previously.

Test: go test
2020-09-17 11:43:15 +01:00
Colin Cross
c4773d90a2 Support pausing parallelVisit
Pass a channel to visitor functions called by parallelVisit that
allows them to pause the current visitor until a given visitor
has finished.  This allows parallelVisit to work on a dependency
graph while it is being mutated.

Test: Test_parallelVisit
Change-Id: Id8b1542c22ac9914439310e31d992ae0d7318d69
2020-09-16 12:58:39 -07:00
colincross
4b3efdc5b8
Merge pull request #321 from colincross/far_variations
Relax check in moduleMatchingVariant
2020-09-11 20:15:21 -07:00
Colin Cross
edbdb8c2d3 Relax check in moduleMatchingVariant
Pull request #317 made the equality check in moduleMatchingVariant
more correct by comparing the variant maps instead of the names.
Using only the names effectively ignores any variation with an
empty name.  Unfortuantely this broke a current user of
ReplaceDependenciesIf.  Go back to the relaxed check for now.

Test: build on a branch with sdk modules
Change-Id: I11016c8df7bd91fd022d04fd3033756f54d7fa0b
2020-09-11 19:24:59 -07:00
colincross
277bac9904
Merge pull request #317 from colincross/far_variations
Fix AddFarVariationDependencies
2020-09-11 14:57:09 -07:00
Colin Cross
5dc6759951 Fix AddFarVariationDependencies subset checks
AddFarVariationDependencies claims to take the first variant that
matches all the requested variations, but it did nothing of the sort.
It took the first variant that either matched or did not contain each
of the requested variations.  A module with no variations was always
matched, and requesting variations that didn't apply to a module
still matched (for example, requesting an image variation for a
host module that was ignored by the image mutator).

Fix AddFarVariationDependencies by making subset actually check
for subsets.

Test: Test_findVariant
Change-Id: I10063fec342db2a1c0685a7db08e4a650d14bd4e
2020-09-09 18:29:15 -07:00
Colin Cross
5df74a8e38 Maintain ordering between variants and aliases
AddFarVariationDependencies takes the first matching variant.  To
maintain sensible behavior on a module with aliases, the ordering
of aliases and module variants needs to be maintained so that
AddFarVariationDependencies can find an earlier matching alias
instead of a more specific variant.

Test: go test .
Change-Id: I78f4e96edd98159f3a62d94e240e5d652667bec4
2020-09-09 18:29:15 -07:00
Colin Cross
39644c0903 Add tests for findVariant
Add tests for findVariant behavior that provides the matching
behaviors of AddVariationDependencies, AddFarVariationDependencies,
etc.

Test: Test_findVariant
Change-Id: I3494d57179c8b3d62f7d32e5a1b43c9b9672c2df
2020-09-09 18:27:32 -07:00
colincross
ad63e18efe
Merge pull request #320 from colincross/bootstrap_variants
Enable variants of bootstrap modules
2020-09-09 15:01:12 -07:00
Colin Cross
d2458a23bf Enable variants of bootstrap modules
The primary builder may want to create variants of bootstrap
modules if they need to fit in to the primary builder's dependency
graph.  Enable arbitrary variants of bootstrap modules by only
running the module's actions on the primary variant and then
copying the result to any other variants that exist.

Test: m checkbuild
Change-Id: I24b97771bb11faeacab4079ed8cf69aef59da140
2020-09-09 14:32:42 -07:00