From f84e8c3245db1bdda88acfd9836330a4947f6641 Mon Sep 17 00:00:00 2001 From: Long Cao Date: Tue, 20 Aug 2019 11:32:52 -0400 Subject: [PATCH 1/5] move library_attrs to common_attributes.bzl --- scala/private/common_attributes.bzl | 9 +++++++++ scala/scala.bzl | 19 ++++--------------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/scala/private/common_attributes.bzl b/scala/private/common_attributes.bzl index 8a3e4b50b..7fd87c580 100644 --- a/scala/private/common_attributes.bzl +++ b/scala/private/common_attributes.bzl @@ -124,6 +124,15 @@ launcher_template = { ), } + +library_attrs = { + "main_class": attr.string(), + "exports": attr.label_list( + allow_files = False, + aspects = [_coverage_replacements_provider.aspect], + ), +} + # Single dep to allow IDEs to pickup all the implicit dependencies. resolve_deps = { "_scala_toolchain": attr.label_list( diff --git a/scala/scala.bzl b/scala/scala.bzl index c2b88b4a5..1fa755f71 100644 --- a/scala/scala.bzl +++ b/scala/scala.bzl @@ -9,14 +9,11 @@ load( "common_attrs", "common_attrs_for_plugin_bootstrapping", "implicit_deps", + "library_attrs", "resolve_deps", ) load("@io_bazel_rules_scala//scala/private:common.bzl", "sanitize_string_for_usage") load("@io_bazel_rules_scala//scala/private:common_outputs.bzl", "common_outputs") -load( - "@io_bazel_rules_scala//scala/private:coverage_replacements_provider.bzl", - _coverage_replacements_provider = "coverage_replacements_provider", -) load( "@io_bazel_rules_scala//specs2:specs2_junit.bzl", _specs2_junit_dependencies = "specs2_junit_dependencies", @@ -47,21 +44,13 @@ load( _scala_test_suite = "scala_test_suite", ) -_library_attrs = { - "main_class": attr.string(), - "exports": attr.label_list( - allow_files = False, - aspects = [_coverage_replacements_provider.aspect], - ), -} - _scala_library_attrs = {} _scala_library_attrs.update(implicit_deps) _scala_library_attrs.update(common_attrs) -_scala_library_attrs.update(_library_attrs) +_scala_library_attrs.update(library_attrs) _scala_library_attrs.update(resolve_deps) @@ -80,7 +69,7 @@ _scala_library_for_plugin_bootstrapping_attrs = {} _scala_library_for_plugin_bootstrapping_attrs.update(implicit_deps) -_scala_library_for_plugin_bootstrapping_attrs.update(_library_attrs) +_scala_library_for_plugin_bootstrapping_attrs.update(library_attrs) _scala_library_for_plugin_bootstrapping_attrs.update(resolve_deps) @@ -105,7 +94,7 @@ _scala_macro_library_attrs.update(implicit_deps) _scala_macro_library_attrs.update(common_attrs) -_scala_macro_library_attrs.update(_library_attrs) +_scala_macro_library_attrs.update(library_attrs) _scala_macro_library_attrs.update(resolve_deps) From 43466d0c0a52e9cecf481d8cef758c05e66e366c Mon Sep 17 00:00:00 2001 From: Long Cao Date: Tue, 20 Aug 2019 11:44:30 -0400 Subject: [PATCH 2/5] move scala_macro_library rule to its own file --- scala/private/rule_impls.bzl | 17 ++---- scala/private/rules/scala_macro_library.bzl | 58 +++++++++++++++++++++ scala/scala.bzl | 39 ++------------ 3 files changed, 66 insertions(+), 48 deletions(-) create mode 100644 scala/private/rules/scala_macro_library.bzl diff --git a/scala/private/rule_impls.bzl b/scala/private/rule_impls.bzl index 69dc3327a..cbb481fad 100644 --- a/scala/private/rule_impls.bzl +++ b/scala/private/rule_impls.bzl @@ -795,7 +795,7 @@ def collect_jars_from_common_ctx( deps_providers = deps_providers, ) -def _lib( +def lib( ctx, base_classpath, non_macro_lib, @@ -889,7 +889,7 @@ def scala_library_impl(ctx): print("'jvm_flags' for scala_library is deprecated. It does nothing today and will be removed from scala_library to avoid confusion.") scalac_provider = get_scalac_provider(ctx) unused_dependency_checker_mode = get_unused_dependency_checker_mode(ctx) - return _lib( + return lib( ctx, scalac_provider.default_classpath, True, @@ -899,7 +899,7 @@ def scala_library_impl(ctx): def scala_library_for_plugin_bootstrapping_impl(ctx): scalac_provider = get_scalac_provider(ctx) - return _lib( + return lib( ctx, scalac_provider.default_classpath, True, @@ -907,17 +907,6 @@ def scala_library_for_plugin_bootstrapping_impl(ctx): unused_dependency_checker_mode = "off", ) -def scala_macro_library_impl(ctx): - scalac_provider = get_scalac_provider(ctx) - unused_dependency_checker_mode = get_unused_dependency_checker_mode(ctx) - return _lib( - ctx, - scalac_provider.default_macro_classpath, - False, # don't build the ijar for macros - unused_dependency_checker_mode, - ctx.attr.unused_dependency_checker_ignored_targets, - ) - # Common code shared by all scala binary implementations. def scala_binary_common( ctx, diff --git a/scala/private/rules/scala_macro_library.bzl b/scala/private/rules/scala_macro_library.bzl new file mode 100644 index 000000000..6806ccf12 --- /dev/null +++ b/scala/private/rules/scala_macro_library.bzl @@ -0,0 +1,58 @@ +load( + "@io_bazel_rules_scala//scala/private:common_attributes.bzl", + "common_attrs", + "implicit_deps", + "library_attrs", + "resolve_deps", +) +load("@io_bazel_rules_scala//scala/private:common_outputs.bzl", "common_outputs") +load( + "@io_bazel_rules_scala//scala/private:rule_impls.bzl", + "get_scalac_provider", + "get_unused_dependency_checker_mode", + "lib", +) + +def _scala_macro_library_impl(ctx): + scalac_provider = get_scalac_provider(ctx) + unused_dependency_checker_mode = get_unused_dependency_checker_mode(ctx) + return lib( + ctx, + scalac_provider.default_macro_classpath, + False, # don't build the ijar for macros + unused_dependency_checker_mode, + ctx.attr.unused_dependency_checker_ignored_targets, + ) + +_scala_macro_library_attrs = { + "main_class": attr.string(), + "exports": attr.label_list(allow_files = False), +} + +_scala_macro_library_attrs.update(implicit_deps) + +_scala_macro_library_attrs.update(common_attrs) + +_scala_macro_library_attrs.update(library_attrs) + +_scala_macro_library_attrs.update(resolve_deps) + +# Set unused_dependency_checker_mode default to off for scala_macro_library +_scala_macro_library_attrs["unused_dependency_checker_mode"] = attr.string( + default = "off", + values = [ + "warn", + "error", + "off", + "", + ], + mandatory = False, +) + +scala_macro_library = rule( + attrs = _scala_macro_library_attrs, + fragments = ["java"], + outputs = common_outputs, + toolchains = ["@io_bazel_rules_scala//scala:toolchain_type"], + implementation = _scala_macro_library_impl, +) \ No newline at end of file diff --git a/scala/scala.bzl b/scala/scala.bzl index 1fa755f71..a036abefd 100644 --- a/scala/scala.bzl +++ b/scala/scala.bzl @@ -2,7 +2,6 @@ load( "@io_bazel_rules_scala//scala/private:rule_impls.bzl", _scala_library_for_plugin_bootstrapping_impl = "scala_library_for_plugin_bootstrapping_impl", _scala_library_impl = "scala_library_impl", - _scala_macro_library_impl = "scala_macro_library_impl", ) load( "@io_bazel_rules_scala//scala/private:common_attributes.bzl", @@ -34,6 +33,10 @@ load( "@io_bazel_rules_scala//scala/private:rules/scala_junit_test.bzl", _scala_junit_test = "scala_junit_test", ) +load( + "@io_bazel_rules_scala//scala/private:rules/scala_macro_library.bzl", + _scala_macro_library = "scala_macro_library", +) load( "@io_bazel_rules_scala//scala/private:rules/scala_repl.bzl", _scala_repl = "scala_repl", @@ -85,39 +88,6 @@ scala_library_for_plugin_bootstrapping = rule( implementation = _scala_library_for_plugin_bootstrapping_impl, ) -_scala_macro_library_attrs = { - "main_class": attr.string(), - "exports": attr.label_list(allow_files = False), -} - -_scala_macro_library_attrs.update(implicit_deps) - -_scala_macro_library_attrs.update(common_attrs) - -_scala_macro_library_attrs.update(library_attrs) - -_scala_macro_library_attrs.update(resolve_deps) - -# Set unused_dependency_checker_mode default to off for scala_macro_library -_scala_macro_library_attrs["unused_dependency_checker_mode"] = attr.string( - default = "off", - values = [ - "warn", - "error", - "off", - "", - ], - mandatory = False, -) - -scala_macro_library = rule( - attrs = _scala_macro_library_attrs, - fragments = ["java"], - outputs = common_outputs, - toolchains = ["@io_bazel_rules_scala//scala:toolchain_type"], - implementation = _scala_macro_library_impl, -) - # Scala library suite generates a series of scala libraries # then it depends on them with a meta one which exports all the sub targets def scala_library_suite( @@ -162,6 +132,7 @@ def scala_specs2_junit_test(name, **kwargs): scala_binary = _scala_binary scala_doc = _scala_doc scala_junit_test = _scala_junit_test +scala_macro_library = _scala_macro_library scala_repl = _scala_repl scala_repositories = _scala_repositories scala_test = _scala_test From 0cbe2a6f673fd9293cb675e944a45c3d4dfc71fa Mon Sep 17 00:00:00 2001 From: Long Cao Date: Tue, 20 Aug 2019 18:20:45 -0400 Subject: [PATCH 3/5] move all _library rules to scala_library.bzl, private stuff too --- scala/private/common_attributes.bzl | 8 - scala/private/rule_impls.bzl | 23 --- scala/private/rules/scala_library.bzl | 178 ++++++++++++++++++++ scala/private/rules/scala_macro_library.bzl | 58 ------- scala/scala.bzl | 91 +--------- 5 files changed, 185 insertions(+), 173 deletions(-) create mode 100644 scala/private/rules/scala_library.bzl delete mode 100644 scala/private/rules/scala_macro_library.bzl diff --git a/scala/private/common_attributes.bzl b/scala/private/common_attributes.bzl index 7fd87c580..eec37a799 100644 --- a/scala/private/common_attributes.bzl +++ b/scala/private/common_attributes.bzl @@ -125,14 +125,6 @@ launcher_template = { } -library_attrs = { - "main_class": attr.string(), - "exports": attr.label_list( - allow_files = False, - aspects = [_coverage_replacements_provider.aspect], - ), -} - # Single dep to allow IDEs to pickup all the implicit dependencies. resolve_deps = { "_scala_toolchain": attr.label_list( diff --git a/scala/private/rule_impls.bzl b/scala/private/rule_impls.bzl index cbb481fad..414513461 100644 --- a/scala/private/rule_impls.bzl +++ b/scala/private/rule_impls.bzl @@ -884,29 +884,6 @@ def get_unused_dependency_checker_mode(ctx): else: return ctx.toolchains["@io_bazel_rules_scala//scala:toolchain_type"].unused_dependency_checker_mode -def scala_library_impl(ctx): - if ctx.attr.jvm_flags: - print("'jvm_flags' for scala_library is deprecated. It does nothing today and will be removed from scala_library to avoid confusion.") - scalac_provider = get_scalac_provider(ctx) - unused_dependency_checker_mode = get_unused_dependency_checker_mode(ctx) - return lib( - ctx, - scalac_provider.default_classpath, - True, - unused_dependency_checker_mode, - ctx.attr.unused_dependency_checker_ignored_targets, - ) - -def scala_library_for_plugin_bootstrapping_impl(ctx): - scalac_provider = get_scalac_provider(ctx) - return lib( - ctx, - scalac_provider.default_classpath, - True, - unused_dependency_checker_ignored_targets = [], - unused_dependency_checker_mode = "off", - ) - # Common code shared by all scala binary implementations. def scala_binary_common( ctx, diff --git a/scala/private/rules/scala_library.bzl b/scala/private/rules/scala_library.bzl new file mode 100644 index 000000000..0288b3441 --- /dev/null +++ b/scala/private/rules/scala_library.bzl @@ -0,0 +1,178 @@ +load("@io_bazel_rules_scala//scala/private:common.bzl", "sanitize_string_for_usage") +load( + "@io_bazel_rules_scala//scala/private:common_attributes.bzl", + "common_attrs", + "common_attrs_for_plugin_bootstrapping", + "implicit_deps", + "resolve_deps", +) +load("@io_bazel_rules_scala//scala/private:common_outputs.bzl", "common_outputs") +load( + "@io_bazel_rules_scala//scala/private:coverage_replacements_provider.bzl", + _coverage_replacements_provider = "coverage_replacements_provider", +) +load( + "@io_bazel_rules_scala//scala/private:rule_impls.bzl", + "get_scalac_provider", + "get_unused_dependency_checker_mode", + "lib", +) + +## +# Common stuff to _library rules +## + +_library_attrs = { + "main_class": attr.string(), + "exports": attr.label_list( + allow_files = False, + aspects = [_coverage_replacements_provider.aspect], + ), +} + +## +# scala_library +## + +def _scala_library_impl(ctx): + if ctx.attr.jvm_flags: + print("'jvm_flags' for scala_library is deprecated. It does nothing today and will be removed from scala_library to avoid confusion.") + scalac_provider = get_scalac_provider(ctx) + unused_dependency_checker_mode = get_unused_dependency_checker_mode(ctx) + return lib( + ctx, + scalac_provider.default_classpath, + True, + unused_dependency_checker_mode, + ctx.attr.unused_dependency_checker_ignored_targets, + ) + +_scala_library_attrs = {} + +_scala_library_attrs.update(implicit_deps) + +_scala_library_attrs.update(common_attrs) + +_scala_library_attrs.update(_library_attrs) + +_scala_library_attrs.update(resolve_deps) + +scala_library = rule( + attrs = _scala_library_attrs, + fragments = ["java"], + outputs = common_outputs, + toolchains = ["@io_bazel_rules_scala//scala:toolchain_type"], + implementation = _scala_library_impl, +) + +# Scala library suite generates a series of scala libraries +# then it depends on them with a meta one which exports all the sub targets +def scala_library_suite( + name, + srcs = [], + exports = [], + visibility = None, + **kwargs): + ts = [] + for src_file in srcs: + n = "%s_lib_%s" % (name, sanitize_string_for_usage(src_file)) + scala_library( + name = n, + srcs = [src_file], + visibility = visibility, + exports = exports, + unused_dependency_checker_mode = "off", + **kwargs + ) + ts.append(n) + scala_library( + name = name, + visibility = visibility, + exports = exports + ts, + deps = ts, + ) + +## +# scala_library_for_plugin_bootstrapping +## + +def _scala_library_for_plugin_bootstrapping_impl(ctx): + scalac_provider = get_scalac_provider(ctx) + return lib( + ctx, + scalac_provider.default_classpath, + True, + unused_dependency_checker_ignored_targets = [], + unused_dependency_checker_mode = "off", + ) + +# the scala compiler plugin used for dependency analysis is compiled using `scala_library`. +# in order to avoid cyclic dependencies `scala_library_for_plugin_bootstrapping` was created for this purpose, +# which does not contain plugin related attributes, and thus avoids the cyclic dependency issue +_scala_library_for_plugin_bootstrapping_attrs = {} + +_scala_library_for_plugin_bootstrapping_attrs.update(implicit_deps) + +_scala_library_for_plugin_bootstrapping_attrs.update(_library_attrs) + +_scala_library_for_plugin_bootstrapping_attrs.update(resolve_deps) + +_scala_library_for_plugin_bootstrapping_attrs.update( + common_attrs_for_plugin_bootstrapping, +) + +scala_library_for_plugin_bootstrapping = rule( + attrs = _scala_library_for_plugin_bootstrapping_attrs, + fragments = ["java"], + outputs = common_outputs, + toolchains = ["@io_bazel_rules_scala//scala:toolchain_type"], + implementation = _scala_library_for_plugin_bootstrapping_impl, +) + +## +# scala_macro_library +## + +def _scala_macro_library_impl(ctx): + scalac_provider = get_scalac_provider(ctx) + unused_dependency_checker_mode = get_unused_dependency_checker_mode(ctx) + return lib( + ctx, + scalac_provider.default_macro_classpath, + False, # don't build the ijar for macros + unused_dependency_checker_mode, + ctx.attr.unused_dependency_checker_ignored_targets, + ) + +_scala_macro_library_attrs = { + "main_class": attr.string(), + "exports": attr.label_list(allow_files = False), +} + +_scala_macro_library_attrs.update(implicit_deps) + +_scala_macro_library_attrs.update(common_attrs) + +_scala_macro_library_attrs.update(_library_attrs) + +_scala_macro_library_attrs.update(resolve_deps) + +# Set unused_dependency_checker_mode default to off for scala_macro_library +_scala_macro_library_attrs["unused_dependency_checker_mode"] = attr.string( + default = "off", + values = [ + "warn", + "error", + "off", + "", + ], + mandatory = False, +) + +scala_macro_library = rule( + attrs = _scala_macro_library_attrs, + fragments = ["java"], + outputs = common_outputs, + toolchains = ["@io_bazel_rules_scala//scala:toolchain_type"], + implementation = _scala_macro_library_impl, +) diff --git a/scala/private/rules/scala_macro_library.bzl b/scala/private/rules/scala_macro_library.bzl deleted file mode 100644 index 6806ccf12..000000000 --- a/scala/private/rules/scala_macro_library.bzl +++ /dev/null @@ -1,58 +0,0 @@ -load( - "@io_bazel_rules_scala//scala/private:common_attributes.bzl", - "common_attrs", - "implicit_deps", - "library_attrs", - "resolve_deps", -) -load("@io_bazel_rules_scala//scala/private:common_outputs.bzl", "common_outputs") -load( - "@io_bazel_rules_scala//scala/private:rule_impls.bzl", - "get_scalac_provider", - "get_unused_dependency_checker_mode", - "lib", -) - -def _scala_macro_library_impl(ctx): - scalac_provider = get_scalac_provider(ctx) - unused_dependency_checker_mode = get_unused_dependency_checker_mode(ctx) - return lib( - ctx, - scalac_provider.default_macro_classpath, - False, # don't build the ijar for macros - unused_dependency_checker_mode, - ctx.attr.unused_dependency_checker_ignored_targets, - ) - -_scala_macro_library_attrs = { - "main_class": attr.string(), - "exports": attr.label_list(allow_files = False), -} - -_scala_macro_library_attrs.update(implicit_deps) - -_scala_macro_library_attrs.update(common_attrs) - -_scala_macro_library_attrs.update(library_attrs) - -_scala_macro_library_attrs.update(resolve_deps) - -# Set unused_dependency_checker_mode default to off for scala_macro_library -_scala_macro_library_attrs["unused_dependency_checker_mode"] = attr.string( - default = "off", - values = [ - "warn", - "error", - "off", - "", - ], - mandatory = False, -) - -scala_macro_library = rule( - attrs = _scala_macro_library_attrs, - fragments = ["java"], - outputs = common_outputs, - toolchains = ["@io_bazel_rules_scala//scala:toolchain_type"], - implementation = _scala_macro_library_impl, -) \ No newline at end of file diff --git a/scala/scala.bzl b/scala/scala.bzl index a036abefd..fe87532c8 100644 --- a/scala/scala.bzl +++ b/scala/scala.bzl @@ -1,18 +1,3 @@ -load( - "@io_bazel_rules_scala//scala/private:rule_impls.bzl", - _scala_library_for_plugin_bootstrapping_impl = "scala_library_for_plugin_bootstrapping_impl", - _scala_library_impl = "scala_library_impl", -) -load( - "@io_bazel_rules_scala//scala/private:common_attributes.bzl", - "common_attrs", - "common_attrs_for_plugin_bootstrapping", - "implicit_deps", - "library_attrs", - "resolve_deps", -) -load("@io_bazel_rules_scala//scala/private:common.bzl", "sanitize_string_for_usage") -load("@io_bazel_rules_scala//scala/private:common_outputs.bzl", "common_outputs") load( "@io_bazel_rules_scala//specs2:specs2_junit.bzl", _specs2_junit_dependencies = "specs2_junit_dependencies", @@ -34,7 +19,10 @@ load( _scala_junit_test = "scala_junit_test", ) load( - "@io_bazel_rules_scala//scala/private:rules/scala_macro_library.bzl", + "@io_bazel_rules_scala//scala/private:rules/scala_library.bzl", + _scala_library = "scala_library", + _scala_library_suite = "scala_library_suite", + _scala_library_for_plugin_bootstrapping = "scala_library_for_plugin_bootstrapping", _scala_macro_library = "scala_macro_library", ) load( @@ -47,74 +35,6 @@ load( _scala_test_suite = "scala_test_suite", ) -_scala_library_attrs = {} - -_scala_library_attrs.update(implicit_deps) - -_scala_library_attrs.update(common_attrs) - -_scala_library_attrs.update(library_attrs) - -_scala_library_attrs.update(resolve_deps) - -scala_library = rule( - attrs = _scala_library_attrs, - fragments = ["java"], - outputs = common_outputs, - toolchains = ["@io_bazel_rules_scala//scala:toolchain_type"], - implementation = _scala_library_impl, -) - -# the scala compiler plugin used for dependency analysis is compiled using `scala_library`. -# in order to avoid cyclic dependencies `scala_library_for_plugin_bootstrapping` was created for this purpose, -# which does not contain plugin related attributes, and thus avoids the cyclic dependency issue -_scala_library_for_plugin_bootstrapping_attrs = {} - -_scala_library_for_plugin_bootstrapping_attrs.update(implicit_deps) - -_scala_library_for_plugin_bootstrapping_attrs.update(library_attrs) - -_scala_library_for_plugin_bootstrapping_attrs.update(resolve_deps) - -_scala_library_for_plugin_bootstrapping_attrs.update( - common_attrs_for_plugin_bootstrapping, -) - -scala_library_for_plugin_bootstrapping = rule( - attrs = _scala_library_for_plugin_bootstrapping_attrs, - fragments = ["java"], - outputs = common_outputs, - toolchains = ["@io_bazel_rules_scala//scala:toolchain_type"], - implementation = _scala_library_for_plugin_bootstrapping_impl, -) - -# Scala library suite generates a series of scala libraries -# then it depends on them with a meta one which exports all the sub targets -def scala_library_suite( - name, - srcs = [], - exports = [], - visibility = None, - **kwargs): - ts = [] - for src_file in srcs: - n = "%s_lib_%s" % (name, sanitize_string_for_usage(src_file)) - scala_library( - name = n, - srcs = [src_file], - visibility = visibility, - exports = exports, - unused_dependency_checker_mode = "off", - **kwargs - ) - ts.append(n) - scala_library( - name = name, - visibility = visibility, - exports = exports + ts, - deps = ts, - ) - def scala_specs2_junit_test(name, **kwargs): _scala_junit_test( name = name, @@ -132,6 +52,9 @@ def scala_specs2_junit_test(name, **kwargs): scala_binary = _scala_binary scala_doc = _scala_doc scala_junit_test = _scala_junit_test +scala_library_for_plugin_bootstrapping = _scala_library_for_plugin_bootstrapping +scala_library = _scala_library +scala_library_suite = _scala_library_suite scala_macro_library = _scala_macro_library scala_repl = _scala_repl scala_repositories = _scala_repositories From 4772f728e770c7f71b4a6bd27e4912ea129cbf3d Mon Sep 17 00:00:00 2001 From: Long Cao Date: Tue, 20 Aug 2019 18:35:51 -0400 Subject: [PATCH 4/5] move _lib into scala_library.bzl --- scala/private/rule_impls.bzl | 95 ++---------------------- scala/private/rules/scala_library.bzl | 103 ++++++++++++++++++++++++-- 2 files changed, 104 insertions(+), 94 deletions(-) diff --git a/scala/private/rule_impls.bzl b/scala/private/rule_impls.bzl index 414513461..7107bd963 100644 --- a/scala/private/rule_impls.bzl +++ b/scala/private/rule_impls.bzl @@ -403,7 +403,7 @@ def collect_java_providers_of(deps): providers.append(dep[JavaInfo]) return providers -def _compile_or_empty( +def compile_or_empty( ctx, manifest, jars, @@ -548,7 +548,7 @@ def _create_scala_compilation_provider(ctx, ijar, source_jar, deps_providers): runtime_deps = runtime_deps, ) -def _build_deployable(ctx, jars_list): +def build_deployable(ctx, jars_list): # This calls bazels singlejar utility. # For a full list of available command line options see: # https://github.com/bazelbuild/bazel/blob/master/src/java_tools/singlejar/java/com/google/devtools/build/singlejar/SingleJar.java#L311 @@ -795,89 +795,6 @@ def collect_jars_from_common_ctx( deps_providers = deps_providers, ) -def lib( - ctx, - base_classpath, - non_macro_lib, - unused_dependency_checker_mode, - unused_dependency_checker_ignored_targets): - # Build up information from dependency-like attributes - - # This will be used to pick up srcjars from non-scala library - # targets (like thrift code generation) - srcjars = collect_srcjars(ctx.attr.deps) - - unused_dependency_checker_is_off = unused_dependency_checker_mode == "off" - jars = collect_jars_from_common_ctx( - ctx, - base_classpath, - unused_dependency_checker_is_off = unused_dependency_checker_is_off, - ) - - (cjars, transitive_rjars) = (jars.compile_jars, jars.transitive_runtime_jars) - - write_manifest(ctx) - outputs = _compile_or_empty( - ctx, - ctx.outputs.manifest, - cjars, - srcjars, - non_macro_lib, - jars.transitive_compile_jars, - jars.jars2labels.jars_to_labels, - [], - unused_dependency_checker_ignored_targets = [ - target.label - for target in base_classpath + ctx.attr.exports + - unused_dependency_checker_ignored_targets - ], - unused_dependency_checker_mode = unused_dependency_checker_mode, - deps_providers = jars.deps_providers, - ) - - transitive_rjars = depset(outputs.full_jars, transitive = [transitive_rjars]) - - _build_deployable(ctx, transitive_rjars.to_list()) - - # Using transitive_files since transitive_rjars a depset and avoiding linearization - runfiles = ctx.runfiles( - transitive_files = transitive_rjars, - collect_data = True, - ) - - # Add information from exports (is key that AFTER all build actions/runfiles analysis) - # Since after, will not show up in deploy_jar or old jars runfiles - # Notice that compile_jars is intentionally transitive for exports - exports_jars = collect_jars(ctx.attr.exports) - transitive_rjars = depset( - transitive = [transitive_rjars, exports_jars.transitive_runtime_jars], - ) - - source_jars = _pack_source_jars(ctx) + outputs.source_jars - - scalaattr = create_scala_provider( - class_jar = outputs.class_jar, - compile_jars = depset( - outputs.ijars, - transitive = [exports_jars.compile_jars], - ), - deploy_jar = ctx.outputs.deploy_jar, - full_jars = outputs.full_jars, - ijar = outputs.ijar, - source_jars = source_jars, - statsfile = ctx.outputs.statsfile, - transitive_runtime_jars = transitive_rjars, - ) - - return struct( - files = depset([ctx.outputs.jar] + outputs.full_jars), # Here is the default output - instrumented_files = outputs.coverage.instrumented_files, - jars_to_labels = jars.jars2labels, - providers = [outputs.merged_provider, jars.jars2labels] + outputs.coverage.providers, - runfiles = runfiles, - scala = scalaattr, - ) - def get_unused_dependency_checker_mode(ctx): if ctx.attr.unused_dependency_checker_mode: return ctx.attr.unused_dependency_checker_mode @@ -899,7 +816,7 @@ def scala_binary_common( implicit_junit_deps_needed_for_java_compilation = [], runfiles_ext = []): write_manifest(ctx) - outputs = _compile_or_empty( + outputs = compile_or_empty( ctx, ctx.outputs.manifest, cjars, @@ -915,7 +832,7 @@ def scala_binary_common( ) # no need to build an ijar for an executable rjars = depset(outputs.full_jars, transitive = [rjars]) - _build_deployable(ctx, rjars.to_list()) + build_deployable(ctx, rjars.to_list()) runfiles = ctx.runfiles( transitive_files = depset( @@ -925,7 +842,7 @@ def scala_binary_common( collect_data = True, ) - source_jars = _pack_source_jars(ctx) + outputs.source_jars + source_jars = pack_source_jars(ctx) + outputs.source_jars scalaattr = create_scala_provider( class_jar = outputs.class_jar, @@ -975,7 +892,7 @@ def _pack_source_jar(ctx): return scala_source_jar -def _pack_source_jars(ctx): +def pack_source_jars(ctx): source_jar = _pack_source_jar(ctx) #_pack_source_jar may return None if java_common.pack_sources returned None (and it can) return [source_jar] if source_jar else [] diff --git a/scala/private/rules/scala_library.bzl b/scala/private/rules/scala_library.bzl index 0288b3441..ee656568e 100644 --- a/scala/private/rules/scala_library.bzl +++ b/scala/private/rules/scala_library.bzl @@ -1,4 +1,11 @@ -load("@io_bazel_rules_scala//scala/private:common.bzl", "sanitize_string_for_usage") +load("@io_bazel_rules_scala//scala:providers.bzl", "create_scala_provider") +load( + "@io_bazel_rules_scala//scala/private:common.bzl", + "collect_jars", + "collect_srcjars", + "sanitize_string_for_usage", + "write_manifest", +) load( "@io_bazel_rules_scala//scala/private:common_attributes.bzl", "common_attrs", @@ -13,9 +20,12 @@ load( ) load( "@io_bazel_rules_scala//scala/private:rule_impls.bzl", + "build_deployable", + "collect_jars_from_common_ctx", + "compile_or_empty", "get_scalac_provider", "get_unused_dependency_checker_mode", - "lib", + "pack_source_jars", ) ## @@ -30,6 +40,89 @@ _library_attrs = { ), } +def _lib( + ctx, + base_classpath, + non_macro_lib, + unused_dependency_checker_mode, + unused_dependency_checker_ignored_targets): + # Build up information from dependency-like attributes + + # This will be used to pick up srcjars from non-scala library + # targets (like thrift code generation) + srcjars = collect_srcjars(ctx.attr.deps) + + unused_dependency_checker_is_off = unused_dependency_checker_mode == "off" + jars = collect_jars_from_common_ctx( + ctx, + base_classpath, + unused_dependency_checker_is_off = unused_dependency_checker_is_off, + ) + + (cjars, transitive_rjars) = (jars.compile_jars, jars.transitive_runtime_jars) + + write_manifest(ctx) + outputs = compile_or_empty( + ctx, + ctx.outputs.manifest, + cjars, + srcjars, + non_macro_lib, + jars.transitive_compile_jars, + jars.jars2labels.jars_to_labels, + [], + unused_dependency_checker_ignored_targets = [ + target.label + for target in base_classpath + ctx.attr.exports + + unused_dependency_checker_ignored_targets + ], + unused_dependency_checker_mode = unused_dependency_checker_mode, + deps_providers = jars.deps_providers, + ) + + transitive_rjars = depset(outputs.full_jars, transitive = [transitive_rjars]) + + build_deployable(ctx, transitive_rjars.to_list()) + + # Using transitive_files since transitive_rjars a depset and avoiding linearization + runfiles = ctx.runfiles( + transitive_files = transitive_rjars, + collect_data = True, + ) + + # Add information from exports (is key that AFTER all build actions/runfiles analysis) + # Since after, will not show up in deploy_jar or old jars runfiles + # Notice that compile_jars is intentionally transitive for exports + exports_jars = collect_jars(ctx.attr.exports) + transitive_rjars = depset( + transitive = [transitive_rjars, exports_jars.transitive_runtime_jars], + ) + + source_jars = pack_source_jars(ctx) + outputs.source_jars + + scalaattr = create_scala_provider( + class_jar = outputs.class_jar, + compile_jars = depset( + outputs.ijars, + transitive = [exports_jars.compile_jars], + ), + deploy_jar = ctx.outputs.deploy_jar, + full_jars = outputs.full_jars, + ijar = outputs.ijar, + source_jars = source_jars, + statsfile = ctx.outputs.statsfile, + transitive_runtime_jars = transitive_rjars, + ) + + return struct( + files = depset([ctx.outputs.jar] + outputs.full_jars), # Here is the default output + instrumented_files = outputs.coverage.instrumented_files, + jars_to_labels = jars.jars2labels, + providers = [outputs.merged_provider, jars.jars2labels] + outputs.coverage.providers, + runfiles = runfiles, + scala = scalaattr, + ) + ## # scala_library ## @@ -39,7 +132,7 @@ def _scala_library_impl(ctx): print("'jvm_flags' for scala_library is deprecated. It does nothing today and will be removed from scala_library to avoid confusion.") scalac_provider = get_scalac_provider(ctx) unused_dependency_checker_mode = get_unused_dependency_checker_mode(ctx) - return lib( + return _lib( ctx, scalac_provider.default_classpath, True, @@ -98,7 +191,7 @@ def scala_library_suite( def _scala_library_for_plugin_bootstrapping_impl(ctx): scalac_provider = get_scalac_provider(ctx) - return lib( + return _lib( ctx, scalac_provider.default_classpath, True, @@ -136,7 +229,7 @@ scala_library_for_plugin_bootstrapping = rule( def _scala_macro_library_impl(ctx): scalac_provider = get_scalac_provider(ctx) unused_dependency_checker_mode = get_unused_dependency_checker_mode(ctx) - return lib( + return _lib( ctx, scalac_provider.default_macro_classpath, False, # don't build the ijar for macros From b145c7e38f304a0051d04de62684d02800bb20da Mon Sep 17 00:00:00 2001 From: Long Cao Date: Tue, 20 Aug 2019 18:37:49 -0400 Subject: [PATCH 5/5] alphasort --- scala/scala.bzl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scala/scala.bzl b/scala/scala.bzl index fe87532c8..fb4a9eeaf 100644 --- a/scala/scala.bzl +++ b/scala/scala.bzl @@ -21,8 +21,8 @@ load( load( "@io_bazel_rules_scala//scala/private:rules/scala_library.bzl", _scala_library = "scala_library", - _scala_library_suite = "scala_library_suite", _scala_library_for_plugin_bootstrapping = "scala_library_for_plugin_bootstrapping", + _scala_library_suite = "scala_library_suite", _scala_macro_library = "scala_macro_library", ) load( @@ -52,8 +52,8 @@ def scala_specs2_junit_test(name, **kwargs): scala_binary = _scala_binary scala_doc = _scala_doc scala_junit_test = _scala_junit_test -scala_library_for_plugin_bootstrapping = _scala_library_for_plugin_bootstrapping scala_library = _scala_library +scala_library_for_plugin_bootstrapping = _scala_library_for_plugin_bootstrapping scala_library_suite = _scala_library_suite scala_macro_library = _scala_macro_library scala_repl = _scala_repl