diff --git a/dart/build_rules/core.bzl b/dart/build_rules/core.bzl index 891cc21..92ad329 100644 --- a/dart/build_rules/core.bzl +++ b/dart/build_rules/core.bzl @@ -26,6 +26,7 @@ dart_library = rule( allow_files = True, cfg = "data", ), + "enable_ddc": attr.bool(default = True), "pub_pkg_name": attr.string(default = ""), "deps": attr.label_list(providers = ["dart"]), "force_ddc_compile": attr.bool(default = False), diff --git a/dart/build_rules/internal/dart_library.bzl b/dart/build_rules/internal/dart_library.bzl index be998c1..c75731b 100644 --- a/dart/build_rules/internal/dart_library.bzl +++ b/dart/build_rules/internal/dart_library.bzl @@ -14,8 +14,8 @@ def dart_library_impl(ctx): """Implements the dart_library() rule.""" assert_third_party_licenses(ctx) - ddc_output = ctx.outputs.ddc_output - source_map_output = ctx.outputs.ddc_sourcemap + ddc_output = ctx.outputs.ddc_output if ctx.attr.enable_ddc else None + source_map_output = ctx.outputs.ddc_sourcemap if ctx.attr.enable_ddc else None strong_summary = ctx.outputs.strong_summary _has_dart_sources = has_dart_sources(ctx.files.srcs) @@ -34,42 +34,48 @@ def dart_library_impl(ctx): else: summary_action(ctx, dart_ctx) - if not _has_dart_sources: - ctx.file_action( - output=ddc_output, - content=("// intentionally empty: package %s has no dart sources" % - ctx.label.name)) - ctx.file_action( - output=source_map_output, - content=("// intentionally empty: package %s has no dart sources" % - ctx.label.name)) - else: - ddc_action(ctx, dart_ctx, ddc_output, source_map_output) + if ctx.attr.enable_ddc: + if not _has_dart_sources: + ctx.file_action( + output=ddc_output, + content=("// intentionally empty: package %s has no dart sources" % + ctx.label.name)) + ctx.file_action( + output=source_map_output, + content=("// intentionally empty: package %s has no dart sources" % + ctx.label.name)) + else: + ddc_action(ctx, dart_ctx, ddc_output, source_map_output) return struct( dart=dart_ctx, ddc=struct( + enabled=ctx.attr.enable_ddc, output=ddc_output, sourcemap=source_map_output, ), ) -def dart_library_outputs(): +def dart_library_outputs(enable_ddc): """Returns the outputs of a Dart library rule. Dart library targets emit the following outputs: * name.api.ds: the strong-mode summary from dart analyzer (API only), if specified. - * name.js: the js generated by DDC - * name.js.map: the source map generated by DDC + * name.js: the js generated by DDC if enabled + * name.js.map: the source map generated by DDC if enabled Returns: a dict of types of outputs to their respective file suffixes """ outs = { - "ddc_output": "%{name}.js", - "ddc_sourcemap": "%{name}.js.map", "strong_summary": "%{name}." + api_summary_extension, } + if enable_ddc: + outs += { + "ddc_output": "%{name}.js", + "ddc_sourcemap": "%{name}.js.map", + } + return outs diff --git a/dart/build_rules/internal/ddc.bzl b/dart/build_rules/internal/ddc.bzl index 4e0b2bd..7124a0b 100644 --- a/dart/build_rules/internal/ddc.bzl +++ b/dart/build_rules/internal/ddc.bzl @@ -29,6 +29,9 @@ def ddc_action(ctx, dart_ctx, ddc_output, source_map_output): # Specify all input summaries on the command line args for dep in dart_ctx.transitive_deps.values(): + if not dep.ddc.enabled: + continue + strict_transitive_srcs += dep.dart.srcs if has_dart_sources(dep.dart.srcs): if dep.ddc.output and dep.dart.strong_summary: @@ -135,7 +138,7 @@ def dart_ddc_bundle_impl(ctx): dart_srcs_to_pkgs = {} for dep in dart_ctx.transitive_deps.values(): - if has_dart_sources(dep.dart.srcs): + if dep.ddc.enabled and has_dart_sources(dep.dart.srcs): # Collect dict of dart srcs to packages, if checking duplicate srcs # Note that we skip angular2 which is an exception to this rule for now. if (ctx.attr.check_duplicate_srcs and