aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrice Arruda2019-05-10 19:08:22 -0500
committerandroid-build-merger2019-05-10 19:08:22 -0500
commitc0b973ac72d79a7744ef3e5d44f7520abec3b14e (patch)
tree23a44181addfde142f5b00bc8896ee07e021ca89
parent350f0987bf6cd23519fd620f454f0286da25a16f (diff)
parentbebfdea43764ba062e180cc30d55ef186543f44d (diff)
downloadplatform-build-soong-c0b973ac72d79a7744ef3e5d44f7520abec3b14e.tar.gz
platform-build-soong-c0b973ac72d79a7744ef3e5d44f7520abec3b14e.tar.xz
platform-build-soong-c0b973ac72d79a7744ef3e5d44f7520abec3b14e.zip
Merge "Soong: Add mk2bp conversion for prebuilt_usr_share."
am: bebfdea437 Change-Id: I42048f913b1620aa7cdbfbec67c492264bdbc968
-rw-r--r--androidmk/cmd/androidmk/androidmk_test.go75
-rw-r--r--bpfix/bpfix/bpfix.go86
2 files changed, 124 insertions, 37 deletions
diff --git a/androidmk/cmd/androidmk/androidmk_test.go b/androidmk/cmd/androidmk/androidmk_test.go
index 34e673c5..88c5304e 100644
--- a/androidmk/cmd/androidmk/androidmk_test.go
+++ b/androidmk/cmd/androidmk/androidmk_test.go
@@ -879,7 +879,6 @@ prebuilt_etc {
879} 879}
880`, 880`,
881 }, 881 },
882
883 { 882 {
884 desc: "prebuilt_etc_PRODUCT_OUT/system/etc", 883 desc: "prebuilt_etc_PRODUCT_OUT/system/etc",
885 in: ` 884 in: `
@@ -1065,6 +1064,80 @@ prebuilt_etc {
1065`, 1064`,
1066 }, 1065 },
1067 { 1066 {
1067 desc: "prebuilt_usr_share",
1068 in: `
1069include $(CLEAR_VARS)
1070LOCAL_MODULE := foo
1071LOCAL_MODULE_CLASS := ETC
1072LOCAL_MODULE_PATH := $(TARGET_OUT)/usr/share
1073LOCAL_SRC_FILES := foo.txt
1074include $(BUILD_PREBUILT)
1075`,
1076 expected: `
1077prebuilt_usr_share {
1078 name: "foo",
1079
1080 src: "foo.txt",
1081}
1082`,
1083 },
1084 {
1085 desc: "prebuilt_usr_share subdir_bar",
1086 in: `
1087include $(CLEAR_VARS)
1088LOCAL_MODULE := foo
1089LOCAL_MODULE_CLASS := ETC
1090LOCAL_MODULE_PATH := $(TARGET_OUT)/usr/share/bar
1091LOCAL_SRC_FILES := foo.txt
1092include $(BUILD_PREBUILT)
1093`,
1094 expected: `
1095prebuilt_usr_share {
1096 name: "foo",
1097
1098 src: "foo.txt",
1099 sub_dir: "bar",
1100}
1101`,
1102 },
1103 {
1104 desc: "prebuilt_usr_share_host",
1105 in: `
1106include $(CLEAR_VARS)
1107LOCAL_MODULE := foo
1108LOCAL_MODULE_CLASS := ETC
1109LOCAL_MODULE_PATH := $(HOST_OUT)/usr/share
1110LOCAL_SRC_FILES := foo.txt
1111include $(BUILD_PREBUILT)
1112`,
1113 expected: `
1114prebuilt_usr_share_host {
1115 name: "foo",
1116
1117 src: "foo.txt",
1118}
1119`,
1120 },
1121 {
1122 desc: "prebuilt_usr_share_host subdir_bar",
1123 in: `
1124include $(CLEAR_VARS)
1125LOCAL_MODULE := foo
1126LOCAL_MODULE_CLASS := ETC
1127LOCAL_MODULE_PATH := $(HOST_OUT)/usr/share/bar
1128LOCAL_SRC_FILES := foo.txt
1129include $(BUILD_PREBUILT)
1130`,
1131 expected: `
1132prebuilt_usr_share_host {
1133 name: "foo",
1134
1135 src: "foo.txt",
1136 sub_dir: "bar",
1137}
1138`,
1139 },
1140 {
1068 desc: "vts_config", 1141 desc: "vts_config",
1069 in: ` 1142 in: `
1070include $(CLEAR_VARS) 1143include $(CLEAR_VARS)
diff --git a/bpfix/bpfix/bpfix.go b/bpfix/bpfix/bpfix.go
index 706c0ec2..f217da6a 100644
--- a/bpfix/bpfix/bpfix.go
+++ b/bpfix/bpfix/bpfix.go
@@ -431,14 +431,6 @@ func getStringProperty(prop *parser.Property, fieldName string) string {
431 return "" 431 return ""
432} 432}
433 433
434// Create sub_dir: attribute for the given path
435func makePrebuiltEtcDestination(mod *parser.Module, path string) {
436 mod.Properties = append(mod.Properties, &parser.Property{
437 Name: "sub_dir",
438 Value: &parser.String{Value: path},
439 })
440}
441
442// Set the value of the given attribute to the error message 434// Set the value of the given attribute to the error message
443func indicateAttributeError(mod *parser.Module, attributeName string, format string, a ...interface{}) error { 435func indicateAttributeError(mod *parser.Module, attributeName string, format string, a ...interface{}) error {
444 msg := fmt.Sprintf(format, a...) 436 msg := fmt.Sprintf(format, a...)
@@ -464,16 +456,52 @@ func resolveLocalModule(mod *parser.Module, val parser.Expression) parser.Expres
464 return val 456 return val
465} 457}
466 458
467// A prefix to strip before setting 'filename' attribute and an array of boolean attributes to set. 459// etcPrebuiltModuleUpdate contains information on updating certain parts of a defined module such as:
468type filenamePrefixToFlags struct { 460// * changing the module type from prebuilt_etc to a different one
461// * stripping the prefix of the install path based on the module type
462// * appending additional boolean properties to the prebuilt module
463type etcPrebuiltModuleUpdate struct {
464 // The prefix of the install path defined in local_module_path. The prefix is removed from local_module_path
465 // before setting the 'filename' attribute.
469 prefix string 466 prefix string
470 flags []string 467
468 // There is only one prebuilt module type in makefiles. In Soong, there are multiple versions of
469 // prebuilts based on local_module_path. By default, it is "prebuilt_etc" if modType is blank. An
470 // example is if the local_module_path contains $(TARGET_OUT)/usr/share, the module type is
471 // considered as prebuilt_usr_share.
472 modType string
473
474 // Additional boolean attributes to be added in the prebuilt module. Each added boolean attribute
475 // has a value of true.
476 flags []string
477}
478
479func (f etcPrebuiltModuleUpdate) update(m *parser.Module, path string) bool {
480 updated := false
481 if path == f.prefix {
482 updated = true
483 } else if trimmedPath := strings.TrimPrefix(path, f.prefix+"/"); trimmedPath != path {
484 m.Properties = append(m.Properties, &parser.Property{
485 Name: "sub_dir",
486 Value: &parser.String{Value: trimmedPath},
487 })
488 updated = true
489 }
490 if updated {
491 for _, flag := range f.flags {
492 m.Properties = append(m.Properties, &parser.Property{Name: flag, Value: &parser.Bool{Value: true, Token: "true"}})
493 }
494 if f.modType != "" {
495 m.Type = f.modType
496 }
497 }
498 return updated
471} 499}
472 500
473var localModulePathRewrite = map[string][]filenamePrefixToFlags{ 501var localModuleUpdate = map[string][]etcPrebuiltModuleUpdate{
474 "HOST_OUT": {{prefix: "/etc"}}, 502 "HOST_OUT": {{prefix: "/etc", modType: "prebuilt_etc_host"}, {prefix: "/usr/share", modType: "prebuilt_usr_share_host"}},
475 "PRODUCT_OUT": {{prefix: "/system/etc"}, {prefix: "/vendor/etc", flags: []string{"proprietary"}}}, 503 "PRODUCT_OUT": {{prefix: "/system/etc"}, {prefix: "/vendor/etc", flags: []string{"proprietary"}}},
476 "TARGET_OUT": {{prefix: "/etc"}}, 504 "TARGET_OUT": {{prefix: "/etc"}, {prefix: "/usr/share", modType: "prebuilt_usr_share"}},
477 "TARGET_OUT_ETC": {{prefix: ""}}, 505 "TARGET_OUT_ETC": {{prefix: ""}},
478 "TARGET_OUT_PRODUCT": {{prefix: "/etc", flags: []string{"product_specific"}}}, 506 "TARGET_OUT_PRODUCT": {{prefix: "/etc", flags: []string{"product_specific"}}},
479 "TARGET_OUT_PRODUCT_ETC": {{prefix: "", flags: []string{"product_specific"}}}, 507 "TARGET_OUT_PRODUCT_ETC": {{prefix: "", flags: []string{"product_specific"}}},
@@ -526,37 +554,23 @@ func rewriteAndroidmkPrebuiltEtc(f *Fixer) error {
526 if prop_local_module_path, ok := mod.GetProperty(local_module_path); ok { 554 if prop_local_module_path, ok := mod.GetProperty(local_module_path); ok {
527 removeProperty(mod, local_module_path) 555 removeProperty(mod, local_module_path)
528 prefixVariableName := getStringProperty(prop_local_module_path, "var") 556 prefixVariableName := getStringProperty(prop_local_module_path, "var")
529 path := getStringProperty(prop_local_module_path, "fixed") 557 if moduleUpdates, ok := localModuleUpdate[prefixVariableName]; ok {
530 if prefixRewrites, ok := localModulePathRewrite[prefixVariableName]; ok { 558 path := getStringProperty(prop_local_module_path, "fixed")
531 rewritten := false 559 updated := false
532 for _, prefixRewrite := range prefixRewrites { 560 for i := 0; i < len(moduleUpdates) && !updated; i++ {
533 if path == prefixRewrite.prefix { 561 updated = moduleUpdates[i].update(mod, path)
534 rewritten = true
535 } else if trimmedPath := strings.TrimPrefix(path, prefixRewrite.prefix+"/"); trimmedPath != path {
536 makePrebuiltEtcDestination(mod, trimmedPath)
537 rewritten = true
538 }
539 if rewritten {
540 for _, flag := range prefixRewrite.flags {
541 mod.Properties = append(mod.Properties, &parser.Property{Name: flag, Value: &parser.Bool{Value: true, Token: "true"}})
542 }
543 break
544 }
545 } 562 }
546 if !rewritten { 563 if !updated {
547 expectedPrefices := "" 564 expectedPrefices := ""
548 sep := "" 565 sep := ""
549 for _, prefixRewrite := range prefixRewrites { 566 for _, moduleUpdate := range moduleUpdates {
550 expectedPrefices += sep 567 expectedPrefices += sep
551 sep = ", " 568 sep = ", "
552 expectedPrefices += prefixRewrite.prefix 569 expectedPrefices += moduleUpdate.prefix
553 } 570 }
554 return indicateAttributeError(mod, "filename", 571 return indicateAttributeError(mod, "filename",
555 "LOCAL_MODULE_PATH value under $(%s) should start with %s", prefixVariableName, expectedPrefices) 572 "LOCAL_MODULE_PATH value under $(%s) should start with %s", prefixVariableName, expectedPrefices)
556 } 573 }
557 if prefixVariableName == "HOST_OUT" {
558 mod.Type = "prebuilt_etc_host"
559 }
560 } else { 574 } else {
561 return indicateAttributeError(mod, "filename", "Cannot handle $(%s) for the prebuilt_etc", prefixVariableName) 575 return indicateAttributeError(mod, "filename", "Cannot handle $(%s) for the prebuilt_etc", prefixVariableName)
562 } 576 }