Commit graph

90 commits

Author SHA1 Message Date
Jaewoong Jung
8bc6bf1090 bpdoc preformatted text improvments
1. Apply preformatted text (<pre>...</pre>) handling logic to module
type text too. It used to be applied to property texts only.
2. Improve <pre> handling logic itself for better readability.
- Insert a blank line before <pre>.
- Prevent from ending <pre> blocks prematurely by checking if an
unindented line isn't just a blank line between indented lines.

Change-Id: Id40fa668d4c6781caf7ed140b2f40784cdeb8c35
2019-03-11 11:16:31 -07:00
Sasha Smundak
797563bec4 Export CollapseDuplicateProperties, Soong writedocs uses it 2019-02-14 10:58:48 -08:00
Jaewoong Jung
781f6b2896 bpdoc improvements
1. Extract module type documentation.
2. Support primary builder customization of factory function to use for
documentation for each module type.
3. Change the ModuleType list order so that they are grouped by package.

This is basically minor refactoring + readability improvement done on
top of https://github.com/google/blueprint/pull/232.

Change-Id: If7413e5ac23486b85f18d02fb3ba288a38730c32
2019-02-08 15:48:27 -08:00
Colin Cross
de7afaaf74 Write ninja file directly to the output file
Writing the ninja file to a byte buffer causes a significant amount
of time to be spent in memmove when growing the byte slice.  Write
the file directly to disk instead.

This also fixes some unhandled error warnings, which become more
likely when doing disk IO instead of byte buffer writes.

Change-Id: I5094e4c45cab4012713037f60c5a4fb00718f92e
2019-01-23 13:26:42 -08:00
Dan Willemsen
dac90d33ca Add --empty-ninja-file for test usecases
In cases that we want to run blueprint-based builds in many
configurations to verify all of the logic works without errors, but
don't care about running the final ninja file, writing it out only
wastes time and disk space. So add a --empty-ninja-file option that
writes out an empty ninja file instead.

Our specific use case (Soong's build_test / multiproduct_kati) runs
Soong several hundred times for different configurations, and the ninja
files are around 1GB, which leads to several hundred gigabytes of disk
writes (and persistent use during incremental generation).

Change-Id: I0198dfb2f744ce22284c05d5214dac2ab5dc9700
2018-10-26 09:57:24 -07:00
Colin Cross
1be9abc109 Add link dependency on test package archive
The test package archive was being picked up through "-L" + testRoot,
but did not have a dependency on it.  If the *_test.go file was
changed but not the implementation then the tests would not be
rerun.

Test: Add t.Fatal() to a *_test.go file and rebuild.
Change-Id: I32b8c7a0fa1d5b76b1242646887fe937e396e318
2018-10-24 13:13:13 -07:00
Colin Cross
0e58dc0176 Add missing dependencies when linking tests
Linking tests needs the same dependencies that linking binaries
got in https://github.com/google/blueprint/pull/222.

Test: m checkbuild
Change-Id: I33330f3184b8c0fd2bc20b48736c20d6edeaea68
2018-10-05 11:12:53 -07:00
Colin Cross
6c92af937e Enable restat for go binaries
Many Android build tools are written in go, and changes to Soong or
Blueprint can cause them to rebuild.  Almost everything in an
Android build is downstream of at least one of these tools, so
they all rebuild too.

Go binaries are static, so their contents will always change if any
of their dependencies change.  Only update output files of go compile
and go link if the contents change, and enable restat for the rules.

Test: m soong_zip && m soong_zip
Test: m soong_zip && touch build/soong/zip/cmd/main.go && m soong_zip
Change-Id: I9267580f644b42b44d43fb0a2674dc5234f127e5
2018-10-02 21:52:50 -07:00
Dan Willemsen
734f20c205 Fix issues found by go vet
Change-Id: If3e20a1f394d757554d6a7da5ed4c41fe194f55f
2018-07-21 13:10:25 -07:00
Dan Willemsen
ab223a512b Run globs during earlier bootstrap phases
Instead of sometimes re-running minibp/the primary builder during the
next phase, run bpglob earlier to check dependencies.

We've run into issues where the environment is slightly different
between bootstrapping phase and the main build phase. It's also a
problem because our primary builder (Soong) exports information used by
another tool (Kati) that runs in between the bootstrapping phases and
the main phase. When Soong would run in the main phase, it could get out
of sync, and would require the build to be run again.

To do this, add a "subninja" include a build-globs.ninja file to each
build.ninja file. The first time, this will be an empty file, but we'll
always run minibp / the primary builder anyway. When the builder runs,
in addition to writing a dependency file, write out the
build-globs.ninja file with the rules to run bpglob.

Since bpglob may need to be run very early, before it would normally be
built, build it with microfactory.

Change-Id: I89fcd849a8729e892f163d40060ab90b5d4dfa5d
2018-07-06 10:39:38 -07:00
Dan Willemsen
ff2c5b4cc8
Merge pull request #203 from danw/numcpu_cap
Cap the number of cpus for Go compiles
2018-03-02 16:02:06 -08:00
Dan Willemsen
20c343b89e Cap the number of cpus for Go compiles
When passing "-c" to the Go compiler, any time this value changes, we'd
force all of the Go compiles to rebuild. This could trigger a
substantial portion of the tree to rebuild (anything that transitive
depends on a Go helper tool).

We're running into issues when moving output directories between
multiple GCE machines with different core counts, but are otherwise
identical. This could also hit users moving/mounting disks between
machines, though changes to other host tools can make an impact too.

On my 48-core machine, I get a ~15% benefit from going from -c 1 to -c
48, but also ~12% benefit from going from -c 1 to -c 8. So this will
still let us scale somewhat, but prevent rebuilds when transitioning
between machines that are more likely building Android.
2018-03-02 15:32:22 -08:00
Dan Willemsen
a1e6eeeb44 Try to make GOROOT relative in Go 1.10
In Go 1.10, runtime.GOROOT() will attempt to find the current location
of the go binaries, instead of using the GOROOT_FINAL that was baked
into the binaries. This means that GOROOT() will usually return an
absolute path.

We avoid putting absolute paths into the ninja file, since any change to
the paths would then cause all of the actions including it to rebuild.
Since we've got a decent number of build tools in Android using Go now,
this causes us to rebuild a decent portion of the tree.

Instead of passing the GOROOT around manually in a side channel, just
let the Go 1.10 detection do its thing, and always try to turn the
result into a relative path.
2018-03-02 15:29:35 -08:00
Colin Cross
c1d878159c Fix format issues found by go vet
Test: m checkbuild
Change-Id: I5135e0daecd20abce9a66631f5f55230168613de
2018-02-23 14:05:03 -08:00
Dan Willemsen
2d9b59bc20 Store build.ninja deps in .ninja_deps
We're already going to load the .ninja_deps file, so we may as well use
it. These are the only two files in our build that don't.

Test: dump the .ninja_deps file, see the dependencies
2017-12-18 09:14:16 -08:00
Colin Cross
28b2843b78 Allow primary builder to stop bootstrap early
Allow the primary builder to stop bootstrap between
ResolveDependencies and PrepareBuildActions so that it can
use the build graph to write customized documentation.

Change-Id: I67ee5e6e438a0c2c3ec844c4c453d223971e60a2
2017-12-11 16:31:41 -08:00
Colin Cross
5eb116a46e Move auto-generated docs to main stage
Move the docs to the main stage and make a phony rule to build
them.  This will allow the primaray builder to choose not to
build them so that it can use its own rule instead.

Change-Id: Ib788f74717ccdcd85c2e5b6a581cc744d439341a
2017-12-11 16:31:41 -08:00
Colin Cross
92639f3fbb Refactor bpdoc
Separate the extraction of documentation-related info from writing
it out so that the primary builder can choose to write it out in
a customized format.

Change-Id: If2c91d6f13b8cea2e9e1cca75d8c2d684ad7f6df
2017-12-11 16:31:41 -08:00
Jeff Gaston
c3e2844dfe Support for a custom list of Blueprints files to parse
Bug: 64363847
Test: BLUEPRINT_LIST_FILE=out/.module_paths/Android.bp.list minibp

Change-Id: Id7f8cb1ab3a6684b3f8265d77bb32413957f1c93
2017-10-30 15:00:19 -07:00
Colin Cross
7311337d4c Support preformatted property documentation
Treat any property documentation lines that are indented as
preformatted.

Bug: 67909957
Test: manual inspection
Change-Id: Ib014bc301880eca02c60ed1692e49f07dca05fb3
2017-10-17 18:01:53 -07:00
Colin Cross
4ef23afc91 HTML escape property documentation
Property documentation that contained text that looked like HTML
tags was getting passed through.  Use html/template instead of
text/template so that it gets escaped automatically.

Bug: 67909957
Test: manual inspection
Change-Id: I2050c34c04d7be3cdacd5a76967a739f9f837e89
2017-10-17 18:01:53 -07:00
colincross
b67c1d433c Merge pull request #166 from colincross/create
Add TopDownMutatorContext.CreateModule
2017-09-20 14:09:15 -07:00
Dan Willemsen
87f71fa623 Expose the installed path for Go binaries
In case the primary builder wants to depend on a go binary by name,
expose an interface to find the real installed path of the binary.

Most of this change is changing it so that we're storing the install
path without any ninja references.

Change-Id: I873378ebdd47d8036d3cef5aab76f036846a3db1
2017-09-13 15:30:54 -07:00
Colin Cross
874a346904 Let mutators use ctx.AddNinjaFileDeps
Propagate extra ninja file deps through mutators so that they
can use ctx.AddNinjaFileDeps.

Test: blueprint tests
Change-Id: I299a0665c3f63b020ae345889fd78b91b91b215a
2017-08-01 15:12:12 -07:00
Dan Willemsen
c54c072667 Support parallel Go compiles with Go 1.9
Change-Id: I80f3ad6e563fef1b4f22e936016675262f7ce8bf
2017-07-25 11:08:20 -07:00
Dan Willemsen
feb1a225f2 Update documentation
Change-Id: I59daf7802a1b04961d0372c2417869ad9bd6d0b2
2017-07-24 14:02:51 -07:00
Dan Willemsen
cd4e0cebc9 Unify .ninja_log files
Having separate .ninja_log files doesn't work very well after
04d886b110
since the last successful timestamp is not recorded in the ninja log.
This was triggering the primary builder to be run twice on every build
since it was always considered out of date in the primary, then main
stages.

The two bootstrap stages already were unified when minibootstrap was
simplified, but this combines the main stage as well. This means that
we'll save some time running globs that are shared between minibp and
the primary builder as well (subdirs globs).

The cleanup code needed to be refactored, since the ninja_log will have
entries from the main stage as well. So instead of looking at everything
in the ninja log, take a string prefix to limit what we may clean.

Change-Id: I8d43168643aa8a0c6c3e48c6101eaa45d174bbe5
2017-07-24 14:02:51 -07:00
Dan Willemsen
af456eaae4 Define everything in both stages
Now that packages and binaries are only built when needed, they need to
be defined in both stages in case something building in the main stage
needs something that was defined, but didn't need to be built in the
earlier stage.

Change-Id: I67704fba1d670e82218eba5ce91f0c01896557a2
2017-07-24 14:02:51 -07:00
Dan Willemsen
f60525a63d Mark intermediates as optional
Instead of forcing things to be built alongside the primary builder,
mark all packages and binaries as optional, unless they're explicitly
marked as default.

Change-Id: Ie53c90a01b41ce886d651f9aa4c4900d1edb0157
2017-07-24 14:02:51 -07:00
Dan Willemsen
91e2483024 Fix and test rebuilds of bootstrap ninja when using tests
Add testing of bootstrap.bash -t to travis, and fix spacing issues
causing rebuilds.

Change-Id: Ia30367e40f5cf32de9749b2742d68b57e9201278
2017-07-24 14:02:51 -07:00
Dan Willemsen
1e72321e58 Use microfactory to build the bootstrap minibp
This duplicates building common blueprint go packages between minibp and
the primary builder, but drastically simplifies the first stage,
removing the need to check in a generated build.ninja.in.

Change-Id: I639a9637f1ed36d4210823ef276c0f7a064a83bd
2017-07-24 14:02:51 -07:00
Dan Willemsen
aee3eac6ce Fix bad ninja file if only GOOS-specific tests exist
When only linux/darwin tests were specified, we weren't setting
testArchiveFile, so we had a corrupted ninja file (build : ...).
2017-03-15 23:25:20 -07:00
Dan Willemsen
f14e096607 Support darwin/linux specific go sources
In order to use certain syscalls, some source must only be compiled on
one of darwin or linux. There are also cases where it's simplest to have
two implementations of a method (or struct) instead of choosing an
implementation at runtime.

The standard go tools use _<GOOS>.go for this, but the explicit structs
map better into the current blueprint format (and you can still use
_darwin.go / _linux.go to maintain compatiblity with those tools).

Test: Define _linux.go / _darwin.go files, ensure only one is compiled.
Change-Id: I58bffefbf839ba52dea3d8e7d3ec67eaa721c463
2017-02-18 15:12:13 -08:00
Dan Willemsen
e8a33ee623 Enable go tests for blueprint_tools
We haven't been building the tests for any Go tools that get built
during the primary stage, since we haven't been passing -t to the
primary builder. So enable them there so that we test those tools.

Change-Id: Ic7720c0679419f9e1ba61c7e151f37eb5c7bc8dc
2017-01-18 14:34:46 -08:00
Colin Cross
127d2eae8b Import globbing from Soong
Add globbing with dependency checking to blueprint.  Calling
ModuleContext.GlobWithDeps or SingletonContext.GlobWithDeps will return
a list of files that match the globs, while also adding efficient
dependencies to rerun the primary builder if a file that matches the
glob is added or removed.

Also use the globbing support for optional_subdirs=, subdirs= and build=
lines in blueprints files.  The globbing slightly changes the behavior
of subname= lines, it no longer falls back to looking for a file called
"Blueprints".  Blueprint files that need to include a subdirectory with
a different name can use build= instead of subdir= to directly include
them.  The Blueprints file is updated to reset subname="Blueprints" in
case we want to include subdirectories inside blueprint and the primary
builder has changed the subname.

Also adds a new test directory that contains a simple primary builder
tree to test regeneration for globbing, and runs the tests in travis.

Change-Id: I83ce525fd11e11579cc58ba5308d01ca8eea7bc6
2016-11-03 13:54:03 -07:00
Dan Willemsen
9bd6b38617 Refactor test running to improve parallelism
Before this change, we would ensure that tests for a package were run
before anything used that package, even just to compile. With this
change, we'll let other packages compile, but still run the tests in
dependency order, and before the binaries are finally installed.

This shrinks our initial build time from ~9 seconds to ~5 seconds on my
machine. Most of the improvements come from building the "real" package
and the test package in parallel.

Change-Id: I935670feecadacbf09b250bcaa1659a3599edc58
2016-11-02 13:10:27 -07:00
Dan Willemsen
460c80eb12 Clean up unnecessary dependencies
Other than cleaning up the code, the only change in behavior is to run
the docs build in parallel with the primary builder, saving about a
second on a Soong bootstrap (10s -> 9s).

Change-Id: Iaff51d6d1a37af842f294f12db11d5774d48d440
2016-11-02 13:10:27 -07:00
Dan Willemsen
b6d88a4f0a Allow build.ninja regeneration (fix Soong globs)
Soong (and soon, Blueprint) embeds the results of filesystem globs into
the build.ninja, and uses a helper tool to detect when the glob changes
and we need to rebuild the build.ninja file. This is more flexible than
listing the affected directories in the depfiles, since it can check to
see if a file we actually cared about was added, instead of re-running
anytime any file was added/removed (which happens on atomic file
modifications as well).

My recent bootstrap simplification broke this, since the helper rules
are in the main build.ninja, but I removed the ability to regenerate
that file from itself. So keep the current model, but add a rule into
the primary and main stages that allow themselves to re-run their
generator and write out a new build.ninja file if necessary. The actual
build rules of the generator aren't necessary, since we already built
them in the previous stage.

Change-Id: Ib51245920b2ec3ee5306c0c269361a5a8733caa8
2016-11-02 13:10:27 -07:00
Dan Willemsen
3692331afe Cleanup outfile args in bootstrap/bootstrap.go
This would have been a case for implicit outputs, but these just aren't
needed anymore.
2016-10-31 17:36:53 -07:00
Colin Cross
0b7e83e11a Ask primary builder for module names
Remove the assumed Name and Deps properties.  Instead, ask the Module
for the Name, and require them to use the existing replacements for
Deps.

Change-Id: I729045d86277686078b3aa0bba71c67d612ead2c
2016-10-12 13:33:37 -07:00
colincross
53d4357592 Merge pull request #127 from colincross/memprofile
Add support for memory profiling
2016-10-12 11:16:42 -07:00
Colin Cross
2c62844274 Improve error reporting
Report module name and variant and property names in errors.

Change-Id: I747f840402497b2c92bf8c565d7c50af33e6ab0e
2016-10-12 11:14:18 -07:00
Colin Cross
2ecec57e47 Add support for memory profiling
Add -memprofile argument to support capturing a heap profile, and -nogc
to disable the garbage collector to see all allocations.

Change-Id: I0d4c5f2bf79786aed4b2af4be112ecf0a2810a91
2016-10-12 11:12:54 -07:00
Dan Willemsen
7d0dddd84d Simplify bootstrap
tl;dr: Read if you don't use the wrapper or use SKIP_NINJA

Previously, we were relying on the ninja behavior of restarting the
build when the build.ninja file was updated to switch between different
bootstrap stages. But that means that every step that could produce a
build.ninja must pass in order to switch to a different stage. That
wasn't a big problem when we had a two stage build -- there was very
little that could fail in the second stage before we chose to go back to
the first stage. But when we had a three stage build, it was possible to
get into a state (usually during development) where you were in the
second stage, but the build was failing because the first stage needed
to be run. This was fixed in d79f1af742
by adding a wrapper that always started building at the first stage.

But this kept all of the complexity of using ninja restarts without any
of the benefits, so this change removes that complexity and just runs
each stage sequentially in the wrapper. So the wrapper is now required.

Since we're no longer going through choosestage, we can also skip the
template parsing for the later stages that don't need to be templated --
this can save a couple of seconds for large files.

In addition to all of the above, this also lets Soong reduce the number
of times the main ninja file is loaded. We had been running the wrapper
once (3 stages), then running ninja again after combining the
Soong-generated build.ninja with the Kati-generated build.ninja. This
change lets us removing the intermediate parsing of Soong's build.ninja,
so that we only execute ninja 3 times per build. It also lets us have
dependencies on pools or rules from Kati in the primary builder, since
we're never executing the main build.ninja without the Kati build.ninja.

The wrapper has a new option, NINJA to provide the path to ninja. This
used to be hardcoded to `ninja`, and will still default to that. But
we'll be running the first two bootstrap stages with $NINJA even if
SKIP_NINJA is set.

The wrapper passes "-w dupbuild=err" to ninja now -- this really should
always be turned on if you care about reliable builds.

Change-Id: I6f656b74eb3d064b8b9e69d1d6dac1129d72b747
2016-08-30 17:26:56 -07:00
Colin Cross
c3d731258a Support nil pointers to structs in properties
Allow primary builders to reduce allocations of empty structures by
allowing nil pointers to concrete struct types.  Property readers will
not recurse into nil pointers, property writers will replace the nil
pointer with a pointer to the zero value of the pointer element type.

Allows a >50% primary builder time improvement with a trivial change in
Soong.

Change-Id: If6ad674bf7bf2a694c335378a074643a97d3c50b
2016-08-05 17:19:36 -07:00
Colin Cross
aec881da86 Add option to trace goroutine execution
Passing -trace <file> on the command line produces a trace file that can
be used with go tool trace to examine concurrency.

Change-Id: I7d27bca64d0f0816cb4e518e947b70bc1c0573a3
2016-08-05 14:00:30 -07:00
Colin Cross
79324963f2 Fix documentation property type for pointers
Change-Id: I7964215adb5e04f5e7a50370e3d98b51ee100ee5
2016-06-02 12:38:24 -07:00
Colin Cross
d9f6fd55dd Remove naming stutter in bpdoc
The word "doc" spread all over bpdoc is redundant and makes it harder to
differentiate the various types and variables.  Everything in bpdoc is a
doc, so remove it.  Also rename Collector to Context.

Change-Id: Ia616d789ee27e7c94d9be231bdb248d45b2b7f39
2016-06-02 12:38:24 -07:00
Dan Willemsen
be275236ac Add blueprint_go_binary for user-run tools
Move these tools from $buildDir/.bootstrap/bin to $buildDir/bin
(configurable by the primary builder).

Also delay building them until the main stage, and give them a phony
target "blueprint_tools".
2016-05-26 10:09:35 -07:00
Colin Cross
2c1f3d1b28 Add support for dependency tags
Primary builder logic is becoming complicated due to the two pass nature
of mutators that add dependencies and GenerateBuildActions that handle
the dependencies.  The reason why the dependency was added is lost by
the time GenerateBuildActions is called, resulting in build logic that
has to recreate all the dependencies and try to match them up to the
modules returned by VisitDirectDeps.

Change the API of AddDependency to take a DependencyTag interface, which
is satisifed by anything that embeds BaseDependencyTag.  Mutators and
GenerateBuildActions that call VisitDirectDeps can pass each Module to
ctx.OtherModuleDependencyTag to retreive the DependencyTag that was
passed when adding the dependency.

Change-Id: I0814dcd26d1670302d340b77e8dc8704ed7b60bf
2016-04-12 14:52:46 -07:00