Commit graph

55 commits

Author SHA1 Message Date
Treehugger Robot
190e536e64 Merge "Allow filter calls with a list as a pattern" 2022-02-11 00:46:58 +00:00
Cole Faust
9932f75151 Allow filter calls with a list as a pattern
This commit doesn't attempt to replace the filter
calls with anything more idomatic for now.

It also removes the case for filter-out, because
the actual function name is filter_out and wasn't
being used anyways. Even if I were to change it
to filter_out, that would produce buggy results:

ifneq (,$(filter $(TARGET_BUILD_VARIANT), userdebug eng))
endif
ifneq (,$(filter-out $(TARGET_BUILD_VARIANT), userdebug eng))
endif

Both of these would produce:

if g["TARGET_BUILD_VARIANT"] in ["userdebug", "eng"]:
  pass

Fixes: 218702402
Test: go test
Change-Id: I566079e5d3a364c42db14045aa1bab9d99eba05f
2022-02-09 14:15:47 -08:00
Cole Faust
f4e72cf642 Update warning message
As requested on aosp/1975486

Fixes: 217248902
Test: Presubmits
Change-Id: I14e65722d8ab96125827d34e8501b4a518a27b57
2022-02-08 13:10:26 -08:00
Cole Faust
9b6111aaed Remove --root, require the cwd to be the root
This allows us to use relative paths everywhere.
It also produces more accurate emulation of TOPDIR,
which should be an empty string.

Bug: 213508006
Test: go test
Change-Id: Ie4e357687486e84e9f4aad0f6776d8feb2b9fc63
2022-02-07 11:45:01 -08:00
Cole Faust
dd569aea07 Return starlarkNodes from the functions that parse them
Currently, mk2rbc is structured around having a global
"receiver" object that accepts all starlarkNodes. As soon
as they are parsed they are added to the receiver.

Returning the parsed nodes to the calling function is more
flexible, as it allows the calling function to restructure
them as necessary. This is the first step to supporting
complicated statements involving $(eval), such as
`$(foreach v,$(MY_LIST),$(eval MY_LIST_2 += $(v)))`

Test: go test
Change-Id: Ia194123cf090d2b9559a25b975ccbc5749357cc0
2022-02-02 14:59:59 -08:00
Cole Faust
7940c6a5b5 Remove RBC hints from generated starlark
The hints no longer need to be there in the generated code.

Fixes: 217269465
Test: go test
Change-Id: If2049780a874b42eb9df9351dda4f29c85482470
2022-02-02 11:53:19 -08:00
Cole Faust
f8a4bb6d7f Merge "Allow variable-prefixed include statements in mk2rbc" 2022-02-01 18:44:28 +00:00
Treehugger Robot
6a21d959e5 Merge "Remove variableDefinedExpr" 2022-02-01 04:16:02 +00:00
Cole Faust
069aba64f6 Allow variable-prefixed include statements in mk2rbc
mk2rbc was already searching the whole android tree
for Makefiles, so allowing variable-prefixed include
statements doesn't affect performance on the file searching
front. On the generated code front, there's already a cap
of 150 potentially-included makefiles that prevents the
performance from getting too bad, and it can be lowered
if necessary.

Bug: 213508006
Test: go test
Change-Id: I3a4e81acb3d97bee08ac3dbe63052a274acf5793
2022-01-31 15:35:28 -08:00
Sasha Smundak
845cb29c2b Fix the names of the dynamically inherited modules.
The module name passed to rbld.inherit should be its path without the suffix.

Bug: 215182113
Test: internal
Change-Id: Ic65a5b73037be84f31f8db29f71f793b6c6034bb
2022-01-28 17:41:15 -08:00
Cole Faust
71514c07d2 Remove variableDefinedExpr
VariableDefinedExpr was under-developed, and would not
take into account if a variable was from the globals
or product config dictionary.

It also always emitted `g.get("VARIABLE") != None`, which
is not correct behavior. In this example makefile:

```
MY_VAR :=

ifdef MY_VAR
$(info MY_VAR is defined)
else
$(info MY_VAR is not defined)
endif

ifdef MY_UNDEFINED_VAR
$(info MY_UNDEFINED_VAR is defined)
else
$(info MY_UNDEFINED_VAR is not defined)
endif

MY_VAR ?= true
MY_UNDEFINED_VAR ?= true


$(info MY_VAR after ?= is $(MY_VAR))
$(info MY_UNDEFINED_VAR after ?= is $(MY_UNDEFINED_VAR))


.PHONY: all
all:
	@:
```

We get the output:

MY_VAR is not defined
MY_UNDEFINED_VAR is not defined
MY_VAR after ?= is
MY_UNDEFINED_VAR after ?= is true

So we can see that even if a variable was set, it's considered
not defined if it was set to an empty value. However, ?= works
differently, and does require the != None, so that was left
as is.

Just use a variableRefExpr and rely on the fact
that variables will be truthy if they're defined.

Fixes: 216700361
Test: go test
Change-Id: If8944da2579e8658e3fc4f666b1f3b2815f8c8b1
2022-01-28 19:47:34 +00:00
Alexander Smundak
3f0088944b Merge "Check missing uncoditionally loaded missing modules at runtime" 2022-01-14 17:56:27 +00:00
Sasha Smundak
6bc132aff9 Check missing uncoditionally loaded missing modules at runtime
A potentially inherited (via dynamically calculated path) module may in turn
unconditionally load a module that does no exist in a source tree -- it is
not an error if this potentially inherited module is actually never inherited
because its dynamically calculated path will never reference it. Instead of
emitting an uncoditional `load` for a non-existent file (which is going to fail
in the Starlark parser), emit conditional load and a runtime check.

Fixes: 213922819
Test: internal
Change-Id: I92177878e199a1f00e5f0c4045c0c0daeddd6bdb
2022-01-10 19:58:14 -08:00
Treehugger Robot
35f94eba51 Merge "Consolidate conversions of is-board-platform(2)" 2022-01-11 03:51:21 +00:00
Treehugger Robot
4cfd37e617 Merge "Convert math functions" 2022-01-11 03:28:01 +00:00
Cole Faust
b2e0b60126 Consolidate conversions of is-board-platform(2)
mk2rbc implements conversions for both
is-board-platform(-in-list) and
is-board-platform(-in-list)2. The conversions
are not the same despite the functions being the
same. Make them convert to the same thing.

Bug: 201477826
Test: go test
Change-Id: I688a2f6114e1688c713e42f0f9229cbc5ee6a917
2022-01-07 15:46:58 -08:00
Cole Faust
6c934f6341 Make include_top comments only apply to the next statement
Previously adding an include_top comment would make it apply
for the rest of the file. This was confusing behavior, and
could also cause extra roots to be searched in a situation
like the following:

\#RBC# include_top foo
include $(VAR)/file.mk
\#RBC# include_top bar
include $(VAR)/file.mk

Here the second include would have file.mk from both the foo
and bar directories in its _entry dictionary.

Bug: 213508006
Test: go test
Change-Id: If3430594759bee1390255400fe29b43d77f7b6a6
2022-01-07 15:09:16 -08:00
Cole Faust
b1103e2578 Convert math functions
Converts the following functions from build/make/common/math.mk:
 - math_max
 - math_min
 - math_gt_or_eq
 - math_gt
 - math_lt

Fixes: 213497955
Test: go test
Change-Id: I8c4e8fee321f03b813428fa10038fa8f06188cef
2022-01-07 14:59:55 -08:00
Cole Faust
69e8731101 Merge "Fix "unknown binary op: string + list" errors" 2021-12-23 18:41:34 +00:00
Cole Faust
0484c2378f Fix "unknown binary op: string + list" errors
Convert lists to strings when adding them to a string.

Bug: 201700692
Test: go test
Change-Id: Iefb68f48191136e7115a6d6bfa0608c73d5afdac
2021-12-22 14:08:08 -08:00
Cole Faust
7321b0985e Improve error message when a required makefile can't be found
Bug: 193566316
Test: go test
Change-Id: I41a28808c95df76f212980ef1e59047312fe587b
2021-12-21 16:11:16 -08:00
Cole Faust
f7ed5343de Prevent duplicate entries in ctx.include_tops
The include_tops hints are global for the whole parse
context (which is probably also something to fix), which
means that if an include_top hint is duplicated there will
be duplicated keys generated in the _entry starlark dictionary.

Bug: 193566316
Test: go test
Change-Id: I01a0546ac9be91ef46c5248e87e1a40e0f211193
2021-12-21 14:34:51 -08:00
Cole Faust
a6628d24c4 Merge "Handle foreach expressions in mk2rbc" 2021-12-16 21:16:49 +00:00
Cole Faust
b0d32ab960 Handle foreach expressions in mk2rbc
Bug: 201700692
Test: go test
Change-Id: Ia23494a63567a1fe2d4bb797a2d4dd5925b3431d
2021-12-15 13:06:47 -08:00
Cole Faust
0e9418ced0 Allow generic $(findstring) calls
Previously they were only allowed in if statements.
Also update the if statement condition to allow comparisons
to the search term.

Bug: 201700692
Test: go test
Change-Id: I8bee8f716819d383423c0de233ab970e49890543
2021-12-13 16:33:25 -08:00
Cole Faust
c36c962670 Handle substitution references in mk2rbc
Bug: 201700692
Test: go test
Change-Id: I5ba5e51848e795e39f1f65dc153e4c1530066860
2021-12-08 17:32:57 -08:00
Cole Faust
4eadba7438 Support if expressions in mk2rbc
Bug: 201700692
Test: go test
Change-Id: Icdf30c4d625d81974db946bd91660a29a0373ac7
2021-12-08 10:00:14 -08:00
Cole Faust
eec0d8137e Fix filter-out being negated in rbc product configuration
Bug: 201700692
Test: go test
Change-Id: I3245e33dc88dd2e456a24780c8cc20ed605d67a6
2021-12-06 16:23:51 -08:00
Treehugger Robot
f18bedf1c3 Merge changes from topics "dist_for_goals", "mk2star"
* changes:
  Generate runtime conversion diagnostics
  Convert dist-for-goals.
2021-11-18 22:04:52 +00:00
Cole Faust
f1f44d3d21 Simplify equality expressions when comparing to "true"
If a boolean type is compared to a string literal with
the value "true", it should just output that boolean
type unchanged (or prefixed with "not" if ifneq).

Fixes: 206637085
Test: go test
Change-Id: I0c116bb68b96d21ba3783c01fc4ca524aaa04143
2021-11-18 10:15:26 -08:00
Sasha Smundak
422b614355 Generate runtime conversion diagnostics
Instead of inserting a comment with error description into the generated code,
generate a call to a function that will print out a conversion error when executed.
Do not print generic "partially converted" message anymore.
Remove --verbose and --no_warnings options.

Bug: 204062171
Test: internal
Change-Id: Ib126e16dc76f49635e4939e670922f2561781049
2021-11-18 10:01:37 -08:00
Sasha Smundak
d679785d0d Convert dist-for-goals.
Bug: 198496782
Test: internal
Change-Id: I64ae938a5809238c18aca272ba73e4328fcb9efe
2021-11-18 10:01:37 -08:00
Cole Faust
f83202143a Allow generic if statements
Previously, only comparisons between strings/variable references
and other strings/variable references or certain function calls
were allowed. After this cl, any two starlark expressions can
be compared. If they have different types, they will be converted
to strings first.

Fixes: 205995738
Bug: 201700692
Test: go test
Change-Id: Ib463de7b24d3abcd032dbdcba7c3f1351c314d01
2021-11-15 11:29:29 -08:00
Sasha Smundak
ea3bc3a953 Flag 'override' directives.
Bug: 201087531
Test: internal
Change-Id: I2e08b126d769b1595172b04a3539e99b3e72cb2b
2021-11-10 13:19:01 -08:00
Cole Faust
18e7785f26 Merge "Translate soong_config_get calls to rbc" 2021-11-10 19:46:48 +00:00
Cole Faust
c00184e2d7 Translate soong_config_get calls to rbc
Bug: 201700692
Test: go test
Change-Id: I3621396c048d4a46c1b12342e884709a13eb2b79
2021-11-08 15:10:18 -08:00
Sasha Smundak
35434ed55a Allow non-constant from/to arguments in subst and patsubst
Fixes: 198502623
Test: internal
Change-Id: Ia41a5a2e9315fcce351691749ac15de5df6916a4
2021-11-05 16:30:17 -07:00
Sasha Smundak
c4fa93e76a Handle ifdef for local variables.
Fixes: 205337522
Test: internal
Change-Id: Ib29654e76e8dc7c0982bfe0b471a1aca33935117
2021-11-05 14:42:41 -07:00
Sasha Smundak
4f1f118a8d Fix: negate the condition for is-vendor-board-qcom
Bug: 193540681
Test: internal
Change-Id: Ia4087574f7cbcd5282687234892314c9a5fcc174
2021-11-05 08:45:49 -07:00
Sasha Smundak
3a9b8e8943 Convert is-board-platform2/is-board-platform-in-list2/is-vendor-board-qcom macros.
Bug: 193540681
Test: internal
Change-Id: I76c46d89f10b16b75438803479fec4aa468e3010
2021-10-27 11:23:29 -07:00
Sasha Smundak
2afb9d7722 Fix how the rule is displayed in the error message.
Bug: 204001941
Test: internal
Change-Id: I19c73356cc305ec7a6dfd3bddbde775ef9ca4953
2021-10-27 10:56:47 -07:00
Sasha Smundak
6d852dd16a Implement include path annotation.
Include top annotation is a specially formatted comment line providing
the include/inhherit file location hint. E.g., adding
```
```
before
```
$(call inherit-product $(SRC)/foo.mk
```
is a hint to the converter to look for the `foo.mk` files under
`vendor/my_vendor/` in addition to `vendor/google_devices/'

Bug: 193566316
Test: internal
Change-Id: I01c5dde2504f1a9eb724098b1cc03d2176ca2cf9
2021-10-27 10:56:47 -07:00
Sasha Smundak
65b547edc2 Better Soong config namespace support.
Old macros (`add_soong_config/namespace` & `add_soong_config_var_value`) are
going away, to be replaced with `soong_config_set`. A new macro,
`soong_config_append` is added to append to the existing value.
Also, flag the attempts to reference the values of the variables in the
Soong config namespace.

Bug: 200297238
Test: internal
Change-Id: Idb6a31632db75d7faef038b83e6a86d9dcf1e736
2021-10-27 10:56:46 -07:00
Sasha Smundak
5f463be4a9 Fix wildcard ('%') handling in the filter pattern.
Fixes: 200094780
Test: internal
Change-Id: I5f6a46679cdfa965ad98b9c0c22ef396a13a0bf6
2021-10-06 09:38:22 -07:00
Sasha Smundak
868c5e3ab2 Emit unconditional module load only when inherit/include is on the top level.
That is, when a makefile contains
```
ifneq (,$(foo))
  $(call inherit-product,module.mk)
endif
```

module.mk has to be present only if `foo` is set.

Fixes: 200163602
Test: internal
Change-Id: Ic5f10ce8d49d6b87162bfe77922bba5e2cce228b
2021-09-27 10:02:41 -07:00
Sasha Smundak
468e11fbbe Additional heuristics: variables with names ending with _LIST are lists
Bug: 193540681
Test: internal
Change-Id: Ic23bf0f0eadb159285650f0b7e20307788c12387
2021-09-02 09:34:47 -07:00
Sasha Smundak
0445308bc3 Support product-copy-files-by-pattern macro
Bug: 193566316
Test: internal
Change-Id: I5ffdbaee231669166aaa3f40f84ecac8f571f981
2021-08-17 18:15:03 -07:00
Sasha Smundak
02183cfc53 Most of the TARGET_COPY_OUT_xxx variables are not constant
Bug: 193566316
Test: internal
Change-Id: I484a88de933904a2ac2e36084509838d7a85262c
2021-08-16 13:39:48 -07:00
Sasha Smundak
3deb968aef Translate copy-files, add_soong_config_namespace and add_soong_config_var_value macros
Bug: 194521362
Test: internal

Change-Id: I88fb62f057476d96dfb056813a900e8497e7bbb9
2021-08-03 11:06:54 -07:00
Sasha Smundak
16e0773e7f Translate more Make builtin functions
Adds support for abspath/firstword/dir/lastword/notdir functions

Bug: 194521362
Test: internal
Change-Id: I34dd6a81f21a4ef2f8f0a72bd80284ced8957b5c
2021-08-02 15:13:59 -07:00