Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 80029b9

Browse files
committedDec 28, 2023
run buildifier over all source files
$ buildifier -r .
1 parent e324107 commit 80029b9

File tree

8 files changed

+622
-613
lines changed

8 files changed

+622
-613
lines changed
 

‎WORKSPACE

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
workspace(name = "io_bazel_rules_dart")
22

33
load("//dart/build_rules:repositories.bzl", "dart_repositories")
4+
45
dart_repositories()

‎dart/build_rules/core.bzl

+17-19
Original file line numberDiff line numberDiff line change
@@ -14,33 +14,31 @@
1414

1515
"""Dart rules shared across deployment platforms."""
1616

17-
1817
load(":internal.bzl", "assert_third_party_licenses", "make_dart_context")
1918

20-
2119
def _dart_library_impl(ctx):
22-
"""Implements the dart_library() rule."""
23-
assert_third_party_licenses(ctx)
20+
"""Implements the dart_library() rule."""
21+
assert_third_party_licenses(ctx)
2422

25-
dart_ctx = make_dart_context(ctx.label,
26-
srcs=ctx.files.srcs,
27-
data=ctx.files.data,
28-
deps=ctx.attr.deps)
29-
30-
return struct(
31-
dart=dart_ctx,
32-
)
23+
dart_ctx = make_dart_context(
24+
ctx.label,
25+
srcs = ctx.files.srcs,
26+
data = ctx.files.data,
27+
deps = ctx.attr.deps,
28+
)
3329

30+
return struct(
31+
dart = dart_ctx,
32+
)
3433

3534
dart_library_attrs = {
36-
"srcs": attr.label_list(allow_files=True, mandatory=True),
37-
"data": attr.label_list(allow_files=True),
38-
"deps": attr.label_list(providers=["dart"]),
39-
"license_files": attr.label_list(allow_files=True)
35+
"srcs": attr.label_list(allow_files = True, mandatory = True),
36+
"data": attr.label_list(allow_files = True),
37+
"deps": attr.label_list(providers = ["dart"]),
38+
"license_files": attr.label_list(allow_files = True),
4039
}
4140

42-
4341
dart_library = rule(
44-
implementation=_dart_library_impl,
45-
attrs=dart_library_attrs,
42+
implementation = _dart_library_impl,
43+
attrs = dart_library_attrs,
4644
)

‎dart/build_rules/internal.bzl

+213-216
Large diffs are not rendered by default.

‎dart/build_rules/repositories.bzl

+26-27
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
1818

19-
2019
_DART_SDK_BUILD_FILE = """
2120
package(default_visibility = [ "//visibility:public" ])
2221
@@ -55,33 +54,33 @@ filegroup(
5554
"""
5655

5756
def dart_repositories():
58-
sdk_channel = "stable"
59-
sdk_version = "2.17.7"
60-
linux_x64_sha = "ba8bc85883e38709351f78c527cbf72e22cd234b3678a1ec6a2e781f7984e624"
61-
macos_arm64_sha = "a4be379202cf731c7e33de20b4abc4ca1e2e726bc5973222b3a7ae5a0cabfce1"
62-
macos_x64_sha = "ba258fff40822cb410c4f1f7916b63f0837903a6bae8f4bd83341053b10ecbe3"
57+
sdk_channel = "stable"
58+
sdk_version = "2.17.7"
59+
linux_x64_sha = "ba8bc85883e38709351f78c527cbf72e22cd234b3678a1ec6a2e781f7984e624"
60+
macos_arm64_sha = "a4be379202cf731c7e33de20b4abc4ca1e2e726bc5973222b3a7ae5a0cabfce1"
61+
macos_x64_sha = "ba258fff40822cb410c4f1f7916b63f0837903a6bae8f4bd83341053b10ecbe3"
6362

64-
sdk_base_url = ("https://storage.googleapis.com/dart-archive/channels/" +
65-
sdk_channel + "/release/" +
66-
sdk_version + "/sdk/")
63+
sdk_base_url = ("https://storage.googleapis.com/dart-archive/channels/" +
64+
sdk_channel + "/release/" +
65+
sdk_version + "/sdk/")
6766

68-
http_archive(
69-
name = "dart_linux_x86_64",
70-
url = sdk_base_url + "dartsdk-linux-x64-release.zip",
71-
sha256 = linux_x64_sha,
72-
build_file_content = _DART_SDK_BUILD_FILE,
73-
)
67+
http_archive(
68+
name = "dart_linux_x86_64",
69+
url = sdk_base_url + "dartsdk-linux-x64-release.zip",
70+
sha256 = linux_x64_sha,
71+
build_file_content = _DART_SDK_BUILD_FILE,
72+
)
7473

75-
http_archive(
76-
name = "dart_darwin_arm64",
77-
url = sdk_base_url + "dartsdk-macos-arm64-release.zip",
78-
sha256 = macos_arm64_sha,
79-
build_file_content = _DART_SDK_BUILD_FILE,
80-
)
74+
http_archive(
75+
name = "dart_darwin_arm64",
76+
url = sdk_base_url + "dartsdk-macos-arm64-release.zip",
77+
sha256 = macos_arm64_sha,
78+
build_file_content = _DART_SDK_BUILD_FILE,
79+
)
8180

82-
http_archive(
83-
name = "dart_darwin_x86_64",
84-
url = sdk_base_url + "dartsdk-macos-x64-release.zip",
85-
sha256 = macos_x64_sha,
86-
build_file_content = _DART_SDK_BUILD_FILE,
87-
)
81+
http_archive(
82+
name = "dart_darwin_x86_64",
83+
url = sdk_base_url + "dartsdk-macos-x64-release.zip",
84+
sha256 = macos_x64_sha,
85+
build_file_content = _DART_SDK_BUILD_FILE,
86+
)

‎dart/build_rules/vm.bzl

+200-200
Large diffs are not rendered by default.

‎dart/build_rules/web.bzl

+151-143
Original file line numberDiff line numberDiff line change
@@ -14,161 +14,169 @@
1414

1515
"""Dart rules targeting web clients."""
1616

17-
1817
load(":internal.bzl", "collect_files", "layout_action", "make_dart_context", "package_spec_action")
1918

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+
)
8794

8895
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()
128134

129135
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
143148

144149
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),
152157
# 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),
158163
# tools
159164
"_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+
),
164170
"_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+
),
167174
"_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+
),
172180
},
173-
outputs=_dart_web_application_outputs,
181+
outputs = _dart_web_application_outputs,
174182
)

‎examples/hello_bin/BUILD

+10-4
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@ dart_vm_binary(
1515
dart_vm_binary(
1616
name = "hello_bin_checked",
1717
srcs = ["bin/hello.dart"],
18+
script_args = [
19+
"foo",
20+
"bar",
21+
],
1822
script_file = "bin/hello.dart",
19-
script_args = ["foo", "bar"],
2023
vm_flags = ["--enable-asserts"],
2124
deps = [
2225
"//examples/goodbye_lib",
@@ -27,8 +30,8 @@ dart_vm_binary(
2730
dart_vm_binary(
2831
name = "nested_bin",
2932
srcs = ["bin/nested.dart"],
30-
script_file = "bin/nested.dart",
3133
data = [":hello_bin"],
34+
script_file = "bin/nested.dart",
3235
deps = [
3336
"//examples/goodbye_lib",
3437
],
@@ -37,12 +40,15 @@ dart_vm_binary(
3740
dart_vm_binary(
3841
name = "hello_bin_snapshot",
3942
srcs = ["bin/hello.dart"],
43+
script_args = [
44+
"foo",
45+
"bar",
46+
],
4047
script_file = "bin/hello.dart",
41-
script_args = ["foo", "bar"],
48+
snapshot = True,
4249
vm_flags = ["--enable-asserts"],
4350
deps = [
4451
"//examples/goodbye_lib",
4552
"//examples/hello_lib",
4653
],
47-
snapshot = True,
4854
)

‎examples/web_app/BUILD

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,26 @@ dart_library(
1212

1313
genrule(
1414
name = "gen_lib",
15-
cmd = """echo 'String generatedFunc() => "generated";' > $@""",
1615
outs = ["web/generated.dart"],
16+
cmd = """echo 'String generatedFunc() => "generated";' > $@""",
1717
)
1818

1919
dart_web_application(
2020
name = "js_debug",
2121
srcs = [":gen_lib"] + glob(["web/**"]),
22-
script_file = "web/main.dart",
2322
deferred_lib_count = 1,
23+
dump_info = True,
2424
enable_asserts = True,
2525
minify = False,
26-
dump_info = True,
26+
script_file = "web/main.dart",
2727
deps = [":web_app"],
2828
)
2929

3030
dart_web_application(
3131
name = "js_release",
3232
srcs = glob(["web/**"]),
33-
script_file = "web/main.dart",
3433
deferred_lib_count = 1,
34+
script_file = "web/main.dart",
3535
deps = [
3636
":web_app",
3737
"//examples/hello_lib",

0 commit comments

Comments
 (0)
Please sign in to comment.