From 674ede2bf91638336bed68eb9595beb6cba9840d Mon Sep 17 00:00:00 2001 From: "i@jerrymarino.com" Date: Mon, 4 Oct 2021 11:50:23 -0700 Subject: [PATCH] Genrule mixed module build test Per discussions on github last week we found a hole in test coverage. While this may not be failing specifically, it rules out the possibility of future regressions --- .../frameworks/genrule-inputs/App/main.swift | 0 .../ios/frameworks/genrule-inputs/BUILD.bazel | 12 ++++++ .../frameworks/genrule-inputs/a/BUILD.bazel | 10 +++++ .../ios/frameworks/genrule-inputs/a/lib.swift | 5 +++ .../frameworks/genrule-inputs/b/BUILD.bazel | 9 +++++ .../ios/frameworks/genrule-inputs/b/lib.swift | 10 +++++ .../frameworks/genrule-inputs/c/BUILD.bazel | 39 +++++++++++++++++++ .../unit-test/test-imports-app/BUILD.bazel | 7 +++- 8 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 tests/ios/frameworks/genrule-inputs/App/main.swift create mode 100644 tests/ios/frameworks/genrule-inputs/BUILD.bazel create mode 100644 tests/ios/frameworks/genrule-inputs/a/BUILD.bazel create mode 100644 tests/ios/frameworks/genrule-inputs/a/lib.swift create mode 100644 tests/ios/frameworks/genrule-inputs/b/BUILD.bazel create mode 100644 tests/ios/frameworks/genrule-inputs/b/lib.swift create mode 100644 tests/ios/frameworks/genrule-inputs/c/BUILD.bazel diff --git a/tests/ios/frameworks/genrule-inputs/App/main.swift b/tests/ios/frameworks/genrule-inputs/App/main.swift new file mode 100644 index 00000000..e69de29b diff --git a/tests/ios/frameworks/genrule-inputs/BUILD.bazel b/tests/ios/frameworks/genrule-inputs/BUILD.bazel new file mode 100644 index 00000000..55371849 --- /dev/null +++ b/tests/ios/frameworks/genrule-inputs/BUILD.bazel @@ -0,0 +1,12 @@ +load("//rules:app.bzl", "ios_application") + +ios_application( + name = "App", + srcs = ["App/main.swift"], + bundle_id = "com.example.app", + minimum_os_version = "10.0", + visibility = ["//visibility:public"], + deps = [ + "//tests/ios/frameworks/genrule-inputs/a", + ], +) diff --git a/tests/ios/frameworks/genrule-inputs/a/BUILD.bazel b/tests/ios/frameworks/genrule-inputs/a/BUILD.bazel new file mode 100644 index 00000000..aeff8ff5 --- /dev/null +++ b/tests/ios/frameworks/genrule-inputs/a/BUILD.bazel @@ -0,0 +1,10 @@ +load("//rules:framework.bzl", "apple_framework") + +apple_framework( + name = "a", + srcs = glob(["*.swift"]), + infoplists = ["//rules/test_host_app:Info.plist"], + platforms = {"ios": "10.0"}, + visibility = ["//visibility:public"], + deps = ["//tests/ios/frameworks/genrule-inputs/b"], +) diff --git a/tests/ios/frameworks/genrule-inputs/a/lib.swift b/tests/ios/frameworks/genrule-inputs/a/lib.swift new file mode 100644 index 00000000..fcc959fb --- /dev/null +++ b/tests/ios/frameworks/genrule-inputs/a/lib.swift @@ -0,0 +1,5 @@ +import b + +struct A { + public static func run() { B.run() } +} diff --git a/tests/ios/frameworks/genrule-inputs/b/BUILD.bazel b/tests/ios/frameworks/genrule-inputs/b/BUILD.bazel new file mode 100644 index 00000000..d4bcea00 --- /dev/null +++ b/tests/ios/frameworks/genrule-inputs/b/BUILD.bazel @@ -0,0 +1,9 @@ +load("//rules:framework.bzl", "apple_framework") + +apple_framework( + name = "b", + srcs = glob(["*.swift"]), + platforms = {"ios": "10.0"}, + visibility = ["//visibility:public"], + deps = ["//tests/ios/frameworks/genrule-inputs/c"], +) diff --git a/tests/ios/frameworks/genrule-inputs/b/lib.swift b/tests/ios/frameworks/genrule-inputs/b/lib.swift new file mode 100644 index 00000000..b3ccdebb --- /dev/null +++ b/tests/ios/frameworks/genrule-inputs/b/lib.swift @@ -0,0 +1,10 @@ +import c + +public struct B { + public static func run() { + C.run() + guard LibC != "B" else { + fatalError() + } + } +} diff --git a/tests/ios/frameworks/genrule-inputs/c/BUILD.bazel b/tests/ios/frameworks/genrule-inputs/c/BUILD.bazel new file mode 100644 index 00000000..d207fb6b --- /dev/null +++ b/tests/ios/frameworks/genrule-inputs/c/BUILD.bazel @@ -0,0 +1,39 @@ +load("//rules:framework.bzl", "apple_framework") + +genrule( + name="lib-src.swift", + cmd = """ +cat > $(OUTS) <<-EOF +public struct C { + + public static func run() { + print("runs here") + guard LibC == "LibC" else { + fatalError() + } + } +} +EOF + """, + outs = ["lib.swift"] +) + +genrule( + name="lib-src.h", + cmd = """ +cat > $(OUTS) <<-EOF + @import Foundation; + static NSString *const LibC = @"LibC"; +EOF + """, + outs = ["lib-src.h"] +) + +apple_framework( + name = "c", + # Note: supplying a hader file, e.g. `lib-src.h` named `:lib-src.h` + # string will cause the umbrella header rule to break. + srcs = [":lib-src.swift", "lib-src.h"], + platforms = {"ios": "10.0"}, + visibility = ["//visibility:public"], +) diff --git a/tests/ios/unit-test/test-imports-app/BUILD.bazel b/tests/ios/unit-test/test-imports-app/BUILD.bazel index 275f53e3..ae78f519 100644 --- a/tests/ios/unit-test/test-imports-app/BUILD.bazel +++ b/tests/ios/unit-test/test-imports-app/BUILD.bazel @@ -76,5 +76,10 @@ ios_unit_test( visibility = ["//visibility:public"], deps = [ ":TestImports-App_framework_unlinked", - ], + ] + select({ + # Note: without using apple_framework, it won't set enable_framework_vfs + # imported it won't actually be seen + "@build_bazel_rules_ios//:virtualize_frameworks": [":SomeFramework"], + "//conditions:default": [], + }), )