-
-
Notifications
You must be signed in to change notification settings - Fork 289
Aspect-based scrooge implementation #524
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
Changes from 4 commits
d47b079
fcd3214
e1cf910
dafcb3a
d7dae2f
dcfda86
0f693ab
4d7577c
ddef410
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,22 @@ | ||
load("//thrift:thrift.bzl", "thrift_library") | ||
|
||
filegroup( | ||
java_import( | ||
name = "barejar1", | ||
srcs = ["bare-thrift-1.jar"], | ||
jars = ["bare-thrift-1.jar"], | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
java_import( | ||
name = "bare_jar_1_remote", | ||
jars = ["bare_jar_1_scrooge.jar"], | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
thrift_library( | ||
name = "bare_jar_1", | ||
external_jars = [":barejar1"], | ||
external_jars = [ | ||
":barejar1", | ||
":bare_jar_1_remote", | ||
], | ||
visibility = ["//visibility:public"], | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,22 @@ | ||
load("//thrift:thrift.bzl", "thrift_library") | ||
|
||
filegroup( | ||
java_import( | ||
name = "barejar2", | ||
srcs = ["bare-thrift-2.jar"], | ||
jars = ["bare-thrift-2.jar"], | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
java_import( | ||
name = "bare_jar_2_remote", | ||
jars = ["bare_jar_2_scrooge.jar"], | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
thrift_library( | ||
name = "bare_jar_2", | ||
external_jars = [":barejar2"], | ||
external_jars = [ | ||
":barejar2", | ||
":bare_jar_2_remote", | ||
], | ||
visibility = ["//visibility:public"], | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,21 @@ | ||
"""Rules for organizing thrift files.""" | ||
|
||
_thrift_filetype = FileType([".thrift"]) | ||
load("@io_bazel_rules_scala//thrift:thrift_info.bzl", "ThriftInfo") | ||
|
||
ThriftInfo = provider(fields = [ | ||
"srcs", # The source files in this rule | ||
"transitive_srcs", # the transitive version of the above | ||
"external_jars", # external jars of thrift files | ||
"transitive_external_jars" # transitive version of the above | ||
]) | ||
def empty_thrift_info(): | ||
return ThriftInfo( | ||
srcs = depset(), | ||
transitive_srcs = depset(), | ||
external_jars = depset(), | ||
transitive_external_jars = depset()) | ||
|
||
def merge_thrift_infos(tis): | ||
return ThriftInfo( | ||
srcs = depset(transitive = [t.srcs for t in tis]), | ||
transitive_srcs = depset(transitive = [t.transitive_srcs for t in tis]), | ||
external_jars = depset(transitive = [t.external_jars for t in tis]), | ||
transitive_external_jars = depset( | ||
transitive = [t.transitive_external_jars for t in tis])) | ||
|
||
def _common_prefix(strings): | ||
pref = None | ||
|
@@ -62,7 +70,6 @@ def _thrift_library_impl(ctx): | |
zipper_arg_path = ctx.actions.declare_file( | ||
"%s_zipper_args" % ctx.outputs.libarchive.path) | ||
ctx.actions.write(zipper_arg_path, zipper_args) | ||
_valid_thrift_deps(ctx.attr.deps) | ||
# We move the files and touch them so that the output file is a purely deterministic | ||
# product of the _content_ of the inputs | ||
cmd = """ | ||
|
@@ -81,6 +88,7 @@ rm -f {out} | |
progress_message = "making thrift archive %s (%s files)" % | ||
(ctx.label, len(src_paths)), | ||
) | ||
srcs_depset = depset([ctx.outputs.libarchive]) | ||
else: | ||
# we still have to create the output we declared | ||
ctx.actions.run_shell( | ||
|
@@ -95,20 +103,28 @@ rm {out}.contents | |
zipper = ctx.executable._zipper.path), | ||
progress_message = "making empty thrift archive %s" % ctx.label, | ||
) | ||
srcs_depset = depset() | ||
|
||
# external jars are references to thrift we depend on, | ||
# BUT WE DON'T BUILD. When we build the code, the code can | ||
# do a thrift include to this, but we won't generate the source or bytecode. | ||
remotes = [] | ||
for f in ctx.attr.external_jars: | ||
remotes.extend(f.files.to_list()) | ||
|
||
transitive_srcs = depset( | ||
[ctx.outputs.libarchive], | ||
transitive = _collect_thrift_srcs(ctx.attr.deps)) | ||
jarfiles = _collect_thrift_external_jars(ctx.attr.deps) | ||
for jar in ctx.attr.external_jars: | ||
jarfiles.append(depset(jar.files)) | ||
transitive_external_jars = depset(transitive = jarfiles) | ||
transitive = _collect_thrift_srcs(ctx.attr.deps) + [srcs_depset]) | ||
transitive_external_jars = depset( | ||
remotes, | ||
transitive = [ | ||
d[ThriftInfo].transitive_external_jars for d in ctx.attr.deps | ||
]) | ||
|
||
return [ | ||
ThriftInfo( | ||
srcs = ctx.outputs.libarchive, | ||
srcs = srcs_depset, | ||
transitive_srcs = transitive_srcs, | ||
external_jars = ctx.attr.external_jars, | ||
external_jars = depset(remotes), | ||
transitive_external_jars = transitive_external_jars, | ||
) | ||
] | ||
|
@@ -119,17 +135,6 @@ def _collect_thrift_srcs(targets): | |
ds.append(target[ThriftInfo].transitive_srcs) | ||
return ds | ||
|
||
def _collect_thrift_external_jars(targets): | ||
ds = [] | ||
for target in targets: | ||
ds.append(target[ThriftInfo].transitive_external_jars) | ||
return ds | ||
|
||
def _valid_thrift_deps(targets): | ||
for target in targets: | ||
if not ThriftInfo in target: | ||
fail("thrift_library can only depend on thrift_library", target) | ||
|
||
# Some notes on the raison d'etre of thrift_library vs. code gen specific | ||
# targets. The idea is to be able to separate concerns -- thrift_library is | ||
# concerned purely with the ownership and organization of thrift files. It | ||
|
@@ -141,8 +146,8 @@ def _valid_thrift_deps(targets): | |
thrift_library = rule( | ||
implementation = _thrift_library_impl, | ||
attrs = { | ||
"srcs": attr.label_list(allow_files = _thrift_filetype), | ||
"deps": attr.label_list(), | ||
"srcs": attr.label_list(allow_files = [".thrift"]), | ||
"deps": attr.label_list(providers = [ThriftInfo]), | ||
#TODO this is not necessarily the best way to do this... the goal | ||
# is that we want thrifts to be able to be imported via an absolute | ||
# path. But the thrift files have no clue what part of their path | ||
|
@@ -160,6 +165,9 @@ thrift_library = rule( | |
"absolute_prefix": attr.string(default = '', mandatory = False), | ||
"absolute_prefixes": attr.string_list(), | ||
# This is a list of JARs which only contain Thrift files | ||
# these files will NOT be compiled as part of the current target, | ||
# but the current thrifts do include these. It should also include | ||
|
||
# the compiled versions of these thrifts | ||
"external_jars": attr.label_list(), | ||
"_zipper": attr.label( | ||
executable = True, | ||
|
@@ -168,4 +176,5 @@ thrift_library = rule( | |
allow_files = True) | ||
}, | ||
outputs = {"libarchive": "lib%{name}.jar"}, | ||
provides = [ThriftInfo], | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
ThriftInfo = provider(fields = [ | ||
"srcs", # The source files in this rule | ||
"transitive_srcs", # the transitive version of the above | ||
"external_jars", # external jars of thrift files | ||
"transitive_external_jars", # transitive version of the above | ||
]) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
build --experimental_local_disk_cache | ||
build --experimental_local_disk_cache_path=.bazel_cache | ||
#build --experimental_local_disk_cache | ||
|
||
#build --experimental_local_disk_cache_path=.bazel_cache |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is
thrifts_scrooge
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is the compiled scrooge code.