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

Commit b77043e2 authored by Colin Cross's avatar Colin Cross
Browse files

Add a systemModules utility type

Storing system modules in a classpath is clumsy, as there should
only ever be one system modules, and it needs to store both a
directory to pass as the argument and a set of generated files
to use as dependencies.  Store them in a separate systemModules
type instead.

Test: m checkbuild
Change-Id: I020556c736bd5091865bcca51dc0fb9e4db6b45b
parent 33961b54
Loading
Loading
Loading
Loading
+30 −27
Original line number Diff line number Diff line
@@ -153,8 +153,7 @@ type javaBuilderFlags struct {
	classpath     classpath
	processorPath classpath
	processor     string
	systemModules     classpath
	systemModulesDeps android.Paths
	systemModules *systemModules
	aidlFlags     string
	aidlDeps      android.Paths
	javaVersion   string
@@ -249,8 +248,9 @@ func transformJavaToClasses(ctx android.ModuleContext, outputFile android.Writab

	var bootClasspath string
	if flags.javaVersion == "1.9" {
		deps = append(deps, flags.systemModulesDeps...)
		bootClasspath = flags.systemModules.FormJavaSystemModulesPath("--system=", ctx.Device())
		var systemModuleDeps android.Paths
		bootClasspath, systemModuleDeps = flags.systemModules.FormJavaSystemModulesPath(ctx.Device())
		deps = append(deps, systemModuleDeps...)
	} else {
		deps = append(deps, flags.bootClasspath...)
		if len(flags.bootClasspath) == 0 && ctx.Device() {
@@ -424,21 +424,6 @@ func (x *classpath) FormJavaClassPath(optName string) string {
	}
}

// Returns a --system argument in the form javac expects with -source 1.9.  If forceEmpty is true,
// returns --system=none if the list is empty to ensure javac does not fall back to the default
// system modules.
func (x *classpath) FormJavaSystemModulesPath(optName string, forceEmpty bool) string {
	if len(*x) > 1 {
		panic("more than one system module")
	} else if len(*x) == 1 {
		return optName + (*x)[0].String()
	} else if forceEmpty {
		return optName + "none"
	} else {
		return ""
	}
}

func (x *classpath) FormTurbineClasspath(optName string) []string {
	if x == nil || *x == nil {
		return nil
@@ -466,3 +451,21 @@ func (x *classpath) Strings() []string {
	}
	return ret
}

type systemModules struct {
	dir  android.Path
	deps android.Paths
}

// Returns a --system argument in the form javac expects with -source 1.9.  If forceEmpty is true,
// returns --system=none if the list is empty to ensure javac does not fall back to the default
// system modules.
func (x *systemModules) FormJavaSystemModulesPath(forceEmpty bool) (string, android.Paths) {
	if x != nil {
		return "--system=" + x.dir.String(), x.deps
	} else if forceEmpty {
		return "--system=none", nil
	} else {
		return "", nil
	}
}
+4 −8
Original line number Diff line number Diff line
@@ -636,8 +636,7 @@ func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps {
			if sm.outputDir == nil && len(sm.outputDeps) == 0 {
				panic("Missing directory for system module dependency")
			}
			deps.systemModules = sm.outputDir
			deps.systemModulesDeps = sm.outputDeps
			deps.systemModules = &systemModules{sm.outputDir, sm.outputDeps}
		}
	})
	// do not pass exclude_srcs directly when expanding srcFiles since exclude_srcs
@@ -714,13 +713,10 @@ func (j *Javadoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {

	javaVersion := getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j))
	if len(deps.bootClasspath) > 0 {
		var systemModules classpath
		if deps.systemModules != nil {
			systemModules = append(systemModules, deps.systemModules)
		}
		implicits = append(implicits, deps.systemModulesDeps...)
		bootClasspathArgs = systemModules.FormJavaSystemModulesPath("--system ", ctx.Device())
		var systemModulesDeps android.Paths
		bootClasspathArgs, systemModulesDeps = deps.systemModules.FormJavaSystemModulesPath(ctx.Device())
		bootClasspathArgs = bootClasspathArgs + " --patch-module java.base=."
		implicits = append(implicits, systemModulesDeps...)
	}
	if len(deps.classpath.Strings()) > 0 {
		classpathArgs = "-classpath " + strings.Join(deps.classpath.Strings(), ":")
+3 −8
Original line number Diff line number Diff line
@@ -632,8 +632,7 @@ type deps struct {
	aidlIncludeDirs    android.Paths
	srcs               android.Paths
	srcJars            android.Paths
	systemModules      android.Path
	systemModulesDeps  android.Paths
	systemModules      *systemModules
	aidlPreprocess     android.OptionalPath
	kotlinStdlib       android.Paths
	kotlinAnnotations  android.Paths
@@ -844,8 +843,7 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps {
				if sm.outputDir == nil || len(sm.outputDeps) == 0 {
					panic("Missing directory for system module dependency")
				}
				deps.systemModules = sm.outputDir
				deps.systemModulesDeps = sm.outputDeps
				deps.systemModules = &systemModules{sm.outputDir, sm.outputDeps}
			}
		}
	})
@@ -973,10 +971,7 @@ func (j *Module) collectBuilderFlags(ctx android.ModuleContext, deps deps) javaB
	}

	// systemModules
	if deps.systemModules != nil {
		flags.systemModules = append(flags.systemModules, deps.systemModules)
		flags.systemModulesDeps = append(flags.systemModulesDeps, deps.systemModulesDeps...)
	}
	flags.systemModules = deps.systemModules

	// aidl flags.
	flags.aidlFlags, flags.aidlDeps = j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)