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

Commit 2f3791f8 authored by Cole Faust's avatar Cole Faust
Browse files

Remove BuildWithUnescapedNinjaVars

This was added during the bazel migration, but is no longer needed/used.

Bug: 380945706
Test: m nothing --no-skip-soong-tests
Change-Id: Id0dde64e7f3b9c359458a0c34c7ff1099a0e115b
parent fc7b83d3
Loading
Loading
Loading
Loading
+4 −35
Original line number Diff line number Diff line
@@ -488,21 +488,15 @@ func (r *RuleBuilder) depFileMergerCmd(depFiles WritablePaths) *RuleBuilderComma
		Inputs(depFiles.Paths())
}

// BuildWithNinjaVars adds the built command line to the build graph, with dependencies on Inputs and Tools, and output files for
// Outputs. This function will not escape Ninja variables, so it may be used to write sandbox manifests using Ninja variables.
func (r *RuleBuilder) BuildWithUnescapedNinjaVars(name string, desc string) {
	r.build(name, desc, false)
}

// Build adds the built command line to the build graph, with dependencies on Inputs and Tools, and output files for
// Outputs.
func (r *RuleBuilder) Build(name string, desc string) {
	r.build(name, desc, true)
	r.build(name, desc)
}

var sandboxEnvOnceKey = NewOnceKey("sandbox_environment_variables")

func (r *RuleBuilder) build(name string, desc string, ninjaEscapeCommandString bool) {
func (r *RuleBuilder) build(name string, desc string) {
	name = ninjaNameEscape(name)

	if len(r.missingDeps) > 0 {
@@ -765,30 +759,7 @@ func (r *RuleBuilder) build(name string, desc string, ninjaEscapeCommandString b
		if err != nil {
			ReportPathErrorf(r.ctx, "sbox manifest failed to marshal: %q", err)
		}
		if ninjaEscapeCommandString {
		WriteFileRule(r.ctx, r.sboxManifestPath, string(pbText))
		} else {
			// We need  to have a rule to write files that is
			// defined on the RuleBuilder's pctx in order to
			// write Ninja variables in the string.
			// The WriteFileRule function above rule can only write
			// raw strings because it is defined on the android
			// package's pctx, and it can't access variables defined
			// in another context.
			r.ctx.Build(r.pctx, BuildParams{
				Rule: r.ctx.Rule(r.pctx, "unescapedWriteFile", blueprint.RuleParams{
					Command:        `rm -rf ${out} && cat ${out}.rsp > ${out}`,
					Rspfile:        "${out}.rsp",
					RspfileContent: "${content}",
					Description:    "write file",
				}, "content"),
				Output:      r.sboxManifestPath,
				Description: "write sbox manifest " + r.sboxManifestPath.Base(),
				Args: map[string]string{
					"content": string(pbText),
				},
			})
		}

		// Generate a new string to use as the command line of the sbox rule.  This uses
		// a RuleBuilderCommand as a convenience method of building the command line, then
@@ -882,9 +853,7 @@ func (r *RuleBuilder) build(name string, desc string, ninjaEscapeCommandString b
		pool = localPool
	}

	if ninjaEscapeCommandString {
	commandString = proptools.NinjaEscape(commandString)
	}

	args_vars := make([]string, len(r.args))
	i := 0
+7 −57
Original line number Diff line number Diff line
@@ -478,7 +478,6 @@ type testRuleBuilderModule struct {
		Restat      bool
		Sbox        bool
		Sbox_inputs bool
		Unescape_ninja_vars bool
	}
}

@@ -498,7 +497,7 @@ func (t *testRuleBuilderModule) GenerateAndroidBuildActions(ctx ModuleContext) {

	testRuleBuilder_Build(ctx, in, implicit, orderOnly, validation, t.properties.Flags,
		out, outDep, outDir,
		manifestPath, t.properties.Restat, t.properties.Sbox, t.properties.Sbox_inputs, t.properties.Unescape_ninja_vars,
		manifestPath, t.properties.Restat, t.properties.Sbox, t.properties.Sbox_inputs,
		rspFile, rspFileContents, rspFile2, rspFileContents2)
}

@@ -523,14 +522,14 @@ func (t *testRuleBuilderSingleton) GenerateBuildActions(ctx SingletonContext) {
	manifestPath := PathForOutput(ctx, "singleton/sbox.textproto")

	testRuleBuilder_Build(ctx, in, implicit, orderOnly, validation, nil, out, outDep, outDir,
		manifestPath, true, false, false, false,
		manifestPath, true, false, false,
		rspFile, rspFileContents, rspFile2, rspFileContents2)
}

func testRuleBuilder_Build(ctx BuilderContext, in Paths, implicit, orderOnly, validation Path,
	flags []string,
	out, outDep, outDir, manifestPath WritablePath,
	restat, sbox, sboxInputs, unescapeNinjaVars bool,
	restat, sbox, sboxInputs bool,
	rspFile WritablePath, rspFileContents Paths, rspFile2 WritablePath, rspFileContents2 Paths) {

	rule := NewRuleBuilder(pctx_ruleBuilderTest, ctx)
@@ -558,12 +557,8 @@ func testRuleBuilder_Build(ctx BuilderContext, in Paths, implicit, orderOnly, va
		rule.Restat()
	}

	if unescapeNinjaVars {
		rule.BuildWithUnescapedNinjaVars("rule", "desc")
	} else {
	rule.Build("rule", "desc")
}
}

var prepareForRuleBuilderTest = FixtureRegisterWithContext(func(ctx RegistrationContext) {
	ctx.RegisterModuleType("rule_builder_test", testRuleBuilderFactory)
@@ -777,48 +772,3 @@ func TestRuleBuilderHashInputs(t *testing.T) {
		})
	}
}

func TestRuleBuilderWithNinjaVarEscaping(t *testing.T) {
	bp := `
		rule_builder_test {
			name: "foo_sbox_escaped",
			flags: ["${cmdFlags}"],
			sbox: true,
			sbox_inputs: true,
		}
		rule_builder_test {
			name: "foo_sbox_unescaped",
			flags: ["${cmdFlags}"],
			sbox: true,
			sbox_inputs: true,
			unescape_ninja_vars: true,
		}
	`
	result := GroupFixturePreparers(
		prepareForRuleBuilderTest,
		FixtureWithRootAndroidBp(bp),
	).RunTest(t)

	escapedNinjaMod := result.ModuleForTests("foo_sbox_escaped", "").Output("sbox.textproto")
	AssertStringEquals(t, "expected rule", "android/soong/android.rawFileCopy", escapedNinjaMod.Rule.String())
	AssertStringDoesContain(
		t,
		"",
		ContentFromFileRuleForTests(t, result.TestContext, escapedNinjaMod),
		"${cmdFlags}",
	)

	unescapedNinjaMod := result.ModuleForTests("foo_sbox_unescaped", "").Rule("unescapedWriteFile")
	AssertStringDoesContain(
		t,
		"",
		unescapedNinjaMod.BuildParams.Args["content"],
		"${cmdFlags}",
	)
	AssertStringDoesNotContain(
		t,
		"",
		unescapedNinjaMod.BuildParams.Args["content"],
		"$${cmdFlags}",
	)
}