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

Commit a99df921 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Add property for incremental nsjail genrules" into main am: 44c5548d am: d272b9e5

parents 1b57b416 d272b9e5
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -282,7 +282,7 @@ func createLimitNdkExportRule() []Rule {
}

func createLimitDirgroupRule() []Rule {
	reason := "dirgroup module and dir_srcs property of genrule is allowed only to Trusty build rule."
	reason := "dirgroup module and dir_srcs / keep_gendir property of genrule is allowed only to Trusty build rule."
	return []Rule{
		NeverAllow().
			ModuleType("dirgroup").
@@ -297,6 +297,13 @@ func createLimitDirgroupRule() []Rule {
			Without("name", "trusty-x86_64.lk.elf.gen").
			Without("name", "trusty-x86_64-test.lk.elf.gen").
			WithMatcher("dir_srcs", isSetMatcherInstance).Because(reason),
		NeverAllow().
			ModuleType("genrule").
			Without("name", "trusty-arm64.lk.elf.gen").
			Without("name", "trusty-arm64-virt-test-debug.lk.elf.gen").
			Without("name", "trusty-x86_64.lk.elf.gen").
			Without("name", "trusty-x86_64-test.lk.elf.gen").
			With("keep_gendir", "true").Because(reason),
	}
}

+22 −0
Original line number Diff line number Diff line
@@ -63,6 +63,7 @@ type RuleBuilder struct {
	missingDeps      []string
	args             map[string]string
	nsjail           bool
	nsjailKeepGendir bool
	nsjailBasePath   WritablePath
	nsjailImplicits  Paths
}
@@ -208,6 +209,18 @@ func (r *RuleBuilder) NsjailImplicits(inputs Paths) *RuleBuilder {
	return r
}

// By default, nsjail rules truncate outputDir and baseDir before running commands, similar to Sbox
// rules which always run commands in a fresh sandbox. Calling NsjailKeepGendir keeps outputDir and
// baseDir as-is, leaving previous artifacts. This is useful when the rules support incremental
// builds.
func (r *RuleBuilder) NsjailKeepGendir() *RuleBuilder {
	if !r.nsjail {
		panic("NsjailKeepGendir() must be called after Nsjail()")
	}
	r.nsjailKeepGendir = true
	return r
}

// SandboxTools enables tool sandboxing for the rule by copying any referenced tools into the
// sandbox.
func (r *RuleBuilder) SandboxTools() *RuleBuilder {
@@ -555,8 +568,17 @@ func (r *RuleBuilder) build(name string, desc string) {
	if r.nsjail {
		var nsjailCmd strings.Builder
		nsjailPath := r.ctx.Config().PrebuiltBuildTool(r.ctx, "nsjail")
		if !r.nsjailKeepGendir {
			nsjailCmd.WriteString("rm -rf ")
			nsjailCmd.WriteString(r.nsjailBasePath.String())
			nsjailCmd.WriteRune(' ')
			nsjailCmd.WriteString(r.outDir.String())
			nsjailCmd.WriteString(" && ")
		}
		nsjailCmd.WriteString("mkdir -p ")
		nsjailCmd.WriteString(r.nsjailBasePath.String())
		nsjailCmd.WriteRune(' ')
		nsjailCmd.WriteString(r.outDir.String())
		nsjailCmd.WriteString(" && ")
		nsjailCmd.WriteString(nsjailPath.String())
		nsjailCmd.WriteRune(' ')
+23 −8
Original line number Diff line number Diff line
@@ -232,6 +232,7 @@ type generateTask struct {
	// For nsjail tasks
	useNsjail  bool
	dirSrcs    android.DirectoryPaths
	keepGendir bool
}

func (g *Module) GeneratedSourceFiles() android.Paths {
@@ -487,6 +488,9 @@ func (g *Module) generateCommonBuildActions(ctx android.ModuleContext) {
		name := "generator"
		if task.useNsjail {
			rule = android.NewRuleBuilder(pctx, ctx).Nsjail(task.genDir, android.PathForModuleOut(ctx, "nsjail_build_sandbox"))
			if task.keepGendir {
				rule.NsjailKeepGendir()
			}
		} else {
			manifestName := "genrule.sbox.textproto"
			if task.shards > 0 {
@@ -897,6 +901,12 @@ func NewGenRule() *Module {
			return nil
		}

		keepGendir := Bool(properties.Keep_gendir)
		if keepGendir && !useNsjail {
			ctx.PropertyErrorf("keep_gendir", "can't use keep_gendir if use_nsjail is false")
			return nil
		}

		outs := make(android.WritablePaths, len(properties.Out))
		for i, out := range properties.Out {
			outs[i] = android.PathForModuleGen(ctx, out)
@@ -908,6 +918,7 @@ func NewGenRule() *Module {
			cmd:        rawCommand,
			useNsjail:  useNsjail,
			dirSrcs:    dirSrcs,
			keepGendir: keepGendir,
		}}
	}

@@ -928,6 +939,10 @@ type genRuleProperties struct {
	// dir_srcs is limited only to Trusty build.
	Dir_srcs []string `android:"path"`

	// If set to true, $(genDir) is not truncated. Useful when this genrule can be incrementally
	// built. Can be set only when use_nsjail is true.
	Keep_gendir *bool

	// names of the output files that will be generated
	Out []string `android:"arch_variant"`
}