Commit graph

366 commits

Author SHA1 Message Date
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
Dan Willemsen
5c43e07937 Support implicit outputs
Added in Ninja 1.7, for outputs that will not show up in $out.
2016-10-31 17:36:49 -07:00
colincross
52798022db Merge pull request #128 from colincross/name
Modify module name handling
2016-10-12 13:47:21 -07:00
Colin Cross
9cfd198dd8 Add ReplaceDependencies
ReplaceDependencies allows a module to replace dependencies on a
matching variant of a target module with itself.

Change-Id: I22946dec23c38ed5e1ad23b87121d72668268c01
2016-10-12 13:33:37 -07:00
Colin Cross
c4e5b8157b Add Rename
Allow modules to be renamed by mutators.  This will allow modules to
dynamically adapt to the presence or absence of modules with the same
name.  For example, if a source module does not exist, a prebuilt module
could rename itself to the name of the source module so that
dependenices on the module name are satisified.

Change-Id: I44004604c6d9db041bb7d38fe6c1ca877bc7d6f1
2016-10-12 13:33:37 -07:00
Colin Cross
b3f96c3306 Add OtherModuleExists
Allow dependency modifying mutators to check if another module exists
based on its name.  Allows primary builders to have custom handling for
missing-module errors, for example by falling back to another module.

Change-Id: I04ddd66be43c514f1f8928e15b2a79cadebcfc17
2016-10-12 13:33:37 -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
colincross
b2bee4ee14 Merge pull request #126 from colincross/errors
Improve error reporting
2016-10-12 11:16:29 -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
colincross
ad914cea1a Merge pull request #125 from colincross/build_deps
Add dependency on build= blueprint files
2016-10-11 10:31:12 -07:00
Colin Cross
2458712c0b Add dependency on build= blueprint files
Blueprint files included with build= statements were not adding a
dependency to cause regenerating when they were changed.

Bug: 32085516
Test: touch external/boringssl/sources.bp && mmma -j external/boringssl
Change-Id: Id4fdf3b6788ae5c1e94547dc63ec6b55424a66a0
2016-10-11 10:03:14 -07:00
colincross
888b21f87b Merge pull request #124 from colincross/escape
Add proptools functions to escape strings
2016-09-29 15:49:14 -07:00
Colin Cross
41ca49ff91 Add proptools functions to escape strings
Blueprint properties that end up as command line arguments need to be
both ninja and shell escaped.  Provide helpers that primary builders can
use to appropriately escape them.

Change-Id: Ifd697d87edb1c6f0a910377835c391bbe8f95b42
2016-09-29 14:31:40 -07:00
Dan Willemsen
f5909d9cb5 Merge pull request #122 from danw/structof
Support structures built with StructOf
2016-09-09 13:24:50 -07:00
Dan Willemsen
ec5ba986ae Support structures built with StructOf
In Go 1.7, all generated types (including StructOf) are marked as
unexported types. This is not a problem with regular named fields, since
the whether the field is exported is based on the name, not the type.
But for unnamed (anonymous) fields, there is no name, and it falls back
to whether the type is exported or not. When the field isn't exported,
we're unable to use reflection to set the value.

Special case fields named "BlueprintEmbed" to act like exported unnamed
fields during unpacking. There is no functionality lost here, since code
can not directly access these runtime generated fields.

Structures embedded in the source shouldn't be affected by this change,
unless they happen to use the "BlueprintEmbed" field, which is not a
normal field name due to the capitalization.

Change-Id: I53f3b32b2286c47b2bb1918d6008d0180ad0605e
2016-09-09 13:19:47 -07:00
Dan Willemsen
4a35b51495 Merge pull request #121 from danw/simple_bootstrap
Simplify bootstrap
2016-08-31 00:43:41 -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
colincross
3fc513f94c Merge pull request #120 from colincross/builtin
Add NewBuiltinRule and NewBuiltinPool
2016-08-29 15:22:12 -07:00
Colin Cross
e0e473efb4 Add NewBuiltinRule and NewBuiltinPool
Allow Blueprint build statements and rules to reference rules and pools
defined outside of Blueprint.

Change-Id: I48644497d16a4c2bab88db400dbe7f7fe169d933
2016-08-29 15:12:33 -07:00
colincross
b9fb0ad53d Merge pull request #119 from colincross/extend
Relax type requirements when extending properties
2016-08-22 16:01:27 -07:00
Colin Cross
bf2adbfee2 Relax type requirements when extending properties
Allow using ExtendMatchingProperties to extend pointer to a struct or an
interface containing a pointer to a struct using a struct, and
vice-versa.

Also fixes a pre-existing bug where extending a nested structure could
fail if there were multiple possible destnations and some of them did
not have a matching nested property.

Change-Id: I6e69d78eb6595ba7dd2603e3aa7dd8de3f292744
2016-08-22 15:35:17 -07:00
colincross
7fda24e54b Merge pull request #118 from mortonfox/patch-1
Update link to Ninja
2016-08-17 22:45:39 -07:00
Morton Fox
ebb354179b Update link to Ninja 2016-08-18 00:48:20 -04:00
colincross
e412f09f7e Merge pull request #117 from colincross/variant
Elide empty variations
2016-08-15 12:22:37 -07:00
colincross
087b721ea8 Merge pull request #115 from colincross/parallel
Parallelize TopDownMutators
2016-08-11 17:10:59 -07:00
Colin Cross
badc8817fa Elide empty variations
Don't add a "_" to the variant name if the variation name is empty.  For
example, when splitting a variant with name "foo" into variations "" and
"bar", the new variants would be named "foo" and "foo_bar" instead of
"foo_" and "foo_bar".

Change-Id: I82342d57e2a8e9f2d65a7d8d2872dcb7b3512899
2016-08-11 17:03:26 -07:00
colincross
45f63e414a Merge pull request #116 from colincross/fix
Fix error reporting in parallel mutators
2016-08-11 16:58:40 -07:00
Colin Cross
0fff742172 Fix error reporting in parallel mutators
runMutators was sending the wrong value into errsCh, hiding all errors.
parallelVisit had a data race on error, send the cancel signal over a
channel instead of writing to a bool from a goroutine.

Change-Id: I18919d71464c094db5846badbfac80f99366d70c
2016-08-11 15:41:57 -07:00
Colin Cross
3702ac7531 Parallelize TopDownMutators
Convert parallelVisitAllBottomUp into a generic parallelVisit that takes
a visitOrderer to select top down or bottom up.  Combine
runTopDownMutator and runBottomUpMutator into runMutators that takes a
mutatorDirection to select the visitOrderer for parallelVisit and which
function pointer in the mutatorInfo to run.  Optimize out the
updateDependencies to only run if dependencies have been modified to
avoid running it after TopDownMutators that cannot modify dependencies.

Change-Id: Ib00302db1108ebab2ce8e01b20aa026140d382a4
2016-08-11 14:40:53 -07:00
colincross
056963fe71 Merge pull request #113 from colincross/parallel
Add concurrency to BottomUpMutators and cloneModules
2016-08-11 11:18:15 -07:00
colincross
fcaf58b591 Merge pull request #114 from colincross/gofmt
Enforce gofmt in travis
2016-08-11 11:17:39 -07:00
Colin Cross
5b0231b027 Enforce gofmt in travis
Run gofmt -l . during travis to catch pull requests that have not had
gofmt run on them.

Change-Id: Ibfdf988a535d82721f3c4bc328b189f606f12778
2016-08-11 10:21:37 -07:00
Colin Cross
c93490c679 Parallelize cloneModules
cloneModules duplicates every module, which can be slow.  Spawn a new
goroutine for each module to spread the factory and CopyProperties calls
over multiple cpus.

Change-Id: I2597f921dadfd321ccb705aec9a904c71b75f9ef
2016-08-10 16:31:35 -07:00
Colin Cross
a028bf49ba Fix gofmt
Change-Id: I27b918b801dec25a85e65f88ab90331382ee1ec3
2016-08-10 16:31:35 -07:00
Colin Cross
49c279ab26 Parallelize BottomUpMutators
Allow BottomUpMutators to run in parallel by calling Parallel() on the
return value of RegisterBottomUpMutator.  To avoid locking, moves
updates of global state into a separate goroutine that receives updates
over channels from the mutator goroutines.

Change-Id: Ic59b612da9b406cf59ec44940f0c1dee0c051a51
2016-08-10 16:31:35 -07:00
Colin Cross
f8b5042c86 Implement EarlyMutators with BottomUpMutators
Get rid of runEarlyMutators, and implement EarlyMutators as a shim
around BottomUpMutators.  Removes mostly-duplicate code between
runEarlyMutators and runBottomUpMutator to allow parallelizing
runBottomUpMutator.

Change-Id: I66a051cb8710770b47da21d35e55aa49c84e9be8
2016-08-10 16:31:35 -07:00
Colin Cross
93c4cf6861 Revert "Add dependency visiting methods to BottomUpMutatorContext"
This reverts commit a2b2080fcd.

Dependency visiting methods conflict with the dependency adding methods
already present on BottomUpMutatorContext - mixing calls to visit
dependencies and adding dependencies produces requires hard-to-define
semantics, and complicates parallizing mutators.

Change-Id: I2f793c8db45b97f4d79badc9fe88315fe38d90cd
2016-08-10 16:31:35 -07:00
colincross
1c1ec45ebb Merge pull request #111 from colincross/visit
Reimplement VisitDirectDeps[If] on Context.walkdeps
2016-08-09 13:37:18 -07:00
colincross
1aece72b35 Merge pull request #112 from colincross/opt
Only instantiate nil struct pointers that are used
2016-08-09 12:36:18 -07:00
Colin Cross
a437135876 Only instantiate nil struct pointers that are used
unpackProperties was instantiating all nil struct pointers in any struct
that had a property set.  Check if the property is set first, and only
instantiate the struct if it was set.

This has a slight behavioral change, as now structures that only exist
through nil pointers and are never set into will not be type-checked.
This should be fixed in a later patch set that moves the type checking
to be done across all property structs once per factory before blueprint
files are loaded.

Change-Id: I0dea34d7fff76bb4fc907516a2d996e4ea2408d6
2016-08-08 17:35:29 -07:00
Colin Cross
bafd5f5a2b Reimplement VisitDirectDeps[If] in on Context.walkdeps
VisitDirectDeps[If] need to know the parent in order to support
OtherModuleDependencyTag(), remove Context.visitDirectDeps[If] and
reimplement [Module]Context.VisitDirectDeps[If] using Context.walkdeps.

Change-Id: I2faac2d100d2a0ad2a4f1d8250997eed1a7ef6f0
Test: TestVisit
2016-08-08 17:30:38 -07:00
Colin Cross
365bc6b3ea Add tests for Visit*
Change-Id: I52505ee4e23ec8b1c5763b3216788e999de9c8d3
2016-08-08 17:26:57 -07:00
Colin Cross
d7b0f60802 Allow tests to mock filesystem
Tests can call Context.MockFileSystem to pass in a map of filenames to
contents.

Change-Id: Idd67c68f7cb43bc2117cc78336347db7e2f21991
2016-08-08 17:26:57 -07:00
colincross
fd1ef9ec7a Merge pull request #110 from colincross/opt
Optimize proptools
2016-08-08 15:48:13 -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
01ee36eeea Optimize proptools
proptools cloning and extending are a significant portion of the run
time for Soong.  Optimize out calls to reflect.Type.Field(), which must
allocate a []int to store the index, by caching all the fields of each
type as it is seen, and by iterating over a slice of cached fields
instead of calling Field(i) for each one.  Also avoid calling
reflect.Value.Interface() twice on the same Value.

Change-Id: I4e13fc85f30d8614a5586283e928c0a6d7f24809
2016-08-05 14:00:30 -07:00
Dan Willemsen
9544a07d2f Merge pull request #107 from danw/moduletype
Expose ModuleType to Singletons
2016-07-27 13:42:46 -07:00