Commit graph

21 commits

Author SHA1 Message Date
Jingwen Chen
01812020c1 Add support for writing all Soong config variables into @soong_injection.
Also remove the need to use bp2build_available on
soong_config_module_types as we want to convert every single of them
into the tree for a complete soong_injection soong_config_variables.bzl
file.

The variables are split into their bool, value and string types
respectively, as they all need to be handled differently on the Bazel
product_platform side, as well as for generating constraint values and
settings. For example, value variables need to integrate with
TemplateVariableInfo, and string variables need to include the string
value itself into the select key/constraint value.

Sample soong_config_variables.bzl file: https://gist.github.com/jin/cef700bfb20c8656a931306dd71d47e1

Test: CI
Bug: 198556411
Change-Id: I8665dd1269a507edb37de62407ed3641564bea5c
2021-11-23 08:37:30 +00:00
Chris Parsons
3b1f83d076 Add x86_host vars to config.bzl
Test: USE_BAZEL_ANALYSIS=1 m adbd
Test: Manually verified config.bzl contains various x86_host flags after
bp2build.
Test: Unit tests

Change-Id: Ie9201ea2be4cd1c6659bea088a797cedbae37403
2021-10-19 12:18:13 -04:00
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux
447f6c99c9 Bp2Build common properties auto-handling
Introduce `commonAttributes` & `fillCommonBp2BuildModuleAttrs used in
CreateBazelTargetModule

Adapt `bp2BuildInfo` to use `commonAttrs` instead of `Name`.
And thus also all downstream users of `CreateBazelTargetModule`.

As initial user, the Soong `required` property will be
translated to Bazel's `data`.

Bug: 198146582, 196091467
Test: build_converstion_test.go:TestCommonBp2BuildModuleAttrs
Test: go test
Test: mixed_{libc,droid}.sh
Change-Id: Ib500e40f7e2cb48c459f1ebe3188962fc41ec124
2021-10-04 14:43:04 +00:00
Liz Kammer
7a210ac233 bp2build: Add support for export_.*headers props
Soong supports export_.*_headers properties, the libraries contained in
this list must also be within a shared/static/whole_static/header libs
property. For bp2build, we eliminate this duplication. The libraries
not listed in an export_.*_headers property will migrate to an attribute
prepended with implementation_, those in export_.*_headers will not have
a prefix.

Test: build/bazel/ci/bp2build.sh
Test: build/bazel/ci/mixed_libc.sh
Bug: 198241472
Change-Id: I3eb84c983ec5d241c8a568e411dfd5619d3184a7
2021-09-23 16:07:45 -04:00
Jingwen Chen
6117450ead bp2build: add converted modules to codegen metrics, and remove the
compat layer.

The list of converted modules is used for tracking bp2build progress.

The module_name_to_label aliases weren't really adding much value to
mixed builds, so let's drop the feature for now and simplify the code.

Test: CI
Test: USE_BAZEL_ANALYSIS=1 m droid
Change-Id: I3269344cfe6d1c72c108d66c6e820bc0ec19bb34
2021-09-17 08:47:16 +00:00
Jingwen Chen
c63677b3c9 Direct Bazel builds from m.
This CL adds support to bp2build/Soong to dump a BUILD file under
out/soong/soong_injection/targets containing alias targets to their real
targets for every converted Soong module, regardless of whether they are
handcrafted or generated.

Test: TH
Change-Id: Ic1816fda5d019c395301618134fac68b3057d752
2021-06-21 06:12:34 +00:00
Jingwen Chen
4910976314 Make BUILD file merging slightly smarter.
This change enables checked-in BUILD files like
prebuilts/clang/host/linux-x86/BUILD.bazel to be merged cleanly with the
bp2build generated one into the synthetic workspace.

The checked-in BUILD file contains a package() declaration that bp2build
also generates. To avoid double declaration, the BUILD file writer now
checks if the BazelTargets contain handcrafted targets. If so, it
delegates the package declaration to the handcrafted BUILD file instead.

This change also sorts the bp2build targets before the handcrafted ones,
and adds a section header to demarcate the two sets of targets.

Test: TH
Change-Id: I3ecdeaab3226b895b623daf0791d24a657f7a7c6
2021-05-25 07:01:55 +00:00
Rupert Shuttleworth
0096079bbc Make bazel build //external/... work by only allowing "approved" existing BUILD files in the Bazel workspace.
Test: bazel build //bionic/... //external/... //frameworks/... //system/...

Test: ./build/bazel/scripts/run_presubmits.sh

Change-Id: I91865ca87c6535053e7a14d2526ff3ce0991bfea
2021-05-17 06:34:53 -04:00
Jingwen Chen
bf61afb7f7 bp2build: export some cc toolchain flags into Starlark.
This CL exports common/global/device/host clang/ld/ldd flags
from their Ninja variable initialization locations in
cc/config/global.go and cc/config/clang.go to make Bazel's cc_toolchain
and Soong's cc actions more consistent with each other.

This does not handle env-dependent or arch-specific toolchain flags
yet (logic in compiler.go and linker.go).

Test: TH
Bug: 187086342
Bug: 187084737
Bug: 186628704
Bug: 187857770
Change-Id: Ie403d7cd23f35160897b9dd902c799cbf1bd7f0c
2021-05-13 06:25:47 +00:00
Liz Kammer
78c68655e1 Write all BUILD files for queryview
Some BUILD files cannot be written to support bp2build as they already
exist in the tree; however, all BUILD files should be written for
queryview as they are not intended to coexist with handwritten BUILD
files.

Test: $ bazel query --config=queryview
  "somepath(//system/linkerconfig:linkerconfig--android_arm64_armv8-a ,
  //bionic/libc:libc_openbsd--android_arm64_armv8-a_static)"
Test: build/bazel/ci/bp2build.sh
Fixes: 186132826
Change-Id: I2cb26b7482e7eb5523cee33452be3753ad37e1b0
2021-04-22 14:40:17 -04:00
Rupert Shuttleworth
2a4fc3ecdc Generate BUILD files for every directory that has an Android.bp file.
Test: Added an integration test
Test: bazel build --package_path=out/soong/workspace //bionic/...

Change-Id: Ie34bd23ab3c5428e6c9c9919e5fb6fcb4e709adc
2021-04-21 07:15:50 -04:00
Jingwen Chen
6c309cd0ac bp2build: don't generate a WORKSPACE.
bp2build doesn't need to generate a WORKSPACE file.

Also cleanup conversion_test.go.

Test: TH
Change-Id: Iba2f4b2f71d72ccf8b148cd11d78c190f93560c4
2021-04-01 11:50:27 +00:00
Jingwen Chen
12b4c2706d bp2build: add allowlist for package-level conversions.
This CL adds the support for specifying lists of directories in
build/soong/android/bazel.go, which are then written into
out/soong/bp2build/MANIFEST. Using this configuration,
modules/directories can either default to bp2build_available: true or
false, while still retaining the ability to opt-in or out at the module level.

It also ensures that ConvertWithBp2Build returns true iff the module
type has a registered bp2build converter.

Test: go tests
Test: demo.sh full
Test: TreeHugger presubmits for bp2build and mixed builds.

Change-Id: I0e0f6f4b1b2ec045f2f1c338f7084defc5d23a55
2021-03-24 02:27:19 -04:00
Liz Kammer
ba3ea16f14 Use handcrafted build targets in bp2build
If both bp2build_available and label are specified, label will be
preferred.

Initially, we copy the entire BUILD.bazel file. Eventually we may move
this to use bazel query for a more accurate result.

Test: go test *
Test: build/bazel/scripts/milestone-2/demo.sh full
Test: GENERATE_BAZEL_FILES=true m nothing
      edit bionic/libc/tools/BUILD.bazel
      GENERATE_BAZEL_FILES=true m nothing and verify changes picked up
Bug: 180516554
Change-Id: I43025583300e6b10d2c18032cd4a76237b578d59
2021-03-15 13:09:25 -04:00
Jingwen Chen
88ae408a0f queryview: add "size" to ignored prop.
Test: m queryview && bazel query //... --config=queryview
Change-Id: Ia84be6e2fc5b302b4a147f94bfa219a729b67be1
2021-02-24 19:55:50 -05:00
Jingwen Chen
bb483cbcf5 bp2build: rename generated files to BUILD
The checked in files are named BUILD.bazel, while bp2build files are
named BUILD.

Test: GENERATE_BAZEL_FILES=true m nothing
Change-Id: If226f581b5075088f774dc4f5f9ee88259821835
2021-02-09 04:26:18 +00:00
Jingwen Chen
1c2317315c bp2build: make generated BUILD files publicly visible.
This is obviously not good build hygiene, but since Soong modules are in a global namespace, making BUILD files fully public will increase our velocity during the initial migration phases.

We'd want to lock visibility down to private by default as soon as possible, but for the purposes of migration, these will be public.

Test: bazel build //bionic/...
Change-Id: I99d62f3f8826712240decd325928435333870352
2021-02-05 09:38:15 -05:00
Jingwen Chen
40067de675 bp2build: support Starlark rules and load statements.
This CL adds support to bp2build for declaring the location of the
Starlark rule definition when creating BazelTargetModules. This is
needed for non-native rules that needs to be loaded from .bzl files
somewhere in the tree.

Since load statements are aggregated at the top of the BUILD file, away
from the targets that actually use them, this CL also introduces an
abstraction to group BazelTargets together and compute their load
statements and target string representations separately, allowing load
statements to be decoupled and written into a BUILD file before the
targets themselves.

Test: soong tests
Test: TH
Test: GENERATE_BAZEL_FILES=true m nothing && build/bazel/scripts/bp2build-sync.sh write && bazel cquery //bionic/...
Fixes: 178531760

Test: TH
Change-Id: Ie5f793a00006eb024eaef07ddd9fde7aaefc054e
2021-01-26 22:46:20 -05:00
Jingwen Chen
33832f96e0 bp2build: introduce CodegenMode.
The CodegenMode enum helps to differentiate between bp2build and queryview modes of generating BUILD files from the Soong module graph.

bp2build is used for generating BUILD files from an unconfigured Soong module graph for Soong->Bazel conversion, whereas QueryView is a front-end for querying the existing Soong configured module graph with Bazel query.

Test: go test

Test: TH
Change-Id: I5709f591f1ae08b2770adf272d8ce60c9ee1f46a
2021-01-26 00:30:30 -05:00
Jingwen Chen
7385067640 bp2build: framework for generating BazelTargetModules.
This CL creates the framework necessary for generating
BazelTargetModules from regular Soong Android modules.
BazelTargetModules are code-generated into Bazel targets in BUILD files.

See the follow-up CL for examples of creating filegroup/genrule
BazelTargetModules.

Test: GENERATE_BAZEL_FILES=true m nothing # creates out/soong/bp2build
with no BUILD files, because there are no BazelTargetModules in the
module graph.

Change-Id: I33a96365bd439043b13af6db9e439592e9983188
2021-01-21 22:46:11 -05:00
Liz Kammer
2dd9ca422d Refactor queryview.
Splits queryview into queryview and bp2build. The latter runs as a
presingleton (could be converted to a singleton). This prevents needing
to run soong_ui a subsequent time to build the query. Queryview remains
as a separate step to prevent increasing runtime due to this generation
every time Soong runs.

Currently this is running as a presingleton as this gives a translation
of Android.bp files after only LoadHooks have run, no mutators.

Test: go tests
Test: m queryview && bazel query --config=queryview //...
Change-Id: If2ba28c7ef60fbd41f43bda6623d41c8c7d23a1b
2021-01-07 14:34:00 -05:00