bazel: put source jars in the same package.
This lets us associate the jar and the src jar in the java_import() declaration, so IDE plugins could understand how artifacts and source are connected. Classpath generation for Eclipse IDE was adjusted to reflect the changed location of the source artifact. Change-Id: I2cf9c6db3ad4b648457f2ac8d380c3771b4a3ee2
This commit is contained in:
parent
9875c00ed9
commit
c1a6976b50
@ -27,12 +27,12 @@ gwt_module(
|
||||
genrule2(
|
||||
name = 'jgit_edit_src',
|
||||
cmd = ' && '.join([
|
||||
'unzip -qd $$TMP $(location @jgit//src) ' +
|
||||
'unzip -qd $$TMP $(location @jgit//jar:src) ' +
|
||||
'org/eclipse/jgit/diff/Edit.java',
|
||||
'cd $$TMP',
|
||||
'zip -Dq $$ROOT/$@ org/eclipse/jgit/diff/Edit.java',
|
||||
]),
|
||||
tools = ['@jgit//src'],
|
||||
tools = ['@jgit//jar:src'],
|
||||
outs = [ 'edit.srcjar' ],
|
||||
)
|
||||
|
||||
|
@ -32,7 +32,7 @@ java_library(
|
||||
|
||||
java_library(
|
||||
name = 'gwtjsonrpc_src',
|
||||
exports = ['@gwtjsonrpc//src'],
|
||||
exports = ['@gwtjsonrpc//jar:src'],
|
||||
visibility = ['//visibility:public'],
|
||||
data = ['//lib:LICENSE-Apache2.0'],
|
||||
)
|
||||
@ -53,7 +53,7 @@ java_library(
|
||||
|
||||
java_library(
|
||||
name = 'gwtorm_client_src',
|
||||
exports = ['@gwtorm_client//src'],
|
||||
exports = ['@gwtorm_client//jar:src'],
|
||||
visibility = ['//visibility:public'],
|
||||
data = ['//lib:LICENSE-Apache2.0'],
|
||||
)
|
||||
|
@ -32,15 +32,14 @@ java_library(
|
||||
|
||||
java_library(
|
||||
name = 'javax-validation_src',
|
||||
exports = ['@javax_validation//src'],
|
||||
exports = ['@javax_validation//jar:src'],
|
||||
visibility = ['//visibility:public'],
|
||||
data = ['//lib:LICENSE-Apache2.0'],
|
||||
)
|
||||
|
||||
java_library(
|
||||
name = 'jsinterop-annotations_src',
|
||||
exports = ['@jsinterop_annotations//src'],
|
||||
exports = ['@jsinterop_annotations//jar:src'],
|
||||
visibility = ['//visibility:public'],
|
||||
data = ['//lib:LICENSE-Apache2.0'],
|
||||
)
|
||||
|
||||
|
@ -81,7 +81,7 @@ DEPS = GWT_TRANSITIVE_DEPS + [
|
||||
'//gerrit-gwtexpui:CSS',
|
||||
'//lib:gwtjsonrpc',
|
||||
'//lib/gwt:dev',
|
||||
'@jgit//src',
|
||||
'@jgit//jar:src',
|
||||
]
|
||||
|
||||
USER_AGENT_XML = """<module rename-to='gerrit_ui'>
|
||||
|
@ -49,24 +49,29 @@ def _create_coordinates(fully_qualified_name):
|
||||
version = version,
|
||||
)
|
||||
|
||||
# Provides the syntax "@jar_name//jar" for bin classifier
|
||||
# and "@jar_name//src" for sources
|
||||
def _generate_build_file(ctx, classifier, filename):
|
||||
def _generate_build_file(ctx, binjar, srcjar):
|
||||
srcjar_attr = ""
|
||||
if srcjar:
|
||||
srcjar_attr = 'srcjar = "%s",' % srcjar
|
||||
contents = """
|
||||
# DO NOT EDIT: automatically generated BUILD file for maven_archive rule {rule_name}
|
||||
package(default_visibility = ['//visibility:public'])
|
||||
java_import(
|
||||
name = '{classifier}',
|
||||
jars = ['{filename}'],
|
||||
visibility = ['//visibility:public']
|
||||
name = 'jar',
|
||||
{srcjar_attr}
|
||||
jars = ['{binjar}'],
|
||||
)
|
||||
filegroup(
|
||||
name = 'file',
|
||||
srcs = ['{filename}'],
|
||||
visibility = ['//visibility:public']
|
||||
)\n""".format(classifier = classifier,
|
||||
\n""".format(srcjar_attr = srcjar_attr,
|
||||
rule_name = ctx.name,
|
||||
filename = filename)
|
||||
ctx.file('%s/BUILD' % ctx.path(classifier), contents, False)
|
||||
binjar = binjar)
|
||||
if srcjar:
|
||||
contents += """
|
||||
java_import(
|
||||
name = 'src',
|
||||
jars = ['{srcjar}'],
|
||||
)
|
||||
""".format(srcjar = srcjar)
|
||||
ctx.file('%s/BUILD' % ctx.path("jar"), contents, False)
|
||||
|
||||
def _maven_jar_impl(ctx):
|
||||
"""rule to download a Maven archive."""
|
||||
@ -83,10 +88,6 @@ def _maven_jar_impl(ctx):
|
||||
binjar_path = ctx.path('/'.join(['jar', binjar]))
|
||||
binurl = url + '.jar'
|
||||
|
||||
srcjar = jar + '-src.jar'
|
||||
srcjar_path = ctx.path('/'.join(['src', srcjar]))
|
||||
srcurl = url + '-sources.jar'
|
||||
|
||||
python = ctx.which("python")
|
||||
script = ctx.path(ctx.attr._download_script)
|
||||
|
||||
@ -100,16 +101,20 @@ def _maven_jar_impl(ctx):
|
||||
|
||||
if out.return_code:
|
||||
fail("failed %s: %s" % (' '.join(args), out.stderr))
|
||||
_generate_build_file(ctx, "jar", binjar)
|
||||
|
||||
srcjar = None
|
||||
if ctx.attr.src_sha1 or ctx.attr.attach_source:
|
||||
srcjar = jar + '-src.jar'
|
||||
srcurl = url + '-sources.jar'
|
||||
srcjar_path = ctx.path('jar/' + srcjar)
|
||||
args = [python, script, "-o", srcjar_path, "-u", srcurl]
|
||||
if ctx.attr.src_sha1:
|
||||
args.extend(['-v', ctx.attr.src_sha1])
|
||||
out = ctx.execute(args)
|
||||
if out.return_code:
|
||||
fail("failed %s: %s" % (args, out.stderr))
|
||||
_generate_build_file(ctx, "src", srcjar)
|
||||
|
||||
_generate_build_file(ctx, binjar, srcjar)
|
||||
|
||||
maven_jar=repository_rule(
|
||||
implementation=_maven_jar_impl,
|
||||
|
@ -210,7 +210,7 @@ def gen_classpath(ext):
|
||||
if m:
|
||||
prefix = m.group(1)
|
||||
suffix = m.group(2)
|
||||
p = path.join(prefix, "src", "%s-src.jar" % suffix)
|
||||
p = path.join(prefix, "jar", "%s-src.jar" % suffix)
|
||||
if path.exists(p):
|
||||
s = p
|
||||
# TODO(davido): make plugins actually work
|
||||
|
Loading…
x
Reference in New Issue
Block a user