Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4dd99f65 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Support prebuilt libraries in prebuilt_apis.go"

parents 33ab6f61 a01c2a51
Loading
Loading
Loading
Loading
+103 −46
Original line number Diff line number Diff line
@@ -50,6 +50,20 @@ func (module *prebuiltApis) GenerateAndroidBuildActions(ctx android.ModuleContex
	// no need to implement
}

func parseJarPath(ctx android.BaseModuleContext, path string) (module string, apiver string, scope string) {
	elements := strings.Split(path, "/")

	apiver = elements[0]
	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")
	return
}

func parseApiFilePath(ctx android.BaseModuleContext, path string) (module string, apiver int, scope string) {
	elements := strings.Split(path, "/")
	ver, err := strconv.Atoi(elements[0])
@@ -70,6 +84,22 @@ func parseApiFilePath(ctx android.BaseModuleContext, path string) (module string
	return
}

func createImport(mctx android.TopDownMutatorContext, module string, scope string, apiver string, path string) {
	props := struct {
		Name        *string
		Jars        []string
		Sdk_version *string
		Installable *bool
	}{}
	props.Name = proptools.StringPtr("sdk_" + scope + "_" + apiver + "_" + module)
	props.Jars = append(props.Jars, path)
	// TODO(hansson): change to scope after migration is done.
	props.Sdk_version = proptools.StringPtr("current")
	props.Installable = proptools.BoolPtr(false)

	mctx.CreateModule(android.ModuleFactoryAdaptor(ImportFactory), &props)
}

func createFilegroup(mctx android.TopDownMutatorContext, module string, scope string, apiver string, path string) {
	fgName := module + ".api." + scope + "." + apiver
	filegroupProps := struct {
@@ -81,8 +111,29 @@ func createFilegroup(mctx android.TopDownMutatorContext, module string, scope st
	mctx.CreateModule(android.ModuleFactoryAdaptor(android.FileGroupFactory), &filegroupProps)
}

func prebuiltApisMutator(mctx android.TopDownMutatorContext) {
	if _, ok := mctx.Module().(*prebuiltApis); ok {
func prebuiltSdkStubs(mctx android.TopDownMutatorContext) {
	mydir := mctx.ModuleDir() + "/"
	// <apiver>/<scope>/<module>.jar
	files, err := mctx.GlobWithDeps(mydir+"*/*/*.jar", nil)
	if err != nil {
		mctx.ModuleErrorf("failed to glob jar files under %q: %s", mydir, err)
	}
	if len(files) == 0 {
		mctx.ModuleErrorf("no jar file found under %q", mydir)
	}

	for _, f := range files {
		// create a Import module for each jar file
		localPath := strings.TrimPrefix(f, mydir)
		module, apiver, scope := parseJarPath(mctx, localPath)

		if len(module) != 0 {
			createImport(mctx, module, scope, apiver, localPath)
		}
	}
}

func prebuiltApiFiles(mctx android.TopDownMutatorContext) {
	mydir := mctx.ModuleDir() + "/"
	// <apiver>/<scope>/api/<module>.txt
	files, err := mctx.GlobWithDeps(mydir+"*/*/api/*.txt", nil)
@@ -131,6 +182,12 @@ func prebuiltApisMutator(mctx android.TopDownMutatorContext) {
		createFilegroup(mctx, info.module, info.scope, "latest", info.path)
	}
}

func prebuiltApisMutator(mctx android.TopDownMutatorContext) {
	if _, ok := mctx.Module().(*prebuiltApis); ok {
		prebuiltApiFiles(mctx)
		prebuiltSdkStubs(mctx)
	}
}

func prebuiltApisFactory() android.Module {