Loading bp2build/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -12,6 +12,7 @@ bootstrap_go_package { "soong-android", "soong-bazel", "soong-genrule", "soong-sh", ], testSrcs: [ "build_conversion_test.go", Loading bp2build/build_conversion_test.go +24 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package bp2build import ( "android/soong/android" "android/soong/genrule" "android/soong/sh" "strings" "testing" ) Loading Loading @@ -357,6 +358,12 @@ load("//build/bazel/rules:java.bzl", "java_binary")`, ruleClass: "genrule", // Note: no bzlLoadLocation for native rules }, BazelTarget{ name: "sh_binary_target", ruleClass: "sh_binary", // Note: no bzlLoadLocation for native rules // TODO(ruperts): Could open source the existing, experimental Starlark sh_ rules? }, }, expectedLoadStatements: `load("//build/bazel/rules:cc.bzl", "cc_binary") load("//build/bazel/rules:java.bzl", "java_binary")`, Loading Loading @@ -853,6 +860,23 @@ genrule { )`, }, }, { description: "sh_binary test", moduleTypeUnderTest: "sh_binary", moduleTypeUnderTestFactory: sh.ShBinaryFactory, moduleTypeUnderTestBp2BuildMutator: sh.ShBinaryBp2Build, bp: `sh_binary { name: "foo", src: "foo.sh", bazel_module: { bp2build_available: true }, }`, expectedBazelTargets: []string{`sh_binary( name = "foo", srcs = [ "foo.sh", ], )`}, }, } dir := "." Loading sh/sh_binary.go +64 −0 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ import ( "github.com/google/blueprint/proptools" "android/soong/android" "android/soong/bazel" "android/soong/cc" "android/soong/tradefed" ) Loading @@ -43,6 +44,8 @@ func init() { android.RegisterModuleType("sh_binary_host", ShBinaryHostFactory) android.RegisterModuleType("sh_test", ShTestFactory) android.RegisterModuleType("sh_test_host", ShTestHostFactory) android.RegisterBp2BuildMutator("sh_binary", ShBinaryBp2Build) } type shBinaryProperties struct { Loading Loading @@ -81,6 +84,9 @@ type shBinaryProperties struct { // Make this module available when building for recovery. Recovery_available *bool // Properties for Bazel migration purposes. bazel.Properties } type TestProperties struct { Loading Loading @@ -461,4 +467,62 @@ func ShTestHostFactory() android.Module { return module } type bazelShBinaryAttributes struct { Srcs bazel.LabelList // Bazel also supports the attributes below, but (so far) these are not required for Bionic // deps // data // args // compatible_with // deprecation // distribs // env // exec_compatible_with // exec_properties // features // licenses // output_licenses // restricted_to // tags // target_compatible_with // testonly // toolchains // visibility } type bazelShBinary struct { android.BazelTargetModuleBase bazelShBinaryAttributes } func BazelShBinaryFactory() android.Module { module := &bazelShBinary{} module.AddProperties(&module.bazelShBinaryAttributes) android.InitBazelTargetModule(module) return module } func ShBinaryBp2Build(ctx android.TopDownMutatorContext) { m, ok := ctx.Module().(*ShBinary) if !ok || !m.properties.Bazel_module.Bp2build_available { return } srcs := android.BazelLabelForModuleSrc(ctx, []string{*m.properties.Src}) attrs := &bazelShBinaryAttributes{ Srcs: srcs, } props := bazel.NewBazelTargetModuleProperties(m.Name(), "sh_binary", "") ctx.CreateBazelTargetModule(BazelShBinaryFactory, props, attrs) } func (m *bazelShBinary) Name() string { return m.BaseModuleName() } func (m *bazelShBinary) GenerateAndroidBuildActions(ctx android.ModuleContext) {} var Bool = proptools.Bool Loading
bp2build/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -12,6 +12,7 @@ bootstrap_go_package { "soong-android", "soong-bazel", "soong-genrule", "soong-sh", ], testSrcs: [ "build_conversion_test.go", Loading
bp2build/build_conversion_test.go +24 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package bp2build import ( "android/soong/android" "android/soong/genrule" "android/soong/sh" "strings" "testing" ) Loading Loading @@ -357,6 +358,12 @@ load("//build/bazel/rules:java.bzl", "java_binary")`, ruleClass: "genrule", // Note: no bzlLoadLocation for native rules }, BazelTarget{ name: "sh_binary_target", ruleClass: "sh_binary", // Note: no bzlLoadLocation for native rules // TODO(ruperts): Could open source the existing, experimental Starlark sh_ rules? }, }, expectedLoadStatements: `load("//build/bazel/rules:cc.bzl", "cc_binary") load("//build/bazel/rules:java.bzl", "java_binary")`, Loading Loading @@ -853,6 +860,23 @@ genrule { )`, }, }, { description: "sh_binary test", moduleTypeUnderTest: "sh_binary", moduleTypeUnderTestFactory: sh.ShBinaryFactory, moduleTypeUnderTestBp2BuildMutator: sh.ShBinaryBp2Build, bp: `sh_binary { name: "foo", src: "foo.sh", bazel_module: { bp2build_available: true }, }`, expectedBazelTargets: []string{`sh_binary( name = "foo", srcs = [ "foo.sh", ], )`}, }, } dir := "." Loading
sh/sh_binary.go +64 −0 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ import ( "github.com/google/blueprint/proptools" "android/soong/android" "android/soong/bazel" "android/soong/cc" "android/soong/tradefed" ) Loading @@ -43,6 +44,8 @@ func init() { android.RegisterModuleType("sh_binary_host", ShBinaryHostFactory) android.RegisterModuleType("sh_test", ShTestFactory) android.RegisterModuleType("sh_test_host", ShTestHostFactory) android.RegisterBp2BuildMutator("sh_binary", ShBinaryBp2Build) } type shBinaryProperties struct { Loading Loading @@ -81,6 +84,9 @@ type shBinaryProperties struct { // Make this module available when building for recovery. Recovery_available *bool // Properties for Bazel migration purposes. bazel.Properties } type TestProperties struct { Loading Loading @@ -461,4 +467,62 @@ func ShTestHostFactory() android.Module { return module } type bazelShBinaryAttributes struct { Srcs bazel.LabelList // Bazel also supports the attributes below, but (so far) these are not required for Bionic // deps // data // args // compatible_with // deprecation // distribs // env // exec_compatible_with // exec_properties // features // licenses // output_licenses // restricted_to // tags // target_compatible_with // testonly // toolchains // visibility } type bazelShBinary struct { android.BazelTargetModuleBase bazelShBinaryAttributes } func BazelShBinaryFactory() android.Module { module := &bazelShBinary{} module.AddProperties(&module.bazelShBinaryAttributes) android.InitBazelTargetModule(module) return module } func ShBinaryBp2Build(ctx android.TopDownMutatorContext) { m, ok := ctx.Module().(*ShBinary) if !ok || !m.properties.Bazel_module.Bp2build_available { return } srcs := android.BazelLabelForModuleSrc(ctx, []string{*m.properties.Src}) attrs := &bazelShBinaryAttributes{ Srcs: srcs, } props := bazel.NewBazelTargetModuleProperties(m.Name(), "sh_binary", "") ctx.CreateBazelTargetModule(BazelShBinaryFactory, props, attrs) } func (m *bazelShBinary) Name() string { return m.BaseModuleName() } func (m *bazelShBinary) GenerateAndroidBuildActions(ctx android.ModuleContext) {} var Bool = proptools.Bool