aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorColin Cross <ccross@android.com>2019-02-11 14:11:09 -0800
committerColin Cross <ccross@android.com>2019-02-13 08:03:29 -0800
commitdeabb94380ad37d89e164946f8076adf433bfa22 (patch)
tree9e385ba01c2fbce9e629579f1ea5933e33bec102
parentbd907cb12bad59f35bdb73476c9a785d7be06b7d (diff)
downloadbuild_soong-deabb94380ad37d89e164946f8076adf433bfa22.tar.gz
build_soong-deabb94380ad37d89e164946f8076adf433bfa22.tar.bz2
build_soong-deabb94380ad37d89e164946f8076adf433bfa22.zip
Add RuleBuilder.Installs().String()
Add a RuleBuilderInstalls type for a slice of RuleBuilderInstalls, and give it a String() method that returns the list of installs in the format that is convenient for passing to Make. Test: rule_builder_test.go Change-Id: I2e9cd9abf4dfb0ad312d0a6662f1567baf9cd222
-rw-r--r--android/rule_builder.go23
-rw-r--r--android/rule_builder_test.go13
-rw-r--r--dexpreopt/dexpreopt_test.go6
-rw-r--r--java/androidmk.go6
-rw-r--r--java/dexpreopt.go6
5 files changed, 41 insertions, 13 deletions
diff --git a/android/rule_builder.go b/android/rule_builder.go
index 468b617b..3b869470 100644
--- a/android/rule_builder.go
+++ b/android/rule_builder.go
@@ -28,7 +28,7 @@ import (
// graph.
type RuleBuilder struct {
commands []*RuleBuilderCommand
- installs []RuleBuilderInstall
+ installs RuleBuilderInstalls
temporariesSet map[string]bool
restat bool
missingDeps []string
@@ -46,6 +46,23 @@ type RuleBuilderInstall struct {
From, To string
}
+type RuleBuilderInstalls []RuleBuilderInstall
+
+// String returns the RuleBuilderInstalls in the form used by $(call copy-many-files) in Make, a space separated
+// list of from:to tuples.
+func (installs RuleBuilderInstalls) String() string {
+ sb := strings.Builder{}
+ for i, install := range installs {
+ if i != 0 {
+ sb.WriteRune(' ')
+ }
+ sb.WriteString(install.From)
+ sb.WriteRune(':')
+ sb.WriteString(install.To)
+ }
+ return sb.String()
+}
+
// MissingDeps adds modules to the list of missing dependencies. If MissingDeps
// is called with a non-empty input, any call to Build will result in a rule
// that will print an error listing the missing dependencies and fail.
@@ -145,8 +162,8 @@ func (r *RuleBuilder) Outputs() []string {
}
// Installs returns the list of tuples passed to Install.
-func (r *RuleBuilder) Installs() []RuleBuilderInstall {
- return append([]RuleBuilderInstall(nil), r.installs...)
+func (r *RuleBuilder) Installs() RuleBuilderInstalls {
+ return append(RuleBuilderInstalls(nil), r.installs...)
}
func (r *RuleBuilder) toolsSet() map[string]bool {
diff --git a/android/rule_builder_test.go b/android/rule_builder_test.go
index 53a5b489..f9473489 100644
--- a/android/rule_builder_test.go
+++ b/android/rule_builder_test.go
@@ -84,6 +84,19 @@ func ExampleRuleBuilder_DeleteTemporaryFiles() {
// outputs: ["c"]
}
+func ExampleRuleBuilder_Installs() {
+ rule := NewRuleBuilder()
+
+ rule.Command().Tool("ld").Inputs([]string{"a.o", "b.o"}).FlagWithOutput("-o ", "linked")
+ rule.Install("linked", "/bin/linked")
+ rule.Install("linked", "/sbin/linked")
+
+ fmt.Printf("rule.Installs().String() = %q\n", rule.Installs().String())
+
+ // Output:
+ // rule.Installs().String() = "linked:/bin/linked linked:/sbin/linked"
+}
+
func ExampleRuleBuilderCommand() {
rule := NewRuleBuilder()
diff --git a/dexpreopt/dexpreopt_test.go b/dexpreopt/dexpreopt_test.go
index ecaf8769..40c694f1 100644
--- a/dexpreopt/dexpreopt_test.go
+++ b/dexpreopt/dexpreopt_test.go
@@ -100,7 +100,7 @@ func TestDexPreopt(t *testing.T) {
t.Error(err)
}
- wantInstalls := []android.RuleBuilderInstall{
+ wantInstalls := android.RuleBuilderInstalls{
{"out/test/oat/arm/package.odex", "/system/app/test/oat/arm/test.odex"},
{"out/test/oat/arm/package.vdex", "/system/app/test/oat/arm/test.vdex"},
}
@@ -141,7 +141,7 @@ func TestDexPreoptSystemOther(t *testing.T) {
t.Error(err)
}
- wantInstalls := []android.RuleBuilderInstall{
+ wantInstalls := android.RuleBuilderInstalls{
{"out/test/oat/arm/package.odex", "/system_other/app/test/oat/arm/test.odex"},
{"out/test/oat/arm/package.vdex", "/system_other/app/test/oat/arm/test.vdex"},
}
@@ -164,7 +164,7 @@ func TestDexPreoptProfile(t *testing.T) {
t.Error(err)
}
- wantInstalls := []android.RuleBuilderInstall{
+ wantInstalls := android.RuleBuilderInstalls{
{"out/test/profile.prof", "/system/app/test/test.apk.prof"},
{"out/test/oat/arm/package.art", "/system/app/test/oat/arm/test.art"},
{"out/test/oat/arm/package.odex", "/system/app/test/oat/arm/test.odex"},
diff --git a/java/androidmk.go b/java/androidmk.go
index d86e71f9..04b328dc 100644
--- a/java/androidmk.go
+++ b/java/androidmk.go
@@ -65,7 +65,7 @@ func (library *Library) AndroidMk() android.AndroidMkData {
fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", library.dexJarFile.String())
}
if len(library.dexpreopter.builtInstalled) > 0 {
- fmt.Fprintln(w, "LOCAL_SOONG_BUILT_INSTALLED :=", strings.Join(library.dexpreopter.builtInstalled, " "))
+ fmt.Fprintln(w, "LOCAL_SOONG_BUILT_INSTALLED :=", library.dexpreopter.builtInstalled)
}
fmt.Fprintln(w, "LOCAL_SDK_VERSION :=", library.sdkVersion())
fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", library.implementationAndResourcesJar.String())
@@ -166,7 +166,7 @@ func (binary *Binary) AndroidMk() android.AndroidMkData {
fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", binary.dexJarFile.String())
}
if len(binary.dexpreopter.builtInstalled) > 0 {
- fmt.Fprintln(w, "LOCAL_SOONG_BUILT_INSTALLED :=", strings.Join(binary.dexpreopter.builtInstalled, " "))
+ fmt.Fprintln(w, "LOCAL_SOONG_BUILT_INSTALLED :=", binary.dexpreopter.builtInstalled)
}
},
},
@@ -260,7 +260,7 @@ func (app *AndroidApp) AndroidMk() android.AndroidMkData {
fmt.Fprintln(w, "LOCAL_SOONG_JNI_LIBS_"+jniLib.target.Arch.ArchType.String(), "+=", jniLib.name)
}
if len(app.dexpreopter.builtInstalled) > 0 {
- fmt.Fprintln(w, "LOCAL_SOONG_BUILT_INSTALLED :=", strings.Join(app.dexpreopter.builtInstalled, " "))
+ fmt.Fprintln(w, "LOCAL_SOONG_BUILT_INSTALLED :=", app.dexpreopter.builtInstalled)
}
},
},
diff --git a/java/dexpreopt.go b/java/dexpreopt.go
index a89731ac..127deab9 100644
--- a/java/dexpreopt.go
+++ b/java/dexpreopt.go
@@ -28,7 +28,7 @@ type dexpreopter struct {
isTest bool
isInstallable bool
- builtInstalled []string
+ builtInstalled string
}
type DexpreoptProperties struct {
@@ -196,9 +196,7 @@ func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, dexJarFile android.Mo
dexpreoptRule.Build(pctx, ctx, "dexpreopt", "dexpreopt")
- for _, install := range dexpreoptRule.Installs() {
- d.builtInstalled = append(d.builtInstalled, install.From+":"+install.To)
- }
+ d.builtInstalled = dexpreoptRule.Installs().String()
stripRule, err := dexpreopt.GenerateStripRule(globalConfig, dexpreoptConfig)
if err != nil {