Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
load("@bazel_tools//tools/build_defs/repo:jvm.bzl", "jvm_maven_import_external")

_build_tools_release = "3.3.0"

http_archive(
name = "com_github_bazelbuild_buildtools",
sha256 = "cdaac537b56375f658179ee2f27813cac19542443f4722b6730d84e4125355e6",
strip_prefix = "buildtools-f27d1753c8b3210d9e87cdc9c45bc2739ae2c2db",
url = "https://github.com/bazelbuild/buildtools/archive/f27d1753c8b3210d9e87cdc9c45bc2739ae2c2db.zip",
sha256 = "f11fc80da0681a6d64632a850346ed2d4e5cbb0908306d9a2a2915f707048a10",
strip_prefix = "buildtools-%s" % _build_tools_release,
url = "https://github.com/bazelbuild/buildtools/archive/%s.tar.gz" % _build_tools_release,
)

load("@com_github_bazelbuild_buildtools//buildifier:deps.bzl", "buildifier_dependencies")
Expand Down
4 changes: 2 additions & 2 deletions jmh/jmh.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ def jmh_repositories(maven_servers = _default_maven_server_urls()):
)
_scala_maven_import_external(
name = "io_bazel_rules_scala_net_sf_jopt_simple_jopt_simple",
artifact = "net.sf.jopt-simple:jopt-simple:5.0.3",
artifact_sha256 = "6f45c00908265947c39221035250024f2caec9a15c1c8cf553ebeecee289f342",
artifact = "net.sf.jopt-simple:jopt-simple:4.6",
artifact_sha256 = "3fcfbe3203c2ea521bf7640484fd35d6303186ea2e08e72f032d640ca067ffda",
licenses = ["notice"],
server_urls = maven_servers,
)
Expand Down
20 changes: 4 additions & 16 deletions scala/private/phases/phase_compile.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ load(
)
load(
"@io_bazel_rules_scala//scala/private:rule_impls.bzl",
_compile_java = "compile_java",
_compile_scala = "compile_scala",
_expand_location = "expand_location",
)
Expand Down Expand Up @@ -334,26 +335,13 @@ def _try_to_compile_java_jar(

full_java_jar = ctx.actions.declare_file(ctx.label.name + "_java.jar")

provider = java_common.compile(
provider = _compile_java(
ctx,
source_jars = all_srcjars.to_list(),
source_files = java_srcs,
output = full_java_jar,
javac_opts = _expand_location(
ctx,
ctx.attr.javacopts + ctx.attr.javac_jvm_flags +
java_common.default_javac_opts(
java_toolchain = ctx.attr._java_toolchain[java_common.JavaToolchainInfo],
),
),
deps = providers_of_dependencies,
#exports can be empty since the manually created provider exposes exports
#needs to be empty since we want the provider.compile_jars to only contain the sources ijar
#workaround until https://github.com/bazelbuild/bazel/issues/3528 is resolved
exports = [],
java_toolchain = find_java_toolchain(ctx, ctx.attr._java_toolchain),
host_javabase = find_java_runtime_toolchain(ctx, ctx.attr._host_javabase),
strict_deps = ctx.fragments.java.strict_java_deps,
extra_javac_opts = ctx.attr.javacopts + ctx.attr.javac_jvm_flags,
providers_of_dependencies = providers_of_dependencies,
)

return struct(
Expand Down
24 changes: 24 additions & 0 deletions scala/private/rule_impls.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"""Rules for supporting the Scala language."""

load("@bazel_skylib//lib:paths.bzl", "paths")
load("@bazel_tools//tools/jdk:toolchain_utils.bzl", "find_java_runtime_toolchain", "find_java_toolchain")
load(
":common.bzl",
_collect_plugin_paths = "collect_plugin_paths",
Expand Down Expand Up @@ -209,6 +210,29 @@ StatsfileOutput: {statsfile_output}
] + ["@" + argfile.path],
)

def compile_java(ctx, source_jars, source_files, output, extra_javac_opts, providers_of_dependencies):
return java_common.compile(
ctx,
source_jars = source_jars,
source_files = source_files,
output = output,
javac_opts = expand_location(
ctx,
extra_javac_opts +
java_common.default_javac_opts(
java_toolchain = ctx.attr._java_toolchain[java_common.JavaToolchainInfo],
),
),
deps = providers_of_dependencies,
#exports can be empty since the manually created provider exposes exports
#needs to be empty since we want the provider.compile_jars to only contain the sources ijar
#workaround until https://github.com/bazelbuild/bazel/issues/3528 is resolved
exports = [],
java_toolchain = find_java_toolchain(ctx, ctx.attr._java_toolchain),
host_javabase = find_java_runtime_toolchain(ctx, ctx.attr._host_javabase),
strict_deps = ctx.fragments.java.strict_java_deps,
)

def runfiles_root(ctx):
return "${TEST_SRCDIR}/%s" % ctx.workspace_name

Expand Down
10 changes: 8 additions & 2 deletions src/scala/scripts/ScroogeWorker.scala
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,14 @@ object ScroogeWorker extends Worker.Interface {

val scrooge = new Compiler

if (additionalFlags.contains("--with-finagle")) {
scrooge.flags += WithFinagle
additionalFlags.foreach {
case "--with-finagle" => {
scrooge.flags += WithFinagle
}
case f if f.startsWith("--language=") => {
scrooge.language = f.split("=")(1)
}
case flag => sys.error(s"Unrecognized scrooge flag: ${flag}. This is probably coming from your rule using our custom scrooge wrapper directly. Please modify this wrappers script to correctly handle this additional flag, or remove that flag from the call to the wrapper.")
}

scrooge.compileJars ++= immediateThriftSrcJars
Expand Down
9 changes: 8 additions & 1 deletion test/jmh/BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("@rules_java//java:defs.bzl", "java_library")
load("//scala:scala.bzl", "scala_library")
load("//scala:scala.bzl", "scala_library", "scala_test")
load("//jmh:jmh.bzl", "scala_benchmark_jmh")

java_library(
Expand Down Expand Up @@ -34,3 +34,10 @@ scala_benchmark_jmh(
data = ["data.txt"],
deps = [":add_numbers"],
)

scala_test(
name = "jmh_command_line_parsing_test",
args = ["-h"],
main_class = "org.openjdk.jmh.Main",
deps = [":test_benchmark"],
)
109 changes: 106 additions & 3 deletions test/src/main/scala/scalarules/test/twitter_scrooge/BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("//scala:scala.bzl", "scala_binary", "scala_library")
load("//twitter_scrooge:twitter_scrooge.bzl", "scrooge_scala_library")
load("//twitter_scrooge:twitter_scrooge.bzl", "scrooge_java_library", "scrooge_scala_library")
load("//thrift:thrift.bzl", "thrift_library")
load("//test/src/main/scala/scalarules/test/twitter_scrooge:twitter_scrooge_test.bzl", "twitter_scrooge_test_suite")

Expand All @@ -14,6 +14,28 @@ scrooge_scala_library(
deps = ["//test/src/main/scala/scalarules/test/twitter_scrooge/thrift"],
)

scrooge_scala_library(
name = "scrooge1_scala_and_java",
visibility = ["//visibility:public"],
exports = [
":scrooge2_a",
":scrooge2_b",
":scrooge3_java",
],
deps = ["//test/src/main/scala/scalarules/test/twitter_scrooge/thrift"],
)

scrooge_java_library(
name = "scrooge1_java",
visibility = ["//visibility:public"],
exports = [
":scrooge2_a_java",
":scrooge2_b_java",
":scrooge3_java",
],
deps = ["//test/src/main/scala/scalarules/test/twitter_scrooge/thrift"],
)

scrooge_scala_library(
name = "scrooge2_a",
visibility = ["//visibility:public"],
Expand All @@ -25,6 +47,17 @@ scrooge_scala_library(
],
)

scrooge_java_library(
name = "scrooge2_a_java",
visibility = ["//visibility:public"],
exports = [
":scrooge3_java",
],
deps = [
"//test/src/main/scala/scalarules/test/twitter_scrooge/thrift/thrift2:thrift2_a",
],
)

scrooge_scala_library(
name = "scrooge2_b",
visibility = ["//visibility:public"],
Expand All @@ -36,6 +69,17 @@ scrooge_scala_library(
],
)

scrooge_java_library(
name = "scrooge2_b_java",
visibility = ["//visibility:public"],
exports = [
":scrooge3_java",
],
deps = [
"//test/src/main/scala/scalarules/test/twitter_scrooge/thrift/thrift2:thrift2_b",
],
)

scrooge_scala_library(
name = "scrooge2_b_imp",
deps = [
Expand All @@ -49,6 +93,12 @@ scrooge_scala_library(
deps = ["//test/src/main/scala/scalarules/test/twitter_scrooge/thrift/thrift2/thrift3"],
)

scrooge_java_library(
name = "scrooge3_java",
visibility = ["//visibility:public"],
deps = ["//test/src/main/scala/scalarules/test/twitter_scrooge/thrift/thrift2/thrift3"],
)

scrooge_scala_library(
name = "scrooge2",
visibility = ["//visibility:public"],
Expand Down Expand Up @@ -200,6 +250,46 @@ scala_binary(
deps = [":allscrooges"],
)

scala_library(
name = "allscrooges_java",
exports = [
":scrooge1_java",
":scrooge2_a_java",
":scrooge2_b_java",
":scrooge3_java",
],
)

java_binary(
name = "justscrooges_java",
srcs = ["JustScrooge1.java"],
main_class = "scalarules.test.twitter_scrooge.JustScrooge1",
visibility = ["//visibility:public"],
deps = [":allscrooges_java"],
)

scala_library(
name = "allscrooges_scala_and_java",
exports = [
":scrooge1",
":scrooge1_java",
":scrooge2_a",
":scrooge2_a_java",
":scrooge2_b",
":scrooge2_b_java",
":scrooge3",
":scrooge3_java",
],
)

java_binary(
name = "justscrooges_scala_and_java",
srcs = ["JustScrooge1.java"],
main_class = "scalarules.test.twitter_scrooge.JustScrooge1",
visibility = ["//visibility:public"],
deps = [":allscrooges_scala_and_java"],
)

scala_library(
name = "barethriftslib",
srcs = ["BareThrifts.scala"],
Expand All @@ -215,8 +305,9 @@ scala_binary(

sh_test(
name = "libthrift2_a_not_on_classpath",
srcs = ["grep.sh"],
srcs = ["string_in_file.sh"],
args = [
"false",
"libthrift2_a",
"$(location :justscrooges)",
],
Expand All @@ -225,12 +316,24 @@ sh_test(

sh_test(
name = "java_jar_not_on_classpath",
srcs = ["grep.sh"],
srcs = ["string_in_file.sh"],
args = [
"false",
"_java.jar",
"$(location :justscrooges)",
],
data = [":justscrooges"],
)

sh_test(
name = "java_jar_on_classpath_in_scrooges",
srcs = ["string_in_file.sh"],
args = [
"true",
"_java.jar",
"$(location :justscrooges_java)",
],
data = [":justscrooges_java"],
)

twitter_scrooge_test_suite()
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package scalarules.test.twitter_scrooge;

import scalarules.test.twitter_scrooge.thrift.Struct1;
import scalarules.test.twitter_scrooge.thrift.thrift2.Struct2A;
import scalarules.test.twitter_scrooge.thrift.thrift2.Struct2B;
import scalarules.test.twitter_scrooge.thrift.thrift2.thrift3.Struct3;

public class JustScrooge1 {
public static void main(String[] args) {
}
}
13 changes: 0 additions & 13 deletions test/src/main/scala/scalarules/test/twitter_scrooge/grep.sh

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/sh

# This is used by a sh_test to test whether a string is
# found in a file.
#
# Args:
# . $1: Whether the string should be in the file (accepted values are "true" or "false")
# . $2: String to look for in the file.
# . $3: File to look the string into.
#
# This is used for instance to check if
# stray jars are not making it onto the classpath

should_be_in_file=$1

if test "$should_be_in_file" != "true" -a "$should_be_in_file" != "false" ; then
echo "ERROR: Please use only (\"true\" or \"false\") to specify whether you need the substring to be in the file."
echo "Refer to test/src/main/scala/scalarules/test/twitter_scrooge/string_in_file.sh for documentation."
exit 1
fi

if grep -q $2 $3 ; then
if test "$should_be_in_file" = "true" ; then
exit 0
else
echo "ERROR: Found string $2 in $3, when we were expecting not to find it."
exit 1
fi
else
if test "$should_be_in_file" = "true" ; then
echo "ERROR: Not found string $2 in $3, when we were expecting to find it."
exit 1
else
exit 0
fi
fi
Loading