Skip to content

Commit

Permalink
Merge pull request #112 from eed3si9n/wip/neverlink
Browse files Browse the repository at this point in the history
Encode provided scope as neverlink
  • Loading branch information
eed3si9n authored Nov 3, 2022
2 parents 103b642 + a25b671 commit e1a00e3
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 1 deletion.
46 changes: 46 additions & 0 deletions multiversion-example/export-example/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,49 @@ jvm_export(
snapshot_repo = "https://localhost/",
# python_path = "/opt/ee/python/3.10/bin/python3.10",
)

scala_library(
name = "io4",
srcs = ["IO4.scala"],
tags = [
"maven_coordinates=com.twitter.dpb:io4:{pom_version}",
],
neverlink = True,
)

jvm_export(
name = "io4.publish",
artifacts = [":io4"],
project_name = "IO 4",
project_description = "IO library",
project_url = "http://example.com/",
license = "Apache-2.0",
scm_url = "http://github.com/",
release_repo = "https://localhost/",
snapshot_repo = "https://localhost/",
# python_path = "/opt/ee/python/3.10/bin/python3.10",
)

scala_library(
name = "io5",
srcs = ["IO5.scala"],
tags = [
"maven_coordinates=com.twitter.dpb:io5:{pom_version}",
],
deps = [
":io4",
],
)

jvm_export(
name = "io5.publish",
artifacts = [":io5"],
project_name = "IO 5",
project_description = "IO library",
project_url = "http://example.com/",
license = "Apache-2.0",
scm_url = "http://github.com/",
release_repo = "https://localhost/",
snapshot_repo = "https://localhost/",
# python_path = "/opt/ee/python/3.10/bin/python3.10",
)
3 changes: 3 additions & 0 deletions multiversion-example/export-example/IO4.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.twitter.dpb

case class IO4()
3 changes: 3 additions & 0 deletions multiversion-example/export-example/IO5.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.twitter.dpb

case class IO5()
3 changes: 3 additions & 0 deletions rules_jvm_export/jvm_export/jvm_assembly.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ JarInfo = provider(
"name": "The name of a the JAR (Maven coordinates)",
"deps": "Direct dependencies",
"jar_infos": "The list of dependencies of this JAR. A dependency may be of two types, POM or JAR.",
"neverlink": "Forward neverlink from target",
},
)

Expand All @@ -195,6 +196,7 @@ def _aggregate_dependency_info_impl(target, ctx):
runtime_deps = getattr(ctx.rule.attr, "runtime_deps", [])
exports = getattr(ctx.rule.attr, "exports", [])
deps_all = deps + exports + runtime_deps
neverlink = getattr(ctx.rule.attr, "neverlink", False)

maven_coordinates = find_maven_coordinates(target, tags)
dependencies = []
Expand Down Expand Up @@ -238,6 +240,7 @@ def _aggregate_dependency_info_impl(target, ctx):
for jar in deps_all
],
),
neverlink=neverlink,
)


Expand Down
3 changes: 3 additions & 0 deletions rules_jvm_export/jvm_export/jvm_export.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ def _generate_pom_file(ctx, version):
pom_dependency_version = pom_dependency_coordinates.version
pom_dependency_classifier = getattr(pom_dependency_coordinates, "classifier", "")
pom_dependency_packaging = getattr(pom_dependency_coordinates, "packaging", "jar")
pom_dependency_neverlink = getattr(pom_dependency, "neverlink", False)
if pom_dependency_neverlink:
pom_dependency_classifier = "provided"
v = ctx.attr.version_overrides.get(
pom_dependency_artifact, pom_dependency_version
)
Expand Down
9 changes: 8 additions & 1 deletion rules_jvm_export/jvm_export/support/pom_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
"""


MAVEN_SCOPES = ["compile", "provided", "runtime", "test"]


def main():
args = _parse_args()
version = args.version
Expand Down Expand Up @@ -46,7 +49,11 @@ def _dependencies(args, version):
dependency.append(_elem_text("groupId", dep_coord["group_id"]))
dependency.append(_elem_text("artifactId", dep_coord["artifact_id"]))
if "classifier" in dep_coord:
dependency.append(_elem_text("classifier", dep_coord["classifier"]))
dep_classifier = dep_coord["classifier"]
if dep_classifier in MAVEN_SCOPES:
dependency.append(_elem_text("scope", dep_classifier))
else:
dependency.append(_elem_text("classifier", dep_classifier))

dependency.append(_elem_text("version", dep_version))
dependencies.append(dependency)
Expand Down
2 changes: 2 additions & 0 deletions scripts/ci-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ bazel run export-example:io2.publish --@twitter_rules_jvm_export//jvm_export:ver
cat /tmp/repo/com/twitter/dpb/io2/0.1.0-alpha1/io2-0.1.0-alpha1.pom | tr -d ' ' | tr -d '\n' | grep '<dependency><groupId>com.twitter.dpb</groupId><artifactId>io1</artifactId><version>0.1.0-alpha1</version></dependency>'
bazel run export-example:io3.publish --@twitter_rules_jvm_export//jvm_export:version=0.1.0-alpha1 -- release --publish_to=/tmp/repo
cat /tmp/repo/com/twitter/dpb/io3/0.1.0-alpha1/io3-0.1.0-alpha1.pom | tr -d ' ' | tr -d '\n' | grep '<dependency><groupId>com.twitter.dpb</groupId><artifactId>io2</artifactId><classifier>abc</classifier><version>0.1.0-alpha1</version></dependency>'
bazel run export-example:io5.publish --@twitter_rules_jvm_export//jvm_export:version=0.1.0-alpha1 -- release --publish_to=/tmp/repo
cat /tmp/repo/com/twitter/dpb/io5/0.1.0-alpha1/io5-0.1.0-alpha1.pom | tr -d ' ' | tr -d '\n' | grep '<dependency><groupId>com.twitter.dpb</groupId><artifactId>io4</artifactId><scope>provided</scope><version>0.1.0-alpha1</version></dependency>'

0 comments on commit e1a00e3

Please sign in to comment.