Commit graph

14 commits

Author SHA1 Message Date
Usta Shrestha
7f3c51ca43 cosmetic: use _ for unused args
Test: run `m nothing`
Bug: NA
Change-Id: Idfdb0d4121244e25847822114a2d12c6bb18ebd1
2023-02-23 02:28:12 +00:00
Cole Faust
c5baf11a2d Show the ninja string that failed to parse in errors
So that it's easier to debug what the problem is.

Test: m nothing
Change-Id: I97e81f98f0365e981d34c6b8bec8528de1b7e514
2023-01-19 14:23:04 -08:00
Colin Cross
8a40148408 Write build definitions directly to output writer
buildDef.WriteTo was calling valueList to convert all the build
parameter ninjaStrings into strings, which uses ValueWithEscaper
to build a strings.Builder.  This results in building a string
only to immediately copy it into the output writer's buffer.

Instead, pass an io.StringWriter to ValueWithEscaper so it can
build the string directly into the output writer's buffer.  This
requires converting ninjaWriterWithWrap into an io.StringWriter.

Test: ninja_writer_test.go
Change-Id: I02e1cf8259306267b9d2d0ebe8c81e13dd443725
2021-01-21 22:02:30 -08:00
Colin Cross
2ce594e446 Make ninjaString an interface
There are 8935901 *ninjaString objects generated in an AOSP
aosp_blueline-userdebug build, and 7865180 of those are a literal
string with no ninja variables.
Each of those *ninjaString objects takes a minimum of 48 bytes for
2 slices, plus 8 bytes for the pointer to the ninjaString.  For
the literal string case, one of those slices has a single element,
(costing another 16 bytes for the backing array), and the other
slice is empty, for a total of 72 bytes.

Replace *ninjaString with a ninjaString interface.  This increases
the size of the reference from 8 bytes to 16 bytes, but using
a type alias of a string for the literal string implementation uses
only 16 bytes, saving 40 bytes per literal string or 314 MB.

Test: ninja_strings_test
Change-Id: Ic5fe16ed1f2a244fe6a8ccdf762919634d825cbe
2020-01-29 16:23:40 -08:00
Colin Cross
19ff727ad5 Optimize ninjaString.ValueWithEscaper
ninjaString.ValueWithEscaper is a relatively hot function,
rewrite it with strings.Builder to avoid repeated string
concatenation, which requires an allocation each time.

Before:
BenchmarkNinjaString_Value/constant/1-72       	100000000	        11.9 ns/op
BenchmarkNinjaString_Value/constant/10-72      	100000000	        18.9 ns/op
BenchmarkNinjaString_Value/constant/100-72     	50000000	        22.1 ns/op
BenchmarkNinjaString_Value/constant/1000-72    	30000000	        39.3 ns/op
BenchmarkNinjaString_Value/variable/1-72       	20000000	        95.1 ns/op
BenchmarkNinjaString_Value/variable/10-72      	10000000	       223 ns/op
BenchmarkNinjaString_Value/variable/100-72     	 3000000	       437 ns/op
BenchmarkNinjaString_Value/variable/1000-72    	 2000000	       948 ns/op
BenchmarkNinjaString_Value/variables/1-72      	10000000	       161 ns/op
BenchmarkNinjaString_Value/variables/2-72      	 5000000	       368 ns/op
BenchmarkNinjaString_Value/variables/3-72      	 3000000	       560 ns/op
BenchmarkNinjaString_Value/variables/4-72      	 2000000	       795 ns/op
BenchmarkNinjaString_Value/variables/5-72      	 1000000	      1004 ns/op
BenchmarkNinjaString_Value/variables/10-72     	 1000000	      2275 ns/op
BenchmarkNinjaString_Value/variables/100-72    	   50000	     39667 ns/op
BenchmarkNinjaString_Value/variables/1000-72   	    1000	   2146592 ns/op

After:
BenchmarkNinjaString_Value/constant/1-72       	200000000	        11.3 ns/op
BenchmarkNinjaString_Value/constant/10-72      	100000000	        17.2 ns/op
BenchmarkNinjaString_Value/constant/100-72     	50000000	        21.7 ns/op
BenchmarkNinjaString_Value/constant/1000-72    	30000000	        38.3 ns/op
BenchmarkNinjaString_Value/variable/1-72       	20000000	        91.8 ns/op
BenchmarkNinjaString_Value/variable/10-72      	10000000	       199 ns/op
BenchmarkNinjaString_Value/variable/100-72     	 5000000	       377 ns/op
BenchmarkNinjaString_Value/variable/1000-72    	 2000000	       855 ns/op
BenchmarkNinjaString_Value/variables/1-72      	10000000	       141 ns/op
BenchmarkNinjaString_Value/variables/2-72      	 5000000	       312 ns/op
BenchmarkNinjaString_Value/variables/3-72      	 5000000	       362 ns/op
BenchmarkNinjaString_Value/variables/4-72      	 3000000	       417 ns/op
BenchmarkNinjaString_Value/variables/5-72      	 2000000	       621 ns/op
BenchmarkNinjaString_Value/variables/10-72     	 2000000	       837 ns/op
BenchmarkNinjaString_Value/variables/100-72    	  200000	      9141 ns/op
BenchmarkNinjaString_Value/variables/1000-72   	   20000	     95094 ns/op

Test: ninja_strings_test.go
Change-Id: I6c61e747d8e67f7f1e6cff0cc0c705745301a35f
2019-06-20 11:05:58 -07:00
Jeff Gaston
0e90759bfe Make ninja file deterministic even with dup module names
Bug: 65683273
Test: ./build/soong/scripts/diff_build_graphs.sh \
      --products=aosp_arm '' ''

Change-Id: I5e45b2309ba4993ba2180b5f9a4785f31e28d503
2017-12-04 17:16:21 -08:00
Colin Cross
8de48af6de Escape leading space in ninja strings
Spaces normally don't need to be escaped, but leading spaces are
trimmed.  Escape leading space to allow setting a variable to a
value with leading spaces.

Test: ninja_string_test.go
Change-Id: Ic0ffb076dbd603b7c0203720b9c1ea635c5ded75
2017-05-09 10:14:38 -07: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
Colin Cross
63d5d4d9e4 Fix formatting
gofmt -w .

Change-Id: If9cf0b7bd810f899edffcd2edf361fa83245bd2a
2015-04-20 16:41:55 -07:00
Colin Cross
8c1c6c03f8 Pre-allocate ninjaString slices
Naively pre-allocate ninjaString slices by counting $ characters as
an estimate of how many variables will be needed.  Saves 5% cpu time
on one workload.

Change-Id: Ib3a41df559d728b2db047f6dbbf9eb06d7045303
2015-04-15 11:03:17 -07:00
Colin Cross
b247893deb Fix misparsed $ after variable name
If a $ sign occurs after a variable name, the ninja string parser
fails to check if it is a $$ or a ${.  Go to the
parseDollarStartState instead of the parseDollarState.

Since it is not yet known if the $ is the beginning of a new
variable (${ or $<alphanumeric>) or a string ($$), an empty string
separator cannot be added to the ninjaString strings list.  Instead,
add functions to push strings or variables onto the ninjaString,
and automatically add the blank separator if two variables are
pushed in a row.

Change-Id: Ia1cae6259b1d7e4f633f61b9eadb2a2028bbd5f0
2015-04-14 16:21:53 -07:00
Colin Cross
6134a5c66a Relax module naming restrictions
Forcing module names to be valid ninja names is an unnecessary
restraint on the project build logic.  Allow any string as a
module name, and sanitize and uniquify the module name for use
in module-scoped variables.

Also move the module scope to be per-module instead of per-group
so that modules can use the same local variable name for each variant.

Change-Id: If44cca20712305e2c0b6d6b39daa5eace335c148
2015-03-12 17:22:18 -07: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
Renamed from blueprint/ninja_strings.go (Browse further)