Skip to content

Merge master into scala 2.12 branch #307

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

Merged
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
4 changes: 2 additions & 2 deletions .bazelrc.travis
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ build --verbose_failures
# runs stuff in a container, and since Travis already runs its script
# in a container (unless you require sudo in your .travis.yml) this
# fails to run tests.
build --spawn_strategy=standalone --genrule_strategy=standalone --strategy=Scalac=worker --strategy=ScroogeRule=worker --worker_max_instances=3
test --test_strategy=standalone
build --strategy=Scalac=worker --strategy=ScroogeRule=worker --worker_max_instances=3
#test --test_strategy=standalone

# Below this line, .travis.yml will cat the default bazelrc.
# This is needed so Bazel starts with the base workspace in its
Expand Down
17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<li><a href="#scala_library">scala_library/scala_macro_library</a></li>
<li><a href="#scala_binary">scala_binary</a></li>
<li><a href="#scala_test">scala_test</a></li>
<li><a href="#scalapb_proto_library">scalapb_proto_library</a></li>
</ul>
</div>

Expand Down Expand Up @@ -467,10 +468,20 @@ thrift_library(name, srcs, deps, absolute_prefix, absolute_prefixes)
</tbody>
</table>

<a name="scalapb_proto_library"></a>
## scalapb_proto_library

You first need to add the following to your WORKSPACE file:

```python
load("@io_bazel_rules_scala//scala_proto:scala_proto.bzl", "scala_proto_repositories")
scala_proto_repositories()
```

Then you can import `scalapb_proto_library` in any BUILD file like this:

```python
load("//scala_proto:scala_proto.bzl", "scalapb_proto_library")
load("@io_bazel_rules_scala//scala_proto:scala_proto.bzl", "scalapb_proto_library")
scalapb_proto_library(name, deps, with_grpc, with_java, with_flat_package, with_single_line_to_string)
```

Expand Down Expand Up @@ -498,7 +509,7 @@ generated by the [ScalaPB compiler](https://github.com/scalapb/ScalaPB).
<td><code>deps</code></td>
<td>
<p><code>List of labels, required</code></p>
<p>List of proto dependencies that this target depends on. Must be of type <code>proto_library</code></p>
<p>List of dependencies for this target. Must either be of type <code>proto_library</code> or <code>java_proto_library</code> (allowed only if <code>with_java</code> is enabled) </p>
</td>
</tr>
<tr>
Expand All @@ -512,7 +523,7 @@ generated by the [ScalaPB compiler](https://github.com/scalapb/ScalaPB).
<td><code>with_java</code></td>
<td>
<p><code>boolean; optional (default False)</code></p>
<p>Enables generation of converters to and from java protobuf bindings</p>
<p>Enables generation of converters to and from java protobuf bindings. If you set this to <code>True</code> make sure that you pass the corresponding <code>java_proto_library</code> target in <code>deps</code></p>
</td>
</tr>
<tr>
Expand Down
12 changes: 6 additions & 6 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ maven_jar(

http_archive(
name = "com_google_protobuf",
urls = ["https://github.com/google/protobuf/archive/b4b0e304be5a68de3d0ee1af9b286f958750f5e4.zip"],
strip_prefix = "protobuf-b4b0e304be5a68de3d0ee1af9b286f958750f5e4",
sha256 = "ff771a662fb6bd4d3cc209bcccedef3e93980a49f71df1e987f6afa3bcdcba3a",
urls = ["https://github.com/google/protobuf/archive/b04e5cba356212e4e8c66c61bbe0c3a20537c5b9.zip"],
strip_prefix = "protobuf-b04e5cba356212e4e8c66c61bbe0c3a20537c5b9",
sha256 = "cf4a434ac3a83040e9f65be92e153d00d075d8cd25e3f6c6d8670879f5796aa0",
)

http_archive(
name = "com_google_protobuf_java",
urls = ["https://github.com/google/protobuf/archive/b4b0e304be5a68de3d0ee1af9b286f958750f5e4.zip"],
strip_prefix = "protobuf-b4b0e304be5a68de3d0ee1af9b286f958750f5e4",
sha256 = "ff771a662fb6bd4d3cc209bcccedef3e93980a49f71df1e987f6afa3bcdcba3a",
urls = ["https://github.com/google/protobuf/archive/b04e5cba356212e4e8c66c61bbe0c3a20537c5b9.zip"],
strip_prefix = "protobuf-b04e5cba356212e4e8c66c61bbe0c3a20537c5b9",
sha256 = "cf4a434ac3a83040e9f65be92e153d00d075d8cd25e3f6c6d8670879f5796aa0",
)
41 changes: 19 additions & 22 deletions scala/scala.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"""Rules for supporting the Scala language."""

load("//specs2:specs2_junit.bzl", "specs2_junit_dependencies")
load(":scala_cross_version.bzl", "scala_version", "scala_mvn_artifact")
_jar_filetype = FileType([".jar"])
_java_filetype = FileType([".java"])
_scala_filetype = FileType([".scala"])
Expand Down Expand Up @@ -66,7 +67,7 @@ def _adjust_resources_path(path, resource_strip_prefix):
def _add_resources_cmd(ctx):
res_cmd = []
for f in ctx.files.resources:
c_dir, res_path = _adjust_resources_path(f.path, ctx.attr.resource_strip_prefix)
c_dir, res_path = _adjust_resources_path(f.short_path, ctx.attr.resource_strip_prefix)
target_path = res_path
if target_path[0] == "/":
target_path = target_path[1:]
Expand Down Expand Up @@ -197,6 +198,7 @@ PrintCompileTime: {print_compile_time}
ResourceDests: {resource_dest}
ResourceJars: {resource_jars}
ResourceSrcs: {resource_src}
ResourceShortPaths: {resource_short_paths}
ResourceStripPrefix: {resource_strip_prefix}
ScalacOpts: {scala_opts}
SourceJars: {srcjars}
Expand All @@ -218,8 +220,9 @@ DependencyAnalyzerMode: {dependency_analyzer_mode}
srcjars=",".join([f.path for f in all_srcjars]),
java_files=",".join([f.path for f in java_srcs]),
resource_src=",".join([f.path for f in ctx.files.resources]),
resource_short_paths=",".join([f.short_path for f in ctx.files.resources]),
resource_dest=",".join(
[_adjust_resources_path_by_default_prefixes(f.path)[1] for f in ctx.files.resources]
[_adjust_resources_path_by_default_prefixes(f.short_path)[1] for f in ctx.files.resources]
),
resource_strip_prefix=ctx.attr.resource_strip_prefix,
resource_jars=",".join([f.path for f in ctx.files.resource_jars]),
Expand Down Expand Up @@ -390,15 +393,20 @@ def _write_launcher(ctx, rjars, main_class, jvm_flags, args="", wrapper_preamble
javabin = "%s/%s" % (runfiles_root, ctx.executable._java.short_path)
template = ctx.attr._java_stub_template.files.to_list()[0]

exec_str = ""
if wrapper_preamble == "":
exec_str = "exec "

wrapper = ctx.new_file(ctx.label.name + "_wrapper.sh")
ctx.file_action(
output = wrapper,
content = """#!/bin/bash
{preamble}

{javabin} "$@" {args}
{exec_str}{javabin} "$@" {args}
""".format(
preamble=wrapper_preamble,
exec_str=exec_str,
javabin=javabin,
args=args,
),
Expand Down Expand Up @@ -514,7 +522,7 @@ def _collect_jars_when_dependency_analyzer_is_on(dep_targets):
jars2labels = jars2labels,
transitive_compile_jars = transitive_compile_jars)

def _collect_jars(dep_targets, dependency_analyzer_is_off = True):
def collect_jars(dep_targets, dependency_analyzer_is_off = True):
"""Compute the runtime and compile-time dependencies from the given targets""" # noqa

if dependency_analyzer_is_off:
Expand Down Expand Up @@ -542,10 +550,10 @@ def _collect_jars_from_common_ctx(ctx, extra_deps = [], extra_runtime_deps = [])

# Get jars from deps
auto_deps = [ctx.attr._scalalib, ctx.attr._scalareflect]
deps_jars = _collect_jars(ctx.attr.deps + auto_deps + extra_deps, dependency_analyzer_is_off)
deps_jars = collect_jars(ctx.attr.deps + auto_deps + extra_deps, dependency_analyzer_is_off)
(cjars, transitive_rjars, jars2labels, transitive_compile_jars) = (deps_jars.compile_jars, deps_jars.transitive_runtime_jars, deps_jars.jars2labels, deps_jars.transitive_compile_jars)

runtime_dep_jars = _collect_jars(ctx.attr.runtime_deps + extra_runtime_deps, dependency_analyzer_is_off)
runtime_dep_jars = collect_jars(ctx.attr.runtime_deps + extra_runtime_deps, dependency_analyzer_is_off)
transitive_rjars += runtime_dep_jars.transitive_runtime_jars

if not dependency_analyzer_is_off:
Expand All @@ -556,7 +564,7 @@ def _collect_jars_from_common_ctx(ctx, extra_deps = [], extra_runtime_deps = [])
def _format_full_jars_for_intellij_plugin(full_jars):
return [struct (class_jar = jar, ijar = None) for jar in full_jars]

def _create_java_provider(ctx, scalaattr, transitive_compile_time_jars):
def create_java_provider(ctx, scalaattr, transitive_compile_time_jars):
# This is needed because Bazel >=0.6.0 requires ctx.actions and a Java
# toolchain. Fortunately, the same change that added this requirement also
# added this field to the Java provider so we can use it to test which
Expand Down Expand Up @@ -610,7 +618,7 @@ def _lib(ctx, non_macro_lib):
# Add information from exports (is key that AFTER all build actions/runfiles analysis)
# Since after, will not show up in deploy_jar or old jars runfiles
# Notice that compile_jars is intentionally transitive for exports
exports_jars = _collect_jars(ctx.attr.exports)
exports_jars = collect_jars(ctx.attr.exports)
next_cjars += exports_jars.compile_jars
transitive_rjars += exports_jars.transitive_runtime_jars

Expand All @@ -631,7 +639,7 @@ def _lib(ctx, non_macro_lib):
transitive_exports = [] #needed by intellij plugin
)

java_provider = _create_java_provider(ctx, scalaattr, jars.transitive_compile_jars)
java_provider = create_java_provider(ctx, scalaattr, jars.transitive_compile_jars)

return struct(
files = depset([ctx.outputs.jar]), # Here is the default output
Expand Down Expand Up @@ -695,7 +703,7 @@ def _scala_binary_common(ctx, cjars, rjars, transitive_compile_time_jars, jars2l
transitive_exports = [] #needed by intellij plugin
)

java_provider = _create_java_provider(ctx, scalaattr, transitive_compile_time_jars)
java_provider = create_java_provider(ctx, scalaattr, transitive_compile_time_jars)

return struct(
files=depset([ctx.outputs.executable]),
Expand Down Expand Up @@ -772,7 +780,7 @@ def _scala_test_impl(ctx):
jars.transitive_compile_jars, jars.jars2labels)
# _scalatest is an http_jar, so its compile jar is run through ijar
# however, contains macros, so need to handle separately
scalatest_jars = _collect_jars([ctx.attr._scalatest]).transitive_runtime_jars
scalatest_jars = collect_jars([ctx.attr._scalatest]).transitive_runtime_jars
cjars += scalatest_jars
transitive_rjars += scalatest_jars

Expand Down Expand Up @@ -973,17 +981,6 @@ scala_repl = rule(
fragments = ["java"]
)

def scala_version():
"""return the scala version for use in maven coordinates"""
return "2.12"

def scala_mvn_artifact(artifact):
gav = artifact.split(":")
groupid = gav[0]
artifactid = gav[1]
version = gav[2]
return "%s:%s_%s:%s" % (groupid, artifactid, scala_version(), version)

SCALA_BUILD_FILE = """
# scala.BUILD
java_import(
Expand Down
28 changes: 28 additions & 0 deletions scala/scala_cross_version.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright 2015 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Helper functions for Scala cross-version support. Encapsulates the logic
of abstracting over Scala major version (2.11, 2.12, etc) for dependency
resolution."""

def scala_version():
"""return the scala version for use in maven coordinates"""
return "2.12"

def scala_mvn_artifact(artifact):
gav = artifact.split(":")
groupid = gav[0]
artifactid = gav[1]
version = gav[2]
return "%s:%s_%s:%s" % (groupid, artifactid, scala_version(), version)
Loading