Commit graph

73 commits

Author SHA1 Message Date
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
Jamie Gennis
debef53c56 Add a Glob func that returns dirs searched
Change-Id: I35ab9a5f1c7425f42d0e667bac38450afa34c738
2015-01-23 13:41:48 -08:00
Colin Cross
daf6499a4a update golang build rules for go 1.3.3
Change-Id: I873d5f205bd0596ee3e0f992cfedb458be710e01
2015-01-23 13:41:47 -08:00
Colin Cross
5e3594f623 Add dependencies on golang tools
Add a dependency on the golang tool for each tool output file.  This
will allow updating the go version without cleaning the output
directory.

Change-Id: I55048e96c8847635256bd9491e2cd12ddf29771b
2015-01-23 13:41:47 -08:00
Colin Cross
535434a59d Move cgofilter to be built by bootstrap.ninja
Building cgofilter from main.ninja creates a circular dependency.
Move it to be built by the bootstrap stage instead, where go
files are built without cgofilter.

Change-Id: I853eb0b20a364adbfb93d44b039e1493214a6887
2015-01-23 13:41:47 -08:00
Colin Cross
add65dd4c1 Sort variables by name when writing ninja files
Regenerating build.ninja.in was non-deterministic, sort the maps
of name, value pairs before writing them.

Change-Id: I825734162b1adebc88ddb19d912751108322091e
2015-01-23 13:41:47 -08:00
Jamie Gennis
fbb27fe2d9 Add a utility function for writing depfiles.
Change-Id: Ic365e3e1632d518a5331646ed5deef1b5a36f2f6
2015-01-23 13:41:47 -08:00
Jamie Gennis
61e27fe331 Wrap a line in the docs
Change-Id: Ifea051b4ba89bcaefbaa0d8c8a8685595c377d40
2015-01-23 13:41:47 -08:00
Jamie Gennis
9914aeb703 Allow the multipass workaround to be disabled
Change-Id: I78f38ef4534a86cec9ce169e1bca91c758c66402
2015-01-23 13:41:47 -08:00
Jamie Gennis
30d8a3a2ed Fix a string parsing bug
Change-Id: I70faa1c06f19f70455a6d8f7db1da37203e21797
2015-01-23 13:41:47 -08:00
Jamie Gennis
68540dab06 Fix the context parse test
Change-Id: I411916b4d4d62cd53d870299f2a415371ed644a3
2015-01-23 13:41:47 -08:00
Jamie Gennis
8762292240 Add support for unpacking properties into nested structs.
Change-Id: Idb67dcb9cc7f857258b9b3409db68199d42a8001
2015-01-23 13:41:47 -08:00
Jamie Gennis
b9cbdae701 Add the blueprint/proptools package.
This change adds some utility functions for manipulating properties structs
using reflection.

Change-Id: I62017ef06bceb68d536421e50b853449a73daed3
2015-01-23 13:41:47 -08:00
Jamie Gennis
1174c695eb Revert "Add support for targets in Blueprints."
This reverts commit 63cdbb3c540349e877ac37a82b2b46565ee45fe7.

Change-Id: I5fd4db75ee04dfa706b26757cd0a247bd8748840
2015-01-23 13:41:47 -08:00
Jamie Gennis
6736ec30da Add the offending character to the bad-ninja-name error message.
Change-Id: I93260a064aece41c53afcecad73c037eb87e5aea
2015-01-23 13:41:47 -08:00
Jamie Gennis
2fb2095caa Stop determining package names from the call stack.
This change replaces the automatic caller package divination with a
PackageContext object that must be explicitly passed in by callers.

Change-Id: I139be29ecf75a7cf8488b3958dee5e44363acc22
2015-01-23 13:41:46 -08:00
Jamie Gennis
0c35b2db92 Ignore subdirs starting with a '.'
Change-Id: I67bb7c4fe02942c79973287cd3bf57627b6cdd1c
2015-01-23 13:41:46 -08:00
Jamie Gennis
b9e87f6af2 Add support for dynamic module dependencies.
This change adds the DynamicDependerModule interface.  Any Module type that
implements that interface will be called before Blueprint does its depenedency
analysis to allow the module to add additional dependencies.

Change-Id: I4d9ef8663d187262dcd9a1ec410c180c3ca4f57d
2015-01-23 13:41:46 -08:00
Jamie Gennis
c15544dbc7 Sort various things for deterministic output.
Change-Id: If6457713ad442ae3e4179e594820fa1e02e9b240
2015-01-23 13:41:46 -08:00
Jamie Gennis
b282d5c8d6 Fix a bug that allowed duplicate module names.
Change-Id: I9317e43ac435a26397557328036c11a8a2da7480
2015-01-23 13:41:46 -08:00
Jamie Gennis
7d5b2f82ce Simplify module and singleton registration.
This change eliminates blueprint.ModuleType and replaces it with simple factory
functions.  Rather than using the explicitly provided ModuleType names to
essentially identify the Go factory function in the generated Ninja files, we
now use the actual factory function name.

Change-Id: Ib7813e850322a82cc35cdc56bebff7d580a5c6ec
2015-01-23 13:41:46 -08:00
Romain Guy
285296519a Add support for targets in Blueprints.
The default target selector uses the name of the host OS.
Modules can implement their own target selector by implementing
the context.TargetSelector interface and its unique selectTarget()
method.

Targets are defined this way in Blueprint files:

cc_library {
    name:  "libmylib",
    deps:  ["libmath", "libutils"],
    zones: ["frontend"],
    srcs:  ["main.cpp"],
    targets: {
        darwin: {
            moduleCflags: "-framework OpenGL -framework GLUT",
        },
        linux:  {
            deps: ["libx11headers", "libglu"],
        },
    },
}

In this example, a set of C flags are defined on OS X only and on
Linux, two new dependencies are added.

When a target is selected, its properties are merged with the properties
of the modules:
- a list is appended to the original list (see deps above)
- a string is concatenated to the original string
- a bool replaces the original bool
- a map adds or replaces the key/value pairs of the original map

Change-Id: Ic627d47f795d6a4ff56ca5f6f099cad157621af1
2014-08-12 17:50:11 -07:00
Romain Guy
2476f81d84 Add support for map properties
Example:

foo {
  // string property
  name: "hello",
  // map property
  translations: {
    ge: "guten tag",
    fr: "bonjour",
  },
}

Change-Id: Ib9e6570cb6f355677b4ba0235e8fb4186e40f5f8
2014-07-25 17:01:20 -07:00
Romain Guy
5f7ef51f7a Add support for raw strings
Change-Id: Ib68f1a08c8707b8c955d25bf0a7fd6f491c0b470
2014-07-24 15:29:42 -07:00
Jamie Gennis
ae4430cd9e Stop processing modules when one fails.
This change causes Blueprint to stop calling GenerateBuildActions on modules
when one such call results in errors being generated.  If a module has failed
for some reason and another module depends on it, then processing the dependee
could end up trying to use the failed module, which may be in an invalid state.

Change-Id: I5cc165b7f4e169f90e9570ec7b2a5f9baac2895a
2014-07-23 14:37:21 -07:00
Jamie Gennis
6a40c19e1c Add some ModuleContext error functionality.
Change-Id: I0635de0440da27e1d7cf7e155f268e6f958047eb
2014-07-02 16:40:31 -07:00
Jamie Gennis
0ed63eff29 Fix scoping logic to respect the caller's package.
This change makes the ModuleContext and SingletonContext methods respect the
caller's Go package when performing name lookups.  It does this by re-parenting
the module or singleton's scope to the scope of the caller's package, thus
allowing a Module or Singleton to pass its context to a function defined in
another Go package and have the called function access variables and rules
defined in its own Go package.

Change-Id: Ifdec87ba3095a453b36fb00e38c0bb3a928a2b9b
2014-06-30 18:26:28 -07:00