Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scala2_12 merge from master #435

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
375b34a
jmh normalizes jar timestamps (#396)
ittaiz Jan 18, 2018
77fd23d
fix e2e
ittaiz Jan 18, 2018
7d02925
Merge pull request #398 from ittaiz/fixup_tests
johnynek Jan 19, 2018
7522c86
Emit a the Scala compilation time for downstream metrics (#406)
andyscott Jan 24, 2018
98dc457
Adds the _java_runtime attribute to fix toolchain use in Scala. (#409)
sethkoehler Feb 2, 2018
f257275
Update README scala version to latest HEAD (#414)
jjudd Feb 6, 2018
7c5209d
Add struct members that IntelliJ plugin expects to exist
Feb 6, 2018
827124a
Put the statsfile output in the rule output struct
andyscott Jan 26, 2018
24bc74b
Use OS-specific classpath separator
cgbystrom Feb 10, 2018
dbe55fb
Adding an overload that is called dynamically, in case we’re running …
Feb 18, 2018
8c1f7d0
use transitive_proto_path_flags if exist (#425)
ittaiz Feb 20, 2018
d160afe
add new bazelci configuration
buchgr Feb 23, 2018
8de9f02
Add default javac opts when compiling java srcs
Mar 1, 2018
cf5adf5
Compile reporter using very strict settings
andyscott Mar 1, 2018
1df220c
Merge pull request #433 from andyscott/go-strict-for-bootstrap-code
johnynek Mar 1, 2018
55c5bd2
Merge pull request #431 from anchlovi/reslove-javacopts
johnynek Mar 1, 2018
9151c62
adjust transitive_proto_path_flags skylark name to transitive_proto_path
ittaiz Mar 3, 2018
38bc14c
Merge pull request #434 from ittaiz/adjust_transitive_proto_path
johnynek Mar 4, 2018
efffa52
Allow files for scala_import (#411)
jjudd Mar 6, 2018
e491469
merge commits
or-shachar Mar 6, 2018
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
17 changes: 17 additions & 0 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
platforms:
ubuntu1404:
build_targets:
- "//test/..."
test_targets:
- "//test/..."
ubuntu1604:
build_targets:
- "//test/..."
test_targets:
- "//test/..."
macos:
build_targets:
- "//test/..."
test_targets:
- "//test/..."
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Scala Rules for Bazel
[![Build Status](https://travis-ci.org/bazelbuild/rules_scala.svg?branch=master)](https://travis-ci.org/bazelbuild/rules_scala) [![Build Status](https://ci.bazel.io/buildStatus/icon?job=rules_scala)](https://ci.bazel.io/job/rules_scala)
[![Build Status](https://travis-ci.org/bazelbuild/rules_scala.svg?branch=master)](https://travis-ci.org/bazelbuild/rules_scala) [![Build status](https://badge.buildkite.com/90ce5244556df74db805a3c24a703fb87458396f9e1ddd687e.svg)](https://buildkite.com/bazel/scala-rules-scala-postsubmit)

<div class="toc">
<h2>Rules</h2>
Expand All @@ -24,7 +24,7 @@ you must have bazel 0.5.3 or later and add the following to your WORKSPACE file:

```python

rules_scala_version="5cdae2f034581a05e23c3473613b409de5978833" # update this as needed
rules_scala_version="98dc457356c60b23ccbbdcbf73acfad9e15e8b07" # update this as needed

http_archive(
name = "io_bazel_rules_scala",
Expand Down
62 changes: 42 additions & 20 deletions scala/scala.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,18 @@ def _build_nosrc_jar(ctx, buildijar):
cmd = """
rm -f {jar_output}
{zipper} c {jar_output} @{path}
# ensures that empty src targets still emit a statsfile
touch {statsfile}
""" + ijar_cmd

cmd = cmd.format(
path = zipper_arg_path.path,
jar_output=ctx.outputs.jar.path,
zipper=ctx.executable._zipper.path,
statsfile=ctx.outputs.statsfile.path,
)

outs = [ctx.outputs.jar]
outs = [ctx.outputs.jar, ctx.outputs.statsfile]
if buildijar:
outs.extend([ctx.outputs.ijar])

Expand Down Expand Up @@ -186,7 +189,8 @@ CurrentTarget: {current_target}

plugin_arg = ",".join(list(plugins))

compiler_classpath = ":".join([j.path for j in compiler_classpath_jars])
separator = ctx.configuration.host_path_separator
compiler_classpath = separator.join([j.path for j in compiler_classpath_jars])

toolchain = ctx.toolchains['@io_bazel_rules_scala//scala:toolchain_type']
# always append -YdisableFlatCpCaching, workaround for
Expand Down Expand Up @@ -215,6 +219,7 @@ ResourceStripPrefix: {resource_strip_prefix}
ScalacOpts: {scala_opts}
SourceJars: {srcjars}
DependencyAnalyzerMode: {dependency_analyzer_mode}
StatsfileOutput: {statsfile_output}
""".format(
out=ctx.outputs.jar.path,
manifest=ctx.outputs.manifest.path,
Expand All @@ -236,6 +241,7 @@ DependencyAnalyzerMode: {dependency_analyzer_mode}
resource_strip_prefix=ctx.attr.resource_strip_prefix,
resource_jars=",".join([f.path for f in ctx.files.resource_jars]),
dependency_analyzer_mode = dependency_analyzer_mode,
statsfile_output = ctx.outputs.statsfile.path
)
argfile = ctx.new_file(
ctx.outputs.jar,
Expand All @@ -244,12 +250,9 @@ DependencyAnalyzerMode: {dependency_analyzer_mode}

ctx.file_action(output=argfile, content=scalac_args + optional_scalac_args)

outs = [ctx.outputs.jar]
outs = [ctx.outputs.jar, ctx.outputs.statsfile]
if buildijar:
outs.extend([ctx.outputs.ijar])
# _java_toolchain added manually since _java doesn't currently setup runfiles
# _scalac, as a java_binary, should already have it in its runfiles; however,
# adding does ensure _java not orphaned if _scalac ever was not a java_binary
ins = (list(compiler_classpath_jars) +
list(dep_srcjars) +
list(srcjars) +
Expand All @@ -259,10 +262,9 @@ DependencyAnalyzerMode: {dependency_analyzer_mode}
dependency_analyzer_plugin_jars +
ctx.files.resources +
ctx.files.resource_jars +
ctx.files._java_toolchain +
ctx.files._java_runtime +
[ctx.outputs.manifest,
ctx.executable._ijar,
ctx.executable._java,
argfile])
ctx.action(
inputs=ins,
Expand Down Expand Up @@ -333,7 +335,7 @@ def try_to_compile_java_jar(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),
javac_opts = _expand_location(ctx, ctx.attr.javacopts + ctx.attr.javac_jvm_flags + java_common.default_javac_opts(ctx, java_toolchain_attr = "_java_toolchain")),
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
Expand Down Expand Up @@ -409,13 +411,34 @@ def write_manifest(ctx):
output=ctx.outputs.manifest,
content=manifest)

def _path_is_absolute(path):
# Returns true for absolute path in Linux/Mac (i.e., '/') or Windows (i.e.,
# 'X:\' or 'X:/' where 'X' is a letter), false otherwise.
if len(path) >= 1 and path[0] == "/":
return True
if len(path) >= 3 \
and path[0].isalpha() \
and path[1] == ":" \
and (path[2] == "/" or path[2] == "\\"):
return True

return False

def _write_launcher(ctx, rjars, main_class, jvm_flags, args="", wrapper_preamble=""):
runfiles_root = "${TEST_SRCDIR}/%s" % ctx.workspace_name
# RUNPATH is defined here:
# https://github.com/bazelbuild/bazel/blob/0.4.5/src/main/java/com/google/devtools/build/lib/bazel/rules/java/java_stub_template.txt#L227
classpath = ":".join(["${RUNPATH}%s" % (j.short_path) for j in rjars])
jvm_flags = " ".join([ctx.expand_location(f, ctx.attr.data) for f in jvm_flags])
javabin = "%s/%s" % (runfiles_root, ctx.executable._java.short_path)
# TODO: Replace the following if/else with just .java_executable_runfiles_path
# when that becomes generally available in Bazel (submitted in
# https://github.com/bazelbuild/bazel/commit/f2075d27ca124156fcd7c01242c552175c0cf145).
java_path = str(ctx.attr._java_runtime[java_common.JavaRuntimeInfo].java_executable_exec_path)
if _path_is_absolute(java_path):
javabin = java_path
else:
javabin = "%s/%s" % (runfiles_root, java_path)

template = ctx.attr._java_stub_template.files.to_list()[0]

exec_str = ""
Expand Down Expand Up @@ -608,7 +631,7 @@ def _collect_jars_from_common_ctx(ctx, extra_deps = [], extra_runtime_deps = [])
return struct(compile_jars = cjars, transitive_runtime_jars = transitive_rjars, jars2labels=jars2labels, transitive_compile_jars = transitive_compile_jars)

def _format_full_jars_for_intellij_plugin(full_jars):
return [struct (class_jar = jar, ijar = None) for jar in full_jars]
return [struct (class_jar = jar, ijar = None, source_jar = None, source_jars = []) for jar in full_jars]

def create_java_provider(scalaattr, transitive_compile_time_jars):
# This is needed because Bazel >=0.7.0 requires ctx.actions and a Java
Expand Down Expand Up @@ -667,13 +690,12 @@ def _lib(ctx, non_macro_lib):
next_cjars += exports_jars.compile_jars
transitive_rjars += exports_jars.transitive_runtime_jars



rule_outputs = struct(
ijar = outputs.ijar,
class_jar = outputs.class_jar,
deploy_jar = ctx.outputs.deploy_jar,
jars = _format_full_jars_for_intellij_plugin(outputs.full_jars)
jars = _format_full_jars_for_intellij_plugin(outputs.full_jars),
statsfile = ctx.outputs.statsfile,
)
# Note that, internally, rules only care about compile_jars and transitive_runtime_jars
# in a similar manner as the java_library and JavaProvider
Expand Down Expand Up @@ -728,17 +750,16 @@ def _scala_binary_common(ctx, cjars, rjars, transitive_compile_time_jars, jars2l

java_wrapper = ctx.new_file(ctx.label.name + "_wrapper.sh")

# _java_toolchain added manually since _java doesn't currently setup runfiles
runfiles = ctx.runfiles(
files = list(rjars) + [ctx.outputs.executable, java_wrapper] + ctx.files._java_toolchain,
transitive_files = _get_runfiles(ctx.attr._java),
files = list(rjars) + [ctx.outputs.executable, java_wrapper] + ctx.files._java_runtime,
collect_data = True)

rule_outputs = struct(
ijar=outputs.class_jar,
class_jar=outputs.class_jar,
deploy_jar=ctx.outputs.deploy_jar,
jars = _format_full_jars_for_intellij_plugin(outputs.full_jars)
jars = _format_full_jars_for_intellij_plugin(outputs.full_jars),
statsfile = ctx.outputs.statsfile,
)

scalaattr = struct(
Expand Down Expand Up @@ -894,10 +915,10 @@ _implicit_deps = {
"_scalalib": attr.label(default=Label("//external:io_bazel_rules_scala/dependency/scala/scala_library"), allow_files=True),
"_scalacompiler": attr.label(default=Label("//external:io_bazel_rules_scala/dependency/scala/scala_compiler"), allow_files=True),
"_scalareflect": attr.label(default=Label("//external:io_bazel_rules_scala/dependency/scala/scala_reflect"), allow_files=True),
"_java": attr.label(executable=True, cfg="host", default=Label("@bazel_tools//tools/jdk:java"), allow_files=True),
"_zipper": attr.label(executable=True, cfg="host", default=Label("@bazel_tools//tools/zip:zipper"), allow_files=True),
"_java_toolchain": attr.label(default = Label("@bazel_tools//tools/jdk:current_java_toolchain")),
"_host_javabase": attr.label(default = Label("@bazel_tools//tools/jdk:current_java_runtime"))
"_host_javabase": attr.label(default = Label("@bazel_tools//tools/jdk:current_java_runtime"), cfg="host"),
"_java_runtime": attr.label(default = Label("@bazel_tools//tools/jdk:current_java_runtime"))
}

# Single dep to allow IDEs to pickup all the implicit dependencies.
Expand Down Expand Up @@ -959,6 +980,7 @@ common_outputs = {
"jar": "%{name}.jar",
"deploy_jar": "%{name}_deploy.jar",
"manifest": "%{name}_MANIFEST.MF",
"statsfile": "%{name}.statsfile",
}

library_outputs = {}
Expand Down
4 changes: 3 additions & 1 deletion scala/scala_import.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ def _code_jars_and_intellij_metadata_from(jars):
intellij_metadata.append(struct(
ijar = None,
class_jar = current_class_jar,
source_jar = None,
source_jars = [],
)
)
return struct(code_jars = code_jars, intellij_metadata = intellij_metadata)
Expand Down Expand Up @@ -112,7 +114,7 @@ def _collect_exports(exports):
scala_import = rule(
implementation=_scala_import_impl,
attrs={
"jars": attr.label_list(), #current hidden assumption is that these point to full, not ijar'd jars
"jars": attr.label_list(allow_files=True), #current hidden assumption is that these point to full, not ijar'd jars
"deps": attr.label_list(),
"runtime_deps": attr.label_list(),
"exports": attr.label_list()
Expand Down
18 changes: 18 additions & 0 deletions scala/support/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,22 @@ scala_library(
'//external:io_bazel_rules_scala/dependency/scala/scala_xml',
'//external:io_bazel_rules_scala/dependency/scalatest/scalatest'
],
scalacopts = [
"-deprecation:true",
"-encoding", "UTF-8",
"-feature",
"-language:existentials",
"-language:higherKinds",
"-language:implicitConversions",
"-unchecked",
"-Xfatal-warnings",
"-Xlint",
"-Yno-adapted-args",
"-Ywarn-dead-code",
"-Ywarn-numeric-widen",
"-Ywarn-value-discard",
"-Xfuture",
"-Ywarn-unused-import",
"-Ypartial-unification",
]
)
5 changes: 2 additions & 3 deletions scala/support/JUnitXmlReporter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import java.io.PrintWriter
import java.net.InetAddress
import java.net.UnknownHostException
import java.text.SimpleDateFormat
import java.util.Enumeration
import java.util.Properties
import scala.collection.mutable.ListBuffer
import scala.xml
Expand Down Expand Up @@ -360,10 +359,10 @@ class JUnitXmlReporter extends Reporter {
"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" + withCDATA
}

def xmlify(suites: Iterable[Testsuite]): scala.xml.Elem =
private def xmlify(suites: Iterable[Testsuite]): scala.xml.Elem =
<testsuites> { suites.map(xmlify) } </testsuites>

def xmlify(testsuite: Testsuite): scala.xml.Elem =
private def xmlify(testsuite: Testsuite): scala.xml.Elem =
<testsuite
errors = { "" + testsuite.errors }
failures = { "" + testsuite.failures }
Expand Down
8 changes: 7 additions & 1 deletion scala_proto/scala_proto.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -320,12 +320,16 @@ def _colon_paths(data):

def _gen_proto_srcjar_impl(ctx):
acc_imports = depset()
transitive_proto_paths = depset()

proto_deps, jvm_deps = [], []
for target in ctx.attr.deps:
if hasattr(target, 'proto'):
proto_deps.append(target)
acc_imports += target.proto.transitive_sources
#inline this if after 0.12.0 is the oldest supported version
if hasattr(target.proto, 'transitive_proto_path'):
transitive_proto_paths += target.proto.transitive_proto_path
else:
jvm_deps.append(target)

Expand All @@ -334,11 +338,13 @@ def _gen_proto_srcjar_impl(ctx):

deps_jars = collect_jars(jvm_deps)

worker_content = "{output}\n{paths}\n{flags_arg}".format(
worker_content = "{output}\n{paths}\n{flags_arg}\n{packages}".format(
output = ctx.outputs.srcjar.path,
paths = _colon_paths(acc_imports),
# Command line args to worker cannot be empty so using padding
flags_arg = "-" + ",".join(ctx.attr.flags),
# Command line args to worker cannot be empty so using padding
packages = "-" + ":".join(transitive_proto_paths.to_list())
)
argfile = ctx.new_file(ctx.outputs.srcjar, "%s_worker_input" % ctx.label.name)
ctx.file_action(output=argfile, content=worker_content)
Expand Down
1 change: 0 additions & 1 deletion src/java/io/bazel/rulesscala/jar/JarCreator.java
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ public static void buildJar(String[] args) throws IOException {
}
}
createJar.setCompression(true);
createJar.setNormalize(true);
createJar.execute();
}

Expand Down
2 changes: 1 addition & 1 deletion src/java/io/bazel/rulesscala/jar/JarHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class JarHelper {
protected final String jarFile;

// The properties to describe how to create the Jar
protected boolean normalize;
protected boolean normalize = true;
protected int storageMethod = JarEntry.DEFLATED;
protected boolean verbose = false;

Expand Down
3 changes: 3 additions & 0 deletions src/java/io/bazel/rulesscala/scalac/CompileOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class CompileOptions {
final public String[] indirectTargets;
final public String dependencyAnalyzerMode;
final public String currentTarget;
final public String statsfile;

public CompileOptions(List<String> args) {
Map<String, String> argMap = buildArgMap(args);
Expand Down Expand Up @@ -60,6 +61,8 @@ public CompileOptions(List<String> args) {

dependencyAnalyzerMode = getOrElse(argMap, "DependencyAnalyzerMode", "off");
currentTarget = getOrElse(argMap, "CurrentTarget", "NA");

statsfile = getOrError(argMap, "StatsfileOutput", "Missing required arg StatsfileOutput");
}

private static Map<String, Resource> getResources(Map<String, String> args) {
Expand Down
7 changes: 7 additions & 0 deletions src/java/io/bazel/rulesscala/scalac/ScalacProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,13 @@ private static void compileScalaSources(CompileOptions ops, String[] scalaSource
System.err.println("Compiler runtime: " + (stop - start) + "ms.");
}

try {
Files.write(Paths.get(ops.statsfile), Arrays.asList(
"build_time=" + Long.toString(stop - start)));
} catch (IOException ex) {
throw new RuntimeException(
"Unable to write statsfile to " + ops.statsfile, ex);
}

ConsoleReporter reporter = (ConsoleReporter) reporterField.get(comp);

Expand Down
1 change: 1 addition & 0 deletions src/java/io/bazel/rulesscala/specs2/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ scala_library(
name = "specs2_test_discovery",
srcs = [
"Specs2RunnerBuilder.scala",
"package.scala",
],
visibility = ["//visibility:public"],
deps = ["//src/java/io/bazel/rulesscala/test_discovery:test_discovery",
Expand Down
Loading