Skip to content

Commit

Permalink
Integration Tests
Browse files Browse the repository at this point in the history
Reviewed By: strulovich

fbshipit-source-id: f06a007c27095f53505f5caf73634e90acd40ebf
  • Loading branch information
acejingbo authored and facebook-github-bot committed Sep 14, 2022
1 parent caca38f commit 088ac2b
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.facebook.buck.core.model.BuildTargetFactory;
import com.facebook.buck.core.model.impl.BuildPaths;
import com.facebook.buck.io.ExecutableFinder;
import com.facebook.buck.jvm.core.JavaAbis;
import com.facebook.buck.testutil.ProcessResult;
import com.facebook.buck.testutil.TemporaryPaths;
import com.facebook.buck.testutil.integration.ProjectWorkspace;
Expand Down Expand Up @@ -624,16 +625,57 @@ public void shouldNotGenerateClassUsageFileForKspTargetIfBlocklisted() throws IO
workspace.getPath(getOutputFilePath(bizTargetFqn, "kotlin-used-classes.json"))));
}

@Test
public void shouldNotGenerateJvmAbi() throws IOException {
String targetFqn = "//com/example/child:child";
workspace.addBuckConfigLocalOption("kotlin", "use_jvm_abi_gen", false);
ProcessResult buildResult = workspace.runBuckCommand("build", targetFqn);
buildResult.assertSuccess("Build should have succeeded.");

assertFalse(
"Should not generate jvm-abi",
Files.exists(
workspace.getPath(
JavaAbis.getGenPathForClassAbiPartFromLibraryTarget(getGenDir(targetFqn)))));
}

@Test
public void shouldGenerateJvmAbiIfEnabled() throws IOException {
String targetFqn = "//com/example/child:child";
workspace.addBuckConfigLocalOption("kotlin", "use_jvm_abi_gen", true);
workspace.addBuckConfigLocalOption(
"kotlin", "kosabi_jvm_abi_gen_plugin", "//com/example/libs:jvm-abi-gen");
// Though jvm-abi-gen for class-abi won't use these 2 plugins, Kosabi.getPluginOptionsMappings
// requires all 3 plugins to be valid to return any.
workspace.addBuckConfigLocalOption(
"kotlin", "kosabi_stubs_gen_plugin", "//com/example/libs:jvm-abi-gen");
workspace.addBuckConfigLocalOption(
"kotlin", "kosabi_applicability_plugin", "//com/example/libs:jvm-abi-gen");
ProcessResult buildResult = workspace.runBuckCommand("build", targetFqn);
buildResult.assertSuccess("Build should have succeeded.");

assertTrue(
"Should generate jvm-abi",
Files.exists(
workspace.getPath(
JavaAbis.getGenPathForClassAbiPartFromLibraryTarget(getGenDir(targetFqn)))));
}

private Path getOutputJarPath(String targetFqn) throws IOException {
BuildTarget utilTarget = BuildTargetFactory.newInstance(targetFqn);
return getOutputFilePath(targetFqn, utilTarget.getShortName() + ".jar");
}

private Path getOutputFilePath(String targetFqn, String fileName) throws IOException {
BuildTarget target = BuildTargetFactory.newInstance(targetFqn);
RelPath genDir =
BuildPaths.getGenDir(workspace.getProjectFileSystem().getBuckPaths(), target).getParent();
return genDir.resolve(String.format("lib__%s__output/" + fileName, target.getShortName()));
return getGenDir(targetFqn)
.getParent()
.resolve(String.format("lib__%s__output/" + fileName, target.getShortName()));
}

private RelPath getGenDir(String targetFqn) throws IOException {
BuildTarget target = BuildTargetFactory.newInstance(targetFqn);
return BuildPaths.getGenDir(workspace.getProjectFileSystem().getBuckPaths(), target);
}

private Path getReportFilePath(String targetFqn, String fileName) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
prebuilt_jar(
name = "jvm-abi-gen",
binary_jar = "jvm-abi-gen.jar",
visibility = ["PUBLIC"],
)
Binary file not shown.

0 comments on commit 088ac2b

Please sign in to comment.