Add test mode for java config modules
Test: soong unit tests, verify output files are correct Bug: 288632682 Change-Id: If5a6c916104e60e3688f5614b7420138e1a6323e
This commit is contained in:
@@ -44,6 +44,7 @@ var (
|
|||||||
Command: `rm -rf ${out}.tmp` +
|
Command: `rm -rf ${out}.tmp` +
|
||||||
` && mkdir -p ${out}.tmp` +
|
` && mkdir -p ${out}.tmp` +
|
||||||
` && ${aconfig} create-java-lib` +
|
` && ${aconfig} create-java-lib` +
|
||||||
|
` --mode ${mode}` +
|
||||||
` --cache ${in}` +
|
` --cache ${in}` +
|
||||||
` --out ${out}.tmp` +
|
` --out ${out}.tmp` +
|
||||||
` && $soong_zip -write_if_changed -jar -o ${out} -C ${out}.tmp -D ${out}.tmp` +
|
` && $soong_zip -write_if_changed -jar -o ${out} -C ${out}.tmp -D ${out}.tmp` +
|
||||||
@@ -53,7 +54,7 @@ var (
|
|||||||
"$soong_zip",
|
"$soong_zip",
|
||||||
},
|
},
|
||||||
Restat: true,
|
Restat: true,
|
||||||
})
|
}, "mode")
|
||||||
|
|
||||||
// For java_aconfig_library: Generate java file
|
// For java_aconfig_library: Generate java file
|
||||||
cppRule = pctx.AndroidStaticRule("cc_aconfig_library",
|
cppRule = pctx.AndroidStaticRule("cc_aconfig_library",
|
||||||
|
@@ -30,6 +30,9 @@ var declarationsTag = declarationsTagType{}
|
|||||||
type JavaAconfigDeclarationsLibraryProperties struct {
|
type JavaAconfigDeclarationsLibraryProperties struct {
|
||||||
// name of the aconfig_declarations module to generate a library for
|
// name of the aconfig_declarations module to generate a library for
|
||||||
Aconfig_declarations string
|
Aconfig_declarations string
|
||||||
|
|
||||||
|
// whether to generate test mode version of the library
|
||||||
|
Test bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type JavaAconfigDeclarationsLibraryCallbacks struct {
|
type JavaAconfigDeclarationsLibraryCallbacks struct {
|
||||||
@@ -61,11 +64,20 @@ func (callbacks *JavaAconfigDeclarationsLibraryCallbacks) GenerateSourceJarBuild
|
|||||||
|
|
||||||
// Generate the action to build the srcjar
|
// Generate the action to build the srcjar
|
||||||
srcJarPath := android.PathForModuleGen(ctx, ctx.ModuleName()+".srcjar")
|
srcJarPath := android.PathForModuleGen(ctx, ctx.ModuleName()+".srcjar")
|
||||||
|
var mode string
|
||||||
|
if callbacks.properties.Test {
|
||||||
|
mode = "test"
|
||||||
|
} else {
|
||||||
|
mode = "production"
|
||||||
|
}
|
||||||
ctx.Build(pctx, android.BuildParams{
|
ctx.Build(pctx, android.BuildParams{
|
||||||
Rule: javaRule,
|
Rule: javaRule,
|
||||||
Input: declarations.IntermediatePath,
|
Input: declarations.IntermediatePath,
|
||||||
Output: srcJarPath,
|
Output: srcJarPath,
|
||||||
Description: "aconfig.srcjar",
|
Description: "aconfig.srcjar",
|
||||||
|
Args: map[string]string{
|
||||||
|
"mode": mode,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
// Tell the java module about the .aconfig files, so they can be propagated up the dependency chain.
|
// Tell the java module about the .aconfig files, so they can be propagated up the dependency chain.
|
||||||
|
@@ -15,6 +15,7 @@
|
|||||||
package aconfig
|
package aconfig
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@@ -152,3 +153,39 @@ func TestAndroidMkBinaryThatLinksAgainstAar(t *testing.T) {
|
|||||||
|
|
||||||
runJavaAndroidMkTest(t, bp)
|
runJavaAndroidMkTest(t, bp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testCodegenMode(t *testing.T, bpMode string, ruleMode string) {
|
||||||
|
result := android.GroupFixturePreparers(
|
||||||
|
PrepareForTestWithAconfigBuildComponents,
|
||||||
|
java.PrepareForTestWithJavaDefaultModules).
|
||||||
|
ExtendWithErrorHandler(android.FixtureExpectsNoErrors).
|
||||||
|
RunTestWithBp(t, fmt.Sprintf(`
|
||||||
|
aconfig_declarations {
|
||||||
|
name: "my_aconfig_declarations",
|
||||||
|
package: "com.example.package",
|
||||||
|
srcs: ["foo.aconfig"],
|
||||||
|
}
|
||||||
|
|
||||||
|
java_aconfig_library {
|
||||||
|
name: "my_java_aconfig_library",
|
||||||
|
aconfig_declarations: "my_aconfig_declarations",
|
||||||
|
%s
|
||||||
|
}
|
||||||
|
`, bpMode))
|
||||||
|
|
||||||
|
module := result.ModuleForTests("my_java_aconfig_library", "android_common")
|
||||||
|
rule := module.Rule("java_aconfig_library")
|
||||||
|
android.AssertStringEquals(t, "rule must contain test mode", rule.Args["mode"], ruleMode)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestDefaultProdMode(t *testing.T) {
|
||||||
|
testCodegenMode(t, "", "production")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestProdMode(t *testing.T) {
|
||||||
|
testCodegenMode(t, "test: false,", "production")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestTestMode(t *testing.T) {
|
||||||
|
testCodegenMode(t, "test: true,", "test")
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user