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

Commit 5bc1744e authored by Colin Cross's avatar Colin Cross
Browse files

Build transitive lint reports for apex modules

Build and export transitive lint report zips for apex modules.

Bug: 153485543
Test: m TARGET_BUILD_APPS=com.google.android.wifi lint-check dist
Change-Id: I5a1805440452301a7e2c4ca91482b989638b54fb
Merged-In: I5a1805440452301a7e2c4ca91482b989638b54fb
(cherry picked from commit 08dca38e)
parent 5e218dbc
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
@@ -126,6 +126,26 @@ func (a *AndroidMkEntries) AddOptionalPath(name string, path OptionalPath) {
	}
}

func (a *AndroidMkEntries) SetPaths(name string, paths Paths) {
	if _, ok := a.EntryMap[name]; !ok {
		a.entryOrder = append(a.entryOrder, name)
	}
	a.EntryMap[name] = paths.Strings()
}

func (a *AndroidMkEntries) SetOptionalPaths(name string, paths Paths) {
	if len(paths) > 0 {
		a.SetPaths(name, paths)
	}
}

func (a *AndroidMkEntries) AddPaths(name string, paths Paths) {
	if _, ok := a.EntryMap[name]; !ok {
		a.entryOrder = append(a.entryOrder, name)
	}
	a.EntryMap[name] = append(a.EntryMap[name], paths.Strings()...)
}

func (a *AndroidMkEntries) SetBoolIfTrue(name string, flag bool) {
	if flag {
		if _, ok := a.EntryMap[name]; !ok {
+4 −0
Original line number Diff line number Diff line
@@ -326,6 +326,10 @@ func (a *apexBundle) androidMkForType() android.AndroidMkData {
				if apexType == imageApex {
					fmt.Fprintln(w, "ALL_MODULES.$(LOCAL_MODULE).BUNDLE :=", a.bundleModuleFile.String())
				}
				if len(a.lintReports) > 0 {
					fmt.Fprintln(w, "ALL_MODULES.$(my_register_name).LINT_REPORTS :=",
						strings.Join(a.lintReports.Strings(), " "))
				}

				if a.installedFilesFile != nil {
					goal := "checkbuild"
+14 −0
Original line number Diff line number Diff line
@@ -1265,6 +1265,7 @@ type apexFile struct {
	hostRequiredModuleNames   []string

	jacocoReportClassesFile android.Path     // only for javalibs and apps
	lintDepSets             java.LintDepSets // only for javalibs and apps
	certificate             java.Certificate // only for apps
	overriddenPackageName   string           // only for apps
}
@@ -1387,6 +1388,9 @@ type apexBundle struct {

	// Struct holding the merged notice file paths in different formats
	mergedNotices android.NoticeOutputs

	// Optional list of lint report zip files for apexes that contain java or app modules
	lintReports android.Paths
}

func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
@@ -1749,9 +1753,16 @@ func apexFileForShBinary(ctx android.BaseModuleContext, sh *sh.ShBinary) apexFil
type javaDependency interface {
	DexJar() android.Path
	JacocoReportClassesFile() android.Path
	LintDepSets() java.LintDepSets

	Stem() string
}

var _ javaDependency = (*java.Library)(nil)
var _ javaDependency = (*java.SdkLibrary)(nil)
var _ javaDependency = (*java.DexImport)(nil)
var _ javaDependency = (*java.SdkLibraryImport)(nil)

func apexFileForJavaLibrary(ctx android.BaseModuleContext, lib javaDependency, module android.Module) apexFile {
	dirInApex := "javalib"
	fileToCopy := lib.DexJar()
@@ -1759,6 +1770,7 @@ func apexFileForJavaLibrary(ctx android.BaseModuleContext, lib javaDependency, m
	name := strings.TrimPrefix(module.Name(), "prebuilt_")
	af := newApexFile(ctx, fileToCopy, name, dirInApex, javaSharedLib, module)
	af.jacocoReportClassesFile = lib.JacocoReportClassesFile()
	af.lintDepSets = lib.LintDepSets()
	af.stem = lib.Stem() + ".jar"
	return af
}
@@ -2274,6 +2286,8 @@ func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
	a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)

	a.buildApexDependencyInfo(ctx)

	a.buildLintReports(ctx)
}

// Enforce that Java deps of the apex are using stable SDKs to compile
+9 −0
Original line number Diff line number Diff line
@@ -752,3 +752,12 @@ func (a *apexBundle) buildApexDependencyInfo(ctx android.ModuleContext) {
		},
	})
}

func (a *apexBundle) buildLintReports(ctx android.ModuleContext) {
	depSetsBuilder := java.NewLintDepSetBuilder()
	for _, fi := range a.filesInfo {
		depSetsBuilder.Transitive(fi.lintDepSets)
	}

	a.lintReports = java.BuildModuleLintReportZips(ctx, depSetsBuilder.Build())
}
+2 −6
Original line number Diff line number Diff line
@@ -132,9 +132,7 @@ func (library *Library) AndroidMkEntries() []android.AndroidMkEntries {
					}
					entries.SetString("LOCAL_MODULE_STEM", library.Stem())

					entries.AddOptionalPath("LOCAL_SOONG_LINT_REPORTS", library.linter.outputs.transitiveHTMLZip)
					entries.AddOptionalPath("LOCAL_SOONG_LINT_REPORTS", library.linter.outputs.transitiveTextZip)
					entries.AddOptionalPath("LOCAL_SOONG_LINT_REPORTS", library.linter.outputs.transitiveXMLZip)
					entries.SetOptionalPaths("LOCAL_SOONG_LINT_REPORTS", library.linter.reports)
				},
			},
		}
@@ -388,9 +386,7 @@ func (app *AndroidApp) AndroidMkEntries() []android.AndroidMkEntries {
					entries.AddStrings("LOCAL_SOONG_BUILT_INSTALLED", extra.String()+":"+install)
				}

				entries.AddOptionalPath("LOCAL_SOONG_LINT_REPORTS", app.linter.outputs.transitiveHTMLZip)
				entries.AddOptionalPath("LOCAL_SOONG_LINT_REPORTS", app.linter.outputs.transitiveTextZip)
				entries.AddOptionalPath("LOCAL_SOONG_LINT_REPORTS", app.linter.outputs.transitiveXMLZip)
				entries.SetOptionalPaths("LOCAL_SOONG_LINT_REPORTS", app.linter.reports)
			},
		},
		ExtraFooters: []android.AndroidMkExtraFootersFunc{
Loading