2020-11-26 01:06:39 +01:00
|
|
|
package bp2build
|
|
|
|
|
|
|
|
import (
|
|
|
|
"android/soong/android"
|
2020-12-14 14:25:34 +01:00
|
|
|
"android/soong/bazel"
|
2020-11-26 01:06:39 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
type nestedProps struct {
|
|
|
|
Nested_prop string
|
|
|
|
}
|
|
|
|
|
|
|
|
type customProps struct {
|
|
|
|
Bool_prop bool
|
|
|
|
Bool_ptr_prop *bool
|
|
|
|
// Ensure that properties tagged `blueprint:mutated` are omitted
|
|
|
|
Int_prop int `blueprint:"mutated"`
|
|
|
|
Int64_ptr_prop *int64
|
|
|
|
String_prop string
|
|
|
|
String_ptr_prop *string
|
|
|
|
String_list_prop []string
|
|
|
|
|
|
|
|
Nested_props nestedProps
|
|
|
|
Nested_props_ptr *nestedProps
|
|
|
|
}
|
|
|
|
|
|
|
|
type customModule struct {
|
|
|
|
android.ModuleBase
|
|
|
|
|
|
|
|
props customProps
|
2021-02-05 09:03:24 +01:00
|
|
|
|
|
|
|
bazelProps bazel.Properties
|
2020-11-26 01:06:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// OutputFiles is needed because some instances of this module use dist with a
|
|
|
|
// tag property which requires the module implements OutputFileProducer.
|
|
|
|
func (m *customModule) OutputFiles(tag string) (android.Paths, error) {
|
|
|
|
return android.PathsForTesting("path" + tag), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *customModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|
|
|
// nothing for now.
|
|
|
|
}
|
|
|
|
|
|
|
|
func customModuleFactoryBase() android.Module {
|
|
|
|
module := &customModule{}
|
|
|
|
module.AddProperties(&module.props)
|
2021-02-05 09:03:24 +01:00
|
|
|
module.AddProperties(&module.bazelProps)
|
2020-11-26 01:06:39 +01:00
|
|
|
return module
|
|
|
|
}
|
|
|
|
|
|
|
|
func customModuleFactory() android.Module {
|
|
|
|
m := customModuleFactoryBase()
|
|
|
|
android.InitAndroidModule(m)
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
|
|
|
type testProps struct {
|
|
|
|
Test_prop struct {
|
|
|
|
Test_string_prop string
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type customTestModule struct {
|
|
|
|
android.ModuleBase
|
|
|
|
|
|
|
|
props customProps
|
|
|
|
test_props testProps
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *customTestModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|
|
|
// nothing for now.
|
|
|
|
}
|
|
|
|
|
|
|
|
func customTestModuleFactoryBase() android.Module {
|
|
|
|
m := &customTestModule{}
|
|
|
|
m.AddProperties(&m.props)
|
|
|
|
m.AddProperties(&m.test_props)
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
|
|
|
func customTestModuleFactory() android.Module {
|
|
|
|
m := customTestModuleFactoryBase()
|
|
|
|
android.InitAndroidModule(m)
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
|
|
|
type customDefaultsModule struct {
|
|
|
|
android.ModuleBase
|
|
|
|
android.DefaultsModuleBase
|
|
|
|
}
|
|
|
|
|
|
|
|
func customDefaultsModuleFactoryBase() android.DefaultsModule {
|
|
|
|
module := &customDefaultsModule{}
|
|
|
|
module.AddProperties(&customProps{})
|
|
|
|
return module
|
|
|
|
}
|
|
|
|
|
|
|
|
func customDefaultsModuleFactoryBasic() android.Module {
|
|
|
|
return customDefaultsModuleFactoryBase()
|
|
|
|
}
|
|
|
|
|
|
|
|
func customDefaultsModuleFactory() android.Module {
|
|
|
|
m := customDefaultsModuleFactoryBase()
|
|
|
|
android.InitDefaultsModule(m)
|
|
|
|
return m
|
|
|
|
}
|
2020-12-14 14:25:34 +01:00
|
|
|
|
|
|
|
type customBazelModuleAttributes struct {
|
|
|
|
String_prop string
|
|
|
|
String_list_prop []string
|
|
|
|
}
|
|
|
|
|
|
|
|
type customBazelModule struct {
|
|
|
|
android.BazelTargetModuleBase
|
|
|
|
customBazelModuleAttributes
|
|
|
|
}
|
|
|
|
|
|
|
|
func customBazelModuleFactory() android.Module {
|
|
|
|
module := &customBazelModule{}
|
|
|
|
module.AddProperties(&module.customBazelModuleAttributes)
|
|
|
|
android.InitBazelTargetModule(module)
|
|
|
|
return module
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *customBazelModule) Name() string { return m.BaseModuleName() }
|
|
|
|
func (m *customBazelModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {}
|
|
|
|
|
|
|
|
func customBp2BuildMutator(ctx android.TopDownMutatorContext) {
|
|
|
|
if m, ok := ctx.Module().(*customModule); ok {
|
2021-02-05 09:03:24 +01:00
|
|
|
if !m.bazelProps.Bazel_module.Bp2build_available {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-02-05 09:01:50 +01:00
|
|
|
attrs := &customBazelModuleAttributes{
|
2020-12-14 14:25:34 +01:00
|
|
|
String_prop: m.props.String_prop,
|
|
|
|
String_list_prop: m.props.String_list_prop,
|
2021-02-05 09:01:50 +01:00
|
|
|
}
|
|
|
|
|
2021-02-07 16:05:16 +01:00
|
|
|
props := bazel.NewBazelTargetModuleProperties(m.Name(), "custom", "")
|
2021-02-05 09:01:50 +01:00
|
|
|
|
|
|
|
ctx.CreateBazelTargetModule(customBazelModuleFactory, props, attrs)
|
2020-12-14 14:25:34 +01:00
|
|
|
}
|
|
|
|
}
|
2021-01-27 03:58:43 +01:00
|
|
|
|
|
|
|
// A bp2build mutator that uses load statements and creates a 1:M mapping from
|
|
|
|
// module to target.
|
|
|
|
func customBp2BuildMutatorFromStarlark(ctx android.TopDownMutatorContext) {
|
|
|
|
if m, ok := ctx.Module().(*customModule); ok {
|
2021-02-05 09:03:24 +01:00
|
|
|
if !m.bazelProps.Bazel_module.Bp2build_available {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-02-05 09:01:50 +01:00
|
|
|
baseName := m.Name()
|
|
|
|
attrs := &customBazelModuleAttributes{}
|
|
|
|
|
2021-02-07 16:05:16 +01:00
|
|
|
myLibraryProps := bazel.NewBazelTargetModuleProperties(
|
|
|
|
baseName,
|
|
|
|
"my_library",
|
|
|
|
"//build/bazel/rules:rules.bzl",
|
|
|
|
)
|
2021-02-05 09:01:50 +01:00
|
|
|
ctx.CreateBazelTargetModule(customBazelModuleFactory, myLibraryProps, attrs)
|
|
|
|
|
2021-02-07 16:05:16 +01:00
|
|
|
protoLibraryProps := bazel.NewBazelTargetModuleProperties(
|
|
|
|
baseName+"_proto_library_deps",
|
|
|
|
"proto_library",
|
|
|
|
"//build/bazel/rules:proto.bzl",
|
|
|
|
)
|
2021-02-05 09:01:50 +01:00
|
|
|
ctx.CreateBazelTargetModule(customBazelModuleFactory, protoLibraryProps, attrs)
|
|
|
|
|
2021-02-07 16:05:16 +01:00
|
|
|
myProtoLibraryProps := bazel.NewBazelTargetModuleProperties(
|
|
|
|
baseName+"_my_proto_library_deps",
|
|
|
|
"my_proto_library",
|
|
|
|
"//build/bazel/rules:proto.bzl",
|
|
|
|
)
|
2021-02-05 09:01:50 +01:00
|
|
|
ctx.CreateBazelTargetModule(customBazelModuleFactory, myProtoLibraryProps, attrs)
|
2021-01-27 03:58:43 +01:00
|
|
|
}
|
|
|
|
}
|