diff options
| author | mosimchah <mosimchah@gmail.com> | 2025-12-02 09:27:38 -0500 |
|---|---|---|
| committer | mosimchah <mosimchah@gmail.com> | 2025-12-02 09:27:38 -0500 |
| commit | c7bade461dc55726f62997d13a48582f7c4b4655 (patch) | |
| tree | ea0588da76060a2038f54f67efd046ca77634b10 /java/kotlin_test.go | |
| parent | 0f5414d19317805e8bbbe7c4db5f0fd78769bad5 (diff) | |
| parent | 89d78cff8b00d3b20a90074635c3fe5a2ee49474 (diff) | |
Merge branch 'lineage-23.1' of https://github.com/LineageOS/android_build_soong into HEADw16.1
* 'lineage-23.1' of https://github.com/LineageOS/android_build_soong: (528 commits)
Revert "install_symlink: Make symlink target configurable"
Reapply "Clear as much of cc.Module as possible after GenerateBuildActions"
Revert "rust: config: Fix missing CPU variant LD flags in Rust"
Rename build-flag in outdir
Revert^4 "cipd: Default CIPD proxy server to on, add opt-out"
Convert check-vintf-all to phony with actions
Create a partial implementation of check-vintf-all for soong-only
Configure RBE rust pool based on build variant
Revert^3 "Add sdk version check to arr"
Add jdk.internal.invoke to the allowlist
Make droid always depend on symbols zip
Import Device and Odm skus
Don't install gob_gen in Soong
Remove bazel reference from run_integration_tests.sh
Fix bootstrap_test.sh
Don't panic in aconfig libraries when AllowMissingDependencies is set
Avoid returning nil paths from PathForModuleSrc
Revert "Flag controled clang version"
Rework module target dependencies on required deps
Revert^2 "Add sdk version check to arr"
...
Change-Id: I6e9a63fa14fda917a42e426e5dcebbad7f67e1de
Diffstat (limited to 'java/kotlin_test.go')
| -rw-r--r-- | java/kotlin_test.go | 126 |
1 files changed, 123 insertions, 3 deletions
diff --git a/java/kotlin_test.go b/java/kotlin_test.go index 4b56cff1c..b2556b7af 100644 --- a/java/kotlin_test.go +++ b/java/kotlin_test.go @@ -199,6 +199,34 @@ func TestKotlin(t *testing.T) { } } +func TestSortKotlincFlags(t *testing.T) { + t.Parallel() + + t.Run("Successful sorting of kotlincFlags", func(t *testing.T) { + t.Parallel() + bp := ` + java_library { + name: "Foo", + srcs: ["Foo.kt"], + kotlincflags: ["-Ja", "-Xb", "-JCz", "-JCy", "-JCx", "-Xd"] + } + ` + result := android.GroupFixturePreparers( + PrepareForTestWithJavaDefaultModules, + ).RunTestWithBp(t, bp) + + module := result.ModuleForTests(t, "Foo", "android_common") + kotlincRule := module.Rule("kotlinc") + expectedFlags := "-Ja -JCz -JCy -JCx -Xb -Xd" + + kotlincFlags := kotlincRule.Args["kotlincFlags"] + if !strings.Contains(kotlincFlags, expectedFlags) { + t.Errorf("kotlincFlags expected to have -J flags sorted first:\n Flags: %s\n Expected: %s", kotlincFlags, expectedFlags) + } + }) + +} + func TestKapt(t *testing.T) { t.Parallel() bp := ` @@ -462,7 +490,7 @@ func TestKotlinCompose(t *testing.T) { withCompose.Rule("kotlinc").Implicits.Strings(), composeCompiler.String()) android.AssertStringDoesContain(t, "missing compose compiler plugin", - withCompose.VariablesForTestsRelativeToTop()["kotlincFlags"], "-Xplugin="+composeCompiler.String()) + withCompose.VariablesForTestsRelativeToTop()["composePluginFlag"], "-Xplugin="+composeCompiler.String()) android.AssertStringListContains(t, "missing kapt compose compiler dependency", withCompose.Rule("kapt").Implicits.Strings(), composeCompiler.String()) @@ -471,7 +499,7 @@ func TestKotlinCompose(t *testing.T) { noCompose.Rule("kotlinc").Implicits.Strings(), composeCompiler.String()) android.AssertStringDoesNotContain(t, "unexpected compose compiler plugin", - noCompose.VariablesForTestsRelativeToTop()["kotlincFlags"], "-Xplugin="+composeCompiler.String()) + noCompose.VariablesForTestsRelativeToTop()["composePluginFlag"], "-Xplugin="+composeCompiler.String()) } func TestKotlinPlugin(t *testing.T) { @@ -510,7 +538,7 @@ func TestKotlinPlugin(t *testing.T) { withKotlinPlugin.Rule("kotlinc").Implicits.Strings(), kotlinPlugin.String()) android.AssertStringDoesContain(t, "missing kotlin plugin", - withKotlinPlugin.VariablesForTestsRelativeToTop()["kotlincFlags"], "-Xplugin="+kotlinPlugin.String()) + withKotlinPlugin.VariablesForTestsRelativeToTop()["kotlincPluginFlags"], "-Xplugin="+kotlinPlugin.String()) android.AssertStringListContains(t, "missing kapt kotlin plugin dependency", withKotlinPlugin.Rule("kapt").Implicits.Strings(), kotlinPlugin.String()) @@ -521,3 +549,95 @@ func TestKotlinPlugin(t *testing.T) { android.AssertStringDoesNotContain(t, "unexpected kotlin plugin", noKotlinPlugin.VariablesForTestsRelativeToTop()["kotlincFlags"], "-Xplugin="+kotlinPlugin.String()) } + +func TestKotlinAssociates(t *testing.T) { + t.Parallel() + + targets := []string{"FooUtils", "FooTest"} + for _, target := range targets { + t.Run("Successful associate linking of "+target, func(t *testing.T) { + t.Parallel() + bp := ` + java_library { + name: "Foo", + srcs: ["Foo.kt"], + } + + java_library { + name: "FooUtils", + srcs: ["FooUtils.kt"], + libs: ["Foo"], + associates: ["Foo"], + } + + java_test { + name: "FooTest", + srcs: ["FooTest.kt"], + static_libs: ["Foo"], + associates: ["Foo"], + } + ` + result := android.GroupFixturePreparers( + PrepareForTestWithJavaDefaultModules, + ).RunTestWithBp(t, bp) + + module := result.ModuleForTests(t, target, "android_common") + kotlincRule := module.Rule("kotlinc") + expectedFriendPath := "out/soong/.intermediates/Foo/android_common/kotlin_headers/Foo.jar" + expectedFlag := "-Xfriend-paths=" + expectedFriendPath + + kotlincFlags := kotlincRule.Args["kotlincFlags"] + if !strings.Contains(kotlincFlags, expectedFlag) { + t.Errorf("kotlincFlags missing expected friend path:\n Flags: %s\n Expected: %s", kotlincFlags, expectedFlag) + } + + classpathRspFile := module.Output("kotlinc/classpath.rsp") + classpathContent := android.ContentFromFileRuleForTests(t, result.TestContext, classpathRspFile) + classpathEntries := strings.Fields(classpathContent) + android.AssertStringPathRelativeToTopEquals(t, "first classpath entry", result.Config, expectedFriendPath, classpathEntries[0]) + }) + } + + t.Run("Error: Associate not a dependency", func(t *testing.T) { + t.Parallel() + bp := ` + java_library { + name: "Foo", + srcs: ["Foo.kt"], + } + + java_library { + name: "FooUtils", + srcs: ["FooUtils.kt"], + associates: ["Foo"], + } + ` + android.GroupFixturePreparers( + PrepareForTestWithJavaDefaultModules, + ).ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern( + `\QAssociates: associate module 'Foo' must also be listed as a direct dependency\E`, + )).RunTestWithBp(t, bp) + }) + + t.Run("Error: Associate not a Kotlin module", func(t *testing.T) { + t.Parallel() + bp := ` + java_library { + name: "Foo", + srcs: ["Foo.java"], + } + + java_library { + name: "FooUtils", + srcs: ["FooUtils.kt"], + libs: ["Foo"], + associates: ["Foo"], + } + ` + android.GroupFixturePreparers( + PrepareForTestWithJavaDefaultModules, + ).ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern( + `\QAssociates: associate module 'Foo' is not a Kotlin module\E`, + )).RunTestWithBp(t, bp) + }) +} |
