aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Cross <ccross@android.com>2023-12-12 00:29:45 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2023-12-12 00:29:45 +0000
commit671be72707eb1fe251eb3817c0cafabd85adedd1 (patch)
treea275ff177caf16b64b85d141fc6491d088de2bca
parentca3ccb170afba6d008ba28fc3dd27697591ea3b7 (diff)
parentbf8eefbc742e4343e9bb1fbf0504f894f0909592 (diff)
downloadxsdc-671be72707eb1fe251eb3817c0cafabd85adedd1.tar.gz
Merge "Remove bp2build from system/tools/xsdc" into main am: 76ac4470cb am: 7eb24d0f3a am: bf8eefbc74
Original change: https://android-review.googlesource.com/c/platform/system/tools/xsdc/+/2865143 Change-Id: If459b9cafca07c6850b8c0035b17e483b0d280e4 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--build/Android.bp5
-rw-r--r--build/xsdc.go2
-rw-r--r--build/xsdc_bp2build_conversion.go250
-rw-r--r--build/xsdc_bp2build_conversion_test.go247
4 files changed, 0 insertions, 504 deletions
diff --git a/build/Android.bp b/build/Android.bp
index a135f7b..446cd8f 100644
--- a/build/Android.bp
+++ b/build/Android.bp
@@ -23,15 +23,10 @@ bootstrap_go_package {
"blueprint",
"soong",
"soong-android",
- "soong-bp2build",
"soong-java",
],
srcs: [
"xsdc.go",
- "xsdc_bp2build_conversion.go",
- ],
- testSrcs: [
- "xsdc_bp2build_conversion_test.go",
],
pluginFor: ["soong_build"],
}
diff --git a/build/xsdc.go b/build/xsdc.go
index c758573..818e938 100644
--- a/build/xsdc.go
+++ b/build/xsdc.go
@@ -83,7 +83,6 @@ type xsdConfigProperties struct {
type xsdConfig struct {
android.ModuleBase
- android.BazelModuleBase
properties xsdConfigProperties
@@ -342,7 +341,6 @@ func xsdConfigFactory() android.Module {
module := &xsdConfig{}
module.AddProperties(&module.properties)
android.InitAndroidModule(module)
- android.InitBazelModule(module)
return module
}
diff --git a/build/xsdc_bp2build_conversion.go b/build/xsdc_bp2build_conversion.go
deleted file mode 100644
index 794a9da..0000000
--- a/build/xsdc_bp2build_conversion.go
+++ /dev/null
@@ -1,250 +0,0 @@
-// Copyright 2023 Google Inc. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package xsdc
-
-import (
- "github.com/google/blueprint/proptools"
-
- "android/soong/android"
- "android/soong/bazel"
-)
-
-type xsdFilegroupAttributes struct {
- Srcs bazel.LabelListAttribute
-}
-
-type xsdCcAttributes struct {
- Src bazel.LabelAttribute
- Include_files bazel.LabelListAttribute
- Package_name bazel.StringAttribute
- Gen_writer bazel.BoolAttribute
- Enums_only bazel.BoolAttribute
- Parser_only bazel.BoolAttribute
- Boolean_getter bazel.BoolAttribute
- Tinyxml bazel.BoolAttribute
- Root_elements bazel.StringListAttribute
- Deps bazel.LabelListAttribute
- Implementation_dynamic_deps bazel.LabelListAttribute
-}
-
-func (xsd *xsdConfig) bp2buildFilegroupTarget(ctx android.Bp2buildMutatorContext) {
- ctx.CreateBazelTargetModule(
- bazel.BazelTargetModuleProperties{
- Rule_class: "filegroup",
- },
- android.CommonAttributes{
- Name: xsd.Name(),
- },
- &xsdFilegroupAttributes{
- Srcs: bazel.MakeLabelListAttribute(
- android.BazelLabelForModuleSrc(ctx, append(xsd.properties.Srcs, xsd.properties.Include_files...)),
- ),
- },
- )
-}
-
-var (
- ccXsdConfigLibraryDenylist = map[string]bool{
- "audio_policy_engine_configurable_configuration_V1_0": true,
- "compatibility_matrix": true,
- "hal_manifest": true,
- "media_profiles": true,
- "platform-compat-config": true,
- }
-)
-
-func (xsd *xsdConfig) bp2buildCcTarget(ctx android.Bp2buildMutatorContext) {
- // Every xsd_config generates .cpp files in Soong, but not all of them are compile-able
- // One such category is .xsd file that contain xs:element not nested under xs:complexType
- // Use a denylist to skip generating cc_xsd_config_library for these Soong modules.
- if _, exists := ccXsdConfigLibraryDenylist[xsd.Name()]; exists {
- return
- }
- if len(xsd.properties.Srcs) != 1 {
- ctx.PropertyErrorf("srcs", "xsd_config must a single src. Got %v", xsd.properties.Srcs)
- }
- xsdFile := xsd.properties.Srcs[0]
-
- xmlLib := "libxml2"
- if proptools.Bool(xsd.properties.Tinyxml) {
- xmlLib = "libtinyxml2"
- }
- ctx.CreateBazelTargetModule(
- bazel.BazelTargetModuleProperties{
- Bzl_load_location: "//build/bazel/rules/cc:cc_xsd_config_library.bzl",
- Rule_class: "cc_xsd_config_library",
- },
- android.CommonAttributes{
- Name: xsd.CppBp2buildTargetName(),
- },
- &xsdCcAttributes{
- Src: *bazel.MakeLabelAttribute(
- android.BazelLabelForModuleSrcSingle(ctx, xsdFile).Label,
- ),
- Include_files: bazel.MakeLabelListAttribute(
- android.BazelLabelForModuleSrc(ctx, xsd.properties.Include_files),
- ),
- Package_name: bazel.StringAttribute{
- Value: xsd.properties.Package_name,
- },
- Gen_writer: bazel.BoolAttribute{
- Value: xsd.properties.Gen_writer,
- },
- Enums_only: bazel.BoolAttribute{
- Value: xsd.properties.Enums_only,
- },
- Parser_only: bazel.BoolAttribute{
- Value: xsd.properties.Parser_only,
- },
- Boolean_getter: bazel.BoolAttribute{
- Value: xsd.properties.Boolean_getter,
- },
- Tinyxml: bazel.BoolAttribute{
- Value: xsd.properties.Tinyxml,
- },
- Root_elements: bazel.MakeStringListAttribute(
- xsd.properties.Root_elements,
- ),
- // The generated cpp file includes additional .h files from xsdc.
- // This needs to be added to the deps so that we can compile the internal cc_static_library.
- // https://cs.android.com/android/_/android/platform/system/tools/xsdc/+/be3543328eb878d094870364333f1fd02f50ddfd:src/main/java/com/android/xsdc/cpp/CppCodeGenerator.java;l=171-174;drc=1da17e8ed45748c16a5c2bade198ae22fb411949;bpv=1;bpt=0
- Deps: bazel.MakeLabelListAttribute(
- android.BazelLabelForModuleDeps(ctx, []string{"libxsdc-utils"}),
- ),
- Implementation_dynamic_deps: bazel.MakeLabelListAttribute(
- android.BazelLabelForModuleDeps(ctx, []string{xmlLib}),
- ),
- },
- )
-
-}
-
-type xsdJavaAttributes struct {
- Src bazel.LabelAttribute
- Sdk_version bazel.StringAttribute
- Include_files bazel.LabelListAttribute
- Package_name bazel.StringAttribute
- Nullability bazel.BoolAttribute
- Gen_has bazel.BoolAttribute
- Gen_writer bazel.BoolAttribute
- Boolean_getter bazel.BoolAttribute
- Root_elements bazel.StringListAttribute
- Deps bazel.LabelListAttribute
-}
-
-var (
- javaXsdConfigLibraryDenylist = map[string]bool{
- "media_profiles": true,
- }
-)
-
-func (xsd *xsdConfig) bp2buildJavaTarget(ctx android.Bp2buildMutatorContext) {
- // Every xsd_config generates .srcjar in Soong, but not all of them are compile-able
- // One such category is .xsd file that contain xs:complexType nested under xs:elementType nested under xs:complexType
- // Use a denylist to skip generating java_xsd_config_library for these Soong modules.
- if _, exists := javaXsdConfigLibraryDenylist[xsd.Name()]; exists {
- return
- }
- if len(xsd.properties.Srcs) != 1 {
- ctx.PropertyErrorf("srcs", "xsd_config must a single src. Got %v", xsd.properties.Srcs)
- }
- xsdFile := xsd.properties.Srcs[0]
-
- // The generated code depends on stub annotations if either
- // a. `nullability: true` in the xsd_config's Android.bp file
- // https://cs.android.com/search?q=xsd_config%20nullability.*true%20f:%5C.bp&sq=&ss=android%2Fplatform%2Fsuperproject
- // b. .xsd schema requests nullable annotation
- // https://cs.android.com/search?q=annotation.*nullable%20f:%5C.xsd&sq=&ss=android%2Fplatform%2Fsuperproject
- // bp2build does not have sufficient metadata about (b), therefore it aggressivesly adds stub-annotations as dep of all generated java_xsd_config_library targets.
- deps := bazel.MakeLabelListAttribute(
- android.BazelLabelForModuleDeps(ctx, []string{"stub-annotations"}),
- )
- // The generated code depends on org.xmlpull.v1.XmlPullParser.*
- // https://cs.android.com/android/_/android/platform/system/tools/xsdc/+/be3543328eb878d094870364333f1fd02f50ddfd:src/main/java/com/android/xsdc/java/JavaCodeGenerator.java;l=313;drc=1da17e8ed45748c16a5c2bade198ae22fb411949;bpv=0;bpt=0
- // For device libraries, this will come the android SDK
- // For host libraries, this will come from the `kxml` library
- deps.SetSelectValue(bazel.OsConfigurationAxis,
- android.Android.Name,
- // Device variant gets this dep from the android sdk (by using core_current)
- bazel.MakeLabelList(
- []bazel.Label{},
- ),
- )
- deps.SetSelectValue(bazel.OsConfigurationAxis,
- bazel.ConditionsDefaultConfigKey,
- // Version copied from this host java library that uses .java files generated from .xsd
- // https://cs.android.com/android/_/android/platform/system/tools/xsdc/+/be3543328eb878d094870364333f1fd02f50ddfd:tests/Android.bp;l=26;bpv=1;bpt=0;drc=7f84bff87550516b148dc03354363fbed0c5f62b
- android.BazelLabelForModuleDeps(ctx, []string{"kxml2-2.3.0"}),
- )
-
- ctx.CreateBazelTargetModule(
- bazel.BazelTargetModuleProperties{
- Bzl_load_location: "//build/bazel/rules/java:java_xsd_config_library.bzl",
- Rule_class: "java_xsd_config_library",
- },
- android.CommonAttributes{
- Name: xsd.JavaBp2buildTargetName(),
- },
- &xsdJavaAttributes{
- Src: *bazel.MakeLabelAttribute(
- android.BazelLabelForModuleSrcSingle(ctx, xsdFile).Label,
- ),
- Include_files: bazel.MakeLabelListAttribute(
- android.BazelLabelForModuleSrc(ctx, xsd.properties.Include_files),
- ),
- Package_name: bazel.StringAttribute{
- Value: xsd.properties.Package_name,
- },
- Nullability: bazel.BoolAttribute{
- Value: xsd.properties.Nullability,
- },
- Gen_has: bazel.BoolAttribute{
- Value: xsd.properties.Gen_has,
- },
- Gen_writer: bazel.BoolAttribute{
- Value: xsd.properties.Gen_writer,
- },
- Boolean_getter: bazel.BoolAttribute{
- Value: xsd.properties.Boolean_getter,
- },
- Root_elements: bazel.MakeStringListAttribute(
- xsd.properties.Root_elements,
- ),
- Deps: deps,
- // The android.jar corresponding to public, system, ... have package private versions of stub annotations
- // Since the .java generated from .xsd contains nullable annotations, it needs an sdk_version that does not contain package private versions of these classes
- // core api surface is one of them
- Sdk_version: bazel.StringAttribute{
- Value: proptools.StringPtr("core_current"),
- },
- },
- )
-}
-
-func (xsd *xsdConfig) ConvertWithBp2build(ctx android.Bp2buildMutatorContext) {
- xsd.bp2buildFilegroupTarget(ctx)
- xsd.bp2buildCcTarget(ctx)
- xsd.bp2buildJavaTarget(ctx)
-}
-
-// Returns the name of cc_xsd_config_library target created by bp2build.
-func (xsd *xsdConfig) CppBp2buildTargetName() string {
- return xsd.Name() + "-cpp"
-}
-
-// Returns the name of java_xsd_config_library target created by bp2build.
-func (xsd *xsdConfig) JavaBp2buildTargetName() string {
- return xsd.Name() + "-java"
-}
diff --git a/build/xsdc_bp2build_conversion_test.go b/build/xsdc_bp2build_conversion_test.go
deleted file mode 100644
index 9e05d3d..0000000
--- a/build/xsdc_bp2build_conversion_test.go
+++ /dev/null
@@ -1,247 +0,0 @@
-// Copyright 2023 Google Inc. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package xsdc
-
-import (
- "testing"
-
- "android/soong/android"
- "android/soong/bp2build"
- "android/soong/cc"
- "android/soong/java"
-)
-
-const (
- cc_preamble = `
- cc_library {
- name: "libxml2",
- }
- cc_library {
- name: "libtinyxml2",
- }
- cc_library {
- name: "libxsdc-utils",
- }
- `
- java_preamble = `
- java_library {
- name: "stub-annotations",
- sdk_version: "current",
- }
- java_library {
- name: "kxml2-2.3.0",
- sdk_version: "current",
- host_supported: true,
- }
- `
-)
-
-func runXsdConfigTest(t *testing.T, tc bp2build.Bp2buildTestCase) {
- t.Parallel()
- tc.StubbedBuildDefinitions = append(tc.StubbedBuildDefinitions,
- "libxml2", "libtinyxml2", "libxsdc-utils", "stub-annotations", "kxml2-2.3.0")
- bp2build.RunBp2BuildTestCase(
- t,
- func(ctx android.RegistrationContext) {
- cc.RegisterLibraryBuildComponents(ctx)
- ctx.RegisterModuleType("java_library", java.LibraryFactory)
- },
- tc,
- )
-}
-
-func TestXsdConfigSimple(t *testing.T) {
- runXsdConfigTest(t, bp2build.Bp2buildTestCase{
- Description: "xsd_config simple",
- ModuleTypeUnderTest: "xsd_config",
- ModuleTypeUnderTestFactory: xsdConfigFactory,
- Blueprint: cc_preamble + java_preamble + `xsd_config {
- name: "foo",
- srcs: ["foo.xsd"],
-}`,
- ExpectedBazelTargets: []string{
- bp2build.MakeBazelTargetNoRestrictions("filegroup", "foo", bp2build.AttrNameToString{
- "srcs": `["foo.xsd"]`,
- }),
- bp2build.MakeBazelTargetNoRestrictions("cc_xsd_config_library", "foo-cpp", bp2build.AttrNameToString{
- "src": `"foo.xsd"`,
- "deps": `[":libxsdc-utils"]`,
- "implementation_dynamic_deps": `[":libxml2"]`,
- }),
- bp2build.MakeBazelTargetNoRestrictions("java_xsd_config_library", "foo-java", bp2build.AttrNameToString{
- "src": `"foo.xsd"`,
- "deps": `[":stub-annotations"] + select({
- "//build/bazel_common_rules/platforms/os:android": [],
- "//conditions:default": [":kxml2-2.3.0"],
- })`,
- "sdk_version": `"core_current"`,
- }),
- },
- })
-}
-
-func TestXsdConfig(t *testing.T) {
- runXsdConfigTest(t, bp2build.Bp2buildTestCase{
- Description: "xsd_config",
- ModuleTypeUnderTest: "xsd_config",
- ModuleTypeUnderTestFactory: xsdConfigFactory,
- Blueprint: cc_preamble + java_preamble + `xsd_config {
- name: "foo",
- srcs: ["foo.xsd"],
- include_files: ["foo.include.xsd"],
- package_name: "foo",
- gen_writer: true,
- enums_only: true,
- boolean_getter: true,
- tinyxml: true,
- root_elements: ["root_element"],
-}`,
- ExpectedBazelTargets: []string{
- bp2build.MakeBazelTargetNoRestrictions("filegroup", "foo", bp2build.AttrNameToString{
- "srcs": `[
- "foo.xsd",
- "foo.include.xsd",
- ]`,
- }),
- bp2build.MakeBazelTargetNoRestrictions("cc_xsd_config_library", "foo-cpp", bp2build.AttrNameToString{
- "src": `"foo.xsd"`,
- "include_files": `["foo.include.xsd"]`,
- "package_name": `"foo"`,
- "gen_writer": `True`,
- "enums_only": `True`,
- "boolean_getter": `True`,
- "tinyxml": `True`,
- "root_elements": `["root_element"]`,
- "deps": `[":libxsdc-utils"]`,
- "implementation_dynamic_deps": `[":libtinyxml2"]`,
- }),
- bp2build.MakeBazelTargetNoRestrictions("java_xsd_config_library", "foo-java", bp2build.AttrNameToString{
- "src": `"foo.xsd"`,
- "include_files": `["foo.include.xsd"]`,
- "package_name": `"foo"`,
- "gen_writer": `True`,
- "boolean_getter": `True`,
- "root_elements": `["root_element"]`,
- "deps": `[":stub-annotations"] + select({
- "//build/bazel_common_rules/platforms/os:android": [],
- "//conditions:default": [":kxml2-2.3.0"],
- })`,
- "sdk_version": `"core_current"`,
- }),
- },
- })
-}
-
-func TestCcAndJavaLibrariesUseXsdConfigGenSrcs(t *testing.T) {
- runXsdConfigTest(t, bp2build.Bp2buildTestCase{
- Description: "cc_library and java_library use srcs generated from xsd_config",
- ModuleTypeUnderTest: "xsd_config",
- ModuleTypeUnderTestFactory: xsdConfigFactory,
- StubbedBuildDefinitions: []string{"foo"},
- Blueprint: cc_preamble + java_preamble + `
-xsd_config {
- name: "foo",
- srcs: ["foo.xsd"],
-}
-cc_library {
- name: "cclib",
- generated_sources: ["foo"],
- generated_headers: ["foo"],
-}
-java_library {
- name: "javalib",
- srcs: [
- "A.java",
- ":foo"
- ],
- sdk_version: "current",
-}`,
- ExpectedBazelTargets: []string{
- bp2build.MakeBazelTarget("cc_library_static", "cclib_bp2build_cc_library_static", bp2build.AttrNameToString{
- "local_includes": `["."]`,
- "implementation_whole_archive_deps": `[":foo-cpp"]`,
- }),
- bp2build.MakeBazelTarget("cc_library_shared", "cclib", bp2build.AttrNameToString{
- "local_includes": `["."]`,
- "implementation_whole_archive_deps": `[":foo-cpp"]`,
- }),
- bp2build.MakeBazelTarget("java_library", "javalib", bp2build.AttrNameToString{
- "srcs": `["A.java"]`,
- "deps": `[":foo-java"]`,
- "exports": `[":foo-java"]`,
- "sdk_version": `"current"`,
- }),
- bp2build.MakeNeverlinkDuplicateTarget("java_library", "javalib"),
- },
- })
-}
-
-func TestCcAndJavaLibrariesUseXsdConfigGenSrcsNoHdrs(t *testing.T) {
- runXsdConfigTest(t, bp2build.Bp2buildTestCase{
- Description: "cc_library and java_library use srcs generated from xsd_config",
- ModuleTypeUnderTest: "xsd_config",
- ModuleTypeUnderTestFactory: xsdConfigFactory,
- StubbedBuildDefinitions: []string{"foo"},
- Blueprint: cc_preamble + java_preamble + `
-xsd_config {
- name: "foo",
- srcs: ["foo.xsd"],
-}
-cc_library {
- name: "cclib",
- generated_sources: ["foo"],
-}`,
- ExpectedBazelTargets: []string{
- bp2build.MakeBazelTarget("cc_library_static", "cclib_bp2build_cc_library_static", bp2build.AttrNameToString{
- "local_includes": `["."]`,
- "implementation_whole_archive_deps": `[":foo-cpp"]`,
- }),
- bp2build.MakeBazelTarget("cc_library_shared", "cclib", bp2build.AttrNameToString{
- "local_includes": `["."]`,
- "implementation_whole_archive_deps": `[":foo-cpp"]`,
- }),
- },
- })
-}
-
-func TestCcAndJavaLibrariesUseXsdConfigGenSrcsExportHeaders(t *testing.T) {
- runXsdConfigTest(t, bp2build.Bp2buildTestCase{
- Description: "cc_library export headers from xsd_config",
- ModuleTypeUnderTest: "xsd_config",
- ModuleTypeUnderTestFactory: xsdConfigFactory,
- StubbedBuildDefinitions: []string{"foo"},
- Blueprint: cc_preamble + java_preamble + `
-xsd_config {
- name: "foo",
- srcs: ["foo.xsd"],
-}
-cc_library {
- name: "cclib",
- generated_sources: ["foo"],
- generated_headers: ["foo"],
- export_generated_headers: ["foo"],
-}`,
- ExpectedBazelTargets: []string{
- bp2build.MakeBazelTarget("cc_library_static", "cclib_bp2build_cc_library_static", bp2build.AttrNameToString{
- "local_includes": `["."]`,
- "whole_archive_deps": `[":foo-cpp"]`,
- }),
- bp2build.MakeBazelTarget("cc_library_shared", "cclib", bp2build.AttrNameToString{
- "local_includes": `["."]`,
- "whole_archive_deps": `[":foo-cpp"]`,
- }),
- },
- })
-}