Merge "respect "apex_name:" for "apex" module" am: 852116a061 am: a13f0727b9

am: d4b98c58ad

Change-Id: Ie053994116fc3f7ebc022ad1e6e3a5f77420af39
This commit is contained in:
Jooyung Han 2019-09-29 17:42:49 -07:00 committed by android-build-merger
commit 0e429b76c5
2 changed files with 65 additions and 25 deletions

View File

@ -47,13 +47,15 @@ var (
Description: "fs_config ${out}", Description: "fs_config ${out}",
}, "ro_paths", "exec_paths") }, "ro_paths", "exec_paths")
injectApexDependency = pctx.StaticRule("injectApexDependency", blueprint.RuleParams{ apexManifestRule = pctx.StaticRule("apexManifestRule", blueprint.RuleParams{
Command: `rm -f $out && ${jsonmodify} $in ` + Command: `rm -f $out && ${jsonmodify} $in ` +
`-a provideNativeLibs ${provideNativeLibs} ` + `-a provideNativeLibs ${provideNativeLibs} ` +
`-a requireNativeLibs ${requireNativeLibs} -o $out`, `-a requireNativeLibs ${requireNativeLibs} ` +
`${opt} ` +
`-o $out`,
CommandDeps: []string{"${jsonmodify}"}, CommandDeps: []string{"${jsonmodify}"},
Description: "Inject dependency into ${out}", Description: "prepare ${out}",
}, "provideNativeLibs", "requireNativeLibs") }, "provideNativeLibs", "requireNativeLibs", "opt")
// TODO(b/113233103): make sure that file_contexts is sane, i.e., validate // TODO(b/113233103): make sure that file_contexts is sane, i.e., validate
// against the binary policy using sefcontext_compiler -p <policy>. // against the binary policy using sefcontext_compiler -p <policy>.
@ -1223,18 +1225,28 @@ func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
a.installDir = android.PathForModuleInstall(ctx, "apex") a.installDir = android.PathForModuleInstall(ctx, "apex")
a.filesInfo = filesInfo a.filesInfo = filesInfo
// prepare apex_manifest.json
a.manifestOut = android.PathForModuleOut(ctx, "apex_manifest.json") a.manifestOut = android.PathForModuleOut(ctx, "apex_manifest.json")
// put dependency({provide|require}NativeLibs) in apex_manifest.json
manifestSrc := android.PathForModuleSrc(ctx, proptools.StringDefault(a.properties.Manifest, "apex_manifest.json")) manifestSrc := android.PathForModuleSrc(ctx, proptools.StringDefault(a.properties.Manifest, "apex_manifest.json"))
// put dependency({provide|require}NativeLibs) in apex_manifest.json
provideNativeLibs = android.SortedUniqueStrings(provideNativeLibs) provideNativeLibs = android.SortedUniqueStrings(provideNativeLibs)
requireNativeLibs = android.SortedUniqueStrings(android.RemoveListFromList(requireNativeLibs, provideNativeLibs)) requireNativeLibs = android.SortedUniqueStrings(android.RemoveListFromList(requireNativeLibs, provideNativeLibs))
// apex name can be overridden
optCommands := []string{}
if a.properties.Apex_name != nil {
optCommands = append(optCommands, "-v name "+*a.properties.Apex_name)
}
ctx.Build(pctx, android.BuildParams{ ctx.Build(pctx, android.BuildParams{
Rule: injectApexDependency, Rule: apexManifestRule,
Input: manifestSrc, Input: manifestSrc,
Output: a.manifestOut, Output: a.manifestOut,
Args: map[string]string{ Args: map[string]string{
"provideNativeLibs": strings.Join(provideNativeLibs, " "), "provideNativeLibs": strings.Join(provideNativeLibs, " "),
"requireNativeLibs": strings.Join(requireNativeLibs, " "), "requireNativeLibs": strings.Join(requireNativeLibs, " "),
"opt": strings.Join(optCommands, " "),
}, },
}) })
@ -1448,6 +1460,12 @@ func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext, apexType ap
optFlags = append(optFlags, "--no_hashtree") optFlags = append(optFlags, "--no_hashtree")
} }
if a.properties.Apex_name != nil {
// If apex_name is set, apexer can skip checking if key name matches with apex name.
// Note that apex_manifest is also mended.
optFlags = append(optFlags, "--do_not_check_keyname")
}
ctx.Build(pctx, android.BuildParams{ ctx.Build(pctx, android.BuildParams{
Rule: apexRule, Rule: apexRule,
Implicits: implicitInputs, Implicits: implicitInputs,

View File

@ -771,9 +771,9 @@ func TestApexWithRuntimeLibsDependency(t *testing.T) {
// Ensure that runtime_libs dep in included // Ensure that runtime_libs dep in included
ensureContains(t, copyCmds, "image.apex/lib64/libbar.so") ensureContains(t, copyCmds, "image.apex/lib64/libbar.so")
injectRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("injectApexDependency") apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexManifestRule")
ensureListEmpty(t, names(injectRule.Args["provideNativeLibs"])) ensureListEmpty(t, names(apexManifestRule.Args["provideNativeLibs"]))
ensureListContains(t, names(injectRule.Args["requireNativeLibs"]), "libfoo.so") ensureListContains(t, names(apexManifestRule.Args["requireNativeLibs"]), "libfoo.so")
} }
@ -821,11 +821,11 @@ func TestApexDependencyToLLNDK(t *testing.T) {
// Ensure that LLNDK dep is not included // Ensure that LLNDK dep is not included
ensureNotContains(t, copyCmds, "image.apex/lib64/libbar.so") ensureNotContains(t, copyCmds, "image.apex/lib64/libbar.so")
injectRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("injectApexDependency") apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexManifestRule")
ensureListEmpty(t, names(injectRule.Args["provideNativeLibs"])) ensureListEmpty(t, names(apexManifestRule.Args["provideNativeLibs"]))
// Ensure that LLNDK dep is required // Ensure that LLNDK dep is required
ensureListContains(t, names(injectRule.Args["requireNativeLibs"]), "libbar.so") ensureListContains(t, names(apexManifestRule.Args["requireNativeLibs"]), "libbar.so")
} }
@ -1582,34 +1582,56 @@ func TestDependenciesInApexManifest(t *testing.T) {
} }
`) `)
var injectRule android.TestingBuildParams var apexManifestRule android.TestingBuildParams
var provideNativeLibs, requireNativeLibs []string var provideNativeLibs, requireNativeLibs []string
injectRule = ctx.ModuleForTests("myapex_nodep", "android_common_myapex_nodep").Rule("injectApexDependency") apexManifestRule = ctx.ModuleForTests("myapex_nodep", "android_common_myapex_nodep").Rule("apexManifestRule")
provideNativeLibs = names(injectRule.Args["provideNativeLibs"]) provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
requireNativeLibs = names(injectRule.Args["requireNativeLibs"]) requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
ensureListEmpty(t, provideNativeLibs) ensureListEmpty(t, provideNativeLibs)
ensureListEmpty(t, requireNativeLibs) ensureListEmpty(t, requireNativeLibs)
injectRule = ctx.ModuleForTests("myapex_dep", "android_common_myapex_dep").Rule("injectApexDependency") apexManifestRule = ctx.ModuleForTests("myapex_dep", "android_common_myapex_dep").Rule("apexManifestRule")
provideNativeLibs = names(injectRule.Args["provideNativeLibs"]) provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
requireNativeLibs = names(injectRule.Args["requireNativeLibs"]) requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
ensureListEmpty(t, provideNativeLibs) ensureListEmpty(t, provideNativeLibs)
ensureListContains(t, requireNativeLibs, "libfoo.so") ensureListContains(t, requireNativeLibs, "libfoo.so")
injectRule = ctx.ModuleForTests("myapex_provider", "android_common_myapex_provider").Rule("injectApexDependency") apexManifestRule = ctx.ModuleForTests("myapex_provider", "android_common_myapex_provider").Rule("apexManifestRule")
provideNativeLibs = names(injectRule.Args["provideNativeLibs"]) provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
requireNativeLibs = names(injectRule.Args["requireNativeLibs"]) requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
ensureListContains(t, provideNativeLibs, "libfoo.so") ensureListContains(t, provideNativeLibs, "libfoo.so")
ensureListEmpty(t, requireNativeLibs) ensureListEmpty(t, requireNativeLibs)
injectRule = ctx.ModuleForTests("myapex_selfcontained", "android_common_myapex_selfcontained").Rule("injectApexDependency") apexManifestRule = ctx.ModuleForTests("myapex_selfcontained", "android_common_myapex_selfcontained").Rule("apexManifestRule")
provideNativeLibs = names(injectRule.Args["provideNativeLibs"]) provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
requireNativeLibs = names(injectRule.Args["requireNativeLibs"]) requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
ensureListContains(t, provideNativeLibs, "libfoo.so") ensureListContains(t, provideNativeLibs, "libfoo.so")
ensureListEmpty(t, requireNativeLibs) ensureListEmpty(t, requireNativeLibs)
} }
func TestApexName(t *testing.T) {
ctx, _ := testApex(t, `
apex {
name: "myapex",
key: "myapex.key",
apex_name: "com.android.myapex",
}
apex_key {
name: "myapex.key",
public_key: "testkey.avbpubkey",
private_key: "testkey.pem",
}
`)
module := ctx.ModuleForTests("myapex", "android_common_myapex")
apexManifestRule := module.Rule("apexManifestRule")
ensureContains(t, apexManifestRule.Args["opt"], "-v name com.android.myapex")
apexRule := module.Rule("apexRule")
ensureContains(t, apexRule.Args["opt_flags"], "--do_not_check_keyname")
}
func TestNonTestApex(t *testing.T) { func TestNonTestApex(t *testing.T) {
ctx, _ := testApex(t, ` ctx, _ := testApex(t, `
apex { apex {