@@ -50,11 +50,14 @@ def _expected_outs(ctx, label):
50
50
declaration_files += [ctx .new_file (ctx .bin_dir , basename + ext ) for ext in declarations ]
51
51
summary_files += [ctx .new_file (ctx .bin_dir , basename + ext ) for ext in summaries ]
52
52
53
+ i18n_messages_files = [ctx .new_file (ctx .bin_dir , ctx .label .name + "_ngc_messages.xmb" )]
54
+
53
55
return struct (
54
56
closure_js = closure_js_files ,
55
57
devmode_js = devmode_js_files ,
56
58
declarations = declaration_files ,
57
59
summaries = summary_files ,
60
+ i18n_messages = i18n_messages_files ,
58
61
)
59
62
60
63
def _ngc_tsconfig (ctx , files , srcs , ** kwargs ):
@@ -92,7 +95,69 @@ _collect_summaries_aspect = aspect(
92
95
attr_aspects = ["deps" ],
93
96
)
94
97
95
- def _compile_action (ctx , inputs , outputs , config_file_path ):
98
+ # Extra options passed to Node when running ngc.
99
+ _EXTRA_NODE_OPTIONS_FLAGS = [
100
+ # Expose the v8 garbage collection API to JS.
101
+ "--node_options=--expose-gc"
102
+ ]
103
+
104
+ def ngc_compile_action (ctx , label , inputs , outputs , messages_out , config_file_path ,
105
+ locale = None , i18n_args = []):
106
+ mnemonic = "AngularTemplateCompile"
107
+ progress_message = "Compiling Angular templates (ngc) %s" % label
108
+ supports_workers = "0"
109
+ if locale :
110
+ mnemonic = "AngularI18NMerging"
111
+ supports_workers = "0"
112
+ progress_message = ("Recompiling Angular templates (ngc) %s for locale %s" %
113
+ (label , locale ))
114
+ else :
115
+ supports_workers = str (int (ctx .attr ._supports_workers ))
116
+
117
+ arguments = _EXTRA_NODE_OPTIONS_FLAGS
118
+ # One at-sign makes this a params-file, enabling the worker strategy.
119
+ # Two at-signs escapes the argument so it's passed through to ngc
120
+ # rather than the contents getting expanded.
121
+ if supports_workers == "1" :
122
+ arguments += ["@@" + config_file_path ]
123
+ else :
124
+ arguments += ["-p" , config_file_path ]
125
+
126
+ arguments += i18n_args
127
+
128
+ ctx .action (
129
+ progress_message = progress_message ,
130
+ mnemonic = mnemonic ,
131
+ inputs = inputs ,
132
+ outputs = outputs ,
133
+ arguments = arguments ,
134
+ executable = ctx .executable .compiler ,
135
+ execution_requirements = {
136
+ "supports-workers" : supports_workers ,
137
+ },
138
+ )
139
+
140
+ if messages_out != None :
141
+ ctx .action (inputs = list (inputs ),
142
+ outputs = messages_out ,
143
+ executable = ctx .executable ._ng_xi18n ,
144
+ arguments = (_EXTRA_NODE_OPTIONS_FLAGS +
145
+ [config_file_path ] +
146
+ [messages_out [0 ].short_path ]),
147
+ progress_message = "Extracting Angular 2 messages (ng_xi18n)" ,
148
+ mnemonic = "Angular2MessageExtractor" )
149
+
150
+ # Return the parameters of the compilation which will be used to replay the
151
+ # ngc action for i18N.
152
+ if not locale and not ctx .attr .no_i18n :
153
+ return struct (
154
+ label = label ,
155
+ tsconfig = config_file_path ,
156
+ inputs = inputs ,
157
+ outputs = outputs ,
158
+ )
159
+
160
+ def _compile_action (ctx , inputs , outputs , messages_out , config_file_path ):
96
161
summaries = depset ()
97
162
for dep in ctx .attr .deps :
98
163
if hasattr (dep , "collect_summaries_aspect_result" ):
@@ -108,34 +173,16 @@ def _compile_action(ctx, inputs, outputs, config_file_path):
108
173
if hasattr (ctx .attr , "tsconfig" ) and ctx .file .tsconfig :
109
174
action_inputs += [ctx .file .tsconfig ]
110
175
111
- arguments = ["--node_options=--expose-gc" ]
112
- # One at-sign makes this a params-file, enabling the worker strategy.
113
- # Two at-signs escapes the argument so it's passed through to ngc
114
- # rather than the contents getting expanded.
115
- if ctx .attr ._supports_workers :
116
- arguments += ["@@" + config_file_path ]
117
- else :
118
- arguments += ["-p" , config_file_path ]
176
+ return ngc_compile_action (ctx , ctx .label , action_inputs , outputs , messages_out , config_file_path )
119
177
120
- ctx .action (
121
- progress_message = "Compiling Angular templates (ngc) %s" % ctx .label ,
122
- mnemonic = "AngularTemplateCompile" ,
123
- inputs = action_inputs ,
124
- outputs = outputs ,
125
- arguments = arguments ,
126
- executable = ctx .executable .compiler ,
127
- execution_requirements = {
128
- "supports-workers" : str (int (ctx .attr ._supports_workers )),
129
- },
130
- )
131
178
132
179
def _prodmode_compile_action (ctx , inputs , outputs , config_file_path ):
133
180
outs = _expected_outs (ctx , ctx .label )
134
- _compile_action (ctx , inputs , outputs + outs .closure_js , config_file_path )
181
+ return _compile_action (ctx , inputs , outputs + outs .closure_js , outs . i18n_messages , config_file_path )
135
182
136
183
def _devmode_compile_action (ctx , inputs , outputs , config_file_path ):
137
184
outs = _expected_outs (ctx , ctx .label )
138
- _compile_action (ctx , inputs , outputs + outs .devmode_js + outs .declarations + outs .summaries , config_file_path )
185
+ _compile_action (ctx , inputs , outputs + outs .devmode_js + outs .declarations + outs .summaries , None , config_file_path )
139
186
140
187
def ng_module_impl (ctx , ts_compile_actions ):
141
188
providers = ts_compile_actions (
@@ -147,9 +194,11 @@ def ng_module_impl(ctx, ts_compile_actions):
147
194
#addl_declarations = [_expected_outs(ctx)]
148
195
#providers["typescript"]["declarations"] += addl_declarations
149
196
#providers["typescript"]["transitive_declarations"] += addl_declarations
197
+ outs = _expected_outs (ctx , ctx .label )
150
198
providers ["angular" ] = {
151
199
"summaries" : _expected_outs (ctx , ctx .label ).summaries
152
200
}
201
+ providers ["ngc_messages" ] = outs .i18n_messages
153
202
154
203
return providers
155
204
@@ -167,7 +216,6 @@ NG_MODULE_ATTRIBUTES = {
167
216
".html" ,
168
217
]),
169
218
170
- # TODO(alexeagle): wire up when we have i18n in bazel
171
219
"no_i18n" : attr .bool (default = False ),
172
220
173
221
"compiler" : attr .label (
@@ -176,6 +224,12 @@ NG_MODULE_ATTRIBUTES = {
176
224
cfg = "host" ,
177
225
),
178
226
227
+ "_ng_xi18n" : attr .label (
228
+ default = Label ("//src/ngc-wrapped:xi18n" ),
229
+ executable = True ,
230
+ cfg = "host" ,
231
+ ),
232
+
179
233
"_supports_workers" : attr .bool (default = True ),
180
234
}
181
235
@@ -192,4 +246,4 @@ ng_module = rule(
192
246
),
193
247
},
194
248
outputs = COMMON_OUTPUTS ,
195
- )
249
+ )
0 commit comments