From 42d48b7b8b94e301d703656db0b25bc5ee7eb3bc Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Wed, 29 Aug 2018 14:10:52 -0700 Subject: [PATCH] Enforce dependencies have right architecture ctx.AddDependency will succeed if the named dependency only has a single variant, even if that variant is the wrong architecture. Use ctx.AddVariationDependency(nil, ...) instead, which requires that all variations of the calling module match the dependency. Bug: 112707915 Test: no change to out/soong/build.ninja Test: using a device dependency in a host java module is an error Change-Id: I70b661a57d4412eb63b8c9841febfb756e9e025d --- cc/cc.go | 6 +++--- java/aar.go | 8 ++++---- java/droiddoc.go | 14 +++++++------- java/java.go | 30 +++++++++++++++--------------- java/proto.go | 8 ++++---- java/sdk_library.go | 14 +++++++------- java/system_modules.go | 2 +- 7 files changed, 41 insertions(+), 41 deletions(-) diff --git a/cc/cc.go b/cc/cc.go index 07dd23c20..befd68331 100644 --- a/cc/cc.go +++ b/cc/cc.go @@ -1043,13 +1043,13 @@ func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) { actx.AddDependency(c, depTag, gen) } - actx.AddDependency(c, objDepTag, deps.ObjFiles...) + actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...) if deps.CrtBegin != "" { - actx.AddDependency(c, crtBeginDepTag, deps.CrtBegin) + actx.AddVariationDependencies(nil, crtBeginDepTag, deps.CrtBegin) } if deps.CrtEnd != "" { - actx.AddDependency(c, crtEndDepTag, deps.CrtEnd) + actx.AddVariationDependencies(nil, crtEndDepTag, deps.CrtEnd) } if deps.LinkerScript != "" { actx.AddDependency(c, linkerScriptDepTag, deps.LinkerScript) diff --git a/java/aar.go b/java/aar.go index 175e794fe..29f5597a9 100644 --- a/java/aar.go +++ b/java/aar.go @@ -156,7 +156,7 @@ func (a *aapt) deps(ctx android.BottomUpMutatorContext, sdkContext sdkContext) { if !ctx.Config().UnbundledBuild() { sdkDep := decodeSdkDep(ctx, sdkContext) if sdkDep.frameworkResModule != "" { - ctx.AddDependency(ctx.Module(), frameworkResTag, sdkDep.frameworkResModule) + ctx.AddVariationDependencies(nil, frameworkResTag, sdkDep.frameworkResModule) } } } @@ -436,12 +436,12 @@ func (a *AARImport) DepsMutator(ctx android.BottomUpMutatorContext) { if !ctx.Config().UnbundledBuild() { sdkDep := decodeSdkDep(ctx, sdkContext(a)) if sdkDep.useModule && sdkDep.frameworkResModule != "" { - ctx.AddDependency(ctx.Module(), frameworkResTag, sdkDep.frameworkResModule) + ctx.AddVariationDependencies(nil, frameworkResTag, sdkDep.frameworkResModule) } } - ctx.AddDependency(ctx.Module(), libTag, a.properties.Libs...) - ctx.AddDependency(ctx.Module(), staticLibTag, a.properties.Static_libs...) + ctx.AddVariationDependencies(nil, libTag, a.properties.Libs...) + ctx.AddVariationDependencies(nil, staticLibTag, a.properties.Static_libs...) } // Unzip an AAR into its constituent files and directories. Any files in Outputs that don't exist in the AAR will be diff --git a/java/droiddoc.go b/java/droiddoc.go index e4c9e384b..68d78610b 100644 --- a/java/droiddoc.go +++ b/java/droiddoc.go @@ -371,24 +371,24 @@ func (j *Javadoc) addDeps(ctx android.BottomUpMutatorContext) { if ctx.Device() { sdkDep := decodeSdkDep(ctx, sdkContext(j)) if sdkDep.useDefaultLibs { - ctx.AddDependency(ctx.Module(), bootClasspathTag, config.DefaultBootclasspathLibraries...) + ctx.AddVariationDependencies(nil, bootClasspathTag, config.DefaultBootclasspathLibraries...) if ctx.Config().TargetOpenJDK9() { - ctx.AddDependency(ctx.Module(), systemModulesTag, config.DefaultSystemModules) + ctx.AddVariationDependencies(nil, systemModulesTag, config.DefaultSystemModules) } if !Bool(j.properties.No_framework_libs) { - ctx.AddDependency(ctx.Module(), libTag, config.DefaultLibraries...) + ctx.AddVariationDependencies(nil, libTag, config.DefaultLibraries...) } } else if sdkDep.useModule { if ctx.Config().TargetOpenJDK9() { - ctx.AddDependency(ctx.Module(), systemModulesTag, sdkDep.systemModules) + ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules) } - ctx.AddDependency(ctx.Module(), bootClasspathTag, sdkDep.modules...) + ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.modules...) } } - ctx.AddDependency(ctx.Module(), libTag, j.properties.Libs...) + ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...) if j.properties.Srcs_lib != nil { - ctx.AddDependency(ctx.Module(), srcsLibTag, *j.properties.Srcs_lib) + ctx.AddVariationDependencies(nil, srcsLibTag, *j.properties.Srcs_lib) } android.ExtractSourcesDeps(ctx, j.properties.Srcs) diff --git a/java/java.go b/java/java.go index b911078b5..f6c94840b 100644 --- a/java/java.go +++ b/java/java.go @@ -552,41 +552,41 @@ func (j *Module) deps(ctx android.BottomUpMutatorContext) { if !Bool(j.properties.No_standard_libs) { sdkDep := decodeSdkDep(ctx, sdkContext(j)) if sdkDep.useDefaultLibs { - ctx.AddDependency(ctx.Module(), bootClasspathTag, config.DefaultBootclasspathLibraries...) + ctx.AddVariationDependencies(nil, bootClasspathTag, config.DefaultBootclasspathLibraries...) if ctx.Config().TargetOpenJDK9() { - ctx.AddDependency(ctx.Module(), systemModulesTag, config.DefaultSystemModules) + ctx.AddVariationDependencies(nil, systemModulesTag, config.DefaultSystemModules) } if !Bool(j.properties.No_framework_libs) { - ctx.AddDependency(ctx.Module(), libTag, config.DefaultLibraries...) + ctx.AddVariationDependencies(nil, libTag, config.DefaultLibraries...) } } else if sdkDep.useModule { if ctx.Config().TargetOpenJDK9() { - ctx.AddDependency(ctx.Module(), systemModulesTag, sdkDep.systemModules) + ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules) } - ctx.AddDependency(ctx.Module(), bootClasspathTag, sdkDep.modules...) + ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.modules...) if Bool(j.deviceProperties.Optimize.Enabled) { - ctx.AddDependency(ctx.Module(), proguardRaiseTag, config.DefaultBootclasspathLibraries...) - ctx.AddDependency(ctx.Module(), proguardRaiseTag, config.DefaultLibraries...) + ctx.AddVariationDependencies(nil, proguardRaiseTag, config.DefaultBootclasspathLibraries...) + ctx.AddVariationDependencies(nil, proguardRaiseTag, config.DefaultLibraries...) } } } else if j.deviceProperties.System_modules == nil { ctx.PropertyErrorf("no_standard_libs", "system_modules is required to be set when no_standard_libs is true, did you mean no_framework_libs?") } else if *j.deviceProperties.System_modules != "none" && ctx.Config().TargetOpenJDK9() { - ctx.AddDependency(ctx.Module(), systemModulesTag, *j.deviceProperties.System_modules) + ctx.AddVariationDependencies(nil, systemModulesTag, *j.deviceProperties.System_modules) } if ctx.ModuleName() == "framework" { - ctx.AddDependency(ctx.Module(), frameworkResTag, "framework-res") + ctx.AddVariationDependencies(nil, frameworkResTag, "framework-res") } if ctx.ModuleName() == "android_stubs_current" || ctx.ModuleName() == "android_system_stubs_current" || ctx.ModuleName() == "android_test_stubs_current" { - ctx.AddDependency(ctx.Module(), frameworkApkTag, "framework-res") + ctx.AddVariationDependencies(nil, frameworkApkTag, "framework-res") } } - ctx.AddDependency(ctx.Module(), libTag, j.properties.Libs...) - ctx.AddDependency(ctx.Module(), staticLibTag, j.properties.Static_libs...) + ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...) + ctx.AddVariationDependencies(nil, staticLibTag, j.properties.Static_libs...) ctx.AddFarVariationDependencies([]blueprint.Variation{ {Mutator: "arch", Variation: ctx.Config().BuildOsCommonVariant}, }, annoTag, j.properties.Annotation_processors...) @@ -602,11 +602,11 @@ func (j *Module) deps(ctx android.BottomUpMutatorContext) { if j.hasSrcExt(".kt") { // TODO(ccross): move this to a mutator pass that can tell if generated sources contain // Kotlin files - ctx.AddDependency(ctx.Module(), kotlinStdlibTag, "kotlin-stdlib") + ctx.AddVariationDependencies(nil, kotlinStdlibTag, "kotlin-stdlib") } if j.shouldInstrumentStatic(ctx) { - ctx.AddDependency(ctx.Module(), staticLibTag, "jacocoagent") + ctx.AddVariationDependencies(nil, staticLibTag, "jacocoagent") } } @@ -1619,7 +1619,7 @@ func (j *Import) Name() string { func (j *Import) DepsMutator(ctx android.BottomUpMutatorContext) { android.ExtractSourcesDeps(ctx, j.properties.Jars) - ctx.AddDependency(ctx.Module(), libTag, j.properties.Libs...) + ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...) } func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) { diff --git a/java/proto.go b/java/proto.go index 58b039ec7..80280390d 100644 --- a/java/proto.go +++ b/java/proto.go @@ -73,14 +73,14 @@ func genProto(ctx android.ModuleContext, protoFile android.Path, flags javaBuild func protoDeps(ctx android.BottomUpMutatorContext, p *android.ProtoProperties) { switch String(p.Proto.Type) { case "micro": - ctx.AddDependency(ctx.Module(), staticLibTag, "libprotobuf-java-micro") + ctx.AddVariationDependencies(nil, staticLibTag, "libprotobuf-java-micro") case "nano": - ctx.AddDependency(ctx.Module(), staticLibTag, "libprotobuf-java-nano") + ctx.AddVariationDependencies(nil, staticLibTag, "libprotobuf-java-nano") case "lite", "": - ctx.AddDependency(ctx.Module(), staticLibTag, "libprotobuf-java-lite") + ctx.AddVariationDependencies(nil, staticLibTag, "libprotobuf-java-lite") case "full": if ctx.Host() { - ctx.AddDependency(ctx.Module(), staticLibTag, "libprotobuf-java-full") + ctx.AddVariationDependencies(nil, staticLibTag, "libprotobuf-java-full") } else { ctx.PropertyErrorf("proto.type", "full java protos only supported on the host") } diff --git a/java/sdk_library.go b/java/sdk_library.go index 525652a54..d58880178 100644 --- a/java/sdk_library.go +++ b/java/sdk_library.go @@ -156,14 +156,14 @@ type sdkLibrary struct { func (module *sdkLibrary) DepsMutator(ctx android.BottomUpMutatorContext) { // Add dependencies to the stubs library - ctx.AddDependency(ctx.Module(), publicApiStubsTag, module.stubsName(apiScopePublic)) - ctx.AddDependency(ctx.Module(), systemApiStubsTag, module.stubsName(apiScopeSystem)) - ctx.AddDependency(ctx.Module(), testApiStubsTag, module.stubsName(apiScopeTest)) - ctx.AddDependency(ctx.Module(), implLibTag, module.implName()) + ctx.AddVariationDependencies(nil, publicApiStubsTag, module.stubsName(apiScopePublic)) + ctx.AddVariationDependencies(nil, systemApiStubsTag, module.stubsName(apiScopeSystem)) + ctx.AddVariationDependencies(nil, testApiStubsTag, module.stubsName(apiScopeTest)) + ctx.AddVariationDependencies(nil, implLibTag, module.implName()) - ctx.AddDependency(ctx.Module(), publicApiFileTag, module.docsName(apiScopePublic)) - ctx.AddDependency(ctx.Module(), systemApiFileTag, module.docsName(apiScopeSystem)) - ctx.AddDependency(ctx.Module(), testApiFileTag, module.docsName(apiScopeTest)) + ctx.AddVariationDependencies(nil, publicApiFileTag, module.docsName(apiScopePublic)) + ctx.AddVariationDependencies(nil, systemApiFileTag, module.docsName(apiScopeSystem)) + ctx.AddVariationDependencies(nil, testApiFileTag, module.docsName(apiScopeTest)) } func (module *sdkLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { diff --git a/java/system_modules.go b/java/system_modules.go index d98e0abc9..9ee0307ca 100644 --- a/java/system_modules.go +++ b/java/system_modules.go @@ -123,7 +123,7 @@ func (system *SystemModules) GenerateAndroidBuildActions(ctx android.ModuleConte } func (system *SystemModules) DepsMutator(ctx android.BottomUpMutatorContext) { - ctx.AddDependency(ctx.Module(), libTag, system.properties.Libs...) + ctx.AddVariationDependencies(nil, libTag, system.properties.Libs...) } func (system *SystemModules) AndroidMk() android.AndroidMkData {