Commit graph

149 commits

Author SHA1 Message Date
jgennis
b96aa8b58f Merge pull request #3 from colincross/features
New features
2015-03-10 13:06:59 -07:00
jgennis
482e8cf331 Merge pull request #1 from colincross/bugfixes
Miscellaneous bugfixes
2015-03-05 17:19:29 -08:00
jgennis
40e81c3a3e Merge pull request #2 from colincross/docs
Add overall Blueprint documentation
2015-03-05 17:04:50 -08:00
Colin Cross
174ae059cc Report variant errors instead of panicing
Variant errors can be introduced by Blueprints files, so print
a module error instead of panicing.
2015-03-04 14:00:50 -08:00
Colin Cross
cb7b9ad6ca Go back to the old Blueprints file format
Switch back to:
moduleType {
    name: value,
    arch: {
        x86: {
            name: value,
        },
    },
}

This provides better consistency between properties defined at the
top level of a module and properties defined inside a map.

The parser will continue to support the other format for now, but the
printer will only produce the original format.
2015-03-04 14:00:06 -08:00
Colin Cross
d9d92cb75d Print names of files deleted by cleanup phase
Change-Id: Ia9c5408b1b159843dbc57e2e480ca2972598186d
2015-03-04 14:00:06 -08:00
Colin Cross
542fd55c38 Allow adding maps
Add support for + operator on maps.  The semantics are that keys that
exist in both maps are added with the + operator, and keys that exist
in one map are copied to the resulting map.

Change-Id: Iba9a6f886477a1eb7311272d07944800c806e368
2015-03-04 14:00:06 -08:00
Colin Cross
c7ffa30b8a Add VisitDirectDeps to module context
Change-Id: I271db2120aba1a5c99f21198f1eff6370e6e2389
2015-03-04 14:00:06 -08:00
Colin Cross
b274e6c8e5 Support += assignments
Support += assignments to variables.  Variables are now mutable
up until they are referenced, then they become immutable.  This
will allow variables to be modified in a conditional, or allow
better commenting on why parts of a variable are set.

Change-Id: Iad964da7206b493365fe3686eedd7954e6eaf9a2
2015-03-04 14:00:06 -08:00
Colin Cross
9a103c0ed4 Modify printer to be stricter about extra newlines
The printer was allowing extra newlines in odd places, for example
between a property name and the '=' in a module definition.  Make
newline location stricter by explicitly allowing newlines or
line comments.
2015-03-04 13:57:21 -08:00
Colin Cross
8900e9bd37 Exit early from generateModuleBuildActions on error
generateModuleBuildActions was continuing to call GenerateBuildActions
on all modules even after one returned an error.  This could cause a
later module to panic because it was missing information that was
supposed to be generated by the module that returned an error, hiding
the earlier error message.

If a module returns an error, stop triggering any new goroutines to
call GenerateBuildActions on later modules.
2015-03-04 13:27:39 -08:00
Colin Cross
93ef72d283 Don't fail cleanup when a file has turned into a directory
If .ninja_log contains an entry that used to be a file but is now a
non-empty directory the os.Remove call will fail.  Silently ignore
this error, if the files in the directory are abandoned the directory
will be cleaned up when the files are removed.
2015-03-04 13:27:30 -08:00
Colin Cross
11e3b0d000 Fix deadlock when there are no modules
Change-Id: Ibfc1190f2b5ac3c3445d40f1b5dd0cd782e63dfd
2015-03-04 13:27:20 -08:00
Colin Cross
e7a26ff65a Add overall Blueprint documentation
Change-Id: I27f0f010c32b3abe0107e69af830716ab728485a
2015-02-04 11:23:46 -08:00
Jamie Gennis
c4b691f2fb Add an initial README.md 2015-01-27 16:34:17 -05:00
Colin Cross
f5bd828a14 Run bpfmt -w . to reformat Blueprints file
Updates the Blueprints file to the new format and standard layout.

Change-Id: I1bfb67ab106c2a61fbe6f8201195efc3f8ff5566
2015-01-26 16:56:10 -08:00
Colin Cross
8e0c51192a Add license headers and LICENSE file
Change-Id: I6f7c7374093c0745ee4aa677480376a06648b358
2015-01-23 14:23:27 -08:00
Colin Cross
3e8e74f276 Move blueprint/* up a directory
Make integrating with go tools easier by putting the blueprint package
files in the top level directory of the git project instead of in a
subdirectory called blueprint.

Change-Id: I35c144c5fe7ddf34e478d0c47c50b2f6c92c2a03
2015-01-23 14:23:27 -08:00
Colin Cross
6bb4af9e20 Update parser and printer to use new Blueprint format
Updates the standard format from:
module_type {
    property: "value",
}
to:
module_type(
    property = "value",
}

The parser will accept both formats for now, so all files can be
updated to the new format using bpfmt -w .

Change-Id: I9566cf1bd3cd66c6cbf3d4bd9dac1f04b9112927
2015-01-23 13:41:51 -08:00
Colin Cross
a434b3fd69 Keep dependencies in order
Don't sort the dependencies, keep them in the order they were in the
Blueprints file and use a set to prevent adding duplicates to the list.

Change-Id: Icade91d035ccfb12c26ba0584144c1723607019c
2015-01-23 13:41:51 -08:00
Colin Cross
3793062859 Rebootstrap for changes to any bootstrap go binaries
The final build.ninja can't contain a rules to build the primary
builder or it will create a circular dependency, so rules for all
bootstrap go packages and binaries are replaced with phony targets
that trigger a re-bootstrap to rebuild.  Add all bootstrap go
binaries to the dependencies that trigger a rebuild so that they
all get rebuilt.

Also fix the phony rule generation to include rules for the
intermediate files of bootstrap go binaries so that they don't
get deleted by the cleanup phase when the primary builder runs.

Change-Id: Id0cc287789f74cc4b21b062086723712b57ee051
2015-01-23 13:41:51 -08:00
Colin Cross
41c397af78 Initial bpmodify tool
bpmodify can be used to add or remove dependencies or other strings
from selected modules in Blueprint files.

Change-Id: I0df3762976e74bf46fd2922bbd48b46e526b7951
2015-01-23 13:41:51 -08:00
Colin Cross
5ad47f47fc Initial bpfmt tool
bpfmt is based off gofmt, and formats a blueprint file to a standard
format.

Change-Id: I060c1b6030bc937a8db217eaed237d8792c29565
2015-01-23 13:41:51 -08:00
Colin Cross
d1facc1ce7 Return comment and position information from parser
Return comment info from parser, which will be used later for
pretty printing a parsed Blueprint file.  Also add more position
information to the AST.

Change-Id: I3cf0ba8ea4ba5b931d032098ae5fdc350806ed98
2015-01-23 13:41:51 -08:00
Colin Cross
691a60dd98 Parallelize GenerateBuildActions
Modify the Generate phase to call GenerateBuildActions inside a
goroutine to allow parallization.  All modules from a single
moduleGroup are called from a single goroutine, and the goroutines
that processed all dependencies must have finished, so the only
change to the semantics of GenerateBuildActions implementations
is around access to globals.  Locks are added to the lazily
created package context variables and to the live tracker.

Reduces run time by ~33%.

Change-Id: I62a515acf86f1dcecb093ded83444b920ff603be
2015-01-23 13:41:51 -08:00
Colin Cross
7ad621c2b4 Parallelize Blueprints file parsing
Parse multiple Blueprints files simultaneously by using a goroutine
to read the file, call the module factory, parse the properties,
and look for subdirectories.  Requires module factories to be
reentrant, but otherwise does not change any build logic semantics.

Change-Id: Ia07579917a2b6fd064cedbfff655c23d706da718
2015-01-23 13:41:50 -08:00
Colin Cross
1455a0f7b1 Remove pregenerate pass
PreGenerateBuildActions is no longer used by the build logic, remove it.

Change-Id: I621c26e796d2bf6cdc587770a8f9572a769bc705
2015-01-23 13:41:50 -08:00
Colin Cross
80ad04d5f8 Add FinalModule and VisitAllModuleVariants to ModuleContext
Allows modules to determine if they are the last of their variants
to build, and to visit each variant to collect shared information.

Change-Id: I396f0c9d43e0e9b1901822d6dd9c6ad6380ad582
2015-01-23 13:41:50 -08:00
Colin Cross
82b7d51dfd Add support for simple expressions
Add support for the + operator to concatentate strings and lists.

Change-Id: I6b6d74122e8f9e509d411c82250f440b09dc5765
2015-01-23 13:41:50 -08:00
Colin Cross
c0dbc553a2 Add basic variable support
Assignments to arbitrary variables are now supported in Blueprint
files.  Variables cannot be reassigned, and they stay in scope for
the remainder of the current Blueprint file and any subdirs Blueprint
files.  Variables can be used in place of a value in properites or
as an entry in a list.

Change-Id: I04447e4c541304ded802bb82d1ca4ce07d5d95d2
2015-01-23 13:41:50 -08:00
Colin Cross
c902848e5a Add support for Mutators
Add Mutators, which can be used to split a module into multiple
variants.

Change-Id: Ib992da2e93a557559a3a34571d5033192e129e49
2015-01-23 13:41:50 -08:00
Colin Cross
11a114f454 Allow properties to have unsettable int and uint fields
Allow properties structs to contain exported int and uint fields,
but only if they are tagged with blueprint:"mutated".  These fields
will be copied by CopyProperties in order to propagate through
cloning during mutations, but can only be set by Mutators and not
by Blueprint files.

Change-Id: Ic462385799c77667e392f4928d02d424c8f8d900
2015-01-23 13:41:50 -08:00
Colin Cross
bbfa51a229 Module groups to support variants
A future patch will rewrite context and module_ctx to support multiple
variants of a single module.  This requires adding a layer of indirection
between the module defined in a Blueprint file and the Module object
built by the build logic.

What used to be called a moduleInfo struct is now a moduleGroup struct,
and contains the generic information taken from the Blueprint file.
Inside the moduleGroup struct is a list of moduleInfo structs, which
contain a logicModule pointer to the Module object returned by the
ModuleFactory function from the build logic.  moduleInfo also contains
the name of the variant, as well as the dependencies after they have
been resolved from Blueprint string dependencies to dependencies on
a specific Module.

Change-Id: Id4d516ffc13381c3ce07b80eaf32d9090ae43703
2015-01-23 13:41:50 -08:00
Colin Cross
f77510c1eb Fix CopyProperties on interface to pointer to struct
CopyProperties expects to interfaces in a struct to be an
interface to a pointer to a struct, but expects to be called
on a struct.  When a struct contains an interface, dereference
it twice with Elem() before calling CopyProperties on it.

Change-Id: I0d10aff87729273a025ab6d86239fd60662a20c0
2015-01-23 13:41:50 -08:00
Colin Cross
be1a9a10cd Rename DynamicDependerModuleContext to BaseModuleContext
DynamicDependerModuleContext is really a base module context used
by multiple types of ModuleContext interfaces.  Rename it to
BaseModuleContext, and create a new DynamicDependerModuleContext
that just wraps it.

Change-Id: Ibb402e1d680d50ed15d6548e99b32cc0b5b52b12
2015-01-23 13:41:49 -08:00
Colin Cross
573a2fd4fc Store a sorted module list
Walk the dependency tree once in order to create a list of modules
such that that any module is guaranteed to be later in the list than
any of its dependencies.  Allows easily walking the tree in child-first
or parent-first order by walking the list in forward or reverse order.

Change-Id: I8f2013ebf700d1bc4c41b7898742a426f032ea2f
2015-01-23 13:41:49 -08:00
Colin Cross
fea2b75e2d Fix gofmt
Run gofmt -w to fix formatting.

Change-Id: Idae9235fb5cd9d6374026a284ec56d85cdaad0b9
2015-01-23 13:41:49 -08:00
Colin Cross
e4cfdf93a9 Optimize parseNinjaString
The closures in parseNinjaString seem to confuse go's escape
analysis, causing it to allocate a new stateFunc object on the
heap for every character in the string.  Convert the state
functions to normal functions, and pass a pointer to a state
object to provide access to the variables that were in the
closure.

The range iteration on the input string was iterating over
UTF-8 runes, when all of the rune comparisons for state
changes only look at ASCII bytes.  Switch to iterating
over bytes, stringState will pass through multi-byte
characters in strings untouched.

Together this reduces the time spent in parseNinjaString by
>50%, and the overall execution time by >20%.

Change-Id: I4c926b52b883d51e2f12a1673d03fcc2cfe83445
2015-01-23 13:41:49 -08:00
Christian Zander
6e2b232d79 Make Ninja string evaluation more robust
ninjaString's Eval() does not currently check if all of the variables
referenced by the Ninja string being evaluated are present in the
map provided by the caller.  This commit adds such a check.

Change-Id: I15cf3c44cc1eedaf6f93a9533b8cdcbffd74992c
2015-01-23 13:41:49 -08:00
Jamie Gennis
0bb5d8a8d9 Fix predicated visitors.
This change makes the Context.visitDepsDepthFirstIf() method descend into
modules for which the predicate is false rather than skipping their entire
sub-DAG.

Change-Id: I50564c69a714d5e199e1a51a8aa24162b0dc6f11
2015-01-23 13:41:49 -08:00
Colin Cross
b2e7b5d036 Add a PreGenerateBuildActions pass
Call PreGenerateBuildActions on each module that implments it after
resolving dependencies but before calling GenerateBuildActions on
any module.  This allows the build logic to propagate top-down
information, for example what variants of a library need to be
compiled for the binaries it is used in.

Change-Id: I2737504fa9d1a2b42ef747497de32c1c5129233d
2015-01-23 13:41:49 -08:00
Jamie Gennis
c4ed709a71 bootstrap: Fix abandoned file removal.
This change makes removeAbandonedFiles perform some of the string substitutions
that are done by the bootstrap script before considering whether a built target
still exists.  It fixes a bug where the bootstrap manifest would get deleted
and subsequently regenerated, resulting in more re-bootstrap iterations than
was necessary.

Change-Id: I946c883dcc31fb77496f64d2573b395ad2cf095d
2015-01-23 13:41:49 -08:00
Jamie Gennis
df935ac324 Make Context.AllTargets() evaluate variables.
Change-Id: Iaa7e134cb5cb9fd1491a2508a7953fb4cbc53d1e
2015-01-23 13:41:48 -08:00
Jamie Gennis
9e2a4c295b bootstrap: Don't export the script-substituted Ninja vars
Change-Id: I8999f9489415cc53661e079401df519f9d83258e
2015-01-23 13:41:48 -08:00
Colin Cross
42cad4b7dc Add pathtools.ReplaceExtension
Change-Id: I67d08700fce37b7949e6103132212766cdbe54ec
2015-01-23 13:41:48 -08:00
Colin Cross
46f8d184fb Pipe the Optional flag from BuildParams to the build definition
An Optional flag on buildDef is not very useful on its own,
BuildParams is what is exposed to modules.

Change-Id: I49b341654162adbc4eab884e88c21e68bbce8c75
2015-01-23 13:41:48 -08:00
Colin Cross
aa847f2893 Add support for Optional parameter to build definitions
Build definitions can now specify Optional.  If Optional is not
specified the build definition will be followed by a default definition
for all outputs.

Change-Id: Iada83b2ef32bfb599b3cc580263f12bc002e1cdb
2015-01-23 13:41:48 -08:00
David Allison
701fbad02b Add the ability to check if a property is present
This adds (to the ModuleContext) a facility to check if a property is
defined in a module in a Blueprints file.

Change-Id: I16a35fd236717d8797f15093c019f7cc1049fb3c
2015-01-23 13:41:48 -08:00
Nico Hailey
b6a5039e88 pathtools: Fixed absolute path bug in Glob.
Change-Id: I30ba550449787648f6dca052b89f4eb7722bcb55
2015-01-23 13:41:48 -08:00
Jamie Gennis
af43556ce3 Add support for removing abandoned files.
This change makes the bootstrapping process remove any files that were
previously created by invoking a Ninja rule (i.e. they appear in the .ninja_log
file) but are no longer a build output target.

Change-Id: I3c78e563393b97f8ca196ac85c7caa2b3866ffa6
2015-01-23 13:41:48 -08:00