Skip to content
Closed
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
bazel-*
.idea
hash1
hash2
*.iml
3 changes: 3 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
workspace(name = "io_bazel_rules_scala")

load("//specs2:specs2.bzl", "specs2")
specs2()

load("//scala:scala.bzl", "scala_repositories", "scala_mvn_artifact")
scala_repositories()

Expand Down
66 changes: 65 additions & 1 deletion scala/scala.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,28 @@ def _write_test_launcher(ctx, jars):
output=ctx.outputs.executable,
content=content)

def _write_specs2_launcher(ctx, jars):
cmd = "{n1} {java} -cp {cp} {test_runner}"
runner = ctx.attr.main_class
# -n1 - a parameter for xargs that we need to run specs2.run tests. It will execute runner separately for each test.
n1 = " -n1" if runner.strip() == "specs2.run" else ""

# read all *Spec.class files from the jar and run them
content = """#!/bin/bash
jar -tf """+ ctx.outputs.jar.short_path + """ | grep 'Spec.class$' | sed 's~/~.~g;s/.\{6\}$//' | xargs """

cmd = cmd.format(
n1 = n1,
test_runner = ctx.attr.main_class,
java=ctx.file._java.short_path,
cp=":".join([j.short_path for j in jars]))

content = content + cmd

ctx.file_action(
output=ctx.outputs.executable,
content=content)

def collect_srcjars(targets):
srcjars = set()
for target in targets:
Expand Down Expand Up @@ -462,6 +484,18 @@ def _scala_test_impl(ctx):
_write_test_launcher(ctx, rjars)
return _scala_binary_common(ctx, cjars, rjars)

def _scala_specs2_test_impl(ctx):
deps = ctx.attr.deps
jars = _collect_jars(deps)
(cjars, rjars) = (jars.compiletime, jars.runtime)
rjars += [ctx.outputs.jar]
rjars += _collect_jars(ctx.attr.runtime_deps).runtime
# Add all jars required for specs2 to runtime and compile time classpath
cjars += ctx.attr._specs2_all.java.transitive_runtime_deps
rjars += ctx.attr._specs2_all.java.transitive_runtime_deps
_write_specs2_launcher(ctx, rjars)
return _scala_binary_common(ctx, cjars, rjars)

_implicit_deps = {
"_ijar": attr.label(executable=True, default=Label("@bazel_tools//tools/jdk:ijar"), single_file=True, allow_files=True),
"_scala": attr.label(executable=True, default=Label("@scala//:bin/scala"), single_file=True, allow_files=True),
Expand All @@ -476,7 +510,6 @@ _implicit_deps = {
"_jar_bin": attr.label(executable=True, default=Label("//src/java/io/bazel/rulesscala/jar")),
"_jdk": attr.label(default=Label("//tools/defaults:jdk"), allow_files=True),
}

# Common attributes reused across multiple rules.
_common_attrs = {
"srcs": attr.label_list(
Expand Down Expand Up @@ -548,6 +581,36 @@ scala_test = rule(
test=True,
)

scala_specs2_test = rule(
implementation=_scala_specs2_test_impl,
attrs={
"main_class": attr.string(default="specs2.run"),
"_specs2_all": attr.label(default=Label("//specs2:specs2_all"), allow_files=True),
} + _implicit_deps + _common_attrs,
outputs={
"jar": "%{name}.jar",
"deploy_jar": "%{name}_deploy.jar",
"manifest": "%{name}_MANIFEST.MF",
},
executable=True,
test=True,
)

scala_specs2_junit_test = rule(
implementation=_scala_specs2_test_impl,
attrs={
"main_class": attr.string(default="org.junit.runner.JUnitCore"),
"_specs2_all": attr.label(default=Label("//specs2:specs2_with_junit"), allow_files=True),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we can just have a junit target, and then in a macro, etc... have junit + specs. Some might just want to run a junit test without any specs.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and/or the target can be a bind variable, and the users can set up what to point to.

} + _implicit_deps + _common_attrs,
outputs={
"jar": "%{name}.jar",
"deploy_jar": "%{name}_deploy.jar",
"manifest": "%{name}_MANIFEST.MF",
},
executable=True,
test=True,
)

scala_repl = rule(
implementation=_scala_repl_impl,
attrs= _implicit_deps + _common_attrs,
Expand Down Expand Up @@ -611,6 +674,7 @@ def scala_repositories():
sha256 = "f198967436a5e7a69cfd182902adcfbcb9f2e41b349e1a5c8881a2407f615962",
)


def scala_export_to_java(name, exports, runtime_deps):
jars = []
for target in exports:
Expand Down
38 changes: 38 additions & 0 deletions specs2/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
java_library(
name = "specs2_all",
visibility = ["//visibility:public"],
exports = [
"@org_specs2_specs2_core_2_11//jar",
"@org_scala_lang_modules_scala_parser_combinators_2_11//jar",
"@org_scala_lang_modules_scala_xml_2_11//jar",
"@org_scala_lang_scala_library//jar",
"@org_scala_lang_scala_reflect//jar",
"@org_scalaz_scalaz_concurrent_2_11//jar",
"@org_scalaz_scalaz_core_2_11//jar",
"@org_scalaz_scalaz_effect_2_11//jar",
"@org_specs2_specs2_codata_2_11//jar",
"@org_specs2_specs2_common_2_11//jar",
"@org_specs2_specs2_matcher_2_11//jar",
],
)

java_library(
name = "specs2_with_junit",
visibility = ["//visibility:public"],
exports = [
"@org_specs2_specs2_junit_2_11//jar",
"@junit_junit//jar",
"@org_hamcrest_hamcrest_core//jar",
"@org_scala_lang_modules_scala_parser_combinators_2_11//jar",
"@org_scala_lang_modules_scala_xml_2_11//jar",
"@org_scala_lang_scala_library//jar",
"@org_scala_lang_scala_reflect//jar",
"@org_scalaz_scalaz_concurrent_2_11//jar",
"@org_scalaz_scalaz_core_2_11//jar",
"@org_scalaz_scalaz_effect_2_11//jar",
"@org_specs2_specs2_codata_2_11//jar",
"@org_specs2_specs2_common_2_11//jar",
"@org_specs2_specs2_core_2_11//jar",
"@org_specs2_specs2_matcher_2_11//jar",
],
)
112 changes: 112 additions & 0 deletions specs2/specs2.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
def specs2():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be called spec2_repositories or something like that.


# org.specs2:specs2-common_2.11:jar:3.8.4
native.maven_jar(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is already in the @scala target. Can we not use that one?

name = "org_scala_lang_modules_scala_parser_combinators_2_11",
artifact = "org.scala-lang.modules:scala-parser-combinators_2.11:1.0.4",
sha1 = "7369d653bcfa95d321994660477a4d7e81d7f490",
)

# org.specs2:specs2-common_2.11:jar:3.8.4
native.maven_jar(
name = "org_specs2_specs2_codata_2_11",
artifact = "org.specs2:specs2-codata_2.11:3.8.4",
sha1 = "d73d5caeb5cf064d275bf1511b68ab5a13030649",
)

# org.scalaz:scalaz-concurrent_2.11:bundle:7.2.3
# org.scalaz:scalaz-effect_2.11:bundle:7.2.3
# org.specs2:specs2-common_2.11:jar:3.8.4
# org.specs2:specs2-codata_2.11:jar:3.8.4
native.maven_jar(
name = "org_scalaz_scalaz_core_2_11",
artifact = "org.scalaz:scalaz-core_2.11:7.2.3",
sha1 = "58d29a4615430829ef116e86de12327a17fe4827",
)

native.maven_jar(
name = "org_specs2_specs2_core_2_11",
artifact = "org.specs2:specs2-core_2.11:3.8.4",
)

# org.specs2:specs2-common_2.11:jar:3.8.4
# org.specs2:specs2-core_2.11:jar:3.8.4
native.maven_jar(
name = "org_scala_lang_scala_reflect",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should use the one in the @scala target.

artifact = "org.scala-lang:scala-reflect:2.11.8",
sha1 = "b74530deeba742ab4f3134de0c2da0edc49ca361",
)

# org.specs2:specs2-core_2.11:jar:3.8.4
native.maven_jar(
name = "org_specs2_specs2_matcher_2_11",
artifact = "org.specs2:specs2-matcher_2.11:3.8.4",
sha1 = "51f382c7306cc57aab270e0f4089803dc35a7b1e",
)

# org.specs2:specs2-matcher_2.11:jar:3.8.4
native.maven_jar(
name = "org_specs2_specs2_common_2_11",
artifact = "org.specs2:specs2-common_2.11:3.8.4",
sha1 = "f3b280746b585b6872ef5ada0d78420b54226dfe",
)

# org.specs2:specs2-common_2.11:jar:3.8.4
native.maven_jar(
name = "org_scala_lang_modules_scala_xml_2_11",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use the one in the @scala target.

artifact = "org.scala-lang.modules:scala-xml_2.11:1.0.5",
sha1 = "77ac9be4033768cf03cc04fbd1fc5e5711de2459",
)

# org.specs2:specs2-matcher_2.11:jar:3.8.4
# org.scalaz:scalaz-concurrent_2.11:bundle:7.2.3
# org.scala-lang.modules:scala-xml_2.11:bundle:1.0.5 wanted version 2.11.7
# org.scalaz:scalaz-effect_2.11:bundle:7.2.3
# org.scalaz:scalaz-core_2.11:bundle:7.2.3
# org.scala-lang:scala-reflect:jar:2.11.8
# org.specs2:specs2-common_2.11:jar:3.8.4
# org.specs2:specs2-codata_2.11:jar:3.8.4
# org.specs2:specs2-core_2.11:jar:3.8.4
# org.scala-lang.modules:scala-parser-combinators_2.11:bundle:1.0.4 wanted version 2.11.6
native.maven_jar(
name = "org_scala_lang_scala_library",
artifact = "org.scala-lang:scala-library:2.11.8",
sha1 = "ddd5a8bced249bedd86fb4578a39b9fb71480573",
)

# org.specs2:specs2-common_2.11:jar:3.8.4
# org.specs2:specs2-codata_2.11:jar:3.8.4
native.maven_jar(
name = "org_scalaz_scalaz_concurrent_2_11",
artifact = "org.scalaz:scalaz-concurrent_2.11:7.2.3",
sha1 = "4788f84d28f8de6783b60c91de6da14f85980bca",
)

# org.scalaz:scalaz-concurrent_2.11:bundle:7.2.3
# org.specs2:specs2-common_2.11:jar:3.8.4
# org.specs2:specs2-codata_2.11:jar:3.8.4
native.maven_jar(
name = "org_scalaz_scalaz_effect_2_11",
artifact = "org.scalaz:scalaz-effect_2.11:7.2.3",
sha1 = "8ab944e32781a44f2aecba99d392c3142b25af1c",
)

# Aditional dependencies for specs2 junit runner
native.maven_jar(
name = "org_specs2_specs2_junit_2_11",
artifact = "org.specs2:specs2-junit_2.11:3.8.4",
)

# org.specs2:specs2-junit_2.11:jar:3.8.4
native.maven_jar(
name = "junit_junit",
artifact = "junit:junit:4.12",
sha1 = "2973d150c0dc1fefe998f834810d68f278ea58ec",
)

# junit:junit:jar:4.12
native.maven_jar(
name = "org_hamcrest_hamcrest_core",
artifact = "org.hamcrest:hamcrest-core:1.3",
sha1 = "42a25dc3219429f0e5d060061f71acb49bf010a0",
)