From 9052558d60691dfffd66efea1eee96d738e605ab Mon Sep 17 00:00:00 2001 From: Vadim Smal Date: Thu, 14 Oct 2021 16:27:15 +0100 Subject: [PATCH] Add action type check for prebuild and postbuild --- .../Commands/Postbuild/PostbuildContext.swift | 13 +++++++++++++ .../Commands/Postbuild/XCPostbuild.swift | 5 +++++ .../Commands/Prebuild/PrebuildContext.swift | 13 +++++++++++++ .../Commands/Prebuild/XCPrebuild.swift | 5 +++++ 4 files changed, 36 insertions(+) diff --git a/Sources/XCRemoteCache/Commands/Postbuild/PostbuildContext.swift b/Sources/XCRemoteCache/Commands/Postbuild/PostbuildContext.swift index 3ec2d77..3295477 100644 --- a/Sources/XCRemoteCache/Commands/Postbuild/PostbuildContext.swift +++ b/Sources/XCRemoteCache/Commands/Postbuild/PostbuildContext.swift @@ -29,6 +29,12 @@ enum MachOType: String, Codable { case unknown } +enum PostbuildActionType: String, Codable { + case build + case index = "indexbuild" + case unknown +} + enum PostbuildContextError: Error { /// URL address is not a valid URL case invalidAddress(String) @@ -71,6 +77,8 @@ public struct PostbuildContext { let derivedSourcesDir: URL /// List of all targets to downloaded from the thinning aggregation target var thinnedTargets: [String] + /// Action type: build, indexbuild etc. + var action: PostbuildActionType = .unknown } extension PostbuildContext { @@ -112,5 +120,10 @@ extension PostbuildContext { derivedSourcesDir = try env.readEnv(key: "DERIVED_SOURCES_DIR") let thinFocusedTargetsString: String = env.readEnv(key: "SPT_XCREMOTE_CACHE_THINNED_TARGETS") ?? "" thinnedTargets = thinFocusedTargetsString.split(separator: ",").map(String.init) + if let rawAction = env.readEnv(key: "ACTION") { + action = PostbuildActionType(rawValue: rawAction) ?? .unknown + } else { + action = .unknown + } } } diff --git a/Sources/XCRemoteCache/Commands/Postbuild/XCPostbuild.swift b/Sources/XCRemoteCache/Commands/Postbuild/XCPostbuild.swift index cfd3cd2..b3905ff 100644 --- a/Sources/XCRemoteCache/Commands/Postbuild/XCPostbuild.swift +++ b/Sources/XCRemoteCache/Commands/Postbuild/XCPostbuild.swift @@ -47,6 +47,11 @@ public class XCPostbuild { exit(1, "FATAL: Postbuild initialization failed with error: \(error)") } + guard context.action != .index else { + printToUser("Indexbuild. Skip remote cache") + exit(0) + } + // Postbuild cannot disable marker, so NoopMarkerWriter used instead of a real file writer let modeController = PhaseCacheModeController( tempDir: context.targetTempDir, diff --git a/Sources/XCRemoteCache/Commands/Prebuild/PrebuildContext.swift b/Sources/XCRemoteCache/Commands/Prebuild/PrebuildContext.swift index 1109a79..044579c 100644 --- a/Sources/XCRemoteCache/Commands/Prebuild/PrebuildContext.swift +++ b/Sources/XCRemoteCache/Commands/Prebuild/PrebuildContext.swift @@ -24,6 +24,12 @@ enum PrebuildContextError: Error { case invalidAddress(String) } +enum PrebuildActionType: String, Codable { + case build + case index = "indexbuild" + case unknown +} + public struct PrebuildContext { let targetTempDir: URL let productsDir: URL @@ -43,6 +49,8 @@ public struct PrebuildContext { let targetName: String /// List of all targets to downloaded from the thinning aggregation target var thinnedTargets: [String]? + /// Action type: build, indexbuild etc. + var action: PrebuildActionType = .unknown } extension PrebuildContext { @@ -64,5 +72,10 @@ extension PrebuildContext { self.targetName = targetName let thinFocusedTargetsString: String? = env.readEnv(key: "SPT_XCREMOTE_CACHE_THINNED_TARGETS") thinnedTargets = thinFocusedTargetsString?.split(separator: ",").map(String.init) + if let rawAction = env.readEnv(key: "ACTION") { + action = PrebuildActionType(rawValue: rawAction) ?? .unknown + } else { + action = .unknown + } } } diff --git a/Sources/XCRemoteCache/Commands/Prebuild/XCPrebuild.swift b/Sources/XCRemoteCache/Commands/Prebuild/XCPrebuild.swift index 07e1ecd..73884dc 100644 --- a/Sources/XCRemoteCache/Commands/Prebuild/XCPrebuild.swift +++ b/Sources/XCRemoteCache/Commands/Prebuild/XCPrebuild.swift @@ -36,6 +36,11 @@ public class XCPrebuild { exit(1, "FATAL: Prebuild initialization failed with error: \(error)") } + guard context.action != .index else { + printToUser("Indexbuild. Skip remote cache") + exit(0) + } + // Xcode may call xcprebuild phase even none of compilation files has changed (e.g. when switching between // simulator versions) and modifying 'mdate' of a marker file unnecessary invalidates compilation steps // that have to repeat their "use-from-cache" flow