Skip to content
This repository has been archived by the owner on Dec 13, 2018. It is now read-only.

add enable_ddc attribute to dart_library #60

Merged
merged 1 commit into from
Dec 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dart/build_rules/core.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
42 changes: 24 additions & 18 deletions dart/build_rules/internal/dart_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
5 changes: 4 additions & 1 deletion dart/build_rules/internal/ddc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down