Commit graph

17 commits

Author SHA1 Message Date
Cole Faust
1e27586012 Recognize some unsupported functions
Some functions are called without the use of $(call),
since $(call) is not necessary when the function doesn't
take any arguments. mk2rbc thinks these function calls
are local variables, and converts them as such. This
leads to undefined variable errors when trying to load
(before even executing) the starlark file.

Hardcode a known function that should not be converted
to a local variable.

Bug: 226974242
Test: go test
Change-Id: I5567a34fcc282b181a7e78ac3d5cc9b40bd025a2
2022-04-26 14:53:25 -07:00
Cole Faust
f06326648b Move variable assignment handling to generation context
This allows the parsing code to be cleaner, as it
doesn't have to care about variable assignments.

Bug: 228518745
Test: go test
Change-Id: I33425c2fb51acab4901bfa82a53d337b75210f8e
2022-04-07 15:40:12 -07:00
Cole Faust
f035d405d8 Support converting simple $(eval) expressions
While supporting $(eval) in the general case is
impossible, as it would require emitting code at
runtime, it is possible to handle some special cases
that are common throughout the code base.

Specifically, an assignement expression (where the
left hand side is constant) can be converted without
needing to evaluate strings as code, as its whole
right hand side is treated as one string.

However, this eval with an assignemnt can only be
used as a statement, not an expression. So it requires
the eval to be either a top-level expression, or nested
within other expressions that can be converted to
statements such as $(foreach) or $(if).

Bug: 226974242
Test: go test
Change-Id: Ifc52ef9ab7d62a69251918fcde5463f80a98a542
2022-03-31 12:44:59 -07:00
Cole Faust
b67aa082aa Fix issue with referencing the loop variable in a foreach
Fixes: 222160672
Test: go test
Change-Id: I3f9238d4f1684cf4a2d24c4f7f49c832c3f72b97
2022-03-01 16:11:50 -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
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
9ebf6e44df Refactor knownFunctions
By having knownFunctions contain parsing interfaces
instead of just metadata about the function, we can
remove some hardcoded special cases.

Bug: 201700692
Test: go test
Change-Id: I1723c7f50b72d42b03380e999aa9601b455a969e
2022-01-04 14:12:52 -08:00
Cole Faust
fc43868a5f Remove starlarkExpr.Eval()
It was only used to substitute variable references to
predefined variables with the predefined value, which
is an easy condition to directly parse into instead
of having a separate evalutation pass.

Bug: 201700692
Test: go test
Change-Id: I543d20a1d6435bfabd9faa90ffb09af3084ed28c
2021-12-16 13:20:22 -08: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
4eadba7438 Support if expressions in mk2rbc
Bug: 201700692
Test: go test
Change-Id: Icdf30c4d625d81974db946bd91660a29a0373ac7
2021-12-08 10:00:14 -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
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
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
0554d760fb Allow $(filter ...) with arbitrary args if its result is compared to the empty string
Bug: 172923994
Test: internal
Change-Id: Iea36ecaa8940cf4e495ad63125f10d733c3eb2ee
2021-08-01 14:41:03 -07:00
Sasha Smundak
b051c4ede3 Product config makefiles to Starlark converter
Test: treehugger; internal tests in mk2rbc_test.go
Bug: 172923994
Change-Id: I43120b9c181ef2b8d9453e743233811b0fec268b
2021-07-14 09:51:10 -07:00