Skip to content

Commit

Permalink
Check for ACTION=indexbuild
Browse files Browse the repository at this point in the history
  • Loading branch information
tomlokhorst committed Oct 7, 2021
1 parent af21095 commit fd0a7a6
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions Sources/rswift/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ extension AccessLevel: ArgumentConvertible, CustomStringConvertible {
}

enum PrintCommandArguments: String, ArgumentConvertible {
case xcode
case portable
case complete

Expand Down Expand Up @@ -79,6 +78,8 @@ struct CommanderFlags {

// Default values for non-optional Commander Options
struct EnvironmentKeys {
static let action = "ACTION"

static let bundleIdentifier = "PRODUCT_BUNDLE_IDENTIFIER"
static let productModuleName = "PRODUCT_MODULE_NAME"
static let scriptInputFileCount = "SCRIPT_INPUT_FILE_COUNT"
Expand Down Expand Up @@ -127,7 +128,7 @@ struct CommanderOptions {
static let sourceRoot: Option<String?> = Option("sourceRoot", default: nil, description: "Defaults to environment variable \(EnvironmentKeys.sourceRoot)")

// Print-command
static let arguments: Option<PrintCommandArguments> = Option("arguments", default: .xcode, description: "Which arguments are printed [xcode|portable|complete]")
static let arguments: Option<PrintCommandArguments> = Option("arguments", default: .portable, description: "Which arguments are printed [portable|complete]")
}

// Options grouped in struct for readability
Expand Down Expand Up @@ -223,6 +224,11 @@ let generate = command(

let processInfo = ProcessInfo()

if let action = try? processInfo.environmentVariable(name: EnvironmentKeys.action), action == "indexbuild" {
warn("Not generating code during index build")
exit(EXIT_SUCCESS)
}

if let scriptInputFile = try? processInfo.environmentVariable(name: EnvironmentKeys.scriptInputFile(number: 0)),
scriptInputFile.hasSuffix("/rswift-lastrun")
{
Expand Down Expand Up @@ -356,11 +362,6 @@ let printCommand = command(
let rswiftCommand: String

switch arguments {
case .xcode:
rswiftCommand = CommandLine.arguments.first ?? "rswift"

args.append(escapePath(outputPath.replacingOccurrences(of: "\(sourceRootPath)/", with: "")))

case .portable:
let libraryDirPath = try processInfo.environmentVariable(name: "USER_LIBRARY_DIR")
rswiftCommand = CommandLine.arguments.first?.replacingOccurrences(of: "\(sourceRootPath)/", with: "") ?? "rswift"
Expand All @@ -387,7 +388,7 @@ let printCommand = command(
args.append(escapePath(outputPath))
}

print("\(rswiftCommand) \(args.joined(separator: arguments == .xcode ? " " : " \\\n "))")
print("\(rswiftCommand) \(args.joined(separator: " \\\n "))")
print("error: R.swift command logged (see build log)")
}

Expand Down

0 comments on commit fd0a7a6

Please sign in to comment.