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

Fixes #1204: Release bindings and codegens to Maven Central. #1205

Merged
merged 13 commits into from
Jun 17, 2019
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
163 changes: 95 additions & 68 deletions bazel_tools/scala.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -239,71 +239,107 @@ def _create_scala_source_jar(**kwargs):
srcs = kwargs["srcs"],
)

def _build_nosrc_jar(ctx):
# this ensures the file is not empty
manifest_path = ctx.actions.declare_file("%s_MANIFEST.MF" % ctx.label.name)
ctx.actions.write(manifest_path, "Manifest-Version: 1.0")
resources = "META-INF/MANIFEST.MF=%s\n" % manifest_path.path

zipper_arg_path = ctx.actions.declare_file("%s_zipper_args" % ctx.label.name)
ctx.actions.write(zipper_arg_path, resources)
cmd = """
rm -f {jar_output}
{zipper} c {jar_output} @{path}
"""

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

outs = [ctx.outputs.out]
inputs = [manifest_path]

ctx.actions.run_shell(
inputs = inputs,
tools = [ctx.executable._zipper, zipper_arg_path],
outputs = outs,
command = cmd,
progress_message = "scala %s" % ctx.label,
arguments = [],
)

def _scaladoc_jar_impl(ctx):
# Detect an actual scala source file rather than a srcjar or other label
srcFiles = [
src.path
for src in ctx.files.srcs
if src.is_source
]

# The following plugin handling is lifted from a private library of 'rules_scala'.
# https://github.com/bazelbuild/rules_scala/blob/1cffc5fcae1f553a7619b98bf7d6456d65081665/scala/private/rule_impls.bzl#L130
pluginPaths = []
for p in ctx.attr.plugins:
if hasattr(p, "path"):
pluginPaths.append(p)
elif hasattr(p, "scala"):
pluginPaths.extend([j.class_jar for j in p.scala.outputs.jars])
elif hasattr(p, "java"):
pluginPaths.extend([j.class_jar for j in p.java.outputs.jars])
# support http_file pointed at a jar. http_jar uses ijar,
# which breaks scala macros

elif hasattr(p, "files"):
pluginPaths.extend([f for f in p.files if "-sources.jar" not in f.basename])

transitive_deps = [dep[JavaInfo].transitive_deps for dep in ctx.attr.deps]
classpath = depset([], transitive = transitive_deps).to_list()

outdir = ctx.actions.declare_directory(ctx.label.name + "_tmpdir")

args = ctx.actions.args()
args.add_all(["-d", outdir.path])
args.add("-classpath")
args.add_joined(classpath, join_with = ":")
args.add_joined(pluginPaths, join_with = ",", format_joined = "-Xplugin:%s")
args.add_all(common_scalacopts)
args.add_all(srcFiles)

ctx.actions.run(
executable = ctx.executable._scaladoc,
inputs = ctx.files.srcs + classpath + pluginPaths,
outputs = [outdir],
arguments = [args],
mnemonic = "ScaladocGen",
)
if srcFiles != []:
# The following plugin handling is lifted from a private library of 'rules_scala'.
# https://github.com/bazelbuild/rules_scala/blob/1cffc5fcae1f553a7619b98bf7d6456d65081665/scala/private/rule_impls.bzl#L130
pluginPaths = []
for p in ctx.attr.plugins:
if hasattr(p, "path"):
pluginPaths.append(p)
elif hasattr(p, "scala"):
pluginPaths.extend([j.class_jar for j in p.scala.outputs.jars])
elif hasattr(p, "java"):
pluginPaths.extend([j.class_jar for j in p.java.outputs.jars])
# support http_file pointed at a jar. http_jar uses ijar,
# which breaks scala macros

elif hasattr(p, "files"):
pluginPaths.extend([f for f in p.files if "-sources.jar" not in f.basename])

transitive_deps = [dep[JavaInfo].transitive_deps for dep in ctx.attr.deps]
classpath = depset([], transitive = transitive_deps).to_list()

outdir = ctx.actions.declare_directory(ctx.label.name + "_tmpdir")

args = ctx.actions.args()
args.add_all(["-d", outdir.path])
args.add("-classpath")
args.add_joined(classpath, join_with = ":")
args.add_joined(pluginPaths, join_with = ",", format_joined = "-Xplugin:%s")
args.add_all(common_scalacopts)
args.add_all(srcFiles)

ctx.actions.run(
executable = ctx.executable._scaladoc,
inputs = ctx.files.srcs + classpath + pluginPaths,
outputs = [outdir],
arguments = [args],
mnemonic = "ScaladocGen",
)

# since we only have the output directory of the scaladoc generation we need to find
# all the files below sources_out and add them to the zipper args file
zipper_args_file = ctx.actions.declare_file(ctx.label.name + ".zipper_args")
ctx.actions.run_shell(
mnemonic = "ScaladocFindOutputFiles",
outputs = [zipper_args_file],
inputs = [outdir],
command = "find -L {src_path} -type f | sed -E 's#^{src_path}/(.*)$#\\1={src_path}/\\1#' | sort > {args_file}".format(
src_path = outdir.path,
args_file = zipper_args_file.path,
),
progress_message = "find_scaladoc_output_files %s" % zipper_args_file.path,
use_default_shell_env = True,
)
# since we only have the output directory of the scaladoc generation we need to find
# all the files below sources_out and add them to the zipper args file
zipper_args_file = ctx.actions.declare_file(ctx.label.name + ".zipper_args")
ctx.actions.run_shell(
mnemonic = "ScaladocFindOutputFiles",
outputs = [zipper_args_file],
inputs = [outdir],
command = "find -L {src_path} -type f | sed -E 's#^{src_path}/(.*)$#\\1={src_path}/\\1#' | sort > {args_file}".format(
src_path = outdir.path,
args_file = zipper_args_file.path,
),
progress_message = "find_scaladoc_output_files %s" % zipper_args_file.path,
use_default_shell_env = True,
)

ctx.actions.run(
executable = ctx.executable._zipper,
inputs = ctx.files.srcs + classpath + [outdir, zipper_args_file],
outputs = [ctx.outputs.out],
arguments = ["c", ctx.outputs.out.path, "@" + zipper_args_file.path],
mnemonic = "ScaladocJar",
)
ctx.actions.run(
executable = ctx.executable._zipper,
inputs = ctx.files.srcs + classpath + [outdir, zipper_args_file],
outputs = [ctx.outputs.out],
arguments = ["c", ctx.outputs.out.path, "@" + zipper_args_file.path],
mnemonic = "ScaladocJar",
)
else:
_build_nosrc_jar(ctx)

scaladoc_jar = rule(
implementation = _scaladoc_jar_impl,
Expand Down Expand Up @@ -339,17 +375,8 @@ Arguments:
"""

def _create_scaladoc_jar(**kwargs):
# Try to not create empty scaladoc jars and limit execution to Linux and MacOS
# Detect an actual scala source file rather than a srcjar or other label

create_scaladoc = False
if len(kwargs["srcs"]) > 0 and is_windows == False:
for src in kwargs["srcs"]:
if src.endswith(".scala"):
create_scaladoc = True
break

if create_scaladoc:
# Limit execution to Linux and MacOS
if is_windows == False:
plugins = []
if "plugins" in kwargs:
plugins = kwargs["plugins"]
Expand Down
6 changes: 6 additions & 0 deletions ci/build-unix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ steps:
env:
# to connect to bintray
JFROG_CONFIG_CONTENT: $(JFROG_CONFIG_CONTENT)
# For signing artifacts to be uploaded to Maven Central.
GPG_KEY: $(gpg-code-signing)
# Configuration the Sonatype Open Source Repository Hosting
MAVEN_USER: $(MAVEN_USER)
MAVEN_PASSWORD: $(MAVEN_PASSWORD)
MAVEN_URL: "https://oss.sonatype.org"
name: release
- bash: |
set -euo pipefail
Expand Down
8 changes: 8 additions & 0 deletions dev-env/bin/gpg
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
# Meant to be linked to from `dev-env/bin`, symlink should be named after the
# tool. Execute a Nix tool from a derivation that creates a `result` directory.

DADE_CURRENT_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$DADE_CURRENT_SCRIPT_DIR/../lib/dade-common"
base=$(basename $0)
execTool $base out $base "$@"
23 changes: 0 additions & 23 deletions docs/source/app-dev/bindings-java/code-snippets/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,4 @@
</dependency>
</dependencies>
<!-- end snippet: dependencies -->

<!-- start snippet: repositories -->
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>bintray-digitalassetsdk-DigitalAssetSDK</id>
<name>bintray</name>
<url>https://digitalassetsdk.bintray.com/DigitalAssetSDK</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>bintray-digitalassetsdk-DigitalAssetSDK</id>
<name>bintray</name>
<url>https://digitalassetsdk.bintray.com/DigitalAssetSDK</url>
</pluginRepository>
</pluginRepositories>
<!-- end snippet: repositories -->
</project>
2 changes: 1 addition & 1 deletion docs/source/app-dev/bindings-java/codegen.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ The following snippet is an excerpt from the ``pom.xml`` that is part of the :re

.. literalinclude:: ../../getting-started/quickstart/template-root/pom.xml
:language: xml
:lines: 68-100,116-117
:lines: 47-79,95-96
:dedent: 12


Expand Down
15 changes: 4 additions & 11 deletions docs/source/app-dev/bindings-java/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -154,21 +154,14 @@ To use the Java bindings library, add the following dependencies to your project
:end-before: <!-- end snippet: dependencies -->
:dedent: 4

Replace ``x.y.z`` for both dependencies with the version that you want to use. You can find the available versions at
`https://digitalassetsdk.bintray.com/DigitalAssetSDK/com/daml/ledger/`.

You also have to add the DAML Bintray Repository to your ``pom.xml``:

.. literalinclude:: ./code-snippets/pom.xml
:language: xml
:start-after: <!-- start snippet: repositories -->
:end-before: <!-- end snippet: repositories -->
:dedent: 4
Replace ``x.y.z`` for both dependencies with the version that you want to use. You can find the available versions by checking
the `Maven Central Repository <https://search.maven.org/search?q=g:com.daml.ledger>`__.

.. note::
As of DAML SDK release 0.13.1, the Java Bindings libraries are available via the public Maven Central repository. Earlier releases are available from the `DAML Bintray repository <https://digitalassetsdk.bintray.com>`__.

You can also take a look at the ``pom.xml`` file from the :ref:`quickstart project <quickstart>`.


.. _ledger-api-java-binding-connecting:

Connecting to the ledger
Expand Down
21 changes: 0 additions & 21 deletions docs/source/getting-started/quickstart/template-root/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,27 +42,6 @@
</dependency>
</dependencies>

<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>bintray-digitalassetsdk-DigitalAssetSDK</id>
<name>bintray</name>
<url>https://digitalassetsdk.bintray.com/DigitalAssetSDK</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>bintray-digitalassetsdk-DigitalAssetSDK</id>
<name>bintray</name>
<url>https://digitalassetsdk.bintray.com/DigitalAssetSDK</url>
</pluginRepository>
</pluginRepositories>

<build>
<plugins>
<plugin>
Expand Down
8 changes: 8 additions & 0 deletions docs/source/support/release-notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ Language

- Add an instance for ``IsParties (Optional Party)``, allowing ``Optional`` values to be used in ``signatory``, ``observer`` and ``maintainer`` clauses.

Java Bindings
~~~~~~~~~~~~~

- Release the Java Bindings to the public Maven Central repository. To move to using the Maven Central repository, remove
the ``<repository>...</repository>`` and ``<pluginRepository>...</pluginRepository>`` blocks from Maven POM files
that use version 0.12.26 (or later) of the Java Bindings.
See `#1205 <https://github.com/digital-asset/daml/issues/1205>`__.

.. _release-0-13-0:

0.13.0 - 2019-06-17
Expand Down
16 changes: 16 additions & 0 deletions language-support/codegen-main/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
load(
"//bazel_tools:scala.bzl",
"da_scala_binary",
"scala_source_jar",
"scaladoc_jar",
)
load(
"@com_github_johnynek_bazel_jar_jar//:jar_jar.bzl",
"jar_jar",
)
load("//bazel_tools:pom_file.bzl", "pom_file")
load("@os_info//:os_info.bzl", "is_windows")

da_scala_binary(
name = "codegen-main",
Expand All @@ -36,3 +39,16 @@ pom_file(
target = ":shaded_binary",
visibility = ["//visibility:public"],
)

# Create empty Scaladoc JAR for uploading to Maven Central
scaladoc_jar(
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we make scaladoc_jar and scala_source_jar implicit in da_scala_binary? Having to add that manually everywhere seems rather cumbersome and easy to forget.

name = "shaded_binary_scaladoc",
srcs = [],
deps = [],
) if is_windows == False else None
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
) if is_windows == False else None
) if not is_windows else None


# Create empty Sources JAR for uploading to Maven Central
scala_source_jar(
name = "shaded_binary_src",
srcs = [],
)
16 changes: 16 additions & 0 deletions language-support/java/codegen/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ load(
"da_scala_binary",
"da_scala_library",
"da_scala_test",
"scala_source_jar",
"scaladoc_jar",
)
load(
"//rules_daml:daml.bzl",
Expand All @@ -21,6 +23,7 @@ load(
"jar_jar",
)
load("//bazel_tools:pom_file.bzl", "pom_file")
load("@os_info//:os_info.bzl", "is_windows")

da_scala_binary(
name = "codegen",
Expand Down Expand Up @@ -105,6 +108,19 @@ pom_file(
visibility = ["//visibility:public"],
)

# Create empty Scaladoc JAR for uploading to Maven Central
scaladoc_jar(
name = "shaded_binary_scaladoc",
srcs = [],
deps = [],
) if is_windows == False else None
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
) if is_windows == False else None
) if not is_windows else None


# Create empty Sources JAR for uploading to Maven Central
scala_source_jar(
name = "shaded_binary_src",
srcs = [],
)

daml_lf_target_versions = [
"1.0",
"1.1",
Expand Down
Loading