Merge "Add api_dirs property and use module name as prefix"

am: b1f0f1aecd

Change-Id: Ibf5b2ea7f0e1742228a986ee69f33e570e1c43e2
This commit is contained in:
Sundong Ahn 2018-07-02 22:11:49 -07:00 committed by android-build-merger
commit 4afa0dd6fb
2 changed files with 19 additions and 16 deletions

View file

@ -188,7 +188,7 @@ func testContext(config android.Config, bp string,
"prebuilts/sdk/28/system/api/bar-removed.txt": nil, "prebuilts/sdk/28/system/api/bar-removed.txt": nil,
"prebuilts/sdk/28/test/api/bar-removed.txt": nil, "prebuilts/sdk/28/test/api/bar-removed.txt": nil,
"prebuilts/sdk/tools/core-lambda-stubs.jar": nil, "prebuilts/sdk/tools/core-lambda-stubs.jar": nil,
"prebuilts/sdk/Android.bp": []byte(`prebuilt_apis { name: "prebuilt_apis",}`), "prebuilts/sdk/Android.bp": []byte(`prebuilt_apis { name: "sdk", api_dirs: ["14", "28", "current"],}`),
// For framework-res, which is an implicit dependency for framework // For framework-res, which is an implicit dependency for framework
"AndroidManifest.xml": nil, "AndroidManifest.xml": nil,

View file

@ -38,8 +38,14 @@ func init() {
}) })
} }
type prebuiltApisProperties struct {
// list of api version directories
Api_dirs []string
}
type prebuiltApis struct { type prebuiltApis struct {
android.ModuleBase android.ModuleBase
properties prebuiltApisProperties
} }
func (module *prebuiltApis) DepsMutator(ctx android.BottomUpMutatorContext) { func (module *prebuiltApis) DepsMutator(ctx android.BottomUpMutatorContext) {
@ -55,10 +61,6 @@ func parseJarPath(ctx android.BaseModuleContext, path string) (module string, ap
apiver = elements[0] apiver = elements[0]
scope = elements[1] scope = elements[1]
if scope != "public" && scope != "system" && scope != "test" && scope != "core" {
// scope must be public, system or test
return
}
module = strings.TrimSuffix(elements[2], ".jar") module = strings.TrimSuffix(elements[2], ".jar")
return return
@ -91,7 +93,7 @@ func createImport(mctx android.TopDownMutatorContext, module string, scope strin
Sdk_version *string Sdk_version *string
Installable *bool Installable *bool
}{} }{}
props.Name = proptools.StringPtr("sdk_" + scope + "_" + apiver + "_" + module) props.Name = proptools.StringPtr(mctx.ModuleName() + "_" + scope + "_" + apiver + "_" + module)
props.Jars = append(props.Jars, path) props.Jars = append(props.Jars, path)
// TODO(hansson): change to scope after migration is done. // TODO(hansson): change to scope after migration is done.
props.Sdk_version = proptools.StringPtr("current") props.Sdk_version = proptools.StringPtr("current")
@ -114,22 +116,22 @@ func createFilegroup(mctx android.TopDownMutatorContext, module string, scope st
func prebuiltSdkStubs(mctx android.TopDownMutatorContext) { func prebuiltSdkStubs(mctx android.TopDownMutatorContext) {
mydir := mctx.ModuleDir() + "/" mydir := mctx.ModuleDir() + "/"
// <apiver>/<scope>/<module>.jar // <apiver>/<scope>/<module>.jar
files, err := mctx.GlobWithDeps(mydir+"*/*/*.jar", nil) var files []string
if err != nil { for _, apiver := range mctx.Module().(*prebuiltApis).properties.Api_dirs {
mctx.ModuleErrorf("failed to glob jar files under %q: %s", mydir, err) for _, scope := range []string{"public", "system", "test", "core"} {
} vfiles, err := mctx.GlobWithDeps(mydir+apiver+"/"+scope+"*/*.jar", nil)
if len(files) == 0 { if err != nil {
mctx.ModuleErrorf("no jar file found under %q", mydir) mctx.ModuleErrorf("failed to glob jar files under %q: %s", mydir+apiver+"/"+scope, err)
}
files = append(files, vfiles...)
}
} }
for _, f := range files { for _, f := range files {
// create a Import module for each jar file // create a Import module for each jar file
localPath := strings.TrimPrefix(f, mydir) localPath := strings.TrimPrefix(f, mydir)
module, apiver, scope := parseJarPath(mctx, localPath) module, apiver, scope := parseJarPath(mctx, localPath)
createImport(mctx, module, scope, apiver, localPath)
if len(module) != 0 {
createImport(mctx, module, scope, apiver, localPath)
}
} }
} }
@ -192,6 +194,7 @@ func prebuiltApisMutator(mctx android.TopDownMutatorContext) {
func prebuiltApisFactory() android.Module { func prebuiltApisFactory() android.Module {
module := &prebuiltApis{} module := &prebuiltApis{}
module.AddProperties(&module.properties)
android.InitAndroidModule(module) android.InitAndroidModule(module)
return module return module
} }