Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions swiftpkg/internal/objc_files.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,33 @@ load("@bazel_skylib//lib:sets.bzl", "sets")
load("@cgrindel_bazel_starlib//bzllib:defs.bzl", "lists")
load(":apple_builtin_frameworks.bzl", "apple_builtin_frameworks")

_pound_import = "#import "
_pound_import_len = len(_pound_import)
_at_import = "@import "
_at_import_len = len(_at_import)

def _parse_pound_import(line):
import_idx = line.find(_pound_import)
if import_idx < 0:
return None
start_idx = import_idx + _pound_import_len
line_len = len(line)

# Find the pound sign
pound_idx = line.find("#")
if pound_idx < 0:
return None
start_idx = pound_idx + 1

# Find import
begin_of_import_idx = -1
for idx in range(start_idx, line_len):
char = line[idx]
if char == " " or char == "\t":
continue
elif char == "i":
begin_of_import_idx = idx
break
else:
return None
if not line[begin_of_import_idx:].startswith("import"):
return None
start_idx = begin_of_import_idx + len("import")

# Find the opening bracket
open_bracket_idx = -1
for idx in range(start_idx, line_len):
Expand Down
7 changes: 7 additions & 0 deletions swiftpkg/tests/objc_files_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ def _parse_for_imported_framework_test(ctx):
""",
exp = "CoreTelephony",
),
struct(
msg = "# import, the pound is not adjacent to import ",
line = """\
# import <SystemConfiguration/SystemConfiguration.h>
""",
exp = "SystemConfiguration",
),
struct(
msg = "#import dir/header with brackets, is not framework",
line = """\
Expand Down