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

Commit 900ee6b

Browse files
authored
Archive action (#133)
1 parent 2a1269f commit 900ee6b

3 files changed

Lines changed: 58 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.4.8
2+
3+
* Add utilities for Dart archives.
4+
15
## 0.4.7
26

37
* Add support for build time --define arguments to codegen binaries
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"""Custom internal impl of create_archive."""
2+
3+
def create_archive(ctx, srcs, label):
4+
"""Creates an archive for the supplied srcs.
5+
6+
Args:
7+
ctx: The target context.
8+
srcs: the srcs for the current target
9+
label: the label for the current target
10+
Returns:
11+
- A tar file which contains the supplied srcs.
12+
13+
"""
14+
commands = []
15+
for src in srcs:
16+
commands += ["mkdir -p $(dirname $ARCHIVE_DIR/%s)" % src.short_path]
17+
commands += ["cp -L %s $ARCHIVE_DIR/%s" % (src.path, src.short_path)]
18+
tmp_file = ctx.new_file(label.name + ".archive_inputs")
19+
ctx.file_action(output=tmp_file, content="\n".join(commands))
20+
tar_file = ctx.new_file(label.name + ".dart_archive.tar")
21+
ctx.action(
22+
inputs=srcs +[tmp_file],
23+
outputs=[tar_file],
24+
mnemonic="DartArchive",
25+
command="\n".join([
26+
"export WORKSPACE=${PWD}",
27+
"export ARCHIVE_DIR=$(mktemp -d)",
28+
"bash %s" % tmp_file.path,
29+
"cd $ARCHIVE_DIR",
30+
"tar -chzf temp_tar.tar *",
31+
"cd $WORKSPACE",
32+
"cp $ARCHIVE_DIR/temp_tar.tar %s" % tar_file.path]),
33+
progress_message="Creating Dart archive")
34+
return tar_file

dart/build_rules/common/context.bzl

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ load(
1818
"//dart/build_rules/common:path.bzl",
1919
"filter_files",
2020
)
21+
load(
22+
"//dart/build_rules/common:_archive.bzl",
23+
"create_archive",
24+
)
2125

2226
def collect_dart_context(dart_ctx, transitive = True, include_self = True):
2327
"""Collect direct or transitive deps in a map, merging contexts as needed."""
@@ -83,8 +87,14 @@ def make_dart_context(
8387
dart_srcs = filter_files(dart_filetypes, srcs)
8488
data = set(data or [])
8589
deps = deps or []
86-
transitive_srcs, transitive_dart_srcs, transitive_data, transitive_deps = (
87-
_collect_files(srcs, dart_srcs, data, deps))
90+
archive_srcs = list(srcs + data)
91+
92+
archive = None
93+
if archive_srcs:
94+
archive = create_archive(ctx, archive_srcs, ctx.label)
95+
96+
transitive_srcs, transitive_dart_srcs, transitive_data, transitive_deps, transitive_archives = (
97+
_collect_files(srcs, dart_srcs, data, deps, archive))
8898
strong_analysis = None
8999
strong_summary = None
90100
if enable_summaries:
@@ -113,23 +123,29 @@ def make_dart_context(
113123
transitive_dart_srcs = transitive_dart_srcs,
114124
transitive_data = transitive_data,
115125
transitive_deps = transitive_deps,
126+
archive=archive,
127+
transitive_archives=transitive_archives
116128
)
117129

118-
def _collect_files(srcs, dart_srcs, data, deps):
130+
def _collect_files(srcs, dart_srcs, data, deps, archive):
119131
transitive_srcs = set()
120132
transitive_dart_srcs = set()
121133
transitive_data = set()
122134
transitive_deps = {}
135+
transitive_archives = set()
123136
for dep in deps:
124137
transitive_srcs += dep.dart.transitive_srcs
125138
transitive_dart_srcs += dep.dart.transitive_dart_srcs
126139
transitive_data += dep.dart.transitive_data
127140
transitive_deps += dep.dart.transitive_deps
128141
transitive_deps["%s" % dep.dart.label] = dep
142+
transitive_archives += dep.dart.transitive_archives
129143
transitive_srcs += srcs
130144
transitive_dart_srcs += dart_srcs
131145
transitive_data += data
132-
return (transitive_srcs, transitive_dart_srcs, transitive_data, transitive_deps)
146+
if archive:
147+
transitive_archives += [archive]
148+
return (transitive_srcs, transitive_dart_srcs, transitive_data, transitive_deps, transitive_archives)
133149

134150
def _merge_dart_context(dart_ctx1, dart_ctx2):
135151
"""Merges dart contexts, or fails if they are incompatible."""

0 commit comments

Comments
 (0)