Add initial bp2build convert for prebuilt_etc modules.
Test: Added unit test. Change-Id: Ie63674e4a867e355e4667b4240979b822f0f3c86
This commit is contained in:
@@ -23,6 +23,7 @@ bootstrap_go_package {
|
|||||||
"soong-bazel",
|
"soong-bazel",
|
||||||
"soong-cc",
|
"soong-cc",
|
||||||
"soong-cc-config",
|
"soong-cc-config",
|
||||||
|
"soong-etc",
|
||||||
"soong-genrule",
|
"soong-genrule",
|
||||||
"soong-python",
|
"soong-python",
|
||||||
"soong-sh",
|
"soong-sh",
|
||||||
@@ -37,6 +38,7 @@ bootstrap_go_package {
|
|||||||
"cc_library_static_conversion_test.go",
|
"cc_library_static_conversion_test.go",
|
||||||
"cc_object_conversion_test.go",
|
"cc_object_conversion_test.go",
|
||||||
"conversion_test.go",
|
"conversion_test.go",
|
||||||
|
"prebuilt_etc_conversion_test.go",
|
||||||
"python_binary_conversion_test.go",
|
"python_binary_conversion_test.go",
|
||||||
"sh_conversion_test.go",
|
"sh_conversion_test.go",
|
||||||
"testing.go",
|
"testing.go",
|
||||||
|
55
bp2build/prebuilt_etc_conversion_test.go
Normal file
55
bp2build/prebuilt_etc_conversion_test.go
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
// Copyright 2021 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 bp2build
|
||||||
|
|
||||||
|
import (
|
||||||
|
"android/soong/android"
|
||||||
|
"android/soong/etc"
|
||||||
|
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func runPrebuiltEtcTestCase(t *testing.T, tc bp2buildTestCase) {
|
||||||
|
t.Helper()
|
||||||
|
runBp2BuildTestCase(t, registerPrebuiltEtcModuleTypes, tc)
|
||||||
|
}
|
||||||
|
|
||||||
|
func registerPrebuiltEtcModuleTypes(ctx android.RegistrationContext) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPrebuiltEtcSimple(t *testing.T) {
|
||||||
|
runPrebuiltEtcTestCase(t, bp2buildTestCase{
|
||||||
|
description: "prebuilt_etc - simple example",
|
||||||
|
moduleTypeUnderTest: "prebuilt_etc",
|
||||||
|
moduleTypeUnderTestFactory: etc.PrebuiltEtcFactory,
|
||||||
|
moduleTypeUnderTestBp2BuildMutator: etc.PrebuiltEtcBp2Build,
|
||||||
|
filesystem: map[string]string{},
|
||||||
|
blueprint: `
|
||||||
|
prebuilt_etc {
|
||||||
|
name: "apex_tz_version",
|
||||||
|
src: "version/tz_version",
|
||||||
|
filename: "tz_version",
|
||||||
|
sub_dir: "tz",
|
||||||
|
installable: false,
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
expectedBazelTargets: []string{`prebuilt_etc(
|
||||||
|
name = "apex_tz_version",
|
||||||
|
filename = "tz_version",
|
||||||
|
installable = False,
|
||||||
|
src = "version/tz_version",
|
||||||
|
sub_dir = "tz",
|
||||||
|
)`}})
|
||||||
|
}
|
@@ -36,6 +36,7 @@ import (
|
|||||||
"github.com/google/blueprint/proptools"
|
"github.com/google/blueprint/proptools"
|
||||||
|
|
||||||
"android/soong/android"
|
"android/soong/android"
|
||||||
|
"android/soong/bazel"
|
||||||
"android/soong/snapshot"
|
"android/soong/snapshot"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -61,6 +62,8 @@ func RegisterPrebuiltEtcBuildComponents(ctx android.RegistrationContext) {
|
|||||||
ctx.RegisterModuleType("prebuilt_rfsa", PrebuiltRFSAFactory)
|
ctx.RegisterModuleType("prebuilt_rfsa", PrebuiltRFSAFactory)
|
||||||
|
|
||||||
ctx.RegisterModuleType("prebuilt_defaults", defaultsFactory)
|
ctx.RegisterModuleType("prebuilt_defaults", defaultsFactory)
|
||||||
|
|
||||||
|
android.RegisterBp2BuildMutator("prebuilt_etc", PrebuiltEtcBp2Build)
|
||||||
}
|
}
|
||||||
|
|
||||||
var PrepareForTestWithPrebuiltEtc = android.FixtureRegisterWithContext(RegisterPrebuiltEtcBuildComponents)
|
var PrepareForTestWithPrebuiltEtc = android.FixtureRegisterWithContext(RegisterPrebuiltEtcBuildComponents)
|
||||||
@@ -131,6 +134,7 @@ type PrebuiltEtcModule interface {
|
|||||||
type PrebuiltEtc struct {
|
type PrebuiltEtc struct {
|
||||||
android.ModuleBase
|
android.ModuleBase
|
||||||
android.DefaultableModuleBase
|
android.DefaultableModuleBase
|
||||||
|
android.BazelModuleBase
|
||||||
|
|
||||||
snapshot.VendorSnapshotModuleInterface
|
snapshot.VendorSnapshotModuleInterface
|
||||||
snapshot.RecoverySnapshotModuleInterface
|
snapshot.RecoverySnapshotModuleInterface
|
||||||
@@ -406,6 +410,7 @@ func PrebuiltEtcFactory() android.Module {
|
|||||||
// This module is device-only
|
// This module is device-only
|
||||||
android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
|
android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
|
||||||
android.InitDefaultableModule(module)
|
android.InitDefaultableModule(module)
|
||||||
|
android.InitBazelModule(module)
|
||||||
return module
|
return module
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -647,3 +652,82 @@ func generatePrebuiltSnapshot(s snapshot.SnapshotSingleton, ctx android.Singleto
|
|||||||
|
|
||||||
return snapshotOutputs
|
return snapshotOutputs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// For Bazel / bp2build
|
||||||
|
|
||||||
|
type bazelPrebuiltEtcAttributes struct {
|
||||||
|
Src bazel.LabelAttribute
|
||||||
|
Filename string
|
||||||
|
Sub_dir string
|
||||||
|
Installable bazel.BoolAttribute
|
||||||
|
}
|
||||||
|
|
||||||
|
type bazelPrebuiltEtc struct {
|
||||||
|
android.BazelTargetModuleBase
|
||||||
|
bazelPrebuiltEtcAttributes
|
||||||
|
}
|
||||||
|
|
||||||
|
func BazelPrebuiltEtcFactory() android.Module {
|
||||||
|
module := &bazelPrebuiltEtc{}
|
||||||
|
module.AddProperties(&module.bazelPrebuiltEtcAttributes)
|
||||||
|
android.InitBazelTargetModule(module)
|
||||||
|
return module
|
||||||
|
}
|
||||||
|
|
||||||
|
func PrebuiltEtcBp2Build(ctx android.TopDownMutatorContext) {
|
||||||
|
module, ok := ctx.Module().(*PrebuiltEtc)
|
||||||
|
if !ok {
|
||||||
|
// Not an prebuilt_etc
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !module.ConvertWithBp2build(ctx) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if ctx.ModuleType() != "prebuilt_etc" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
prebuiltEtcBp2BuildInternal(ctx, module)
|
||||||
|
}
|
||||||
|
|
||||||
|
func prebuiltEtcBp2BuildInternal(ctx android.TopDownMutatorContext, module *PrebuiltEtc) {
|
||||||
|
var srcLabelAttribute bazel.LabelAttribute
|
||||||
|
if module.properties.Src != nil {
|
||||||
|
srcLabelAttribute.SetValue(android.BazelLabelForModuleSrcSingle(ctx, *module.properties.Src))
|
||||||
|
}
|
||||||
|
|
||||||
|
var filename string
|
||||||
|
if module.properties.Filename != nil {
|
||||||
|
filename = *module.properties.Filename
|
||||||
|
}
|
||||||
|
|
||||||
|
var subDir string
|
||||||
|
if module.subdirProperties.Sub_dir != nil {
|
||||||
|
subDir = *module.subdirProperties.Sub_dir
|
||||||
|
}
|
||||||
|
|
||||||
|
var installableBoolAttribute bazel.BoolAttribute
|
||||||
|
if module.properties.Installable != nil {
|
||||||
|
installableBoolAttribute.Value = module.properties.Installable
|
||||||
|
}
|
||||||
|
|
||||||
|
attrs := &bazelPrebuiltEtcAttributes{
|
||||||
|
Src: srcLabelAttribute,
|
||||||
|
Filename: filename,
|
||||||
|
Sub_dir: subDir,
|
||||||
|
Installable: installableBoolAttribute,
|
||||||
|
}
|
||||||
|
|
||||||
|
props := bazel.BazelTargetModuleProperties{
|
||||||
|
Rule_class: "prebuilt_etc",
|
||||||
|
Bzl_load_location: "//build/bazel/rules:prebuilt_etc.bzl",
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.CreateBazelTargetModule(BazelPrebuiltEtcFactory, module.Name(), props, attrs)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *bazelPrebuiltEtc) Name() string {
|
||||||
|
return m.BaseModuleName()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *bazelPrebuiltEtc) GenerateAndroidBuildActions(ctx android.ModuleContext) {}
|
||||||
|
Reference in New Issue
Block a user