Make CodegenContext reference *android.Context
Previously, it stored an android.Context (no pointer) which while it worked (because the current contents are themselves pointers) it is inconsistent with how the rest of the code references it and could cause weird behavior if additional fields were added to the Context. Test: m nothing m bp2build Change-Id: I9c70f925dde85e5b15431cc232b0c2eb6371ec6d
This commit is contained in:
@@ -136,7 +136,7 @@ type bpToBuildContext interface {
|
||||
|
||||
type CodegenContext struct {
|
||||
config android.Config
|
||||
context android.Context
|
||||
context *android.Context
|
||||
mode CodegenMode
|
||||
additionalDeps []string
|
||||
unconvertedDepMode unconvertedDepsMode
|
||||
@@ -203,12 +203,12 @@ func (ctx *CodegenContext) AdditionalNinjaDeps() []string {
|
||||
return ctx.additionalDeps
|
||||
}
|
||||
|
||||
func (ctx *CodegenContext) Config() android.Config { return ctx.config }
|
||||
func (ctx *CodegenContext) Context() android.Context { return ctx.context }
|
||||
func (ctx *CodegenContext) Config() android.Config { return ctx.config }
|
||||
func (ctx *CodegenContext) Context() *android.Context { return ctx.context }
|
||||
|
||||
// NewCodegenContext creates a wrapper context that conforms to PathContext for
|
||||
// writing BUILD files in the output directory.
|
||||
func NewCodegenContext(config android.Config, context android.Context, mode CodegenMode) *CodegenContext {
|
||||
func NewCodegenContext(config android.Config, context *android.Context, mode CodegenMode) *CodegenContext {
|
||||
var unconvertedDeps unconvertedDepsMode
|
||||
if config.IsEnvTrue("BP2BUILD_ERROR_UNCONVERTED") {
|
||||
unconvertedDeps = errorModulesUnconvertedDeps
|
||||
|
@@ -209,7 +209,7 @@ func TestGenerateSoongModuleTargets(t *testing.T) {
|
||||
_, errs = ctx.PrepareBuildActions(config)
|
||||
android.FailIfErrored(t, errs)
|
||||
|
||||
codegenCtx := NewCodegenContext(config, *ctx.Context, QueryView)
|
||||
codegenCtx := NewCodegenContext(config, ctx.Context, QueryView)
|
||||
bazelTargets, err := generateBazelTargetsForDir(codegenCtx, dir)
|
||||
android.FailIfErrored(t, err)
|
||||
if actualCount, expectedCount := len(bazelTargets), 1; actualCount != expectedCount {
|
||||
@@ -530,7 +530,7 @@ custom {
|
||||
return
|
||||
}
|
||||
|
||||
codegenCtx := NewCodegenContext(config, *ctx.Context, Bp2Build)
|
||||
codegenCtx := NewCodegenContext(config, ctx.Context, Bp2Build)
|
||||
bazelTargets, err := generateBazelTargetsForDir(codegenCtx, dir)
|
||||
android.FailIfErrored(t, err)
|
||||
|
||||
@@ -903,7 +903,7 @@ load("//build/bazel/rules:rules.bzl", "my_library")`,
|
||||
_, errs = ctx.ResolveDependencies(config)
|
||||
android.FailIfErrored(t, errs)
|
||||
|
||||
codegenCtx := NewCodegenContext(config, *ctx.Context, Bp2Build)
|
||||
codegenCtx := NewCodegenContext(config, ctx.Context, Bp2Build)
|
||||
bazelTargets, err := generateBazelTargetsForDir(codegenCtx, dir)
|
||||
android.FailIfErrored(t, err)
|
||||
if actualCount := len(bazelTargets); actualCount != testCase.expectedBazelTargetCount {
|
||||
@@ -1156,7 +1156,7 @@ func TestAllowlistingBp2buildTargetsExplicitly(t *testing.T) {
|
||||
_, errs = ctx.ResolveDependencies(config)
|
||||
android.FailIfErrored(t, errs)
|
||||
|
||||
codegenCtx := NewCodegenContext(config, *ctx.Context, Bp2Build)
|
||||
codegenCtx := NewCodegenContext(config, ctx.Context, Bp2Build)
|
||||
bazelTargets, err := generateBazelTargetsForDir(codegenCtx, dir)
|
||||
android.FailIfErrored(t, err)
|
||||
if actualCount := len(bazelTargets); actualCount != testCase.expectedCount {
|
||||
@@ -1263,7 +1263,7 @@ filegroup { name: "opt-out-h", bazel_module: { bp2build_available: false } }
|
||||
_, errs = ctx.ResolveDependencies(config)
|
||||
android.FailIfErrored(t, errs)
|
||||
|
||||
codegenCtx := NewCodegenContext(config, *ctx.Context, Bp2Build)
|
||||
codegenCtx := NewCodegenContext(config, ctx.Context, Bp2Build)
|
||||
|
||||
// For each directory, test that the expected number of generated targets is correct.
|
||||
for dir, expectedCount := range testCase.expectedCount {
|
||||
@@ -1398,7 +1398,7 @@ func TestCombineBuildFilesBp2buildTargets(t *testing.T) {
|
||||
if testCase.Dir != "" {
|
||||
checkDir = testCase.Dir
|
||||
}
|
||||
codegenCtx := NewCodegenContext(config, *ctx.Context, Bp2Build)
|
||||
codegenCtx := NewCodegenContext(config, ctx.Context, Bp2Build)
|
||||
bazelTargets, err := generateBazelTargetsForDir(codegenCtx, checkDir)
|
||||
android.FailIfErrored(t, err)
|
||||
bazelTargets.sort()
|
||||
|
@@ -22,11 +22,12 @@ package bp2build
|
||||
// run for longer, set -benchtime to a larger value.
|
||||
|
||||
import (
|
||||
"android/soong/android"
|
||||
"fmt"
|
||||
"math"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"android/soong/android"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -105,7 +106,7 @@ func setup(builddir string, tcSize float64) testConfig {
|
||||
ctx := android.NewTestContext(config)
|
||||
|
||||
registerCustomModuleForBp2buildConversion(ctx)
|
||||
codegenCtx := NewCodegenContext(config, *ctx.Context, Bp2Build)
|
||||
codegenCtx := NewCodegenContext(config, ctx.Context, Bp2Build)
|
||||
return testConfig{
|
||||
config,
|
||||
ctx,
|
||||
|
@@ -155,7 +155,7 @@ func runBp2BuildTestCaseWithSetup(t *testing.T, setup func(ctx *android.TestCont
|
||||
if tc.Dir != "" {
|
||||
checkDir = tc.Dir
|
||||
}
|
||||
codegenCtx := NewCodegenContext(config, *ctx.Context, Bp2Build)
|
||||
codegenCtx := NewCodegenContext(config, ctx.Context, Bp2Build)
|
||||
codegenCtx.unconvertedDepMode = tc.UnconvertedDepsMode
|
||||
bazelTargets, errs := generateBazelTargetsForDir(codegenCtx, checkDir)
|
||||
if tc.ExpectedErr != nil {
|
||||
|
@@ -194,7 +194,7 @@ func runMixedModeBuild(configuration android.Config, ctx *android.Context, extra
|
||||
func runQueryView(queryviewDir, queryviewMarker string, configuration android.Config, ctx *android.Context) {
|
||||
ctx.EventHandler.Begin("queryview")
|
||||
defer ctx.EventHandler.End("queryview")
|
||||
codegenContext := bp2build.NewCodegenContext(configuration, *ctx, bp2build.QueryView)
|
||||
codegenContext := bp2build.NewCodegenContext(configuration, ctx, bp2build.QueryView)
|
||||
absoluteQueryViewDir := shared.JoinPath(topDir, queryviewDir)
|
||||
if err := createBazelWorkspace(codegenContext, absoluteQueryViewDir); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "%s", err)
|
||||
@@ -235,7 +235,7 @@ func runApiBp2build(configuration android.Config, extraNinjaDeps []string) strin
|
||||
ninjaDeps = append(ninjaDeps, globs...)
|
||||
|
||||
// Run codegen to generate BUILD files
|
||||
codegenContext := bp2build.NewCodegenContext(configuration, *ctx, bp2build.ApiBp2build)
|
||||
codegenContext := bp2build.NewCodegenContext(configuration, ctx, bp2build.ApiBp2build)
|
||||
absoluteApiBp2buildDir := shared.JoinPath(topDir, bazelApiBp2buildDir)
|
||||
if err := createBazelWorkspace(codegenContext, absoluteApiBp2buildDir); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "%s", err)
|
||||
@@ -699,7 +699,7 @@ func runBp2Build(configuration android.Config, extraNinjaDeps []string) {
|
||||
|
||||
// Run the code-generation phase to convert BazelTargetModules to BUILD files
|
||||
// and print conversion codegenMetrics to the user.
|
||||
codegenContext := bp2build.NewCodegenContext(configuration, *bp2buildCtx, bp2build.Bp2Build)
|
||||
codegenContext := bp2build.NewCodegenContext(configuration, bp2buildCtx, bp2build.Bp2Build)
|
||||
eventHandler.Do("codegen", func() {
|
||||
codegenMetrics = bp2build.Codegen(codegenContext)
|
||||
})
|
||||
|
Reference in New Issue
Block a user