Skip to content

Commit

Permalink
Add gradle_build_file attribute with example (#15)
Browse files Browse the repository at this point in the history
Remove local_rules_maven_repository rules (obsolete)
Add 0.7.0 to travis matrix
Add hermetic attribute to suppress print transitive form
  • Loading branch information
pcj authored Oct 28, 2017
1 parent 4f5a8bc commit 9c3b07a
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 61 deletions.
26 changes: 5 additions & 21 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ os:

env:
#- V=HEAD
- V=0.7.0
- V=0.6.1
- V=0.5.4
- V=0.5.3
- V=0.5.2
- V=0.4.5
- V=0.3.1

Expand All @@ -35,25 +34,10 @@ before_install:

script:
- |
(cd example/grpc_java && bazel \
--output_base=$HOME/.cache/bazel \
build \
--verbose_failures \
//src/main/java:main) \
&& \
(cd example/robolectric && bazel \
--output_base=$HOME/.cache/bazel \
test \
--verbose_failures \
--test_output=errors \
//:import_test) \
&& \
(cd example/scala && bazel \
--output_base=$HOME/.cache/bazel \
test \
--verbose_failures \
--test_output=errors \
//:test_omit)
(cd example/grpc_java && bazel build //src/main/java:main) && \
(cd example/robolectric && bazel test //:import_test) && \
(cd example/scala && bazel test //:test_omit) && \
(cd example/gradle && bazel build //:main)
notifications:
email: false
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ Given this initial repository rule defintion, `rules_maven` will:
1. write a `@guice//:BUILD` file with the requisite `java_library`
that bundle/export dependencies (one per configuration).

1. print out a formatted `maven_repository` *"closed-form"* rule with
all the transitive dependencies explicitly named.
1. print out a formatted `maven_repository` *"hermetic-form"* rule with
all the transitive dependencies and their sha1 values explicitly named
(can be disabled via the `hermetic = False` attribute)

### 2b. Copy and paste the closed-form back into your WORKSPACE.

Expand Down Expand Up @@ -175,10 +176,12 @@ guice_compile()
| --- | --- | --- | --- |
| `name` | `string` | `None` | The rule name. |
| `deps` | `string_list` | `[]` | List of maven artifacts having the form `NAME:GROUP:VERSION` |
| `gradle_build_file` | `label` | `None` | Use the given `build.gradle` file to name dependencies (rather than generating one based on `deps` |
| `transitive_deps` | `string_list` | `[]` | List of maven artifacts in the transitive set reachable from `deps`. The have the form `SHA1:NAME:GROUP:VERSION`, and are calculated by rules_maven via a generated `build.gradle` file. |
| `exclude` | `string_list_dict` | `{}` | List of artifacts to exclude, in the form `{ 'NAME:GROUP': ['EXCLUDED_GROUP:EXCLUDED_NAME']` |
| `force` | `string_list` | `[]` | List of artifacts to force, in the form `[ 'NAME:GROUP:VERSION']` |
| `omit` | `string_list` | `[]` | List of patterns to skip. The pattern must either be a substring of the coordinate `[ 'NAME:GROUP:VERSION']` or equal to the generated workspace name. |
| `hermetic` | `bool` | `True` | Regurgitate the rule with all transitive deps listed |
| `repositories` | `string_list_dict` | `{}` | A mapping of artifact-id pattern to url (see below) |
| `configurations` | `string_list` | `["compile", "default", "runtime", "compileOnly", "compileClasspath"]` | List of configurations to generate a corresponding rule for. |
| `experimental_disambiguate_maven_jar_workspace_names` | `bool` | `False` | See Note |
Expand Down
7 changes: 7 additions & 0 deletions example/gradle/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

java_binary(
name = "main",
deps = ["@artifact_repo//:runtime"],
srcs = ["Main.java"],
main_class = "Main",
)
5 changes: 5 additions & 0 deletions example/gradle/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public class Main {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
17 changes: 17 additions & 0 deletions example/gradle/WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

local_repository(
name = "org_pubref_rules_maven",
path = "../../",
)

load("@org_pubref_rules_maven//maven:rules.bzl", "maven_repositories", "maven_repository")
maven_repositories()

maven_repository(
name = 'artifact_repo',
gradle_build_file = "//:build.gradle",
hermetic = False,
)

load("@artifact_repo//:rules.bzl", "artifact_repo_runtime")
artifact_repo_runtime()
14 changes: 14 additions & 0 deletions example/gradle/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apply plugin: 'java'

repositories {
mavenCentral()
mavenLocal()
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

dependencies {
compile "joda-time:joda-time:2.2"
testCompile "junit:junit:4.12"
}
63 changes: 29 additions & 34 deletions example/grpc_java/WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# Note: this 'local_rules_maven_repository' is to facilitate testing
# and continuous integration. You should load rules_maven using more
# traditional means (as per the main README.md).
local_repository(
name = "org_pubref_rules_maven",
path = "../../",
Expand All @@ -12,46 +9,44 @@ maven_repositories()
maven_repository(
name = 'grpc_java',
deps = [
'io.grpc:grpc-all:1.2.0',
],
force = [
'com.google.guava:guava:19.0',
'io.grpc:grpc-all:1.7.0',
],
transitive_deps = [
'3760f6a6e13c8ab070aa629876cdd183614ee877:com.google.api.grpc:proto-google-common-protos:0.1.9',
'171da91494a1391aef13b88bd7302b29edb8d3b3:com.google.auth:google-auth-library-credentials:0.4.0',
'5871fb60dc68d67da54a663c3fd636a10a532948:com.google.code.findbugs:jsr305:3.0.0',
'751f548c85fa49f330cecbb1875893f971b33c4e:com.google.code.gson:gson:2.7',
'3624d81fca4e93c67f43bafc222b06e1b1e3b260:com.google.errorprone:error_prone_annotations:2.0.11',
'c3754a0bdd545b00ddc26884f9e7624f8b6a14de:com.google.errorprone:error_prone_annotations:2.0.19',
'6ce200f6b23222af3d8abb6b6459e6c44f4bb0e9:com.google.guava:guava:19.0',
'a2e145e7a7567c6372738f5c5a6f3ba6407ac354:com.google.instrumentation:instrumentation-api:0.3.0',
'41614af3429573dc02645d541638929d877945a2:com.google.instrumentation:instrumentation-api:0.4.3',
'357e60f95cebb87c72151e49ba1f570d899734f8:com.google.protobuf.nano:protobuf-javanano:3.0.0-alpha-5',
'62ccf171a106ff6791507f2d5364c275f9a3131d:com.google.protobuf:protobuf-java:3.2.0',
'25ec9bf5bb119978c514b46f568bed896c5a4a8b:com.google.protobuf:protobuf-java-util:3.2.0',
'59b5b9c6e1a3054696d23492f888c1f8b583f5fc:com.google.protobuf:protobuf-lite:3.0.1',
'b32aba0cbe737a4ca953f71688725972e3ee927c:com.google.protobuf:protobuf-java:3.4.0',
'96aba8ab71c16018c6adf66771ce15c6491bc0fe:com.google.protobuf:protobuf-java-util:3.4.0',
'4de2b4ed3445c37ec1720a7d214712e845a24636:com.squareup.okhttp:okhttp:2.5.0',
'98476622f10715998eacf9240d6b479f12c66143:com.squareup.okio:okio:1.6.0',
'f32006a1245dfa2d68bf92a1b4cc01831889c95b:io.grpc:grpc-all:1.2.0',
'540e20dffcaf91d4a18cb57637f2bfdfc3bb3676:io.grpc:grpc-auth:1.2.0',
'1932db544cbb427bc18f902c7ebbb3f7e44991df:io.grpc:grpc-context:1.2.0',
'f12a213e2b59a0615df2cc9bed35dc15fd2fee37:io.grpc:grpc-core:1.2.0',
'e2682d2dc052898f87433e7a6d03d104ef98df74:io.grpc:grpc-netty:1.2.0',
'fc17023227651ccf369570588b4516a96ca32fed:io.grpc:grpc-okhttp:1.2.0',
'2676852d2dbd20155d9b1a940a456eae5b7445f0:io.grpc:grpc-protobuf:1.2.0',
'5ecc9a6e23e11694f99fad3e66e12cc3ce3b93b4:io.grpc:grpc-protobuf-lite:1.2.0',
'58d8d4ec67fb1c929802450f23f5d5a3a036d3ac:io.grpc:grpc-protobuf-nano:1.2.0',
'964dda53b3085bfd17c7aaf51495f9efc8bda36c:io.grpc:grpc-stub:1.2.0',
'43292c2622e340a0d07178c341ca3bdf3d662034:io.netty:netty-buffer:4.1.8.Final',
'1bd0a2d032e5c7fc3f42c1b483d0f4c57eb516a3:io.netty:netty-codec:4.1.8.Final',
'1e88617c4a6c88da7e86fdbbd9494d22a250c879:io.netty:netty-codec-http:4.1.8.Final',
'105a99ee5767463370ccc3d2e16800bd99f5648e:io.netty:netty-codec-http2:4.1.8.Final',
'7f7c5f5b154646d7c571f8ca944fb813f71b1d51:io.netty:netty-codec-socks:4.1.8.Final',
'ee62c80318413d2375d145e51e48d7d35c901324:io.netty:netty-common:4.1.8.Final',
'db01139bfb11afd009a695eef55b43bbf22c4ef5:io.netty:netty-handler:4.1.8.Final',
'c4d22e8b9071a0ea8d75766d869496c32648a758:io.netty:netty-handler-proxy:4.1.8.Final',
'2e116cdd5edc01b2305072b1dbbd17c0595dbfef:io.netty:netty-resolver:4.1.8.Final',
'905b5dadce881c9824b3039c0df36dabbb7b6a07:io.netty:netty-transport:4.1.8.Final',
'59340bc5e354e2cd8a4e7e7b7d44bd27f876e62e:io.grpc:grpc-all:1.7.0',
'7c7f0b0f8816657cdcfd654f17b866fd77b1546d:io.grpc:grpc-auth:1.7.0',
'e004fa243a627a64e91712154b93c5611d5c3af3:io.grpc:grpc-context:1.7.0',
'307405121aac5a31fa9b45dd883a8b3607ba7ab6:io.grpc:grpc-core:1.7.0',
'2ceeca086ba8388293dea4a26f524815f7f905d1:io.grpc:grpc-netty:1.7.0',
'5b10f46007ef76d30779203d9acef06a13fd9b0c:io.grpc:grpc-okhttp:1.7.0',
'2ee434bb315f074f176913c4293dd3b3bb63bccc:io.grpc:grpc-protobuf:1.7.0',
'a0e2a7b7498cdcdb4a37bbe2f781cd2259a6bdb2:io.grpc:grpc-protobuf-lite:1.7.0',
'a5e51c61ab47b149d43a59d673d50ef5dd5bc396:io.grpc:grpc-protobuf-nano:1.7.0',
'0b80ca6416e1433648de7af49e62b12bf3c4a500:io.grpc:grpc-stub:1.7.0',
'63b5fa95c74785e16f2c30ce268bc222e35c8cb5:io.netty:netty-buffer:4.1.16.Final',
'd84a1f21768b7309c2954521cf5a1f46c2309eb1:io.netty:netty-codec:4.1.16.Final',
'd64312378b438dfdad84267c599a053327c6f02a:io.netty:netty-codec-http:4.1.16.Final',
'45c27cddac120a4fcda8f699659e59389f7b9736:io.netty:netty-codec-http2:4.1.16.Final',
'f42aabfb1dcae4eaf1700f2c2d047eab3c1b8523:io.netty:netty-codec-socks:4.1.16.Final',
'177a6b30cca92f6f5f9873c9befd681377a4c328:io.netty:netty-common:4.1.16.Final',
'fec0e63e7dd7f4eeef7ea8dc47a1ff32dfc7ebc2:io.netty:netty-handler:4.1.16.Final',
'e3007ed3368748ccdc35c1f38c7d6c089768373a:io.netty:netty-handler-proxy:4.1.16.Final',
'f6eb553b53fb3a90a8ac1170697093fed82eae28:io.netty:netty-resolver:4.1.16.Final',
'3c8ee2c4d4a1cbb947a5c184c7aeb2204260958b:io.netty:netty-transport:4.1.16.Final',
'8e3cd27ac3634373aa4e7aba3c13fc5ac22cb6b7:io.opencensus:opencensus-api:0.6.0',
],
)

load("@grpc_java//:rules.bzl", "grpc_java_runtime")
grpc_java_runtime()
load("@grpc_java//:rules.bzl", "grpc_java_compile")
grpc_java_compile()
2 changes: 1 addition & 1 deletion example/grpc_java/src/main/java/BUILD
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
java_binary(
name = "main",
deps = ["@grpc_java//:runtime"],
deps = ["@grpc_java//:compile"],
srcs = ["Main.java"],
main_class = "example.Main",
)
18 changes: 15 additions & 3 deletions maven/internal/maven_repository.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ def _execute(rtx, cmds):
cmds: !list<string>
Returns: struct value from the rtx.execute method.
"""
#print("Execute <%s>" % " ".join(cmds))
result = rtx.execute(cmds)
if result.return_code:
fail(" ".join(cmds) + "failed: %s" %(result.stderr))
Expand Down Expand Up @@ -530,7 +531,10 @@ def _maven_repository_impl(rtx):
rtx.attr.experimental_disambiguate_maven_jar_workspace_names)

# Write a build.gradle file where our exection scope will be.
rtx.file("build.gradle", _format_build_gradle_file(rtx));
if rtx.attr.gradle_build_file:
rtx.symlink(Label(rtx.attr.gradle_build_file, relative_to_caller_repository = True), "build.gradle")
else:
rtx.file("build.gradle", _format_build_gradle_file(rtx));

# Execute the gradle dependencies task
result = _execute(rtx, [java, "-jar", launcher_jar, "dependencies"]);
Expand All @@ -552,9 +556,9 @@ def _maven_repository_impl(rtx):
if artifact.get("new"):
print_rule = True

if print_rule:
if print_rule and rtx.attr.hermetic:
lines = _format_maven_repository(rtx, configs, transitive_artifacts)
print("\n# CLOSED-FORM RULE:\n# You can copy this to your WORKSPACE To suppress this message. \n%s\n" % "\n".join(lines))
print("\n# HERMETIC-FORM RULE:\n# You can copy this to your WORKSPACE To suppress this message. \n%s\n" % "\n".join(lines))

rtx.file("BUILD", _format_build_file(rtx, configs));
rtx.file("rules.bzl", _format_rules_file(rtx, rtx.name, configs, transitive_artifacts));
Expand All @@ -563,6 +567,11 @@ def _maven_repository_impl(rtx):
maven_repository = repository_rule(
implementation = _maven_repository_impl,
attrs = {
"gradle_build_file": attr.string(
#allow_single_file = True,
#executable = True,
#cfg = "host",
),
"deps": attr.string_list(
),
"experimental_disambiguate_maven_jar_workspace_names": attr.bool(
Expand All @@ -587,6 +596,9 @@ maven_repository = repository_rule(
executable = True,
cfg = "host",
),
"hermetic": attr.bool(
default = True,
),
"configurations": attr.string_list(
default = [
"compile",
Expand Down

0 comments on commit 9c3b07a

Please sign in to comment.