Skip to content

Commit fe59701

Browse files
committed
Address code review feedback: formatting and style improvements
- Update .bazelrc files to use shared config imports - Update do_test script to use BIT_BAZEL_BINARY - Wrap long lines in MODULE.bazel to stay under 80 chars - Refactor framework detection with helper function and constants - Move header extensions to constants - Improve line wrapping and formatting throughout
1 parent f0fc809 commit fe59701

File tree

6 files changed

+68
-31
lines changed

6 files changed

+68
-31
lines changed

examples/aws_crt_example/.bazelrc

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
build --enable_bzlmod
2-
build --lockfile_mode=update
3-
build --macos_minimum_os=15.0
4-
build --host_macos_minimum_os=15.0
1+
# Import Shared settings
2+
import %workspace%/../../shared.bazelrc
3+
4+
# Import CI settings.
5+
import %workspace%/../../ci.bazelrc
6+
7+
# Try to import a local.rc file; typically, written by CI
8+
try-import %workspace%/../../local.bazelrc

examples/aws_crt_example/MODULE.bazel

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,16 @@ local_path_override(
77
)
88

99
bazel_dep(name = "apple_support", version = "1.24.2")
10-
bazel_dep(name = "rules_swift", version = "3.1.2", repo_name = "build_bazel_rules_swift")
11-
bazel_dep(name = "rules_apple", version = "4.2.0", repo_name = "build_bazel_rules_apple")
10+
bazel_dep(
11+
name = "rules_swift",
12+
version = "3.1.2",
13+
repo_name = "build_bazel_rules_swift",
14+
)
15+
bazel_dep(
16+
name = "rules_apple",
17+
version = "4.2.0",
18+
repo_name = "build_bazel_rules_apple",
19+
)
1220

1321
apple_cc_configure = use_extension(
1422
"@apple_support//crosstool:setup.bzl",

examples/aws_crt_example/do_test

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,9 @@
22

33
set -euo pipefail
44

5-
bazel test //...
5+
# Use the Bazel binary specified by the integration test. Otherise, fall back
6+
# to bazel.
7+
bazel="${BIT_BAZEL_BINARY:-bazel}"
8+
9+
# Ensure that it builds and tests pass
10+
"${bazel}" test //...

examples/aws_sdk_example/.bazelrc

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
build --enable_bzlmod
2-
build --lockfile_mode=update
3-
build --macos_minimum_os=15.0
4-
build --host_macos_minimum_os=15.0
1+
# Import Shared settings
2+
import %workspace%/../../shared.bazelrc
3+
4+
# Import CI settings.
5+
import %workspace%/../../ci.bazelrc
6+
7+
# Try to import a local.rc file; typically, written by CI
8+
try-import %workspace%/../../local.bazelrc

swiftpkg/internal/module_maps.bzl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,11 @@ def write_module_map(
110110
_add_headers(headers = [umbrella_header], kind = "umbrella header")
111111
elif umbrella_directory:
112112
# Umbrella directory must be absolute path
113-
abs_umbrella = back_to_root_path + umbrella_directory if back_to_root_path else umbrella_directory
113+
abs_umbrella = (
114+
back_to_root_path + umbrella_directory
115+
if back_to_root_path
116+
else umbrella_directory
117+
)
114118
content.add(abs_umbrella, format = ' umbrella "%s"')
115119
else:
116120
_add_headers(headers = public_headers, kind = "header")

swiftpkg/internal/pkginfos.bzl

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,15 +1174,21 @@ def _new_swift_src_info(
11741174

11751175
# MARK: - Clang Source Info
11761176

1177+
_FRAMEWORK_SRC_EXTS = [".c", ".cc", ".cpp", ".m", ".mm", ".h", ".hpp"]
1178+
_HEADER_EXTS = [".h", ".hpp", ".hh", ".hxx", ".inc", ".inl", ".modulemap"]
1179+
1180+
def _is_framework_src(path):
1181+
_root, ext = paths.split_extension(path)
1182+
return lists.contains(_FRAMEWORK_SRC_EXTS, ext)
1183+
11771184
def _detect_frameworks_from_sources(repository_ctx, srcs):
1178-
"""Detect Apple frameworks from #include <Framework/Header.h> patterns in C source files."""
1185+
"""Detect Apple frameworks from #include <Framework/Header.h> patterns in \
1186+
C source files."""
11791187
frameworks_set = sets.make()
11801188

11811189
for src in srcs:
11821190
# Only scan C/C++/ObjC source and header files
1183-
if not (src.endswith(".c") or src.endswith(".cc") or src.endswith(".cpp") or
1184-
src.endswith(".m") or src.endswith(".mm") or src.endswith(".h") or
1185-
src.endswith(".hpp")):
1191+
if not _is_framework_src(src):
11861192
continue
11871193

11881194
# Read the file and look for framework includes
@@ -1191,21 +1197,25 @@ def _detect_frameworks_from_sources(repository_ctx, srcs):
11911197
for line in lines:
11921198
line = line.strip()
11931199

1194-
# Look for #include <Framework/Header.h> or #import <Framework/Header.h>
1195-
if line.startswith("#include") or line.startswith("#import"):
1196-
# Extract the include path
1197-
if "<" in line and ">" in line:
1198-
start = line.index("<") + 1
1199-
end = line.index(">")
1200-
include_path = line[start:end]
1200+
# Look for #include <Framework/Header.h> or
1201+
# #import <Framework/Header.h>
1202+
if not line.startswith("#include") and \
1203+
not line.startswith("#import"):
1204+
continue
12011205

1202-
# Check if it's a framework include (has a slash)
1203-
if "/" in include_path:
1204-
framework = include_path.split("/")[0]
1206+
# Extract the include path
1207+
if "<" in line and ">" in line:
1208+
start = line.index("<") + 1
1209+
end = line.index(">")
1210+
include_path = line[start:end]
12051211

1206-
# Check if it's a known Apple framework
1207-
if sets.contains(apple_builtin.frameworks.all, framework):
1208-
sets.insert(frameworks_set, framework)
1212+
# Check if it's a framework include (has a slash)
1213+
if "/" in include_path:
1214+
framework = include_path.split("/")[0]
1215+
1216+
# Check if it's a known Apple framework
1217+
if sets.contains(apple_builtin.frameworks.all, framework):
1218+
sets.insert(frameworks_set, framework)
12091219

12101220
return sorted(sets.to_list(frameworks_set))
12111221

@@ -1229,7 +1239,9 @@ def _new_clang_src_info_from_sources(
12291239
# Also remove any exclude patterns that would exclude the include directory,
12301240
# since SPM doesn't exclude public headers even if they're in the exclude list.
12311241
if public_hdrs_path == None:
1232-
default_include_path = paths.normalize(paths.join(abs_target_path, "include"))
1242+
default_include_path = paths.normalize(
1243+
paths.join(abs_target_path, "include"),
1244+
)
12331245
if repository_files.is_directory(repository_ctx, default_include_path):
12341246
public_hdrs_path = "include"
12351247

@@ -1303,7 +1315,7 @@ def _new_clang_src_info_from_sources(
13031315
# Filter to only header files
13041316
for f in excluded_files:
13051317
_, ext = paths.split_extension(f)
1306-
if ext in [".h", ".hpp", ".hh", ".hxx", ".inc", ".inl", ".modulemap"]:
1318+
if ext in _HEADER_EXTS:
13071319
all_srcs.append(f)
13081320

13091321
# Organize the source files

0 commit comments

Comments
 (0)