Commit graph

1603 commits

Author SHA1 Message Date
Jooyung Han
ddb5ed7e1f Add ShellEscapeIncludingSpaces(string)
ShellEscape(string) doesn't escape a string with spaces like "arg1
arg2". However, when we want to escape a string to use it as an
argument, then strings with spaces should be escaped.

For example,

  "command " + ShellEscapeIncludingSpaces("a b")

becomes "command 'a b'" so that "command" will get "a b" as a single
argument.

Bug: 182092664
Test: Added tests to escape_test.go
Change-Id: I8f88c18bc4f9f7aacfe9e701b8f0876dd8b9a8c3
2021-03-12 14:37:42 +09:00
Lukács T. Berki
51868f1577 Merge "Fix quoting issues when generating build.ninja ." 2021-03-10 07:03:48 +00:00
Colin Cross
73dd495dee Merge "Fix numericStringLess and add tests" 2021-03-09 17:25:56 +00:00
Lukacs T. Berki
0bd3de33fd Fix quoting issues when generating build.ninja .
Some of these were introduced in aosp/1610784 and some others were
present since a good while.

Test: Manual: "m nothing"
Change-Id: I7d5cb56ca2d87cb439354fd1b298c3b8d97d665d
2021-03-09 09:32:54 +01:00
Colin Cross
eb15c126c3 Fix numericStringLess and add tests
numericStringLess("1a", "11a") would strip the equal prefix "1" and
then compare the bytes "a" and "1", when it should have compared the
numbers 1 and 11.  Fix it by handling the case where the last equal
byte was numeric and the first differing byte is numeric in one
string and non-numeric in the other.

numericStringLess("12", "101") would strip the equal prefix "1" and
then compare the numbers 2 and 01, when it should have compared the
numbers 12 and 101.  Fix it by tracking the beginning of the sequence
of numeric bytes containing the differing byte.

Test: sort_test.go
Change-Id: I8d9252a64625ba6a3c75d09bb1429dcb1115e3e1
2021-03-08 17:59:55 -08:00
Lukacs T. Berki
7d2e60ece7 Use stageDir() to determine the install directory.
In particular, for Go binary modules.

Test: Manual ("m nothing")
Change-Id: I98d184a00f1a48bc68e4b03747331fd449e37de1
2021-03-08 16:48:38 +01:00
Lukacs T. Berki
122b3ee153 Make debugging easier:
- Add the -N -l command line arguments to Microfactory
- Pass the the Delve arguments to the primary builder on the command line

Test: Manual.

Change-Id: I4034f2d48b3e40d9863529053715183dc3dce1f5
2021-03-03 09:15:04 +01:00
Lukacs T. Berki
f802ffcd12 cd / before generating build.ninja .
This is so that soong_build doesn't know the current directory, thereby
avoiding one way to leak information.

Test: Manual.
Change-Id: I976a8663b11d99c5382726487102df10043c5a61
2021-03-03 09:14:22 +01:00
Treehugger Robot
8d9d43c46c Merge "propertyIndexesWithTag can handle slice of struct" am: 2910183696
Original change: https://android-review.googlesource.com/c/platform/build/blueprint/+/1601875

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I4908415cc4eb454030c0224fb990be6c2b89b443
2021-02-24 01:34:38 +00:00
Colin Cross
764d29e796 Add preupload hooks to build/blueprint am: 747b95206b
Original change: https://android-review.googlesource.com/c/platform/build/blueprint/+/1602333

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: Id329902522927d6fa678b17b10753a6f948523c4
2021-02-24 01:17:47 +00:00
Treehugger Robot
2910183696 Merge "propertyIndexesWithTag can handle slice of struct" 2021-02-24 00:54:56 +00:00
Colin Cross
747b95206b Add preupload hooks to build/blueprint
Run gofmt and bpfmt during preupload, and warn about uses of
DO NOT MERGE.

Test: repo upload
Change-Id: I5f8a318f9ec1dbca897d25f25107df36d160e1f6
2021-02-23 10:29:46 -08:00
Jiyong Park
b48d4aea85 propertyIndexesWithTag can handle slice of struct
The function now can traverse into a field whose type is slice of
struct. When reading field values from the returned indexes, Soong will
check if the next field is a slice of struct or not. If so, it will
recurse into all the values in the slice.

Bug: 181018147
Test: m nothing
Change-Id: Ib8a7b7911a0be37a6dc03079adeb906497e60875
2021-02-24 01:02:59 +09:00
Xin Li
f4c3ff67ba Mark ab/7061308 as merged in stage.
Bug: 180401296
Merged-In: If8f454d33ec6def0f7f13ab4866be05ed73cf0a7
Change-Id: I1e39637f944839c99cb6fa41fc8e914ad3455368
2021-02-20 00:24:00 -08:00
Treehugger Robot
e3abb5ce41 Merge "Make bpfmt use exit codes even when reading from stdin." am: 0335565677
Original change: https://android-review.googlesource.com/c/platform/build/blueprint/+/1592922

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: Ifa0a2163ba8ffb6cc4cdd6610f24c00795079cd6
2021-02-18 23:11:12 +00:00
Treehugger Robot
0335565677 Merge "Make bpfmt use exit codes even when reading from stdin." 2021-02-18 22:10:22 +00:00
Hunter Knepshield
9033c957b9 Make bpfmt use exit codes even when reading from stdin.
Previously, an incantation like `bpfmt -o <$BAD_BP` would print to
stderr as expected, but then it would exit with 0. This is different
than the behavior of `bpfmt -o $BAD_BP`, which correctly exits with a
non-zero status code (in addition to printing the issues to stderr).

Test: m bpfmt; out/soong/host/linux-x86/bin/bpfmt -o <$BAD_BP; echo $?
Change-Id: I0a970cddf94fbd818525f9167d9113086b023c81
2021-02-17 20:24:50 -08:00
Thiébaud Weksteen
9d5b6043b5 Fix ReplaceExtension am: 8ec690764e
Original change: https://android-review.googlesource.com/c/platform/build/blueprint/+/1591572

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I915906293c6e245bd433460b0babfa0fe777b2ea
2021-02-17 08:00:50 +00:00
Thiébaud Weksteen
8ec690764e Fix ReplaceExtension
ReplaceExtension had an unexpected behaviour when the file did not have
an extension. In certain cases, the final path would be severely
trimmed: out/.intermediates/my_file would become out/.new_extension.
Explicitly handle the case by appending the new extension.

Test: Run checkbuild on Android Soong
Change-Id: Ie27a98845894cfaee5af5e2a02d44168c40ed821

This is an imported pull request from
https://github.com/google/blueprint/pull/345

GitOrigin-RevId: f9166c0e6151499b4b1a23b89b0bc133203a1116
Change-Id: I63f0798177545792440b8a84b04f1090590f1642
2021-02-16 21:45:01 -08:00
Colin Cross
8cb0bda1b1 Merge remote-tracking branch 'aosp/upstream' am: e980b25b95
Original change: https://android-review.googlesource.com/c/platform/build/blueprint/+/1580817

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I9f7803976201d41d2cd28aa4da5c93a166884023
2021-02-09 22:27:43 +00:00
Colin Cross
e980b25b95 Merge remote-tracking branch 'aosp/upstream'
* aosp/upstream:
  Fix detecting cycles in parallelVisit
  Optimize HasTag function

Test: m checkbuild
Change-Id: Ia121f48bafa1461b8ea0ae6103d1b5bb503e6c16
2021-02-09 10:20:33 -08:00
colincross
aef5f3b7f2
Merge pull request #344 from colincross/parallel
Fix detecting cycles in parallelVisit
2021-02-09 09:17:17 -08:00
Colin Cross
7d4958d84c Fix detecting cycles in parallelVisit
Fix detecting cycles in parallelVisit when the first alphabetical
module is not part of the cycle, but depends on the cycle.  Instead of
starting from the first alphabetical module, check every module in a
determinsitic order and return the first time a cycle is found.

Test: Test_parallelVisit
Change-Id: I03726f838ec42975251088ba75158103940115c2
2021-02-08 15:56:43 -08:00
colincross
e09509592d
Merge pull request #338 from francois-berder/optimize-hastag
Optimize HasTag function
2021-01-28 10:28:04 -08:00
Francois Berder
1ac43bd65a Optimize HasTag function
The commits optimizes HasTag function by avoiding
the call to strings.Split that allocates a list of strings.

HasTag is called from the ExtendProperties family of functions.
So this new implementation would benefit any primary builder
that extensively uses property appending.

Add a small benchmark for HasTag function.
It shows that HasTag is speed up by a factor of 2-3 with the new
implementation.

Before:
goos: linux
goarch: amd64
BenchmarkHasTag/NoTag-56         	20000000	       118 ns/op
BenchmarkHasTag/EmptyTag-56      	20000000	       120 ns/op
BenchmarkHasTag/OtherTag-56      	10000000	       131 ns/op
BenchmarkHasTag/MatchingTag-56   	10000000	       177 ns/op
BenchmarkHasTag/ExtraValues-56   	 5000000	       392 ns/op
BenchmarkHasTag/ExtraTags-56     	10000000	       183 ns/op

After:
goos: linux
goarch: amd64
BenchmarkHasTag/NoTag-56         	200000000	        11.5 ns/op
BenchmarkHasTag/EmptyTag-56      	200000000	        11.5 ns/op
BenchmarkHasTag/OtherTag-56      	50000000	        25.2 ns/op
BenchmarkHasTag/MatchingTag-56   	20000000	        61.4 ns/op
BenchmarkHasTag/ExtraValues-56   	20000000	        94.3 ns/op
BenchmarkHasTag/ExtraTags-56     	20000000	        79.1 ns/op

Signed-off-by: Francois Berder <francois.berder@arm.com>
Change-Id: Ib45498e9ad6aebeca2beddea63543da40c0b1a21
2021-01-28 14:28:34 +00:00
Colin Cross
d7e36a2687 Merge remote-tracking branch 'aosp/upstream' am: 3b6c68cd9e
Original change: https://android-review.googlesource.com/c/platform/build/blueprint/+/1557081

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I468a1f890e0ff8122563edae6980f8b8180b5a3d
2021-01-25 16:32:12 +00:00
Colin Cross
3b6c68cd9e Merge remote-tracking branch 'aosp/upstream'
* aosp/upstream:
  Optimize updateDependencies
  Write build definitions directly to output writer
  Memoize full names of variables, pools and rules
  Optimize arg parsing in buildDef.WriteTo
  Increase ninja file writer buffer
  Use io.StringWriter in ninjaWriter

Test: m checkbuild
Change-Id: I8ff3ca4a95c351809b62af841e9bb77b2de7d1ed
2021-01-22 17:05:34 -08:00
colincross
22343ff42c
Merge pull request #342 from colincross/optimize_updateDependencies
Optimize updateDependencies
2021-01-22 16:22:41 -08:00
colincross
2a29698186
Merge pull request #343 from colincross/optimize_ninja_writer
Optimize ninja writer
2021-01-22 16:22:22 -08:00
Colin Cross
7ff2e8d2a4 Optimize updateDependencies
Avoid reallocating module.forwardDeps and module.reverseDeps every
time through updateDependencies by resetting the slices without
reducing their capacity.  Accumulate dependencies to visit directly
into module.forwardDeps.  Use a loop instead of a map to check
for duplicates, average number of dependencies is measured to be
9.5, although there are a few outliers with up to 2108.

Reduces mean soong_build execution time on internal master from 87s
to 82.7s (5%).

Test: context_test.go
Change-Id: I58fcd5514e494bafa965443461851b21b7bce382
2021-01-22 10:22:21 -08:00
Colin Cross
6715ce49d5 Merge remote-tracking branch 'aosp/upstream' am: eecfdd316b
Original change: https://android-review.googlesource.com/c/platform/build/blueprint/+/1557261

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I8442949eb048eda9112336f446c5eb683d1cf505
2021-01-22 17:54:22 +00: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
92054a49d2 Memoize full names of variables, pools and rules
Variables, pools and rules each computed their full names every time
they were referenced, which required string concatenations.  Since
every one is guaranteed to be accessed at least twice, once when the
definition is written into the ninja file and once for each reference,
precompute the full name.  For local variables that can be done
during initialization, but for global variables add a pass to
PrepareBuildActions to compute the name for each live variable using
the final package names.

Test: ninja_writer_test.go
Change-Id: I2264b05e0409e36651db2fb5d463c16c698d4d5e
2021-01-21 22:02:30 -08:00
Colin Cross
00890dd8f6 Optimize arg parsing in buildDef.WriteTo
Arguments to build definitions were copied from the input map to an
map with the name and value expanded, then to a list of names for
sorting, and then written, which required iterating over a map three
times.  Expand the name and value into a list of name value pairs,
and then do the rest of the operations on the list instead.

Test: ninja_writer_test.go
Change-Id: Id8ff644dafbaa3b4812747c60dc28cce22e21dbe
2021-01-21 22:02:30 -08:00
Colin Cross
c8b9e55289 Increase ninja file writer buffer
Increase the ninja file writer buffer from the default 4k to 16MB.

Test: m checkbuild
Change-Id: Ieb2c82218517b98469ef93f1ea4dd04b5651f7d1
2021-01-21 22:02:30 -08:00
Colin Cross
0335e0900d Use io.StringWriter in ninjaWriter
ninjaWriter repeatedly called io.WriteString() on its writer, which
does a type assertion every time.  Replace its io.Writer with an
io.StringWriter and call WriteString on it directly.

Test: ninja_writer_test.go
Change-Id: Ie073d996a319190242bf6a00af07a13a60d078b5
2021-01-21 22:02:30 -08:00
Colin Cross
eecfdd316b Merge remote-tracking branch 'aosp/upstream'
* aosp/upstream:
  Return a copy of glob lists

Test: m checkbuild
Test: m nothing && m nothing
Change-Id: Ie015670828f3d6e0bf4fa22580cb7254966a2c82
2021-01-21 18:28:20 -08:00
colincross
bcd5686660
Merge pull request #341 from colincross/optimize_glob
Return a copy of glob lists
2021-01-21 18:27:49 -08:00
Colin Cross
a64ca94c0d Return a copy of glob lists
Callers to glob methods may do in-place modifications on the returned
list of globs, return a copy instead of the cached value.

Test: m nothing && m nothing
Change-Id: Ic9140d1e1900e8724ba0a484f27786e5c15dea90
2021-01-21 13:47:59 -08:00
Colin Cross
3d9a6b397e Merge remote-tracking branch 'aosp/upstream' am: e7bc78aa7b
Original change: https://android-review.googlesource.com/c/platform/build/blueprint/+/1553908

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I58c3604c7fd477418f30179663050767cfa4fb75
2021-01-21 00:58:23 +00:00
Colin Cross
ee9fe36a1c Merge remote-tracking branch 'aosp/upstream' am: 92ca1968cf
Original change: https://android-review.googlesource.com/c/platform/build/blueprint/+/1554574

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I4f5d18359f76614010b0f7c87ab92f644e388f92
2021-01-20 22:14:03 +00:00
Colin Cross
e7bc78aa7b Merge remote-tracking branch 'aosp/upstream'
* aosp/upstream:
  Use info.IsDir() instead of info.Mode()&os.ModeDir != 0
  Remove redundant stat/lstat calls from glob

Test: glob_test.go
Change-Id: Iea8f093ca16a57de4c3ef0935f29dfe871ac4a72
2021-01-20 14:01:03 -08:00
colincross
2b2b9f28f2
Merge pull request #340 from colincross/optimize_glob
Use info.IsDir() instead of info.Mode()&os.ModeDir != 0
2021-01-20 13:52:33 -08:00
Colin Cross
4604a81721 Use info.IsDir() instead of info.Mode()&os.ModeDir != 0
Use the info.IsDir() shortcut.

Test: glob_test.go
Change-Id: Ibba8bbc6af295e3d86321b0c070a84c2b7008dd9
2021-01-20 13:47:37 -08:00
colincross
49a8b95d4e
Merge pull request #339 from colincross/optimize_glob
Remove redundant stat/lstat calls from glob
2021-01-20 13:34:51 -08:00
Colin Cross
e535c97cc9 Remove redundant stat/lstat calls from glob
Glob was calling IsSymlink and IsDir on each visited directory entry,
which resulted in an lstat and then a stat call on each.

Instead, use lstat when not following symlinks and use stat when
following symlinks, then use the result to check if the entry is a
directory.

Test: glob_test.go
Change-Id: I83d769e2de64ce8221e952e5204d365aeaf47687
2021-01-20 11:01:41 -08:00
Colin Cross
92ca1968cf Merge remote-tracking branch 'aosp/upstream'
* aosp/upstream:
  Fix silently ignoring values assigned to map properties
  Use UnpackError for incorrect property type errors
  Improve unpack testing

Fixes: 177706602
Test: m nothing
Test: TestUnpackErrors
Change-Id: I2c6b0279dc6210d5c6fef12e19e54b98c473e78b
2021-01-19 11:09:10 -08:00
colincross
94a5c01693
Merge pull request #337 from colincross/map_assign
Fix silently ignoring values assigned to map properties
2021-01-19 10:35:33 -08:00
Colin Cross
3adb240964 Fix silently ignoring values assigned to map properties
Values assigned to map properties were silently ignored instead of
reported as an error.  Add a check when recursing into structs that
the value is a map.

Fixes: 177706602
Test: m nothing
Test: TestUnpackErrors
Change-Id: Ic56aeb1b9da6d5c86b6d98adae7bddb60c450404
2021-01-15 22:21:28 -08:00
Colin Cross
f6ef155884 Use UnpackError for incorrect property type errors
Returning a fmt.Errorf error causes Blueprint to identify the error
as an "internal error", return an UnpackError instead.

Bug: 177706602
Test: TestUnpackErrors
Change-Id: I19fba134ad778d08d5a4d90a0335bdf8cbea6a20
2021-01-15 22:21:28 -08:00