Commit graph

281 commits

Author SHA1 Message Date
Colin Cross
0aa6a5f0ad Catch panics in build logic
Catch panics in the build logic in order to provide extra data on when
the panic occurred, for example which module had GenerateBuildActions
called on it.
2016-01-07 17:24:26 -08:00
Colin Cross
ea5995439c Colorize errors
Prefix errors with "error:" or "internal error:" colored in red using
ANSI codes.  Ninja will strip the ANSI codes when build output is not
going to a terminal that can handle ANSI codes.
2016-01-07 17:24:15 -08:00
Dan Willemsen
2acf987b8b Merge pull request #91 from danw/replace_strptr
AppendProperties: Replace *strings instead of appending
2016-01-06 10:30:05 -08:00
Dan Willemsen
4c00085f2d AppendProperties: Replace *strings instead of appending
This makes *string values act like *bool values -- instead of appending
or prepending the contents of the string, the entire string is replaced.
The use case here is for overriding filenames, where appending doesn't
work.
2016-01-05 14:16:04 -08:00
Dan Willemsen
bd93c9a39c Merge pull request #90 from danw/pctx_addninjafiledeps
Add AddNinjaFileDeps to PackageContext
2015-12-21 12:09:33 -08:00
Dan Willemsen
a481ae2018 Add AddNinjaFileDeps to PackageContext
Soong needs to add dependencies during a VariableFunc. (we're doing a glob)

Change-Id: Iec7b7082b89e1c7fa43fe7240888d2dabb097a9a
2015-12-18 15:22:26 -08:00
Dan Willemsen
61686a1077 Merge pull request #86 from danw/wrapper
Add build wrapper to do stage selection before ninja
2015-12-18 11:14:47 -08:00
colincross
654e20d4c7 Merge pull request #88 from colincross/missing_dependencies
Allow primary builder to handle missing dependencies
2015-12-18 11:07:35 -08:00
colincross
c39cf6b48d Merge pull request #89 from colincross/context_subdir
Add ModuleSubDir to Context and SingletonContext
2015-12-18 11:07:32 -08:00
colincross
1734f30dd2 Merge pull request #87 from colincross/optionalsubdirs
Add optional_subdirs variable support
2015-12-18 11:07:08 -08:00
Colin Cross
8c602f7f16 Add ModuleSubDir to Context and SingletonContext
Singletons may need ModuleSubDir, for example to implement a stable sort
on modules.  Add ModuleSubDir to SingletonContext and Context.
2015-12-17 18:02:58 -08:00
Colin Cross
036a1df374 Allow primary builder to handle missing dependencies
In some cases the primary builder may need to handle missing
dependencies.  Add Context.SetAllowMissingDependencies to cause
Blueprint to store the list of missing dependencies without immediately
emitting an error, and ModuleContext.GetMissingDependencies to return
the missing dependencies to the primary builder.  If the primary builder
does not call ModuleContext.GetMissingDependencies Blueprint will emit
dependency errors.
2015-12-17 17:26:20 -08:00
Colin Cross
7f50740688 Add optional_subdirs variable support
When building a subset of a source tree, some of the subdirectories
mentioned in the subdirs variable may be missing.  Add support for an
optional_subdirs variable, which won't error out if the requested
directory is missing.
2015-12-16 13:03:41 -08:00
Dan Willemsen
d79f1af742 Add build wrapper to do stage selection before ninja
This wrapper script can be used instead of ninja to ensure the build
won't get stuck building the primary builder.

An example of when this would happen:

1. Do a successful build
2. Sync/make a change in the primary builder (soong, etc) that depends
   on a blueprint change.
3. The next build would notice that change, and rewind to the primary
   stage to rebuild the builder. That build would fail.
4. Sync/fix the blueprint code.
5. The next build would still fail. The bootstrap stage would need to
   be run in order to fix the primary stage, but we're still stuck in the
   primary stage. The only way to switch stages is to successfully
   complete everything required to choose the next stage.

This generally isn't a problem in the main stage, since there is no code
being built in the dependency chain leading up to stage selection.

Any existing wrappers (like soong) can execute this wrapper (optionally
skipping ninja execution) if they're worried about the above situation.
This isn't strictly required -- running ninja directly will still work
in most cases, you'll just need to re-run bootstrap.bash if you get into
a bad state.

Change-Id: I5901d7240a1daa388a786ceb1c8259502fc14058
2015-12-10 16:18:15 -08:00
Dan Willemsen
eb97a6e7a1 Merge pull request #85 from danw/sctx_failed
Add SingletonContext.Failed()
2015-12-10 09:21:26 -08:00
Dan Willemsen
265d92c7fa Add SingletonContext.Failed()
Identical to ModuleContext.Failed(), just returns whether there has been
an error added to the context.
2015-12-09 18:06:23 -08:00
Dan Willemsen
e8b63ad172 Merge pull request #84 from danw/pkgctx
Allow wrapping of PackageContext
2015-12-01 12:53:01 -08:00
Dan Willemsen
aeffbf776a Allow wrapping of PackageContext
Turn PackageContext into an interface so that build systems can wrap it
to add more custom helpers.

This does introduce an API change, though it should be fairly simple.
NewPackageContext used to provide an opaque *PackageContext struct, now it
provides a PackageContext interface.

Change-Id: I383c64a303d857ef5e0dec86ad77f791ba4c9639
2015-11-30 17:03:34 -08:00
colincross
6afb72ff1b Merge pull request #83 from colincross/embed
Support embedded anonymous property structs
2015-11-24 11:23:39 -08:00
Colin Cross
5a9f4d1db2 docs: support embedded anonymous property structs
Embedded anonymous structs have no name, use the type as the name for
now.  Eventually we should hide the name completely and put the
properties in the embedding struct.
2015-11-23 13:25:30 -08:00
Colin Cross
9d1469d559 Support embedded anonymous property structs
Allow property structs to contain anonymous embedded structs and
interfaces.  Properties in an anonymous embedded struct or interface are
treated as if they were properties in the embedding struct.
2015-11-20 17:26:52 -08:00
Colin Cross
83cedbec85 Fix ZeroProperties bug on nested interfaces
ZeroProperties was setting nested structs to their zero value, even if
they contained an interface that should be recursed into, not replaced
with nil.
2015-11-20 17:26:52 -08:00
colincross
5c11f817e1 Merge pull request #80 from colincross/optionalremove
Make removing abandoned files optional
2015-11-18 16:21:06 -08:00
colincross
1af8a230c7 Merge pull request #82 from colincross/builddir
Use context builddir for removing abandoned files
2015-11-18 16:20:31 -08:00
Colin Cross
a259945b74 Use context builddir for removing abandoned files
Removing abandoned files needs to know where the .ninja_log file is
stored.  Export the ninja builddir value from Context and use it to
determine the .ninja_log path in any stage.

The ninja builddir (where ninja stores its .ninja_log and .ninja_deps
files) and the bootstrap.BuildDir (where build output files are written)
are distinct, so to reduce confusion replace SetBuildDir with
SetNinjaBuildDir.
2015-11-18 16:06:19 -08:00
colincross
9bb9545db3 Merge pull request #81 from colincross/builddir
Allow multiple calls to ctx.SetBuildDir
2015-11-18 15:33:36 -08:00
Colin Cross
6d529f0e16 Make removing abandoned files optional
Build logic can now implement a RemoveAbandonedFiles, and the bootstrap
logic will only remove abandoned files if that method returns true.
Leaving the method unimplemented will result in the existing behavior of
always removing abandoned files.
2015-11-18 15:29:12 -08:00
Colin Cross
01739302cb Allow multiple calls to ctx.SetBuildDir
ctx.SetBuildDir is called by the bootstrap singleton, which is always
last.  In order to allow the primary builder to set the directory for
.ninja_log/.ninja_deps, remove the panic on multiple calls to
ctx.SetBuildDir, and always used the value passed by the first caller.
2015-11-18 15:15:41 -08:00
Dan Willemsen
e6006362da Merge pull request #78 from danw/ruledeps
Add common implicit deps to Rules
2015-11-17 17:59:43 -08:00
colincross
5b082a9edf Merge pull request #79 from colincross/enotdir
End removing directories on ENOTDIR
2015-11-17 17:49:51 -08:00
colincross
2efbb49023 Merge pull request #76 from colincross/variantmethods
Add variant methods to SingletonContext and Context
2015-11-17 17:49:11 -08:00
colincross
33c55fe809 Merge pull request #74 from dje4g/add-newline-2
Add blank line after build rules, for human readability.
2015-11-17 17:48:59 -08:00
Dan Willemsen
fce63d3c8f Add common implicit deps to Rules
For implicit dependencies that will be common to all users of a Rule,
add a new field 'CommandDeps' to the RuleParam. This is a list of
strings to be prepended to the implicit dependencies in each BuildParam.

This lets us have the dependencies declared next to where they are used,
instead of duplicated in areas that may be far apart.

I looked at passing this information down to ninja too, but it only
saves us a few percent of ninja file, and requires a modification to the
ninja file format.

Change-Id: Ifd910dee1506d4e32a76ed06206f853c4caec622
2015-11-17 17:08:05 -08:00
Colin Cross
24ad587138 Add variant methods to SingletonContext and Context
Add VisitAllModuleVariants, PrimaryModule, and FinalModule to
SingletonContext so singletons and tools can deal with modules with
multiple variants.
2015-11-17 16:47:50 -08:00
Colin Cross
ca3817145c End removing directories on ENOTDIR
An abandoned directory may have been replaced with a file, give up on
removing the directory on ENOTDIR.
2015-11-17 16:35:22 -08:00
colincross
ff7104f98d Merge pull request #75 from colincross/go15
Update travis to use go 1.5
2015-11-17 15:13:17 -08:00
colincross
f5df83e7ee Merge pull request #72 from dje4g/build-rule-comments
Support comments in build rules.
2015-11-09 13:12:26 -08:00
Colin Cross
a2cd69899f Update travis to use go 1.5
Update .travis.yml to specify go 1.5.1, and update build.ninja.in to
include the new in line function names used by go 1.5.
2015-11-09 12:56:38 -08:00
Doug Evans
9c1cbb4a04 Add blank line after build rules, for human readability. 2015-11-09 11:37:39 -08:00
Doug Evans
fcc6739e34 Support comments in build rules.
Tested: sh tests/test.sh
2015-11-08 12:21:58 -08:00
colincross
a17f759660 Merge pull request #69 from colincross/depserrors
Don't rely on deps property position
2015-11-04 11:04:37 -08:00
Colin Cross
7fcb7b00e4 Don't rely on deps property position
Dependency errors were prefixed with ??? because they were associated
with the position of the "deps" property, which is often not used.  Use
the position of the module instead.
2015-11-03 17:33:29 -08:00
colincross
d130c11bc7 Merge pull request #67 from colincross/reversedependencies
Sort reverse dependencies
2015-11-03 17:32:55 -08:00
colincross
eeb5f95873 Merge pull request #68 from colincross/selfdep
Print useful error for self-dependency
2015-11-03 17:32:47 -08:00
Colin Cross
045a597603 Print useful error for self-dependency
beforeInModuleList panic'd when checking if a variant was before itself
in the module list.  Return a real error instead of calling
beforeInModuleList, and also fix beforeInModuleList to return false for
the same module.
2015-11-03 17:00:26 -08:00
Colin Cross
8d8a7af4af Sort reverse dependencies
AddReverseDependencies would add modules the target's dependency list in
a non-deterministic order based on the order the modules were parsed.
Redefine AddReverseDependencies to collect dependencies until the end of
the mutator and then add them sorted by name.
2015-11-03 16:41:29 -08:00
colincross
f401db416d Merge pull request #65 from colincross/propertyerrors
Improve PropertyErrorf
2015-11-03 14:42:24 -08:00
colincross
cd206b2ca0 Merge pull request #66 from colincross/othermodule
Add OtherModuleName and OtherModuleErrorf to mutators
2015-11-03 14:42:07 -08:00
Colin Cross
8d22233f80 Add OtherModuleName and OtherModuleErrorf to mutators
TopDownMutators can visit dependencies, provide OtherModuleName and
OtherModuleErrorf so they can query and report errors on those
dependencies.
2015-11-03 14:31:39 -08:00
Colin Cross
a2ca92c962 Improve PropertyErrorf
PropertyErrorf gets called from build logic, and shouldn't panic if the
build logic reports an error on an unset property.  Fall back to using
the module position if the property wasn't set.

Also put the property name into the error message.
2015-11-03 14:31:19 -08:00