Merge "Use product variables from the overridden apex"
diff --git a/java/aar.go b/java/aar.go
index 7cdcbae..7c45efe 100644
--- a/java/aar.go
+++ b/java/aar.go
@@ -1092,11 +1092,6 @@
} else if !depLabels.Deps.IsEmpty() {
ctx.ModuleErrorf("Module has direct dependencies but no sources. Bazel will not allow this.")
}
-
- if len(a.properties.Common_srcs) != 0 {
- commonAttrs.Common_srcs = bazel.MakeLabelListAttribute(android.BazelLabelForModuleSrc(ctx, a.properties.Common_srcs))
- }
-
name := a.Name()
props := bazel.BazelTargetModuleProperties{
Rule_class: "android_library",
diff --git a/java/app.go b/java/app.go
index 1731970..f596673 100755
--- a/java/app.go
+++ b/java/app.go
@@ -1528,13 +1528,12 @@
Bzl_load_location: "//build/bazel/rules/android:rules.bzl",
}
- if !bp2BuildInfo.hasKotlinSrcs && len(a.properties.Common_srcs) == 0 {
+ if !bp2BuildInfo.hasKotlin {
appAttrs.javaCommonAttributes = commonAttrs
appAttrs.bazelAapt = aapt
appAttrs.Deps = deps
} else {
ktName := a.Name() + "_kt"
- commonAttrs.Common_srcs = bazel.MakeLabelListAttribute(android.BazelLabelForModuleSrc(ctx, a.properties.Common_srcs))
ctx.CreateBazelTargetModule(
bazel.BazelTargetModuleProperties{
Rule_class: "android_library",
diff --git a/java/java.go b/java/java.go
index 6a764cf..63c4416 100644
--- a/java/java.go
+++ b/java/java.go
@@ -2607,10 +2607,10 @@
type javaCommonAttributes struct {
*javaResourcesAttributes
- Srcs bazel.LabelListAttribute
- Plugins bazel.LabelListAttribute
- Javacopts bazel.StringListAttribute
- Common_srcs bazel.LabelListAttribute
+ *kotlinAttributes
+ Srcs bazel.LabelListAttribute
+ Plugins bazel.LabelListAttribute
+ Javacopts bazel.StringListAttribute
}
type javaDependencyLabels struct {
@@ -2637,8 +2637,8 @@
// depending on the module type.
type bp2BuildJavaInfo struct {
// separates dependencies into dynamic dependencies and static dependencies.
- DepLabels *javaDependencyLabels
- hasKotlinSrcs bool
+ DepLabels *javaDependencyLabels
+ hasKotlin bool
}
// convertLibraryAttrsBp2Build returns a javaCommonAttributes struct with
@@ -2785,9 +2785,17 @@
depLabels.Deps = deps
depLabels.StaticDeps = bazel.MakeLabelListAttribute(staticDeps)
+ hasKotlin := !kotlinSrcs.IsEmpty()
+ if len(m.properties.Common_srcs) != 0 {
+ hasKotlin = true
+ commonAttrs.kotlinAttributes = &kotlinAttributes{
+ bazel.MakeLabelListAttribute(android.BazelLabelForModuleSrc(ctx, m.properties.Common_srcs)),
+ }
+ }
+
bp2BuildInfo := &bp2BuildJavaInfo{
- DepLabels: depLabels,
- hasKotlinSrcs: !kotlinSrcs.IsEmpty(),
+ DepLabels: depLabels,
+ hasKotlin: hasKotlin,
}
return commonAttrs, bp2BuildInfo
@@ -2800,6 +2808,10 @@
Neverlink bazel.BoolAttribute
}
+type kotlinAttributes struct {
+ Common_srcs bazel.LabelListAttribute
+}
+
func javaLibraryBp2Build(ctx android.TopDownMutatorContext, m *Library) {
commonAttrs, bp2BuildInfo := m.convertLibraryAttrsBp2Build(ctx)
depLabels := bp2BuildInfo.DepLabels
@@ -2828,14 +2840,12 @@
}
name := m.Name()
- if !bp2BuildInfo.hasKotlinSrcs && len(m.properties.Common_srcs) == 0 {
+ if !bp2BuildInfo.hasKotlin {
props = bazel.BazelTargetModuleProperties{
Rule_class: "java_library",
Bzl_load_location: "//build/bazel/rules/java:library.bzl",
}
} else {
- attrs.javaCommonAttributes.Common_srcs = bazel.MakeLabelListAttribute(android.BazelLabelForModuleSrc(ctx, m.properties.Common_srcs))
-
props = bazel.BazelTargetModuleProperties{
Rule_class: "kt_jvm_library",
Bzl_load_location: "//build/bazel/rules/kotlin:kt_jvm_library.bzl",
@@ -2926,7 +2936,7 @@
Jvm_flags: jvmFlags,
}
- if !bp2BuildInfo.hasKotlinSrcs && len(m.properties.Common_srcs) == 0 {
+ if !bp2BuildInfo.hasKotlin {
attrs.javaCommonAttributes = commonAttrs
attrs.Deps = deps
} else {
@@ -2935,18 +2945,10 @@
Rule_class: "kt_jvm_library",
Bzl_load_location: "//build/bazel/rules/kotlin:kt_jvm_library.bzl",
}
- ktAttrs := &javaLibraryAttributes{
- Deps: deps,
- javaCommonAttributes: &javaCommonAttributes{
- Srcs: commonAttrs.Srcs,
- Plugins: commonAttrs.Plugins,
- Javacopts: commonAttrs.Javacopts,
- javaResourcesAttributes: commonAttrs.javaResourcesAttributes,
- },
- }
- if len(m.properties.Common_srcs) != 0 {
- ktAttrs.javaCommonAttributes.Common_srcs = bazel.MakeLabelListAttribute(android.BazelLabelForModuleSrc(ctx, m.properties.Common_srcs))
+ ktAttrs := &javaLibraryAttributes{
+ Deps: deps,
+ javaCommonAttributes: commonAttrs,
}
ctx.CreateBazelTargetModule(ktProps, android.CommonAttributes{Name: ktName}, ktAttrs)
diff --git a/rust/builder.go b/rust/builder.go
index 5566451..4b20e2b 100644
--- a/rust/builder.go
+++ b/rust/builder.go
@@ -255,7 +255,7 @@
// Disallow experimental features
modulePath := android.PathForModuleSrc(ctx).String()
if !(android.IsThirdPartyPath(modulePath) || strings.HasPrefix(modulePath, "prebuilts")) {
- rustcFlags = append(rustcFlags, "-Zallow-features=\"default_alloc_error_handler,custom_inner_attributes,mixed_integer_ops,slice_internals\"")
+ rustcFlags = append(rustcFlags, "-Zallow-features=\"default_alloc_error_handler,custom_inner_attributes,mixed_integer_ops\"")
}
// Collect linker flags
diff --git a/scripts/conv_linker_config.py b/scripts/conv_linker_config.py
index 2ce0ee2..784a92f 100644
--- a/scripts/conv_linker_config.py
+++ b/scripts/conv_linker_config.py
@@ -19,6 +19,7 @@
import collections
import json
import os
+import sys
import linker_config_pb2 #pylint: disable=import-error
from google.protobuf.descriptor import FieldDescriptor
@@ -27,7 +28,24 @@
def Proto(args):
+ """
+ Merges input json files (--source) into a protobuf message (--output).
+ Fails if the output file exists. Set --force or --append to deal with the existing
+ output file.
+ --force to overwrite the output file with the input (.json files).
+ --append to append the input to the output file.
+ """
pb = linker_config_pb2.LinkerConfig()
+ if os.path.isfile(args.output):
+ if args.force:
+ pass
+ elif args.append:
+ with open(args.output, 'rb') as f:
+ pb.ParseFromString(f.read())
+ else:
+ sys.stderr.write(f'Error: {args.output} exists. Use --force or --append.\n')
+ sys.exit(1)
+
if args.source:
for input in args.source.split(':'):
json_content = ''
@@ -114,6 +132,17 @@
required=True,
type=str,
help='Target path to create protobuf file.')
+ option_for_existing_output = parser_proto.add_mutually_exclusive_group()
+ option_for_existing_output.add_argument(
+ '-f',
+ '--force',
+ action='store_true',
+ help='Overwrite if the output file exists.')
+ option_for_existing_output.add_argument(
+ '-a',
+ '--append',
+ action='store_true',
+ help='Append the input to the output file if the output file exists.')
parser_proto.set_defaults(func=Proto)
print_proto = subparsers.add_parser(
@@ -195,8 +224,12 @@
def main():
- args = GetArgParser().parse_args()
- args.func(args)
+ parser = GetArgParser()
+ args = parser.parse_args()
+ if 'func' in args:
+ args.func(args)
+ else:
+ parser.print_help()
if __name__ == '__main__':