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

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

Merge "Move sysprop gen code to sysprop module"

parents aefd0af5 988f53cf
Loading
Loading
Loading
Loading
+0 −51
Original line number Original line Diff line number Diff line
@@ -23,7 +23,6 @@ import (
)
)


func init() {
func init() {
	pctx.HostBinToolVariable("syspropCmd", "sysprop_java")
	pctx.SourcePathVariable("logtagsCmd", "build/make/tools/java-event-log-tags.py")
	pctx.SourcePathVariable("logtagsCmd", "build/make/tools/java-event-log-tags.py")
	pctx.SourcePathVariable("mergeLogtagsCmd", "build/make/tools/merge-event-log-tags.py")
	pctx.SourcePathVariable("mergeLogtagsCmd", "build/make/tools/merge-event-log-tags.py")
	pctx.SourcePathVariable("logtagsLib", "build/make/tools/event_log_tags.py")
	pctx.SourcePathVariable("logtagsLib", "build/make/tools/event_log_tags.py")
@@ -48,17 +47,6 @@ var (
			Command:     "$mergeLogtagsCmd -o $out $in",
			Command:     "$mergeLogtagsCmd -o $out $in",
			CommandDeps: []string{"$mergeLogtagsCmd", "$logtagsLib"},
			CommandDeps: []string{"$mergeLogtagsCmd", "$logtagsLib"},
		})
		})

	sysprop = pctx.AndroidStaticRule("sysprop",
		blueprint.RuleParams{
			Command: `rm -rf $out.tmp && mkdir -p $out.tmp && ` +
				`$syspropCmd --scope $scope --java-output-dir $out.tmp $in && ` +
				`${config.SoongZipCmd} -jar -o $out -C $out.tmp -D $out.tmp && rm -rf $out.tmp`,
			CommandDeps: []string{
				"$syspropCmd",
				"${config.SoongZipCmd}",
			},
		}, "scope")
)
)


func genAidl(ctx android.ModuleContext, aidlFile android.Path, aidlFlags string, deps android.Paths) android.Path {
func genAidl(ctx android.ModuleContext, aidlFile android.Path, aidlFlags string, deps android.Paths) android.Path {
@@ -93,22 +81,6 @@ func genLogtags(ctx android.ModuleContext, logtagsFile android.Path) android.Pat
	return javaFile
	return javaFile
}
}


func genSysprop(ctx android.ModuleContext, syspropFile android.Path, scope string) android.Path {
	srcJarFile := android.GenPathWithExt(ctx, "sysprop", syspropFile, "srcjar")

	ctx.Build(pctx, android.BuildParams{
		Rule:        sysprop,
		Description: "sysprop_java " + syspropFile.Rel(),
		Output:      srcJarFile,
		Input:       syspropFile,
		Args: map[string]string{
			"scope": scope,
		},
	})

	return srcJarFile
}

func genAidlIncludeFlags(srcFiles android.Paths) string {
func genAidlIncludeFlags(srcFiles android.Paths) string {
	var baseDirs []string
	var baseDirs []string
	for _, srcFile := range srcFiles {
	for _, srcFile := range srcFiles {
@@ -141,29 +113,6 @@ func (j *Module) genSources(ctx android.ModuleContext, srcFiles android.Paths,
		case ".proto":
		case ".proto":
			srcJarFile := genProto(ctx, srcFile, flags.proto)
			srcJarFile := genProto(ctx, srcFile, flags.proto)
			outSrcFiles = append(outSrcFiles, srcJarFile)
			outSrcFiles = append(outSrcFiles, srcJarFile)
		case ".sysprop":
			// internal scope contains all properties
			// public scope only contains public properties
			// use public if the owner is different from client
			scope := "internal"
			if j.properties.Sysprop.Platform != nil {
				isProduct := ctx.ProductSpecific()
				isVendor := ctx.SocSpecific()
				isOwnerPlatform := Bool(j.properties.Sysprop.Platform)

				if isProduct {
					// product can't own any sysprop_library now, so product must use public scope
					scope = "public"
				} else if isVendor && !isOwnerPlatform {
					// vendor and odm can't use system's internal property.
					scope = "public"
				}

				// We don't care about clients under system.
				// They can't use sysprop_library owned by other partitions.
			}
			srcJarFile := genSysprop(ctx, srcFile, scope)
			outSrcFiles = append(outSrcFiles, srcJarFile)
		default:
		default:
			outSrcFiles = append(outSrcFiles, srcFile)
			outSrcFiles = append(outSrcFiles, srcFile)
		}
		}
+0 −4
Original line number Original line Diff line number Diff line
@@ -184,10 +184,6 @@ type CompilerProperties struct {
		Output_params []string
		Output_params []string
	}
	}


	Sysprop struct {
		Platform *bool
	} `blueprint:"mutated"`

	Instrument bool `blueprint:"mutated"`
	Instrument bool `blueprint:"mutated"`


	// List of files to include in the META-INF/services folder of the resulting jar.
	// List of files to include in the META-INF/services folder of the resulting jar.
+146 −27
Original line number Original line Diff line number Diff line
@@ -32,6 +32,86 @@ type dependencyTag struct {
	name string
	name string
}
}


type syspropGenProperties struct {
	Srcs  []string `android:"path"`
	Scope string
}

type syspropJavaGenRule struct {
	android.ModuleBase

	properties syspropGenProperties

	genSrcjars android.Paths
}

var _ android.OutputFileProducer = (*syspropJavaGenRule)(nil)

var (
	syspropJava = pctx.AndroidStaticRule("syspropJava",
		blueprint.RuleParams{
			Command: `rm -rf $out.tmp && mkdir -p $out.tmp && ` +
				`$syspropJavaCmd --scope $scope --java-output-dir $out.tmp $in && ` +
				`$soongZipCmd -jar -o $out -C $out.tmp -D $out.tmp && rm -rf $out.tmp`,
			CommandDeps: []string{
				"$syspropJavaCmd",
				"$soongZipCmd",
			},
		}, "scope")
)

func init() {
	pctx.HostBinToolVariable("soongZipCmd", "soong_zip")
	pctx.HostBinToolVariable("syspropJavaCmd", "sysprop_java")

	android.PreArchMutators(func(ctx android.RegisterMutatorsContext) {
		ctx.BottomUp("sysprop_deps", syspropDepsMutator).Parallel()
	})
}

func (g *syspropJavaGenRule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
	var checkApiFileTimeStamp android.WritablePath

	ctx.VisitDirectDeps(func(dep android.Module) {
		if m, ok := dep.(*syspropLibrary); ok {
			checkApiFileTimeStamp = m.checkApiFileTimeStamp
		}
	})

	for _, syspropFile := range android.PathsForModuleSrc(ctx, g.properties.Srcs) {
		srcJarFile := android.GenPathWithExt(ctx, "sysprop", syspropFile, "srcjar")

		ctx.Build(pctx, android.BuildParams{
			Rule:        syspropJava,
			Description: "sysprop_java " + syspropFile.Rel(),
			Output:      srcJarFile,
			Input:       syspropFile,
			Implicit:    checkApiFileTimeStamp,
			Args: map[string]string{
				"scope": g.properties.Scope,
			},
		})

		g.genSrcjars = append(g.genSrcjars, srcJarFile)
	}
}

func (g *syspropJavaGenRule) OutputFiles(tag string) (android.Paths, error) {
	switch tag {
	case "":
		return g.genSrcjars, nil
	default:
		return nil, fmt.Errorf("unsupported module reference tag %q", tag)
	}
}

func syspropJavaGenFactory() android.Module {
	g := &syspropJavaGenRule{}
	g.AddProperties(&g.properties)
	android.InitAndroidModule(g)
	return g
}

type syspropLibrary struct {
type syspropLibrary struct {
	android.ModuleBase
	android.ModuleBase


@@ -81,13 +161,29 @@ func (m *syspropLibrary) CcModuleName() string {
	return "lib" + m.BaseModuleName()
	return "lib" + m.BaseModuleName()
}
}


func (m *syspropLibrary) javaGenModuleName() string {
	return m.BaseModuleName() + "_java_gen"
}

func (m *syspropLibrary) BaseModuleName() string {
func (m *syspropLibrary) BaseModuleName() string {
	return m.ModuleBase.Name()
	return m.ModuleBase.Name()
}
}


func (m *syspropLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
func (m *syspropLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
	m.currentApiFile = android.PathForSource(ctx, ctx.ModuleDir(), "api", m.BaseModuleName()+"-current.txt")
	baseModuleName := m.BaseModuleName()
	m.latestApiFile = android.PathForSource(ctx, ctx.ModuleDir(), "api", m.BaseModuleName()+"-latest.txt")

	for _, syspropFile := range android.PathsForModuleSrc(ctx, m.properties.Srcs) {
		if syspropFile.Ext() != ".sysprop" {
			ctx.PropertyErrorf("srcs", "srcs contains non-sysprop file %q", syspropFile.String())
		}
	}

	if ctx.Failed() {
		return
	}

	m.currentApiFile = android.PathForSource(ctx, ctx.ModuleDir(), "api", baseModuleName+"-current.txt")
	m.latestApiFile = android.PathForSource(ctx, ctx.ModuleDir(), "api", baseModuleName+"-latest.txt")


	// dump API rule
	// dump API rule
	rule := android.NewRuleBuilder()
	rule := android.NewRuleBuilder()
@@ -96,7 +192,7 @@ func (m *syspropLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext)
		BuiltTool(ctx, "sysprop_api_dump").
		BuiltTool(ctx, "sysprop_api_dump").
		Output(m.dumpedApiFile).
		Output(m.dumpedApiFile).
		Inputs(android.PathsForModuleSrc(ctx, m.properties.Srcs))
		Inputs(android.PathsForModuleSrc(ctx, m.properties.Srcs))
	rule.Build(pctx, ctx, m.BaseModuleName()+"_api_dump", m.BaseModuleName()+" api dump")
	rule.Build(pctx, ctx, baseModuleName+"_api_dump", baseModuleName+" api dump")


	// check API rule
	// check API rule
	rule = android.NewRuleBuilder()
	rule = android.NewRuleBuilder()
@@ -105,8 +201,8 @@ func (m *syspropLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext)
	msg := fmt.Sprintf(`\n******************************\n`+
	msg := fmt.Sprintf(`\n******************************\n`+
		`API of sysprop_library %s doesn't match with current.txt\n`+
		`API of sysprop_library %s doesn't match with current.txt\n`+
		`Please update current.txt by:\n`+
		`Please update current.txt by:\n`+
		`rm -rf %q && cp -f %q %q\n`+
		`m %s-dump-api && rm -rf %q && cp -f %q %q\n`+
		`******************************\n`, m.BaseModuleName(),
		`******************************\n`, baseModuleName, baseModuleName,
		m.currentApiFile.String(), m.dumpedApiFile.String(), m.currentApiFile.String())
		m.currentApiFile.String(), m.dumpedApiFile.String(), m.currentApiFile.String())


	rule.Command().
	rule.Command().
@@ -121,7 +217,7 @@ func (m *syspropLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext)
	msg = fmt.Sprintf(`\n******************************\n`+
	msg = fmt.Sprintf(`\n******************************\n`+
		`API of sysprop_library %s doesn't match with latest version\n`+
		`API of sysprop_library %s doesn't match with latest version\n`+
		`Please fix the breakage and rebuild.\n`+
		`Please fix the breakage and rebuild.\n`+
		`******************************\n`, m.BaseModuleName())
		`******************************\n`, baseModuleName)


	rule.Command().
	rule.Command().
		Text("( ").
		Text("( ").
@@ -138,7 +234,7 @@ func (m *syspropLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext)
		Text("touch").
		Text("touch").
		Output(m.checkApiFileTimeStamp)
		Output(m.checkApiFileTimeStamp)


	rule.Build(pctx, ctx, m.BaseModuleName()+"_check_api", m.BaseModuleName()+" check api")
	rule.Build(pctx, ctx, baseModuleName+"_check_api", baseModuleName+" check api")
}
}


func (m *syspropLibrary) AndroidMk() android.AndroidMkData {
func (m *syspropLibrary) AndroidMk() android.AndroidMkData {
@@ -153,13 +249,13 @@ func (m *syspropLibrary) AndroidMk() android.AndroidMkData {
			fmt.Fprintf(w, "include $(BUILD_SYSTEM)/base_rules.mk\n\n")
			fmt.Fprintf(w, "include $(BUILD_SYSTEM)/base_rules.mk\n\n")
			fmt.Fprintf(w, "$(LOCAL_BUILT_MODULE): %s\n", m.checkApiFileTimeStamp.String())
			fmt.Fprintf(w, "$(LOCAL_BUILT_MODULE): %s\n", m.checkApiFileTimeStamp.String())
			fmt.Fprintf(w, "\ttouch $@\n\n")
			fmt.Fprintf(w, "\ttouch $@\n\n")
			fmt.Fprintf(w, ".PHONY: %s-check-api\n\n", name)
			fmt.Fprintf(w, ".PHONY: %s-check-api %s-dump-api\n\n", name, name)

			// dump API rule
			fmt.Fprintf(w, "%s-dump-api: %s\n\n", name, m.dumpedApiFile.String())


			// check API rule
			// check API rule
			fmt.Fprintf(w, "%s-check-api: %s\n\n", name, m.checkApiFileTimeStamp.String())
			fmt.Fprintf(w, "%s-check-api: %s\n\n", name, m.checkApiFileTimeStamp.String())

			// "make {sysprop_library}" should also build the C++ library
			fmt.Fprintf(w, "%s: %s\n\n", name, m.CcModuleName())
		}}
		}}
}
}


@@ -263,24 +359,45 @@ func syspropLibraryHook(ctx android.LoadHookContext, m *syspropLibrary) {
	ccProps.Sysprop.Platform = proptools.BoolPtr(owner == "Platform")
	ccProps.Sysprop.Platform = proptools.BoolPtr(owner == "Platform")
	ccProps.Header_libs = []string{"libbase_headers"}
	ccProps.Header_libs = []string{"libbase_headers"}
	ccProps.Shared_libs = []string{"liblog"}
	ccProps.Shared_libs = []string{"liblog"}

	// add sysprop_library module to perform check API
	ccProps.Required = []string{m.Name()}
	ccProps.Sysprop.Platform = proptools.BoolPtr(owner == "Platform")
	ccProps.Recovery_available = m.properties.Recovery_available
	ccProps.Recovery_available = m.properties.Recovery_available
	ccProps.Vendor_available = m.properties.Vendor_available
	ccProps.Vendor_available = m.properties.Vendor_available


	ctx.CreateModule(android.ModuleFactoryAdaptor(cc.LibraryFactory), &ccProps)
	ctx.CreateModule(android.ModuleFactoryAdaptor(cc.LibraryFactory), &ccProps)


	// internal scope contains all properties
	// public scope only contains public properties
	// use public if the owner is different from client
	scope := "internal"
	isProduct := ctx.ProductSpecific()
	isVendor := ctx.SocSpecific()
	isOwnerPlatform := owner == "Platform"

	if isProduct {
		// product can't own any sysprop_library now, so product must use public scope
		scope = "public"
	} else if isVendor && !isOwnerPlatform {
		// vendor and odm can't use system's internal property.
		scope = "public"
	}

	javaGenProps := struct {
		Srcs  []string
		Scope string
		Name  *string
	}{
		Srcs:  m.properties.Srcs,
		Scope: scope,
		Name:  proptools.StringPtr(m.javaGenModuleName()),
	}

	ctx.CreateModule(android.ModuleFactoryAdaptor(syspropJavaGenFactory), &javaGenProps)

	javaProps := struct {
	javaProps := struct {
		Name             *string
		Name             *string
		Srcs             []string
		Srcs             []string
		Soc_specific     *bool
		Soc_specific     *bool
		Device_specific  *bool
		Device_specific  *bool
		Product_specific *bool
		Product_specific *bool
		Sysprop          struct {
			Platform *bool
		}
		Required         []string
		Required         []string
		Sdk_version      *string
		Sdk_version      *string
		Installable      *bool
		Installable      *bool
@@ -288,17 +405,19 @@ func syspropLibraryHook(ctx android.LoadHookContext, m *syspropLibrary) {
	}{}
	}{}


	javaProps.Name = proptools.StringPtr(m.BaseModuleName())
	javaProps.Name = proptools.StringPtr(m.BaseModuleName())
	javaProps.Srcs = m.properties.Srcs
	javaProps.Srcs = []string{":" + *javaGenProps.Name}
	javaProps.Soc_specific = proptools.BoolPtr(socSpecific)
	javaProps.Soc_specific = proptools.BoolPtr(socSpecific)
	javaProps.Device_specific = proptools.BoolPtr(deviceSpecific)
	javaProps.Device_specific = proptools.BoolPtr(deviceSpecific)
	javaProps.Product_specific = proptools.BoolPtr(productSpecific)
	javaProps.Product_specific = proptools.BoolPtr(productSpecific)
	javaProps.Installable = m.properties.Installable
	javaProps.Installable = m.properties.Installable

	// add sysprop_library module to perform check API
	javaProps.Required = []string{m.Name()}
	javaProps.Sdk_version = proptools.StringPtr("core_current")
	javaProps.Sdk_version = proptools.StringPtr("core_current")
	javaProps.Sysprop.Platform = proptools.BoolPtr(owner == "Platform")
	javaProps.Libs = []string{stub}
	javaProps.Libs = []string{stub}


	ctx.CreateModule(android.ModuleFactoryAdaptor(java.LibraryFactory), &javaProps)
	ctx.CreateModule(android.ModuleFactoryAdaptor(java.LibraryFactory), &javaProps)
}
}

func syspropDepsMutator(ctx android.BottomUpMutatorContext) {
	if m, ok := ctx.Module().(*syspropLibrary); ok {
		ctx.AddReverseDependency(m, nil, m.javaGenModuleName())
	}
}
+3 −0
Original line number Original line Diff line number Diff line
@@ -62,6 +62,9 @@ func testContext(config android.Config, bp string,
	ctx.PreArchMutators(android.RegisterPrebuiltsPreArchMutators)
	ctx.PreArchMutators(android.RegisterPrebuiltsPreArchMutators)
	ctx.PreArchMutators(android.RegisterPrebuiltsPostDepsMutators)
	ctx.PreArchMutators(android.RegisterPrebuiltsPostDepsMutators)
	ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
	ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
	ctx.PreArchMutators(func(ctx android.RegisterMutatorsContext) {
		ctx.BottomUp("sysprop_deps", syspropDepsMutator).Parallel()
	})


	ctx.RegisterModuleType("cc_library", android.ModuleFactoryAdaptor(cc.LibraryFactory))
	ctx.RegisterModuleType("cc_library", android.ModuleFactoryAdaptor(cc.LibraryFactory))
	ctx.RegisterModuleType("cc_library_headers", android.ModuleFactoryAdaptor(cc.LibraryHeaderFactory))
	ctx.RegisterModuleType("cc_library_headers", android.ModuleFactoryAdaptor(cc.LibraryHeaderFactory))