Skip to content

Commit f97888e

Browse files
authored
[Infra] Check for improper FirebaseCoreExtension imports (#10294)
* [skip ci] Check for improper FirebaseCoreExtension imports * This commit should fail because of the invalid import * [skip ci] Update FirebaseStorage/Sources/Storage.swift * [skip ci] Update FirebaseStorage/Sources/Storage.swift (2)
1 parent 018fd7e commit f97888e

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

scripts/check_imports.swift

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ private class ErrorLogger {
6464
}
6565
}
6666

67-
private func checkFile(_ file: String, logger: ErrorLogger, inRepo repoURL: URL) {
67+
private func checkFile(_ file: String, logger: ErrorLogger, inRepo repoURL: URL,
68+
isSwiftFile: Bool) {
6869
var fileContents = ""
6970
do {
7071
fileContents = try String(contentsOfFile: file, encoding: .utf8)
@@ -73,6 +74,22 @@ private func checkFile(_ file: String, logger: ErrorLogger, inRepo repoURL: URL)
7374
// Not a source file, give up and return.
7475
return
7576
}
77+
78+
guard !isSwiftFile else {
79+
// Swift specific checks.
80+
fileContents.components(separatedBy: .newlines)
81+
.enumerated() // [(lineNum, line), ...]
82+
.filter { $1.starts(with: "import FirebaseCoreExtension") }
83+
.forEach { lineNum, line in
84+
logger
85+
.importLog(
86+
"Use `@_implementationOnly import FirebaseCoreExtension` when importing `FirebaseCoreExtension`.",
87+
file, lineNum
88+
)
89+
}
90+
return
91+
}
92+
7693
let isPublic = file.range(of: "/Public/") != nil &&
7794
// TODO: Skip legacy GDTCCTLibrary file that isn't Public and should be moved.
7895
// This test is used in the GoogleDataTransport's repo's CI clone of this repo.
@@ -186,7 +203,8 @@ private func main() -> Int32 {
186203
if !(file.hasSuffix(".h") ||
187204
file.hasSuffix(".m") ||
188205
file.hasSuffix(".mm") ||
189-
file.hasSuffix(".c")) {
206+
file.hasSuffix(".c") ||
207+
file.hasSuffix(".swift")) {
190208
continue
191209
}
192210
let fullTransformPath = rootURL.path + "/" + file
@@ -195,7 +213,12 @@ private func main() -> Int32 {
195213
continue whileLoop
196214
}
197215
}
198-
checkFile(fullTransformPath, logger: logger, inRepo: repoURL)
216+
checkFile(
217+
fullTransformPath,
218+
logger: logger,
219+
inRepo: repoURL,
220+
isSwiftFile: file.hasSuffix(".swift")
221+
)
199222
}
200223
}
201224
}

0 commit comments

Comments
 (0)