Skip to content

Commit

Permalink
[bazel] Hook publishing into build steps
Browse files Browse the repository at this point in the history
  • Loading branch information
shs96c committed Aug 24, 2019
1 parent ad9bd21 commit fd56557
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 29 deletions.
12 changes: 8 additions & 4 deletions java/private/export.bzl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
load("//java/private:common.bzl", "MAVEN_PREFIX")
load("//java/private:pom.bzl", "pom_file")
load("//java/private:maven_artifacts.bzl", "maven_artifacts")
load("//java/private:pom.bzl", "pom_file")
load("//java/private:publish.bzl", "maven_publish")

def java_export(
name,
Expand Down Expand Up @@ -42,6 +43,9 @@ def java_export(

# And set up the publishing task

# maven_publish(
# name = "%s-publish" % name,
# )
maven_publish(
name = "%s-publish" % name,
maven_coordinates = maven_coordinates,
artifacts = name,
pom = "%s-pom.xml" % name,
)
33 changes: 8 additions & 25 deletions java/private/publish.bzl
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
load("//java/private:common.bzl", "MavenPublishInfo", "combine_jars")
load("//java/private:common.bzl", "combine_jars")

def _first_output(attr, name):
return attr[OutputGroupInfo][name].to_list()[0]

def _maven_publish_impl(ctx):
binjar = _first_output(ctx.attr.artifacts, "binjar")
srcjar = _first_output(ctx.attr.artifacts, "srcjar")
pom = _first_output(ctx.attr.pom, "pom")

combined_binjar = ctx.actions.declare_file("%s-modularized.jar" % ctx.attr.name)
combine_jars(ctx, ctx.executable._singlejar, [ctx.file.module_jar, binjar], combined_binjar)
srcjar = _first_output(ctx.attr.artifacts, "srcjar")

executable = ctx.actions.declare_file("%s-publisher" % ctx.attr.name)

Expand All @@ -23,7 +20,7 @@ def _maven_publish_impl(ctx):
output = executable,
is_executable = True,
substitutions = {
"{coordinates}": ctx.attr.coordinates,
"{coordinates}": ctx.attr.maven_coordinates,
"{gpg_password}": gpg_password,
"{maven_repo}": maven_repo,
"{password}": password,
Expand All @@ -33,52 +30,38 @@ def _maven_publish_impl(ctx):

return [
DefaultInfo(
files = depset([executable, srcjar, combined_binjar]),
files = depset([executable, srcjar, binjar]),
executable = executable,
runfiles = ctx.runfiles(
symlinks = {
"artifact.jar": combined_binjar,
"artifact.jar": binjar,
"artifact-source.jar": srcjar,
"pom.xml": pom,
"pom.xml": ctx.file.pom,
"uploader": ctx.executable._uploader,
},
collect_data = True,
).merge(ctx.attr._uploader[DefaultInfo].data_runfiles),
),
MavenPublishInfo(
bin_jar = depset([combined_binjar]),
src_jar = depset([srcjar]),
transitive_bin_jars = depset([combined_binjar], transitive = []),
),
]

maven_publish = rule(
_maven_publish_impl,
executable = True,
attrs = {
"coordinates": attr.string(
"maven_coordinates": attr.string(
mandatory = True,
),
"artifacts": attr.label(
mandatory = True,
),
"module_jar": attr.label(
mandatory = True,
allow_single_file = True,
),
"pom": attr.label(
mandatory = True,
allow_single_file = True,
),
"_template": attr.label(
default = "//java/private:maven_upload.txt",
allow_single_file = True,
),
"_singlejar": attr.label(
executable = True,
cfg = "host",
default = "//java/client/src/org/openqa/selenium/tools/jar:MergeJars",
allow_files = True,
),
"_uploader": attr.label(
executable = True,
cfg = "host",
Expand Down

0 comments on commit fd56557

Please sign in to comment.