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

Commit ed885bb7 authored by Gurpreet Singh's avatar Gurpreet Singh
Browse files

Add genrule to build *.latest.version build target.

Build a new target *.latest.version which will contain a text file
containing the last finalized version.

Bug: 242316893, 282140551
Test: atest prebuilt_apis_test
(cherry picked from https://android-review.googlesource.com/q/commit:daa314ac97d5ab8076113ee7f269b4e4cc3cf620)
Merged-In: I41fa91c9ec273f342b7807c66c4d65ba13260124
Change-Id: I41fa91c9ec273f342b7807c66c4d65ba13260124
parent 1d2252d6
Loading
Loading
Loading
Loading
+24 −4
Original line number Diff line number Diff line
@@ -135,6 +135,19 @@ func createApiModule(mctx android.LoadHookContext, name string, path string) {
	mctx.CreateModule(genrule.GenRuleFactory, &genruleProps)
}

func createLatestApiModuleExtensionVersionFile(mctx android.LoadHookContext, name string, version string) {
	genruleProps := struct {
		Name *string
		Srcs []string
		Out  []string
		Cmd  *string
	}{}
	genruleProps.Name = proptools.StringPtr(name)
	genruleProps.Out = []string{name}
	genruleProps.Cmd = proptools.StringPtr("echo " + version + " > $(out)")
	mctx.CreateModule(genrule.GenRuleFactory, &genruleProps)
}

func createEmptyFile(mctx android.LoadHookContext, name string) {
	props := struct {
		Name *string
@@ -233,9 +246,10 @@ func prebuiltApiFiles(mctx android.LoadHookContext, p *prebuiltApis) {
	type latestApiInfo struct {
		module, scope, path string
		version             int
		isExtensionApiFile  bool
	}

	getLatest := func(files []string) map[string]latestApiInfo {
	getLatest := func(files []string, isExtensionApiFile bool) map[string]latestApiInfo {
		m := make(map[string]latestApiInfo)
		for _, f := range files {
			module, version, scope := parseFinalizedPrebuiltPath(mctx, f)
@@ -245,16 +259,16 @@ func prebuiltApiFiles(mctx android.LoadHookContext, p *prebuiltApis) {
			key := module + "." + scope
			info, exists := m[key]
			if !exists || version > info.version {
				m[key] = latestApiInfo{module, scope, f, version}
				m[key] = latestApiInfo{module, scope, f, version, isExtensionApiFile}
			}
		}
		return m
	}

	latest := getLatest(apiLevelFiles)
	latest := getLatest(apiLevelFiles, false)
	if p.properties.Extensions_dir != nil {
		extensionApiFiles := globExtensionDirs(mctx, p, "api/*.txt")
		for k, v := range getLatest(extensionApiFiles) {
		for k, v := range getLatest(extensionApiFiles, true) {
			if _, exists := latest[k]; !exists {
				mctx.ModuleErrorf("Module %v finalized for extension %d but never during an API level; likely error", v.module, v.version)
			}
@@ -267,6 +281,12 @@ func prebuiltApiFiles(mctx android.LoadHookContext, p *prebuiltApis) {
	for _, k := range android.SortedKeys(latest) {
		info := latest[k]
		name := PrebuiltApiModuleName(info.module, info.scope, "latest")
		latestExtensionVersionModuleName := PrebuiltApiModuleName(info.module, info.scope, "latest.extension_version")
		if info.isExtensionApiFile {
			createLatestApiModuleExtensionVersionFile(mctx, latestExtensionVersionModuleName, strconv.Itoa(info.version))
		} else {
			createLatestApiModuleExtensionVersionFile(mctx, latestExtensionVersionModuleName, "-1")
		}
		createApiModule(mctx, name, info.path)
	}