Skip to content

Commit a3f1e2c

Browse files
alexeaglekara
authored andcommittedAug 8, 2018
style: format .bzl files with buildifier (angular#23544)
PR Close angular#23544
1 parent 0908245 commit a3f1e2c

File tree

16 files changed

+1405
-1315
lines changed

16 files changed

+1405
-1315
lines changed
 

‎index.bzl

+4-2
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ from source downstream. Alternately, this API is available from the
1212
used in a downstream project.
1313
"""
1414

15-
load("//packages/bazel:index.bzl",
15+
load(
16+
"//packages/bazel:index.bzl",
1617
_ng_module = "ng_module",
1718
_ng_package = "ng_package",
1819
_protractor_web_test = "protractor_web_test",
19-
_protractor_web_test_suite = "protractor_web_test_suite")
20+
_protractor_web_test_suite = "protractor_web_test_suite",
21+
)
2022
load("//tools:ng_setup_workspace.bzl", _ng_setup_workspace = "ng_setup_workspace")
2123

2224
ng_module = _ng_module

‎packages/bazel/index.bzl

+5-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ Users should not load files under "/src"
1010
load("//packages/bazel/src:ng_module.bzl", _ng_module = "ng_module")
1111
load("//packages/bazel/src:ng_setup_workspace.bzl", _ng_setup_workspace = "ng_setup_workspace")
1212
load("//packages/bazel/src/ng_package:ng_package.bzl", _ng_package = "ng_package")
13-
load("//packages/bazel/src/protractor:protractor_web_test.bzl",
14-
_protractor_web_test = "protractor_web_test",
15-
_protractor_web_test_suite = "protractor_web_test_suite")
13+
load(
14+
"//packages/bazel/src/protractor:protractor_web_test.bzl",
15+
_protractor_web_test = "protractor_web_test",
16+
_protractor_web_test_suite = "protractor_web_test_suite",
17+
)
1618

1719
ng_module = _ng_module
1820
ng_package = _ng_package

‎packages/bazel/src/esm5.bzl

+110-105
Original file line numberDiff line numberDiff line change
@@ -28,88 +28,92 @@ ESM5Info = provider(
2828
)
2929

3030
def _map_closure_path(file):
31-
result = file.short_path[:-len(".closure.js")]
32-
# short_path is meant to be used when accessing runfiles in a binary, where
33-
# the CWD is inside the current repo. Therefore files in external repo have a
34-
# short_path of ../external/wkspc/path/to/package
35-
# We want to strip the first two segments from such paths.
36-
if (result.startswith("../")):
37-
result = "/".join(result.split("/")[2:])
38-
return result + ".js"
31+
result = file.short_path[:-len(".closure.js")]
32+
33+
# short_path is meant to be used when accessing runfiles in a binary, where
34+
# the CWD is inside the current repo. Therefore files in external repo have a
35+
# short_path of ../external/wkspc/path/to/package
36+
# We want to strip the first two segments from such paths.
37+
if (result.startswith("../")):
38+
result = "/".join(result.split("/")[2:])
39+
return result + ".js"
3940

4041
def _join(array):
41-
return "/".join([p for p in array if p])
42+
return "/".join([p for p in array if p])
4243

4344
def _esm5_outputs_aspect(target, ctx):
44-
if not hasattr(target, "typescript"):
45-
return []
46-
47-
# We create a new tsconfig.json file that will have our compilation settings
48-
tsconfig = ctx.actions.declare_file("%s_esm5.tsconfig.json" % target.label.name)
49-
50-
workspace = target.label.workspace_root if target.label.workspace_root else ""
51-
52-
# re-root the outputs under a ".esm5" directory so the path don't collide
53-
out_dir = ctx.label.name + ".esm5"
54-
if workspace:
55-
out_dir = out_dir + "/" + workspace
56-
57-
outputs = [ctx.actions.declare_file(_join([out_dir, _map_closure_path(f)]))
58-
for f in target.typescript.replay_params.outputs
59-
if not f.short_path.endswith(".externs.js")]
60-
61-
ctx.actions.run(
62-
executable = ctx.executable._modify_tsconfig,
63-
inputs = [target.typescript.replay_params.tsconfig],
64-
outputs = [tsconfig],
65-
arguments = [
66-
target.typescript.replay_params.tsconfig.path,
67-
tsconfig.path,
68-
_join([workspace, target.label.package, ctx.label.name + ".esm5"]),
69-
ctx.bin_dir.path
70-
],
71-
)
72-
73-
ctx.actions.run(
74-
progress_message = "Compiling TypeScript (ES5 with ES Modules) %s" % target.label,
75-
inputs = target.typescript.replay_params.inputs + [tsconfig],
76-
outputs = outputs,
77-
arguments = [tsconfig.path],
78-
executable = target.typescript.replay_params.compiler,
79-
execution_requirements = {
80-
# TODO(alexeagle): enable worker mode for these compilations
81-
"supports-workers": "0",
82-
},
83-
)
84-
85-
root_dir = _join([
86-
ctx.bin_dir.path,
87-
workspace,
88-
target.label.package,
89-
ctx.label.name + ".esm5",
90-
])
91-
92-
transitive_output={root_dir: depset(outputs)}
93-
for dep in ctx.rule.attr.deps:
94-
if ESM5Info in dep:
95-
transitive_output.update(dep[ESM5Info].transitive_output)
96-
97-
return [ESM5Info(
98-
transitive_output = transitive_output,
99-
)]
45+
if not hasattr(target, "typescript"):
46+
return []
47+
48+
# We create a new tsconfig.json file that will have our compilation settings
49+
tsconfig = ctx.actions.declare_file("%s_esm5.tsconfig.json" % target.label.name)
50+
51+
workspace = target.label.workspace_root if target.label.workspace_root else ""
52+
53+
# re-root the outputs under a ".esm5" directory so the path don't collide
54+
out_dir = ctx.label.name + ".esm5"
55+
if workspace:
56+
out_dir = out_dir + "/" + workspace
57+
58+
outputs = [
59+
ctx.actions.declare_file(_join([out_dir, _map_closure_path(f)]))
60+
for f in target.typescript.replay_params.outputs
61+
if not f.short_path.endswith(".externs.js")
62+
]
63+
64+
ctx.actions.run(
65+
executable = ctx.executable._modify_tsconfig,
66+
inputs = [target.typescript.replay_params.tsconfig],
67+
outputs = [tsconfig],
68+
arguments = [
69+
target.typescript.replay_params.tsconfig.path,
70+
tsconfig.path,
71+
_join([workspace, target.label.package, ctx.label.name + ".esm5"]),
72+
ctx.bin_dir.path,
73+
],
74+
)
75+
76+
ctx.actions.run(
77+
progress_message = "Compiling TypeScript (ES5 with ES Modules) %s" % target.label,
78+
inputs = target.typescript.replay_params.inputs + [tsconfig],
79+
outputs = outputs,
80+
arguments = [tsconfig.path],
81+
executable = target.typescript.replay_params.compiler,
82+
execution_requirements = {
83+
# TODO(alexeagle): enable worker mode for these compilations
84+
"supports-workers": "0",
85+
},
86+
)
87+
88+
root_dir = _join([
89+
ctx.bin_dir.path,
90+
workspace,
91+
target.label.package,
92+
ctx.label.name + ".esm5",
93+
])
94+
95+
transitive_output = {root_dir: depset(outputs)}
96+
for dep in ctx.rule.attr.deps:
97+
if ESM5Info in dep:
98+
transitive_output.update(dep[ESM5Info].transitive_output)
99+
100+
return [ESM5Info(
101+
transitive_output = transitive_output,
102+
)]
100103

101104
# Downstream rules can use this aspect to access the ESM5 output flavor.
102105
# Only terminal rules (those which expect never to be used in deps[]) should do
103106
# this.
104107
esm5_outputs_aspect = aspect(
105108
implementation = _esm5_outputs_aspect,
106109
# Recurse to the deps of any target we visit
107-
attr_aspects = ['deps'],
110+
attr_aspects = ["deps"],
108111
attrs = {
109112
"_modify_tsconfig": attr.label(
110113
default = Label("//packages/bazel/src:modify_tsconfig"),
111114
executable = True,
112-
cfg = "host"),
115+
cfg = "host",
116+
),
113117
# We must list tsc_wrapped here to ensure it's built before the action runs
114118
# For some reason, having the compiler output as an input to the action above
115119
# is not sufficient.
@@ -128,43 +132,44 @@ esm5_outputs_aspect = aspect(
128132
)
129133

130134
def esm5_root_dir(ctx):
131-
return ctx.label.name + ".esm5"
135+
return ctx.label.name + ".esm5"
132136

133137
def flatten_esm5(ctx):
134-
"""Merge together the .esm5 folders from the dependencies.
135-
136-
Two different dependencies A and B may have outputs like
137-
`bazel-bin/path/to/A.esm5/path/to/lib.js`
138-
`bazel-bin/path/to/B.esm5/path/to/main.js`
139-
140-
In order to run rollup on this app, in case main.js contains `import from './lib'`
141-
they need to be together in the same root directory, so if we depend on both A and B
142-
we need the outputs to be
143-
`bazel-bin/path/to/my_rule.esm5/path/to/lib.js`
144-
`bazel-bin/path/to/my_rule.esm5/path/to/main.js`
145-
146-
Args:
147-
ctx: the skylark rule execution context
148-
149-
Returns:
150-
list of flattened files
151-
"""
152-
esm5_sources = []
153-
result = []
154-
for dep in ctx.attr.deps:
155-
if ESM5Info in dep:
156-
transitive_output = dep[ESM5Info].transitive_output
157-
esm5_sources.extend(transitive_output.values())
158-
for f in depset(transitive = esm5_sources).to_list():
159-
path = f.short_path[f.short_path.find(".esm5") + len(".esm5"):]
160-
if (path.startswith("../")):
161-
path = "external/" + path[3:]
162-
rerooted_file = ctx.actions.declare_file("/".join([esm5_root_dir(ctx), path]))
163-
result.append(rerooted_file)
164-
# print("copy", f.short_path, "to", rerooted_file.short_path)
165-
ctx.actions.expand_template(
166-
output = rerooted_file,
167-
template = f,
168-
substitutions = {},
169-
)
170-
return result
138+
"""Merge together the .esm5 folders from the dependencies.
139+
140+
Two different dependencies A and B may have outputs like
141+
`bazel-bin/path/to/A.esm5/path/to/lib.js`
142+
`bazel-bin/path/to/B.esm5/path/to/main.js`
143+
144+
In order to run rollup on this app, in case main.js contains `import from './lib'`
145+
they need to be together in the same root directory, so if we depend on both A and B
146+
we need the outputs to be
147+
`bazel-bin/path/to/my_rule.esm5/path/to/lib.js`
148+
`bazel-bin/path/to/my_rule.esm5/path/to/main.js`
149+
150+
Args:
151+
ctx: the skylark rule execution context
152+
153+
Returns:
154+
list of flattened files
155+
"""
156+
esm5_sources = []
157+
result = []
158+
for dep in ctx.attr.deps:
159+
if ESM5Info in dep:
160+
transitive_output = dep[ESM5Info].transitive_output
161+
esm5_sources.extend(transitive_output.values())
162+
for f in depset(transitive = esm5_sources).to_list():
163+
path = f.short_path[f.short_path.find(".esm5") + len(".esm5"):]
164+
if (path.startswith("../")):
165+
path = "external/" + path[3:]
166+
rerooted_file = ctx.actions.declare_file("/".join([esm5_root_dir(ctx), path]))
167+
result.append(rerooted_file)
168+
169+
# print("copy", f.short_path, "to", rerooted_file.short_path)
170+
ctx.actions.expand_template(
171+
output = rerooted_file,
172+
template = f,
173+
substitutions = {},
174+
)
175+
return result

0 commit comments

Comments
 (0)