Merge "bp2build: Unexport GenerateBazelTargetsForDir."

This commit is contained in:
Jingwen Chen 2021-02-23 03:07:00 +00:00 committed by Gerrit Code Review
commit 0d2497088c
6 changed files with 15 additions and 15 deletions

View file

@ -208,12 +208,6 @@ func GenerateBazelTargets(ctx CodegenContext) (map[string]BazelTargets, CodegenM
return buildFileToTargets, metrics
}
// Helper method for tests to easily access the targets in a dir.
func GenerateBazelTargetsForDir(codegenCtx CodegenContext, dir string) BazelTargets {
bazelTargetsMap, _ := GenerateBazelTargets(codegenCtx)
return bazelTargetsMap[dir]
}
// Helper method to trim quotes around strings.
func trimQuotes(s string) string {
if s == "" {

View file

@ -204,7 +204,7 @@ func TestGenerateSoongModuleTargets(t *testing.T) {
android.FailIfErrored(t, errs)
codegenCtx := NewCodegenContext(config, *ctx.Context, QueryView)
bazelTargets := GenerateBazelTargetsForDir(codegenCtx, dir)
bazelTargets := generateBazelTargetsForDir(codegenCtx, dir)
if actualCount, expectedCount := len(bazelTargets), 1; actualCount != expectedCount {
t.Fatalf("Expected %d bazel target, got %d", expectedCount, actualCount)
}
@ -262,7 +262,7 @@ func TestGenerateBazelTargetModules(t *testing.T) {
}
codegenCtx := NewCodegenContext(config, *ctx.Context, Bp2Build)
bazelTargets := GenerateBazelTargetsForDir(codegenCtx, dir)
bazelTargets := generateBazelTargetsForDir(codegenCtx, dir)
if actualCount, expectedCount := len(bazelTargets), 1; actualCount != expectedCount {
t.Errorf("Expected %d bazel target, got %d", expectedCount, actualCount)
@ -421,7 +421,7 @@ load("//build/bazel/rules:rules.bzl", "my_library")`,
android.FailIfErrored(t, errs)
codegenCtx := NewCodegenContext(config, *ctx.Context, Bp2Build)
bazelTargets := GenerateBazelTargetsForDir(codegenCtx, dir)
bazelTargets := generateBazelTargetsForDir(codegenCtx, dir)
if actualCount := len(bazelTargets); actualCount != testCase.expectedBazelTargetCount {
t.Fatalf("Expected %d bazel target, got %d", testCase.expectedBazelTargetCount, actualCount)
}
@ -912,7 +912,7 @@ genrule {
}
codegenCtx := NewCodegenContext(config, *ctx.Context, Bp2Build)
bazelTargets := GenerateBazelTargetsForDir(codegenCtx, checkDir)
bazelTargets := generateBazelTargetsForDir(codegenCtx, checkDir)
if actualCount, expectedCount := len(bazelTargets), len(testCase.expectedBazelTargets); actualCount != expectedCount {
t.Errorf("%s: Expected %d bazel target, got %d", testCase.description, expectedCount, actualCount)
} else {
@ -1127,7 +1127,7 @@ genrule {
android.FailIfErrored(t, errs)
codegenCtx := NewCodegenContext(config, *ctx.Context, Bp2Build)
bazelTargets := GenerateBazelTargetsForDir(codegenCtx, dir)
bazelTargets := generateBazelTargetsForDir(codegenCtx, dir)
if actualCount := len(bazelTargets); actualCount != 1 {
t.Fatalf("%s: Expected 1 bazel target, got %d", testCase.description, actualCount)
}
@ -1215,7 +1215,7 @@ func TestAllowlistingBp2buildTargets(t *testing.T) {
android.FailIfErrored(t, errs)
codegenCtx := NewCodegenContext(config, *ctx.Context, Bp2Build)
bazelTargets := GenerateBazelTargetsForDir(codegenCtx, dir)
bazelTargets := generateBazelTargetsForDir(codegenCtx, dir)
if actualCount := len(bazelTargets); actualCount != testCase.expectedCount {
t.Fatalf("%s: Expected %d bazel target, got %d", testCase.description, testCase.expectedCount, actualCount)
}

View file

@ -203,7 +203,7 @@ cc_library_headers {
checkDir = testCase.dir
}
codegenCtx := NewCodegenContext(config, *ctx.Context, Bp2Build)
bazelTargets := GenerateBazelTargetsForDir(codegenCtx, checkDir)
bazelTargets := generateBazelTargetsForDir(codegenCtx, checkDir)
if actualCount, expectedCount := len(bazelTargets), len(testCase.expectedBazelTargets); actualCount != expectedCount {
t.Errorf("%s: Expected %d bazel target, got %d", testCase.description, expectedCount, actualCount)
} else {

View file

@ -167,7 +167,7 @@ cc_defaults {
}
codegenCtx := NewCodegenContext(config, *ctx.Context, Bp2Build)
bazelTargets := GenerateBazelTargetsForDir(codegenCtx, dir)
bazelTargets := generateBazelTargetsForDir(codegenCtx, dir)
if actualCount, expectedCount := len(bazelTargets), len(testCase.expectedBazelTargets); actualCount != expectedCount {
fmt.Println(bazelTargets)
t.Errorf("%s: Expected %d bazel target, got %d", testCase.description, expectedCount, actualCount)

View file

@ -116,7 +116,7 @@ func TestShBinaryBp2Build(t *testing.T) {
checkDir = testCase.dir
}
codegenCtx := NewCodegenContext(config, *ctx.Context, Bp2Build)
bazelTargets := GenerateBazelTargetsForDir(codegenCtx, checkDir)
bazelTargets := generateBazelTargetsForDir(codegenCtx, checkDir)
if actualCount, expectedCount := len(bazelTargets), len(testCase.expectedBazelTargets); actualCount != expectedCount {
t.Errorf("%s: Expected %d bazel target, got %d", testCase.description, expectedCount, actualCount)
} else {

View file

@ -175,3 +175,9 @@ func customBp2BuildMutatorFromStarlark(ctx android.TopDownMutatorContext) {
ctx.CreateBazelTargetModule(customBazelModuleFactory, myProtoLibraryProps, attrs)
}
}
// Helper method for tests to easily access the targets in a dir.
func generateBazelTargetsForDir(codegenCtx CodegenContext, dir string) BazelTargets {
buildFileToTargets, _ := GenerateBazelTargets(codegenCtx)
return buildFileToTargets[dir]
}