Skip to content

Commit b9fdb97

Browse files
authored
Reduce the public BUILD API surface (#33)
1 parent f067790 commit b9fdb97

23 files changed

Lines changed: 160 additions & 159 deletions

MODULE.bazel.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/demo_app/MODULE.bazel.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/local_plugin/MODULE.bazel.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/no_plugins/MODULE.bazel.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/pub_plugins/MODULE.bazel.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flutter/defs.bzl

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
"""The supported BUILD-file API for Flutter Consumer Modules.
22
33
Consumer BUILD files load this one entrypoint rather than the implementation
4-
under ``//flutter/private``. The public names below are the complete contract
5-
exercised by the consumer API fixture; implementation files can move without
6-
another consumer migration.
4+
under ``//flutter/private``. Every name here is either written by hand in a
5+
Consumer Module or named by a BUILD file these rules generate; nothing is
6+
exported merely because it exists. Rules composed by the macros below --
7+
``dart_kernel``, ``flutter_android_libs``, ``jni_lib_jar``,
8+
``strip_native_libs`` -- and the ``ABIS`` table stay private, so their
9+
attributes remain free to change without a consumer migration.
710
"""
811

9-
load("//flutter/private:abis.bzl", _ABIS = "ABIS")
1012
load(
1113
"//flutter/private:android.bzl",
1214
_android_native_lib_jar = "android_native_lib_jar",
1315
_flutter_android_binary = "flutter_android_binary",
14-
_flutter_android_libs = "flutter_android_libs",
15-
_jni_lib_jar = "jni_lib_jar",
16-
_strip_native_libs = "strip_native_libs",
1716
)
1817
load(
1918
"//flutter/private:embedding.bzl",
@@ -27,7 +26,6 @@ load(
2726
)
2827
load(
2928
"//flutter/private:rules.bzl",
30-
_dart_kernel = "dart_kernel",
3129
_flutter_aot_library = "flutter_aot_library",
3230
_flutter_app = "flutter_app",
3331
_flutter_assets = "flutter_assets",
@@ -37,19 +35,21 @@ load(
3735

3836
# Explicit assignments make the curated names exports of this module. Merely
3937
# importing names with load() does not re-export them to downstream BUILD files.
40-
ABIS = _ABIS
41-
android_native_lib_jar = _android_native_lib_jar
42-
dart_kernel = _dart_kernel
43-
flutter_android_binary = _flutter_android_binary
44-
flutter_android_libs = _flutter_android_libs
45-
flutter_aot_library = _flutter_aot_library
38+
#
39+
# Written by hand in a Consumer Module.
4640
flutter_app = _flutter_app
47-
flutter_assets = _flutter_assets
41+
flutter_android_binary = _flutter_android_binary
4842
flutter_embedding_library = _flutter_embedding_library
4943
flutter_native_contribution = _flutter_native_contribution
44+
45+
# Named by the BUILD files the plugin extension generates, so they are loaded
46+
# across a repository boundary and have to resolve from this entrypoint.
47+
android_native_lib_jar = _android_native_lib_jar
5048
flutter_native_libs = _flutter_native_libs
49+
50+
# The Dart half on its own, for an app whose Dart layout `flutter_app` refuses.
5151
flutter_pubspec = _flutter_pubspec
52-
jni_lib_jar = _jni_lib_jar
52+
flutter_aot_library = _flutter_aot_library
53+
flutter_assets = _flutter_assets
5354
pub_path_deps_check = _pub_path_deps_check
5455
pub_plugins_check = _pub_plugins_check
55-
strip_native_libs = _strip_native_libs

flutter/private/BUILD.bazel

Lines changed: 72 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,79 @@
11
"""Implementation of the Flutter rules.
22
3-
Nothing here is supported API. Consumer Modules load //flutter:defs.bzl and
4-
//flutter:extensions.bzl; these files are exported only because generated
5-
repositories and the ruleset's own CI guards name them by label.
3+
Nothing here is supported API: Consumer Modules load //flutter:defs.bzl and
4+
//flutter:extensions.bzl, and every `.bzl` beside this file declares
5+
`visibility(["//flutter"])` so Bazel rejects any other load, in this repository
6+
or a consumer's. Two mechanical exceptions need a label, and only those:
7+
8+
* The Python helpers are attribute defaults of rules defined here. Bazel
9+
resolves an implicit dependency against the package of the `.bzl` that
10+
defines the rule, so `//flutter:__subpackages__` is enough even though the
11+
rules are instantiated in another module's packages.
12+
* The five `.bzl` files //tools/ci:key_portability_check reads as `srcs`.
13+
That guard parses their source for action-key portability contracts, which
14+
requires a label, not a load.
15+
16+
`repo.bzl` carries no `visibility()` declaration: tests/consumer's
17+
`android/config.MODULE.bazel` uses its module extension directly, which is that
18+
fixture's only coverage of the explicit embedding debug and release labels.
619
"""
720

8-
package(default_visibility = ["//visibility:public"])
9-
10-
exports_files([
11-
"check_path_deps.py",
12-
"check_native_assets.py",
13-
"inject_version.py",
14-
"merge_native_assets.py",
15-
"read_pubspec.py",
16-
"repo.bzl",
17-
"rules.bzl",
18-
"android.bzl",
19-
"plugins.bzl",
20-
"ndk.bzl",
21-
])
21+
load("//tools/ci:assertions.bzl", "expect_equal", "expect_label_equal")
22+
load(":abis.bzl", "ABIS")
23+
24+
package(default_visibility = ["//visibility:private"])
25+
26+
exports_files(
27+
[
28+
"check_path_deps.py",
29+
"check_native_assets.py",
30+
"inject_version.py",
31+
"merge_native_assets.py",
32+
"read_pubspec.py",
33+
],
34+
visibility = ["//flutter:__subpackages__"],
35+
)
36+
37+
exports_files(
38+
[
39+
"android.bzl",
40+
"ndk.bzl",
41+
"plugins.bzl",
42+
"repo.bzl",
43+
"rules.bzl",
44+
],
45+
visibility = ["//tools/ci:__pkg__"],
46+
)
47+
48+
# The ABI table is implementation, so these assertions live beside it rather
49+
# than in the Consumer Module fixture: a wrong snapshot flag or CPU constraint
50+
# mislabels a platform, and nothing else in the build would notice.
51+
expect_equal(
52+
ABIS["armeabi-v7a"].snapshot_flags,
53+
[
54+
"--no-sim-use-hardfp",
55+
"--no-use-integer-division",
56+
],
57+
"armeabi-v7a snapshot_flags",
58+
)
59+
60+
expect_label_equal(
61+
ABIS["arm64-v8a"].cpu_constraint,
62+
"@platforms//cpu:arm64",
63+
"arm64-v8a cpu_constraint",
64+
)
65+
66+
expect_label_equal(
67+
ABIS["x86_64"].cpu_constraint,
68+
"@platforms//cpu:x86_64",
69+
"x86_64 cpu_constraint",
70+
)
71+
72+
expect_label_equal(
73+
ABIS["armeabi-v7a"].cpu_constraint,
74+
"@platforms//cpu:armv7",
75+
"armeabi-v7a cpu_constraint",
76+
)
2277

2378
# Excluded from wildcard checks because resolving it requires @androidsdk.
2479
alias(

flutter/private/abis.bzl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ there is no `gen_snapshot` to pair with an x86 library however many a package
1515
publishes.
1616
"""
1717

18+
visibility(["//flutter"])
19+
1820
MODES = ["release", "debug"]
1921

2022
# Modes that require gen_snapshot.

flutter/private/android.bzl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ load(":bundle.bzl", "ASSETS", "CLASSES", "FlutterBundleContributionInfo", "NATIV
4444
load(":embedding.bzl", "flutter_embedding_deps")
4545
load(":pubspec.bzl", "FlutterPubspecInfo")
4646

47+
# `//flutter` holds the public facades. `//` is the repository root package,
48+
# which asserts `flutter_assets_dir` there because the root is the one package
49+
# with no path separator and the helper is deliberately not public API.
50+
visibility([
51+
"//",
52+
"//flutter",
53+
])
54+
4755
_MODE_DEBUG = Label("//flutter:mode_debug")
4856
_MODE_RELEASE = Label("//flutter:mode_release")
4957

flutter/private/archive.bzl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ Uses Bazel's declared `zipper`, which fixes metadata and follows argv order.
55
`StripNativeLibs` preserves input order because it discovers entries at execution.
66
"""
77

8+
visibility(["//flutter"])
9+
810
ZIPPER_ATTRS = {
911
"_zipper": attr.label(
1012
default = Label("@bazel_tools//tools/zip:zipper"),

0 commit comments

Comments
 (0)