Skip to content

Commit

Permalink
Scrooge-generator-tests: Bazel migration
Browse files Browse the repository at this point in the history
Problem/Solution

We need to migrate scrooge-generator-tests to bazel, including the workflow.

JIRA Issues: CSL-11969

Differential Revision: https://phabricator.twitter.biz/D913683
  • Loading branch information
heligw authored and jenkins committed Jun 30, 2022
1 parent 00f60f3 commit c37077b
Show file tree
Hide file tree
Showing 22 changed files with 93 additions and 81 deletions.
1 change: 1 addition & 0 deletions scrooge-generator-tests/BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
test_suite(
name = "tests",
tags = ["bazel-compatible"],
dependencies = [
"scrooge/scrooge-generator-tests/src/test/scala",
],
Expand Down
15 changes: 15 additions & 0 deletions scrooge-generator-tests/src/test/resources/BUILD
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
resources(
sources = [
"!**/*.pyc",
"!BUILD*",
#"!test_thrift/**/*",
"!gold_file_output_*/**/*",
"!test_thrift/swift/swift.thrift",
"!gold_file_input/gold.thrift",
"!test_thrift/cocoa.thrift",
"**/*",
],
tags = ["bazel-compatible"],
)

files(
name = "files",
sources = [
"!**/*.pyc",
"!BUILD*",
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
resources(sources = ["**/*.swift"])
resources(
sources = ["**/*.swift"],
tags = ["bazel-compatible"],
)
3 changes: 2 additions & 1 deletion scrooge-generator-tests/src/test/scala/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ junit_tests(
# and instead 'depend' on them
sources = ["**/*.scala"] + exclude_globs(LIB_SOURCES),
compiler_option_sets = ["fatal_warnings"],
tags = ["bazel-compatible"],
dependencies = [
":lib",
"3rdparty/jvm/cglib",
"3rdparty/jvm/com/github/spullara/mustache/java",
"3rdparty/jvm/com/google/guava",
"3rdparty/jvm/junit",
"3rdparty/jvm/org/apache/thrift:libthrift",
"3rdparty/jvm/org/hamcrest:hamcrest-core",
"3rdparty/jvm/org/jmock",
"3rdparty/jvm/org/jmock:jmock-legacy",
Expand All @@ -68,6 +68,7 @@ junit_tests(
"scrooge/scrooge-core",
"scrooge/scrooge-generator",
"scrooge/scrooge-generator-tests/src/test/resources",
"scrooge/scrooge-generator-tests/src/test/resources:files",
"scrooge/scrooge-generator-tests/src/test/thrift",
"scrooge/scrooge-generator-tests/src/test/thrift:constant-sets-thrift-bazel-workaround-android",
"scrooge/scrooge-generator-tests/src/test/thrift:constant-sets-thrift-scala",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@ import com.twitter.scrooge.Main
import java.io._
import com.google.common.base.Charsets
import com.google.common.io.CharStreams
import com.twitter.scrooge.testutil.{Spec, TempDirectory}
import com.twitter.scrooge.testutil.Spec
import com.twitter.scrooge.testutil.TempDirectory
import com.twitter.scrooge.testutil.Utils.verify

class CocoaGeneratorSpec extends Spec {

val templateFiles = List(
"cocoa_output/TFNTwitterThriftScribeAnotherTestStruct.h",
"cocoa_output/TFNTwitterThriftScribeAnotherTestStruct.m",
"cocoa_output/TFNTwitterThriftScribeTestEnum.h",
"cocoa_output/TFNTwitterThriftScribeTestStruct.h",
"cocoa_output/TFNTwitterThriftScribeTestStruct.m",
"cocoa_output/TFNTwitterThriftScribeTestEmptyStruct.h",
"cocoa_output/TFNTwitterThriftScribeTestEmptyStruct.m"
"scrooge/scrooge-generator-tests/src/test/resources/cocoa_output/TFNTwitterThriftScribeAnotherTestStruct.h",
"scrooge/scrooge-generator-tests/src/test/resources/cocoa_output/TFNTwitterThriftScribeAnotherTestStruct.m",
"scrooge/scrooge-generator-tests/src/test/resources/cocoa_output/TFNTwitterThriftScribeTestEnum.h",
"scrooge/scrooge-generator-tests/src/test/resources/cocoa_output/TFNTwitterThriftScribeTestStruct.h",
"scrooge/scrooge-generator-tests/src/test/resources/cocoa_output/TFNTwitterThriftScribeTestStruct.m",
"scrooge/scrooge-generator-tests/src/test/resources/cocoa_output/TFNTwitterThriftScribeTestEmptyStruct.h",
"scrooge/scrooge-generator-tests/src/test/resources/cocoa_output/TFNTwitterThriftScribeTestEmptyStruct.m"
).map { new File(_) }

def getFileContents(resource: String): String = {
Expand All @@ -40,9 +41,7 @@ class CocoaGeneratorSpec extends Spec {

"Cocoa generator" should {
val tempDir = TempDirectory.create(None)

val ccl = Thread.currentThread().getContextClassLoader
val inputThrift = ccl.getResource("test_thrift/cocoa.thrift").getPath()
val inputThrift = "scrooge/scrooge-generator-tests/src/test/resources/test_thrift/cocoa.thrift"

val args = Array[String]("-l", "cocoa", "-d", tempDir.getPath, inputThrift)
Main.main(args)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,7 @@ abstract class GoldFileTest extends AnyFunSuite with BeforeAndAfterAll {
println(s"Temp dir $tempDir")
}

val ccl = Thread.currentThread().getContextClassLoader

val inputThrifts = testThriftFiles.map { r =>
Option(ccl.getResource(r))
.getOrElse(sys.error(s"Couldn't find resource: $r"))
.getPath
}
val inputThrifts = testThriftFiles

val args = Seq(
"--language",
Expand Down Expand Up @@ -88,8 +82,10 @@ abstract class GoldFileTest extends AnyFunSuite with BeforeAndAfterAll {
accumulate(f, Vector.empty)
}

protected def testThriftFiles = Seq("gold_file_input/gold.thrift")
protected def goldFilesRoot: String = s"gold_file_output_$language"
protected def testThriftFiles = Seq(
"scrooge/scrooge-generator-tests/src/test/resources/gold_file_input/gold.thrift")
protected def goldFilesRoot: String =
s"scrooge/scrooge-generator-tests/src/test/resources/gold_file_output_$language"

protected def diff(
gold: InputStream,
Expand Down Expand Up @@ -152,8 +148,6 @@ abstract class GoldFileTest extends AnyFunSuite with BeforeAndAfterAll {

test("generated output looks as expected") {
if (exception.isEmpty) {
val ccl = Thread.currentThread().getContextClassLoader

generatedFiles.foreach { gen =>
// We want to take the path after tempDir and compare to the gold file
// in our resources dir. The +1 removes what would be a leading slash
Expand All @@ -162,7 +156,9 @@ abstract class GoldFileTest extends AnyFunSuite with BeforeAndAfterAll {

withClue(genRelPath) {
val genStream = new ByteArrayInputStream(Files.readBytes(gen))
val goldStream = ccl.getResourceAsStream(s"$goldFilesRoot/$genRelPath")
val goldStream = new java.io.FileInputStream(
new java.io.File(s"$goldFilesRoot/$genRelPath")
)
diff(goldStream, genStream, gen.getName, genRelPath)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ class LuaGoldFileTest extends GoldFileTest {

protected def language: String = LuaGeneratorFactory.language

override def testThriftFiles = super.testThriftFiles :+ "test_thrift/lua.thrift"
override def testThriftFiles =
super.testThriftFiles :+ "scrooge/scrooge-generator-tests/src/test/resources/test_thrift/lua.thrift"
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,14 @@ class SwiftGeneratorSpec extends Spec {
val tempDir = TempDirectory.create(None)

val ccl = Thread.currentThread().getContextClassLoader
val inputThrift = ccl.getResource("test_thrift/swift/swift.thrift").getPath
val inputThrift =
"scrooge/scrooge-generator-tests/src/test/resources/test_thrift/swift/swift.thrift"

val args = Array[String]("-l", "swift", "-d", tempDir.getPath, inputThrift)
Main.main(args)

val output_dir = tempDir.getPath
val output_flist =
getListOfFiles(new File(ccl.getResource("gold_file_output_swift/output/Swift").getPath))
getListOfFiles(new File(output_dir))
val generated_flist = getListOfFiles(tempDir)

"generate some .swift files" in {
Expand All @@ -82,7 +83,8 @@ class SwiftGeneratorSpec extends Spec {
val tempDir = TempDirectory.create(None)

val ccl = Thread.currentThread().getContextClassLoader
val inputThrift = ccl.getResource("test_thrift/swift/swift.thrift").getPath
val inputThrift =
"scrooge/scrooge-generator-tests/src/test/resources/test_thrift/swift/swift.thrift"

val args =
Array[String](
Expand All @@ -94,12 +96,10 @@ class SwiftGeneratorSpec extends Spec {
tempDir.getPath,
inputThrift)
Main.main(args)

val output_dir = tempDir.getPath
val output_flist =
getListOfFiles(
new File(ccl.getResource("gold_file_output_swift/output/Swift-Classes").getPath))
getListOfFiles(new File(output_dir))
val generated_flist = getListOfFiles(tempDir)

"generate some .swift files" in {
assert(
output_flist.size == generated_flist.size,
Expand All @@ -123,7 +123,8 @@ class SwiftGeneratorSpec extends Spec {
val tempDir = TempDirectory.create(None)

val ccl = Thread.currentThread().getContextClassLoader
val inputThrift = ccl.getResource("test_thrift/swift/swift.thrift").getPath
val inputThrift =
"scrooge/scrooge-generator-tests/src/test/resources/test_thrift/swift/swift.thrift"

val args =
Array[String](
Expand All @@ -135,10 +136,9 @@ class SwiftGeneratorSpec extends Spec {
tempDir.getPath,
inputThrift)
Main.main(args)

val output_dir = tempDir.getPath
val output_flist =
getListOfFiles(
new File(ccl.getResource("gold_file_output_swift/output/Swift-Internal").getPath))
getListOfFiles(new File(output_dir))
val generated_flist = getListOfFiles(tempDir)

"generate some .swift files" in {
Expand All @@ -164,7 +164,8 @@ class SwiftGeneratorSpec extends Spec {
val tempDir = TempDirectory.create(None)

val ccl = Thread.currentThread().getContextClassLoader
val inputThrift = ccl.getResource("test_thrift/swift/swift.thrift").getPath
val inputThrift =
"scrooge/scrooge-generator-tests/src/test/resources/test_thrift/swift/swift.thrift"

val args =
Array[String](
Expand All @@ -176,9 +177,9 @@ class SwiftGeneratorSpec extends Spec {
tempDir.getPath,
inputThrift)
Main.main(args)

val output_dir = tempDir.getPath
val output_flist =
getListOfFiles(new File(ccl.getResource("gold_file_output_swift/output/ObjC").getPath))
getListOfFiles(new File(output_dir))
val generated_flist = getListOfFiles(tempDir)

"generate some .swift files" in {
Expand All @@ -205,13 +206,13 @@ class SwiftGeneratorSpec extends Spec {

val ccl = Thread.currentThread().getContextClassLoader
val inputThrift =
ccl.getResource("test_thrift/swift/alternative_type.thrift").getPath
"scrooge/scrooge-generator-tests/src/test/resources/test_thrift/swift/alternative_type.thrift"

val args = Array[String]("-l", "swift", "-d", tempDir.getPath, inputThrift)
Main.main(args)

val output_dir = tempDir.getPath
val output_flist =
getListOfFiles(new File(ccl.getResource("gold_file_output_swift/output/Swift-type").getPath))
getListOfFiles(new File(output_dir))
val generated_flist = getListOfFiles(tempDir)

"generate some .swift files" in {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ scala_library(
"*.java",
"*.scala",
],
tags = ["bazel-compatible"],
dependencies = [
"scrooge/scrooge-core/src/main/scala",
],
Expand Down
5 changes: 2 additions & 3 deletions scrooge-generator-tests/src/test/thrift/BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
resources(
sources = ["*"],
tags = ["bazel-compatible"],
dependencies = [
"scrooge/scrooge-generator-tests/src/test/thrift/airport:resources",
"scrooge/scrooge-generator-tests/src/test/thrift/android_integration:resources",
Expand Down Expand Up @@ -27,7 +28,5 @@ java_thrift_library(
compiler = "scrooge",
default_java_namespace = "android_thrift_default_namespace",
language = "android",
dependencies = [
"3rdparty/jvm/org/apache/thrift:libthrift",
],
tags = ["bazel-compatible"],
)
10 changes: 4 additions & 6 deletions scrooge-generator-tests/src/test/thrift/airport/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ java_thrift_library(
sources = ["*.thrift"],
compiler = "scrooge",
language = "android",
dependencies = [
"3rdparty/jvm/org/apache/thrift:libthrift",
],
tags = ["bazel-compatible"],
)

# namespaced and non-Finagle
Expand All @@ -28,6 +26,7 @@ java_thrift_library(
"thrift.test1": "vanilla.test1",
"thrift.test2": "vanilla.test2",
},
tags = ["bazel-compatible"],
)

java_thrift_library(
Expand All @@ -41,12 +40,11 @@ java_thrift_library(
"androidthrift.test1": "vanilla_android.test1",
"androidthrift.test2": "vanilla_android.test2",
},
dependencies = [
"3rdparty/jvm/org/apache/thrift:libthrift",
],
tags = ["bazel-compatible"],
)

resources(
name = "resources",
sources = ["*.thrift"],
tags = ["bazel-compatible"],
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ java_thrift_library(
sources = ["*.thrift"],
compiler = "scrooge",
language = "android",
dependencies = [
"3rdparty/jvm/org/apache/thrift:libthrift",
],
tags = ["bazel-compatible"],
)

resources(
name = "resources",
sources = ["*.thrift"],
tags = ["bazel-compatible"],
)
5 changes: 2 additions & 3 deletions scrooge-generator-tests/src/test/thrift/defaults/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@ java_thrift_library(
compiler = "scrooge",
default_java_namespace = "apache_java_thrift",
language = "android",
dependencies = [
"3rdparty/jvm/org/apache/thrift:libthrift",
],
tags = ["bazel-compatible"],
)

resources(
name = "resources",
sources = ["*.thrift"],
tags = ["bazel-compatible"],
)
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ create_thrift_libraries(
resources(
name = "resources",
sources = ["*.thrift"],
tags = ["bazel-compatible"],
)
6 changes: 3 additions & 3 deletions scrooge-generator-tests/src/test/thrift/integration/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ java_thrift_library(
"thrift.test": "com.twitter.scrooge.integration_android",
"com.twitter.scrooge.integration_scala": "com.twitter.scrooge.integration_android",
},
dependencies = [
"3rdparty/jvm/org/apache/thrift:libthrift",
],
tags = ["bazel-compatible"],
)

java_thrift_library(
Expand All @@ -37,9 +35,11 @@ java_thrift_library(
"thrift.test": "com.twitter.scrooge.integration_apache",
"com.twitter.scrooge.integration_scala": "com.twitter.scrooge.integration_apache",
},
tags = ["bazel-compatible"],
)

resources(
name = "resources",
sources = ["*.thrift"],
tags = ["bazel-compatible"],
)
5 changes: 2 additions & 3 deletions scrooge-generator-tests/src/test/thrift/namespace/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@ java_thrift_library(
"bar": "android_bar",
"com.fake": "com.android_fake",
},
dependencies = [
"3rdparty/jvm/org/apache/thrift:libthrift",
],
tags = ["bazel-compatible"],
)

resources(
name = "resources",
sources = ["*.thrift"],
tags = ["bazel-compatible"],
)

0 comments on commit c37077b

Please sign in to comment.