diff options
author | TreeHugger Robot <treehugger-gerrit@google.com> | 2019-04-23 06:24:22 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2019-04-23 06:24:22 +0000 |
commit | 6decc5d7ff0e42c2b63828d4bc5b975d57a30528 (patch) | |
tree | 7a686996b5305313a824aa0e2d1b58afd5554ec4 /android | |
parent | d37a882ad462111f6b99bdecbd2771e7f3c3ad07 (diff) | |
parent | dfa933e6e4be84051723ddbc2f75ab972d23d2b7 (diff) | |
download | build_soong-6decc5d7ff0e42c2b63828d4bc5b975d57a30528.tar.gz build_soong-6decc5d7ff0e42c2b63828d4bc5b975d57a30528.tar.bz2 build_soong-6decc5d7ff0e42c2b63828d4bc5b975d57a30528.zip |
Merge changes Ic5f467fb,I68d52668 into qt-dev
* changes:
Ensure that PathsForModuleSrc works with prebuilts
Fix: PathsForModuleSrc does not work for a replaced dependency
Diffstat (limited to 'android')
-rw-r--r-- | android/module.go | 33 | ||||
-rw-r--r-- | android/prebuilt_test.go | 64 |
2 files changed, 86 insertions, 11 deletions
diff --git a/android/module.go b/android/module.go index 201c27a8..11e9e917 100644 --- a/android/module.go +++ b/android/module.go @@ -1034,6 +1034,39 @@ func (a *androidModuleContext) validateAndroidModule(module blueprint.Module) Mo return aModule } +func (a *androidModuleContext) getDirectDepInternal(name string, tag blueprint.DependencyTag) (blueprint.Module, blueprint.DependencyTag) { + type dep struct { + mod blueprint.Module + tag blueprint.DependencyTag + } + var deps []dep + a.VisitDirectDepsBlueprint(func(m blueprint.Module) { + if aModule, _ := m.(Module); aModule != nil && aModule.base().BaseModuleName() == name { + returnedTag := a.ModuleContext.OtherModuleDependencyTag(aModule) + if tag == nil || returnedTag == tag { + deps = append(deps, dep{aModule, returnedTag}) + } + } + }) + if len(deps) == 1 { + return deps[0].mod, deps[0].tag + } else if len(deps) >= 2 { + panic(fmt.Errorf("Multiple dependencies having same BaseModuleName() %q found from %q", + name, a.ModuleName())) + } else { + return nil, nil + } +} + +func (a *androidModuleContext) GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module { + m, _ := a.getDirectDepInternal(name, tag) + return m +} + +func (a *androidModuleContext) GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag) { + return a.getDirectDepInternal(name, nil) +} + func (a *androidModuleContext) VisitDirectDepsBlueprint(visit func(blueprint.Module)) { a.ModuleContext.VisitDirectDeps(visit) } diff --git a/android/prebuilt_test.go b/android/prebuilt_test.go index 319c15df..e1826414 100644 --- a/android/prebuilt_test.go +++ b/android/prebuilt_test.go @@ -41,7 +41,7 @@ var prebuiltsTests = []struct { prebuilt { name: "bar", prefer: false, - srcs: ["prebuilt"], + srcs: ["prebuilt_file"], }`, prebuilt: true, }, @@ -51,7 +51,7 @@ var prebuiltsTests = []struct { prebuilt { name: "bar", prefer: true, - srcs: ["prebuilt"], + srcs: ["prebuilt_file"], }`, prebuilt: true, }, @@ -65,7 +65,7 @@ var prebuiltsTests = []struct { prebuilt { name: "bar", prefer: false, - srcs: ["prebuilt"], + srcs: ["prebuilt_file"], }`, prebuilt: false, }, @@ -79,7 +79,7 @@ var prebuiltsTests = []struct { prebuilt { name: "bar", prefer: true, - srcs: ["prebuilt"], + srcs: ["prebuilt_file"], }`, prebuilt: true, }, @@ -114,6 +114,7 @@ var prebuiltsTests = []struct { modules: ` filegroup { name: "fg", + srcs: ["prebuilt_file"], } prebuilt { name: "bar", @@ -143,10 +144,12 @@ func TestPrebuilts(t *testing.T) { ctx.RegisterModuleType("source", ModuleFactoryAdaptor(newSourceModule)) ctx.Register() ctx.MockFileSystem(map[string][]byte{ + "prebuilt_file": nil, + "source_file": nil, "Blueprints": []byte(` source { name: "foo", - deps: ["bar"], + deps: [":bar"], } ` + test.modules), }) @@ -171,21 +174,45 @@ func TestPrebuilts(t *testing.T) { } }) + deps := foo.Module().(*sourceModule).deps + if deps == nil || len(deps) != 1 { + t.Errorf("deps does not have single path, but is %v", deps) + } + var usingSourceFile, usingPrebuiltFile bool + if deps[0].String() == "source_file" { + usingSourceFile = true + } + if deps[0].String() == "prebuilt_file" { + usingPrebuiltFile = true + } + if test.prebuilt { if !dependsOnPrebuiltModule { t.Errorf("doesn't depend on prebuilt module") } + if !usingPrebuiltFile { + t.Errorf("doesn't use prebuilt_file") + } if dependsOnSourceModule { t.Errorf("depends on source module") } + if usingSourceFile { + t.Errorf("using source_file") + } } else { if dependsOnPrebuiltModule { t.Errorf("depends on prebuilt module") } + if usingPrebuiltFile { + t.Errorf("using prebuilt_file") + } if !dependsOnSourceModule { - t.Errorf("doens't depend on source module") + t.Errorf("doesn't depend on source module") + } + if !usingSourceFile { + t.Errorf("doesn't use source_file") } } }) @@ -198,6 +225,7 @@ type prebuiltModule struct { properties struct { Srcs []string `android:"path"` } + src Path } func newPrebuiltModule() Module { @@ -212,19 +240,28 @@ func (p *prebuiltModule) Name() string { return p.prebuilt.Name(p.ModuleBase.Name()) } -func (p *prebuiltModule) GenerateAndroidBuildActions(ModuleContext) { +func (p *prebuiltModule) GenerateAndroidBuildActions(ctx ModuleContext) { + if len(p.properties.Srcs) >= 1 { + p.src = p.prebuilt.SingleSourcePath(ctx) + } } func (p *prebuiltModule) Prebuilt() *Prebuilt { return &p.prebuilt } +func (p *prebuiltModule) Srcs() Paths { + return Paths{p.src} +} + type sourceModule struct { ModuleBase properties struct { - Deps []string + Deps []string `android:"path"` } dependsOnSourceModule, dependsOnPrebuiltModule bool + deps Paths + src Path } func newSourceModule() Module { @@ -235,10 +272,15 @@ func newSourceModule() Module { } func (s *sourceModule) DepsMutator(ctx BottomUpMutatorContext) { - for _, d := range s.properties.Deps { - ctx.AddDependency(ctx.Module(), nil, d) - } + // s.properties.Deps are annotated with android:path, so they are + // automatically added to the dependency by pathDeps mutator } func (s *sourceModule) GenerateAndroidBuildActions(ctx ModuleContext) { + s.deps = PathsForModuleSrc(ctx, s.properties.Deps) + s.src = PathForModuleSrc(ctx, "source_file") +} + +func (s *sourceModule) Srcs() Paths { + return Paths{s.src} } |