From 59e0969969655f3813b8bdeeba36edd9cf242aba Mon Sep 17 00:00:00 2001 From: Luis Padron Date: Tue, 26 Nov 2024 13:57:12 -0500 Subject: [PATCH] chore: Add example showcasing modulemap issues Adds an example showing issues with modulemap logic in both sandboxed and non-sandboxed builds. --- examples/interesting_deps/BUILD.bazel | 14 ++++++++++++++ examples/interesting_deps/MODULE.bazel | 6 ++++++ examples/interesting_deps/Package.resolved | 21 +++++++++++++++------ examples/interesting_deps/Package.swift | 1 + examples/interesting_deps/do_test | 8 +++++--- examples/interesting_deps/objc_test.m | 16 ++++++++++++++++ 6 files changed, 57 insertions(+), 9 deletions(-) create mode 100644 examples/interesting_deps/objc_test.m diff --git a/examples/interesting_deps/BUILD.bazel b/examples/interesting_deps/BUILD.bazel index 48b890f01..3b45f5926 100644 --- a/examples/interesting_deps/BUILD.bazel +++ b/examples/interesting_deps/BUILD.bazel @@ -1,4 +1,5 @@ load("@bazel_gazelle//:def.bzl", "gazelle", "gazelle_binary") +load("@build_bazel_rules_apple//apple:macos.bzl", "macos_unit_test") load("@build_bazel_rules_swift//swift:swift.bzl", "swift_binary") load("@cgrindel_bazel_starlib//bzltidy:defs.bzl", "tidy") @@ -46,6 +47,19 @@ swift_binary( ], ) +objc_library( + name = "objc_test.lib", + srcs = ["objc_test.m"], + enable_modules = True, + deps = ["@swiftpkg_ocmock//:OCMock"], +) + +macos_unit_test( + name = "objc_test", + minimum_os_version = "10.15", + deps = [":objc_test.lib"], +) + sh_test( name = "simple_test", srcs = ["simple_test.sh"], diff --git a/examples/interesting_deps/MODULE.bazel b/examples/interesting_deps/MODULE.bazel index 407873ac2..821123e02 100644 --- a/examples/interesting_deps/MODULE.bazel +++ b/examples/interesting_deps/MODULE.bazel @@ -23,6 +23,11 @@ bazel_dep( version = "2.2.4", repo_name = "build_bazel_rules_swift", ) +bazel_dep( + name = "rules_apple", + version = "3.6.0", + repo_name = "build_bazel_rules_apple", +) bazel_dep( name = "bazel_skylib_gazelle_plugin", @@ -70,6 +75,7 @@ use_repo( "swiftpkg_cocoalumberjack", "swiftpkg_geoswift", "swiftpkg_libwebp_xcode", + "swiftpkg_ocmock", "swiftpkg_opencombine", "swiftpkg_swift_log", ) diff --git a/examples/interesting_deps/Package.resolved b/examples/interesting_deps/Package.resolved index 4e560e61a..d498e7767 100644 --- a/examples/interesting_deps/Package.resolved +++ b/examples/interesting_deps/Package.resolved @@ -14,8 +14,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/GEOSwift/geos.git", "state" : { - "revision" : "f510e634c822116fca615064d889300dba40d761", - "version" : "8.1.0" + "revision" : "4d8af495e7507f48f1ae9104102debdd2043917b", + "version" : "9.0.0" } }, { @@ -23,8 +23,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/GEOSwift/GEOSwift", "state" : { - "revision" : "2d23ede8c82c067655d3a9f0221bc73f08cd399a", - "version" : "10.1.0" + "revision" : "e42c062c2feb0df61373ae8cd6031a823a0dc981", + "version" : "11.0.0" } }, { @@ -36,6 +36,15 @@ "version" : "1.3.2" } }, + { + "identity" : "ocmock", + "kind" : "remoteSourceControl", + "location" : "https://github.com/erikdoe/ocmock", + "state" : { + "revision" : "2c0bfd373289f4a7716db5d6db471640f91a6507", + "version" : "3.9.4" + } + }, { "identity" : "opencombine", "kind" : "remoteSourceControl", @@ -50,8 +59,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-log", "state" : { - "revision" : "e97a6fcb1ab07462881ac165fdbb37f067e205d5", - "version" : "1.5.4" + "revision" : "96a2f8a0fa41e9e09af4585e2724c4e825410b91", + "version" : "1.6.2" } } ], diff --git a/examples/interesting_deps/Package.swift b/examples/interesting_deps/Package.swift index 6b78de7b5..54e6f5b94 100644 --- a/examples/interesting_deps/Package.swift +++ b/examples/interesting_deps/Package.swift @@ -10,5 +10,6 @@ let package = Package( .package(url: "https://github.com/OpenCombine/OpenCombine", from: "0.14.0"), .package(url: "https://github.com/SDWebImage/libwebp-Xcode.git", from: "1.3.2"), .package(url: "https://github.com/apple/swift-log", from: "1.6.1"), + .package(url: "https://github.com/erikdoe/ocmock", from: "3.9.0"), ] ) diff --git a/examples/interesting_deps/do_test b/examples/interesting_deps/do_test index 903dbf5f4..00998d5c3 100755 --- a/examples/interesting_deps/do_test +++ b/examples/interesting_deps/do_test @@ -2,7 +2,7 @@ set -o errexit -o nounset -o pipefail -# Use the Bazel binary specified by the integration test. Otherise, fall back +# Use the Bazel binary specified by the integration test. Otherwise, fall back # to bazel. bazel="${BIT_BAZEL_BINARY:-bazel}" @@ -12,5 +12,7 @@ bazel="${BIT_BAZEL_BINARY:-bazel}" # Test resolving the package via the `swift_package` repo. "${bazel}" run @swift_package//:resolve -# Ensure that it builds and tests pass -"${bazel}" test //... +# Ensure that it builds in both sandbox and local strategies. +# This tests issues with modulemap include/generation. +bazel clean && "${bazel}" test //... --spawn_strategy=sandboxed,local +bazel clean && "${bazel}" test //... --spawn_strategy=local diff --git a/examples/interesting_deps/objc_test.m b/examples/interesting_deps/objc_test.m new file mode 100644 index 000000000..553005290 --- /dev/null +++ b/examples/interesting_deps/objc_test.m @@ -0,0 +1,16 @@ +#import + +@import Foundation; +@import XCTest; + +@interface ObjcTest : XCTestCase +@end + +@implementation ObjcTest + +- (void)testMock { + OCMockObject *mock = [OCMockObject mockForClass:[NSObject class]]; + XCTAssertNotNil(mock); +} + +@end