Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: only ignore DEBUG conditional compilation #855

Closed
wants to merge 4 commits into from
Closed
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
1 change: 1 addition & 0 deletions examples/ios_sim/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ swift_deps.from_file(
)
use_repo(
swift_deps,
"swiftpkg_rxswift",
"swiftpkg_swift_markdown",
"swiftpkg_swift_nio",
)
Expand Down
62 changes: 59 additions & 3 deletions examples/ios_sim/MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions examples/ios_sim/Package.resolved
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
{
"pins" : [
{
"identity" : "rxswift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/ReactiveX/RxSwift.git",
"state" : {
"revision" : "9dcaa4b333db437b0fbfaf453fad29069044a8b4",
"version" : "6.6.0"
}
},
{
"identity" : "swift-atomics",
"kind" : "remoteSourceControl",
Expand Down
1 change: 1 addition & 0 deletions examples/ios_sim/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ let package = Package(
dependencies: [
.package(url: "https://github.com/apple/swift-nio.git", exact: "2.62.0"),
.package(url: "https://github.com/apple/swift-markdown.git", exact: "0.3.0"),
.package(url: "https://github.com/ReactiveX/RxSwift.git", exact: "6.6.0"),
]
)
1 change: 1 addition & 0 deletions examples/ios_sim/Tests/FooTests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ swift_library(
module_name = "FooTests",
deps = [
"//Sources/Foo",
"@swiftpkg_rxswift//:Sources_RxTest",
"@swiftpkg_swift_markdown//:Sources_Markdown",
"@swiftpkg_swift_nio//:Sources_NIO",
],
Expand Down
1 change: 1 addition & 0 deletions examples/ios_sim/Tests/FooTests/BarTests.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@testable import Foo
import NIO
import RxTest
import XCTest

class BarTests: XCTestCase {
Expand Down
167 changes: 167 additions & 0 deletions examples/ios_sim/swift_deps_index.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,87 @@
{
"direct_dep_identities": [
"rxswift",
"swift-markdown",
"swift-nio"
],
"modules": [
{
"name": "RxBlocking",
"c99name": "RxBlocking",
"src_type": "swift",
"label": "@swiftpkg_rxswift//:Sources_RxBlocking",
"package_identity": "rxswift",
"product_memberships": [
"RxBlocking",
"RxBlocking-Dynamic"
]
},
{
"name": "RxCocoa",
"c99name": "RxCocoa",
"src_type": "swift",
"label": "@swiftpkg_rxswift//:Sources_RxCocoa",
"modulemap_label": "@swiftpkg_rxswift//:Sources_RxCocoa_modulemap",
"package_identity": "rxswift",
"product_memberships": [
"RxCocoa",
"RxCocoa-Dynamic"
]
},
{
"name": "RxCocoaRuntime",
"c99name": "RxCocoaRuntime",
"src_type": "objc",
"label": "@swiftpkg_rxswift//:Sources_RxCocoaRuntime",
"package_identity": "rxswift",
"product_memberships": [
"RxCocoa",
"RxCocoa-Dynamic"
]
},
{
"name": "RxRelay",
"c99name": "RxRelay",
"src_type": "swift",
"label": "@swiftpkg_rxswift//:Sources_RxRelay",
"package_identity": "rxswift",
"product_memberships": [
"RxCocoa",
"RxRelay",
"RxCocoa-Dynamic",
"RxRelay-Dynamic"
]
},
{
"name": "RxSwift",
"c99name": "RxSwift",
"src_type": "swift",
"label": "@swiftpkg_rxswift//:Sources_RxSwift",
"package_identity": "rxswift",
"product_memberships": [
"RxSwift",
"RxCocoa",
"RxRelay",
"RxBlocking",
"RxTest",
"RxSwift-Dynamic",
"RxCocoa-Dynamic",
"RxRelay-Dynamic",
"RxBlocking-Dynamic",
"RxTest-Dynamic"
]
},
{
"name": "RxTest",
"c99name": "RxTest",
"src_type": "swift",
"label": "@swiftpkg_rxswift//:Sources_RxTest",
"package_identity": "rxswift",
"product_memberships": [
"RxTest",
"RxTest-Dynamic"
]
},
{
"name": "Atomics",
"c99name": "Atomics",
Expand Down Expand Up @@ -411,6 +489,86 @@
}
],
"products": [
{
"identity": "rxswift",
"name": "RxBlocking",
"type": "library",
"target_labels": [
"@swiftpkg_rxswift//:Sources_RxBlocking"
]
},
{
"identity": "rxswift",
"name": "RxBlocking-Dynamic",
"type": "library",
"target_labels": [
"@swiftpkg_rxswift//:Sources_RxBlocking"
]
},
{
"identity": "rxswift",
"name": "RxCocoa",
"type": "library",
"target_labels": [
"@swiftpkg_rxswift//:Sources_RxCocoa"
]
},
{
"identity": "rxswift",
"name": "RxCocoa-Dynamic",
"type": "library",
"target_labels": [
"@swiftpkg_rxswift//:Sources_RxCocoa"
]
},
{
"identity": "rxswift",
"name": "RxRelay",
"type": "library",
"target_labels": [
"@swiftpkg_rxswift//:Sources_RxRelay"
]
},
{
"identity": "rxswift",
"name": "RxRelay-Dynamic",
"type": "library",
"target_labels": [
"@swiftpkg_rxswift//:Sources_RxRelay"
]
},
{
"identity": "rxswift",
"name": "RxSwift",
"type": "library",
"target_labels": [
"@swiftpkg_rxswift//:Sources_RxSwift"
]
},
{
"identity": "rxswift",
"name": "RxSwift-Dynamic",
"type": "library",
"target_labels": [
"@swiftpkg_rxswift//:Sources_RxSwift"
]
},
{
"identity": "rxswift",
"name": "RxTest",
"type": "library",
"target_labels": [
"@swiftpkg_rxswift//:Sources_RxTest"
]
},
{
"identity": "rxswift",
"name": "RxTest-Dynamic",
"type": "library",
"target_labels": [
"@swiftpkg_rxswift//:Sources_RxTest"
]
},
{
"identity": "swift-atomics",
"name": "Atomics",
Expand Down Expand Up @@ -573,6 +731,15 @@
}
],
"packages": [
{
"name": "swiftpkg_rxswift",
"identity": "rxswift",
"remote": {
"commit": "9dcaa4b333db437b0fbfaf453fad29069044a8b4",
"remote": "https://github.com/ReactiveX/RxSwift.git",
"version": "6.6.0"
}
},
{
"name": "swiftpkg_swift_atomics",
"identity": "swift-atomics",
Expand Down
5 changes: 5 additions & 0 deletions swiftpkg/internal/pkginfos.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,11 @@ def _new_swift_src_info_from_sources(
if has_objc_directive and imports_xctest:
break

# DEBUG BEGIN
imports_xctest = False

# DEBUG END

# Find any auto-discoverable resources under the target
all_target_files = repository_files.list_files_under(
repository_ctx,
Expand Down
6 changes: 5 additions & 1 deletion swiftpkg/internal/swift_files.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ def _collect_conditional_compilation(contents, idx):
Did not find the end of the conditional compilation block starting at {}.\
""".format(idx))

# Then length of `#if` plus a single space
_POUND_IF_OFFSET = 4

def _is_code(contents, target_idx):
skip_to = -1
for idx in range(0, len(contents)):
Expand All @@ -160,7 +163,8 @@ def _is_code(contents, target_idx):
elif _look_ahead(contents, idx, "/*") >= 0:
skip_to = _collect_multiline_comment(contents, idx)
elif char == "#":
if _look_ahead(contents, idx, "#if") >= 0:
if _look_ahead(contents, idx, "#if") >= 0 and \
_look_ahead(contents, idx + _POUND_IF_OFFSET, "DEBUG") >= 0:
skip_to = _collect_conditional_compilation(contents, idx)

return False
Expand Down
24 changes: 23 additions & 1 deletion swiftpkg/tests/swift_files_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ import XCTest
exp = True,
),
struct(
msg = "inside conditional compilation",
msg = "inside DEBUG conditional compilation",
imp = "XCTest",
content = """\
#if DEBUG
Expand All @@ -153,6 +153,28 @@ import XCTest
#endif
import XCTest
#endif
""",
exp = False,
),
struct(
msg = "inside non-DEBUG conditional compilation",
imp = "XCTest",
content = """\
#if !os(watchOS)
import XCTest
#endif
""",
exp = True,
),
struct(
msg = "inside multi-level non-DEBUG conditional compilation",
imp = "XCTest",
content = """\
#if !os(watchOS)
#if DEBUG
import XCTest
#endif
#endif
""",
exp = False,
),
Expand Down
Loading