|
14 | 14 |
|
15 | 15 | """Dart rules targeting web clients."""
|
16 | 16 |
|
17 |
| - |
18 | 17 | load(":internal.bzl", "collect_files", "layout_action", "make_dart_context", "package_spec_action")
|
19 | 18 |
|
20 |
| - |
21 |
| -def dart2js_action(ctx, dart_ctx, script_file, |
22 |
| - enable_asserts, csp, dump_info, minify, preserve_uris, |
23 |
| - js_output, part_outputs, other_outputs): |
24 |
| - """dart2js compile action.""" |
25 |
| - # Create a build directory. |
26 |
| - build_dir = ctx.label.name + ".build/" |
27 |
| - |
28 |
| - # Emit package spec. |
29 |
| - package_spec_path = ctx.label.package + "/" + ctx.label.name + ".packages" |
30 |
| - package_spec = ctx.actions.declare_file(build_dir + package_spec_path) |
31 |
| - package_spec_action( |
32 |
| - ctx=ctx, |
33 |
| - dart_ctx=dart_ctx, |
34 |
| - output=package_spec, |
35 |
| - ) |
36 |
| - |
37 |
| - # Build a flattened directory of dart2js inputs, including inputs from the |
38 |
| - # src tree, genfiles, and bin. |
39 |
| - all_srcs, _ = collect_files(dart_ctx) |
40 |
| - build_dir_files = layout_action( |
41 |
| - ctx=ctx, |
42 |
| - srcs=all_srcs, |
43 |
| - output_dir=build_dir, |
44 |
| - ) |
45 |
| - out_script = build_dir_files[script_file.short_path] |
46 |
| - |
47 |
| - # Compute action inputs. |
48 |
| - inputs = ( |
49 |
| - build_dir_files.values() + [package_spec] |
50 |
| - ) |
51 |
| - tools = ( |
52 |
| - ctx.files._dart2js + |
53 |
| - ctx.files._dart2js_support |
54 |
| - ) |
55 |
| - |
56 |
| - # Compute dart2js args. |
57 |
| - dart2js_args = [ |
58 |
| - "--packages=%s" % package_spec.path, |
59 |
| - "--out=%s" % js_output.path, |
60 |
| - ] |
61 |
| - if enable_asserts: |
62 |
| - dart2js_args += ["--enable-asserts"] |
63 |
| - if csp: |
64 |
| - dart2js_args += ["--csp"] |
65 |
| - if dump_info: |
66 |
| - dart2js_args += ["--dump-info"] |
67 |
| - if minify: |
68 |
| - dart2js_args += ["--minify"] |
69 |
| - if preserve_uris: |
70 |
| - dart2js_args += ["--preserve-uris"] |
71 |
| - dart2js_args += [out_script.path] |
72 |
| - ctx.actions.run( |
73 |
| - inputs=inputs, |
74 |
| - tools=tools, |
75 |
| - executable=ctx.executable._dart2js_helper, |
76 |
| - arguments=[ |
77 |
| - str(ctx.label), |
78 |
| - str(ctx.attr.deferred_lib_count), |
79 |
| - ctx.outputs.js.path, |
80 |
| - ctx.executable._dart2js.path, |
81 |
| - ] + dart2js_args, |
82 |
| - outputs=[js_output] + part_outputs + other_outputs, |
83 |
| - progress_message="Compiling with dart2js %s" % ctx, |
84 |
| - mnemonic="Dart2jsCompile", |
85 |
| - ) |
86 |
| - |
| 19 | +def dart2js_action( |
| 20 | + ctx, |
| 21 | + dart_ctx, |
| 22 | + script_file, |
| 23 | + enable_asserts, |
| 24 | + csp, |
| 25 | + dump_info, |
| 26 | + minify, |
| 27 | + preserve_uris, |
| 28 | + js_output, |
| 29 | + part_outputs, |
| 30 | + other_outputs): |
| 31 | + """dart2js compile action.""" |
| 32 | + |
| 33 | + # Create a build directory. |
| 34 | + build_dir = ctx.label.name + ".build/" |
| 35 | + |
| 36 | + # Emit package spec. |
| 37 | + package_spec_path = ctx.label.package + "/" + ctx.label.name + ".packages" |
| 38 | + package_spec = ctx.actions.declare_file(build_dir + package_spec_path) |
| 39 | + package_spec_action( |
| 40 | + ctx = ctx, |
| 41 | + dart_ctx = dart_ctx, |
| 42 | + output = package_spec, |
| 43 | + ) |
| 44 | + |
| 45 | + # Build a flattened directory of dart2js inputs, including inputs from the |
| 46 | + # src tree, genfiles, and bin. |
| 47 | + all_srcs, _ = collect_files(dart_ctx) |
| 48 | + build_dir_files = layout_action( |
| 49 | + ctx = ctx, |
| 50 | + srcs = all_srcs, |
| 51 | + output_dir = build_dir, |
| 52 | + ) |
| 53 | + out_script = build_dir_files[script_file.short_path] |
| 54 | + |
| 55 | + # Compute action inputs. |
| 56 | + inputs = ( |
| 57 | + build_dir_files.values() + [package_spec] |
| 58 | + ) |
| 59 | + tools = ( |
| 60 | + ctx.files._dart2js + |
| 61 | + ctx.files._dart2js_support |
| 62 | + ) |
| 63 | + |
| 64 | + # Compute dart2js args. |
| 65 | + dart2js_args = [ |
| 66 | + "--packages=%s" % package_spec.path, |
| 67 | + "--out=%s" % js_output.path, |
| 68 | + ] |
| 69 | + if enable_asserts: |
| 70 | + dart2js_args += ["--enable-asserts"] |
| 71 | + if csp: |
| 72 | + dart2js_args += ["--csp"] |
| 73 | + if dump_info: |
| 74 | + dart2js_args += ["--dump-info"] |
| 75 | + if minify: |
| 76 | + dart2js_args += ["--minify"] |
| 77 | + if preserve_uris: |
| 78 | + dart2js_args += ["--preserve-uris"] |
| 79 | + dart2js_args += [out_script.path] |
| 80 | + ctx.actions.run( |
| 81 | + inputs = inputs, |
| 82 | + tools = tools, |
| 83 | + executable = ctx.executable._dart2js_helper, |
| 84 | + arguments = [ |
| 85 | + str(ctx.label), |
| 86 | + str(ctx.attr.deferred_lib_count), |
| 87 | + ctx.outputs.js.path, |
| 88 | + ctx.executable._dart2js.path, |
| 89 | + ] + dart2js_args, |
| 90 | + outputs = [js_output] + part_outputs + other_outputs, |
| 91 | + progress_message = "Compiling with dart2js %s" % ctx, |
| 92 | + mnemonic = "Dart2jsCompile", |
| 93 | + ) |
87 | 94 |
|
88 | 95 | def _dart_web_application_impl(ctx):
|
89 |
| - """Implements the dart_web_application build rule.""" |
90 |
| - dart_ctx = make_dart_context(ctx.label, |
91 |
| - srcs=ctx.files.srcs, |
92 |
| - data=ctx.files.data, |
93 |
| - deps=ctx.attr.deps) |
94 |
| - |
95 |
| - # Compute outputs. |
96 |
| - js_output = ctx.outputs.js |
97 |
| - other_outputs = [ |
98 |
| - ctx.outputs.deps_file, |
99 |
| - ctx.outputs.sourcemap, |
100 |
| - ] |
101 |
| - if ctx.attr.dump_info: |
102 |
| - other_outputs += [ctx.outputs.info_json] |
103 |
| - part_outputs = [] |
104 |
| - for i in range(1, ctx.attr.deferred_lib_count + 1): |
105 |
| - part_outputs += [getattr(ctx.outputs, "part_js%s" % i)] |
106 |
| - other_outputs += [getattr(ctx.outputs, "part_sourcemap%s" % i)] |
107 |
| - |
108 |
| - # Invoke dart2js. |
109 |
| - dart2js_action( |
110 |
| - ctx=ctx, |
111 |
| - dart_ctx=dart_ctx, |
112 |
| - script_file=ctx.file.script_file, |
113 |
| - enable_asserts=ctx.attr.enable_asserts, |
114 |
| - csp=ctx.attr.csp, |
115 |
| - dump_info=ctx.attr.dump_info, |
116 |
| - minify=ctx.attr.minify, |
117 |
| - preserve_uris=ctx.attr.preserve_uris, |
118 |
| - js_output=js_output, |
119 |
| - part_outputs=part_outputs, |
120 |
| - other_outputs=other_outputs, |
121 |
| - ) |
122 |
| - |
123 |
| - # TODO(cbracken) aggregate, inject licenses |
124 |
| - return struct() |
125 |
| - |
126 |
| - |
127 |
| - |
| 96 | + """Implements the dart_web_application build rule.""" |
| 97 | + dart_ctx = make_dart_context( |
| 98 | + ctx.label, |
| 99 | + srcs = ctx.files.srcs, |
| 100 | + data = ctx.files.data, |
| 101 | + deps = ctx.attr.deps, |
| 102 | + ) |
| 103 | + |
| 104 | + # Compute outputs. |
| 105 | + js_output = ctx.outputs.js |
| 106 | + other_outputs = [ |
| 107 | + ctx.outputs.deps_file, |
| 108 | + ctx.outputs.sourcemap, |
| 109 | + ] |
| 110 | + if ctx.attr.dump_info: |
| 111 | + other_outputs += [ctx.outputs.info_json] |
| 112 | + part_outputs = [] |
| 113 | + for i in range(1, ctx.attr.deferred_lib_count + 1): |
| 114 | + part_outputs += [getattr(ctx.outputs, "part_js%s" % i)] |
| 115 | + other_outputs += [getattr(ctx.outputs, "part_sourcemap%s" % i)] |
| 116 | + |
| 117 | + # Invoke dart2js. |
| 118 | + dart2js_action( |
| 119 | + ctx = ctx, |
| 120 | + dart_ctx = dart_ctx, |
| 121 | + script_file = ctx.file.script_file, |
| 122 | + enable_asserts = ctx.attr.enable_asserts, |
| 123 | + csp = ctx.attr.csp, |
| 124 | + dump_info = ctx.attr.dump_info, |
| 125 | + minify = ctx.attr.minify, |
| 126 | + preserve_uris = ctx.attr.preserve_uris, |
| 127 | + js_output = js_output, |
| 128 | + part_outputs = part_outputs, |
| 129 | + other_outputs = other_outputs, |
| 130 | + ) |
| 131 | + |
| 132 | + # TODO(cbracken) aggregate, inject licenses |
| 133 | + return struct() |
128 | 134 |
|
129 | 135 | def _dart_web_application_outputs(dump_info, deferred_lib_count):
|
130 |
| - """Returns the expected output map for dart_web_application.""" |
131 |
| - outputs = { |
132 |
| - "js": "%{name}.js", |
133 |
| - "deps_file": "%{name}.js.deps", |
134 |
| - "sourcemap": "%{name}.js.map", |
135 |
| - } |
136 |
| - if dump_info: |
137 |
| - outputs["info_json"] = "%{name}.js.info.json" |
138 |
| - for i in range(1, deferred_lib_count + 1): |
139 |
| - outputs["part_js%s" % i] = "%%{name}.js_%s.part.js" % i |
140 |
| - outputs["part_sourcemap%s" % i] = "%%{name}.js_%s.part.js.map" % i |
141 |
| - return outputs |
142 |
| - |
| 136 | + """Returns the expected output map for dart_web_application.""" |
| 137 | + outputs = { |
| 138 | + "js": "%{name}.js", |
| 139 | + "deps_file": "%{name}.js.deps", |
| 140 | + "sourcemap": "%{name}.js.map", |
| 141 | + } |
| 142 | + if dump_info: |
| 143 | + outputs["info_json"] = "%{name}.js.info.json" |
| 144 | + for i in range(1, deferred_lib_count + 1): |
| 145 | + outputs["part_js%s" % i] = "%%{name}.js_%s.part.js" % i |
| 146 | + outputs["part_sourcemap%s" % i] = "%%{name}.js_%s.part.js.map" % i |
| 147 | + return outputs |
143 | 148 |
|
144 | 149 | dart_web_application = rule(
|
145 |
| - implementation=_dart_web_application_impl, |
146 |
| - attrs={ |
147 |
| - "script_file": attr.label(allow_single_file=True, mandatory=True), |
148 |
| - "srcs": attr.label_list(allow_files=True, mandatory=True), |
149 |
| - "data": attr.label_list(allow_files=True), |
150 |
| - "deps": attr.label_list(providers=["dart"]), |
151 |
| - "deferred_lib_count": attr.int(default=0), |
| 150 | + implementation = _dart_web_application_impl, |
| 151 | + attrs = { |
| 152 | + "script_file": attr.label(allow_single_file = True, mandatory = True), |
| 153 | + "srcs": attr.label_list(allow_files = True, mandatory = True), |
| 154 | + "data": attr.label_list(allow_files = True), |
| 155 | + "deps": attr.label_list(providers = ["dart"]), |
| 156 | + "deferred_lib_count": attr.int(default = 0), |
152 | 157 | # compiler flags
|
153 |
| - "enable_asserts": attr.bool(default=False), |
154 |
| - "csp": attr.bool(default=False), |
155 |
| - "dump_info": attr.bool(default=False), |
156 |
| - "minify": attr.bool(default=True), |
157 |
| - "preserve_uris": attr.bool(default=False), |
| 158 | + "enable_asserts": attr.bool(default = False), |
| 159 | + "csp": attr.bool(default = False), |
| 160 | + "dump_info": attr.bool(default = False), |
| 161 | + "minify": attr.bool(default = True), |
| 162 | + "preserve_uris": attr.bool(default = False), |
158 | 163 | # tools
|
159 | 164 | "_dart2js": attr.label(
|
160 |
| - allow_single_file=True, |
161 |
| - executable=True, |
162 |
| - cfg="host", |
163 |
| - default=Label("//dart/build_rules/ext:dart2js")), |
| 165 | + allow_single_file = True, |
| 166 | + executable = True, |
| 167 | + cfg = "host", |
| 168 | + default = Label("//dart/build_rules/ext:dart2js"), |
| 169 | + ), |
164 | 170 | "_dart2js_support": attr.label(
|
165 |
| - allow_files=True, |
166 |
| - default=Label("//dart/build_rules/ext:dart2js_support")), |
| 171 | + allow_files = True, |
| 172 | + default = Label("//dart/build_rules/ext:dart2js_support"), |
| 173 | + ), |
167 | 174 | "_dart2js_helper": attr.label(
|
168 |
| - allow_single_file=True, |
169 |
| - executable=True, |
170 |
| - cfg="host", |
171 |
| - default=Label("//dart/build_rules/tools:dart2js_helper")), |
| 175 | + allow_single_file = True, |
| 176 | + executable = True, |
| 177 | + cfg = "host", |
| 178 | + default = Label("//dart/build_rules/tools:dart2js_helper"), |
| 179 | + ), |
172 | 180 | },
|
173 |
| - outputs=_dart_web_application_outputs, |
| 181 | + outputs = _dart_web_application_outputs, |
174 | 182 | )
|
0 commit comments