Skip to content

Implement generation status #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 16, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 33 additions & 3 deletions Sources/XCHammer/Generator.swift
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@ enum Generator {
/// @note this version is written into the `XCHAMMER_DEPS_HASH` build setting
/// the version can be extracted with a simple search: i.e.
/// grep -m 1 XCHAMMER_DEPS_HASH $PROJ | sed 's,.*version:\(.*\):.*,\1,g'
public static let BinaryVersion = "0.1.2"
public static let BinaryVersion = "0.1.3"

/// Used to store the `depsHash` into the project
static let DepsHashSettingName = "XCHAMMER_DEPS_HASH"
@@ -91,18 +91,28 @@ enum Generator {
// Use whatever command and XCHammer this project was built with
let generateCommand = CommandLine.arguments.filter { $0 != "--force" }

let genStatusPath: String
if let xcworkspacePath = genOptions.xcworkspacePath {
genStatusPath = XCHammerAsset.genStatus.getPath(underProj:
xcworkspacePath)
} else {
genStatusPath = XCHammerAsset.genStatus.getPath(underProj:
genOptions.outputProjectPath)
}

// Exit with a non 0 status to ensure Xcode reloads the project ( by
// forcing another build in the future )
// Determine state by comparing timestamps of the script.
let updateScript = """
# This file is governed by XCHammer
set -e
if [[ $ACTION == "clean" ]]; then
exit 0
fi

PREV_STAT=`stat -f %c "$0"`
PREV_STAT=`stat -f %c "\(genStatusPath)"`
\(generateCommand.joined(separator: " "))
STAT=`stat -f %c "$0"`
STAT=`stat -f %c "\(genStatusPath)"`
if [[ "$PREV_STAT" != "$STAT" ]]; then
echo "error: Xcode project was out-of-date so we updated it for you! Please build again."
exit 1
@@ -305,6 +315,13 @@ enum Generator {
fatalError("Can't write BUILD file")
}

let genStatusPath = XCHammerAsset.genStatus.getPath(underProj:
tempProjectPath)
guard FileManager.default.createFile(atPath: genStatusPath,
contents: "".data(using: .utf8), attributes: nil) else {
fatalError("Can't write genStatus")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this mean for people that run xchammer? We should have something helpful here

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None of the of the fatals here are meaningful to users, as they're invalid program states ( fatal errors ). Perhaps we should cull them into a fatal XCHammer that is more clear.

}

// Add the entitilement rules to the queried rules
let targetsToBuild = genfileLabels + entitlementRules
.map { BuildLabel("/" + relativeProjDir + "/XCHammerAssets:" + $0.name) }
@@ -642,6 +659,19 @@ enum Generator {
depsHash: depsHash)
})

// Write the genStatus into the workspace
if let xcworkspacePath = xcworkspacePath {
try? FileManager.default.createDirectory(atPath:
(xcworkspacePath + Path("XCHammerAssets")).string,
withIntermediateDirectories: true,
attributes: [:])
let genStatusPath = XCHammerAsset.genStatus.getPath(underProj:
xcworkspacePath)
guard FileManager.default.createFile(atPath: genStatusPath,
contents: "".data(using: .utf8), attributes: nil) else {
fatalError("Can't write genStatus")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

}
}
return results.first ?? .success()
}
}
5 changes: 5 additions & 0 deletions Sources/XCHammer/XCHammerAsset.swift
Original file line number Diff line number Diff line change
@@ -33,6 +33,11 @@ enum XCHammerAsset: String {

case genLog = "HammerLog.txt"

/// This file is used to track the status of XCHammer and is updated when we
/// successfully run. Do not use this for anything else, as it is not part
/// the Xcode project and is unstable.
case genStatus = "genStatus"

func getPath() -> String {
return "XCHammerAssets/" + self.rawValue
}
Empty file.
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# This file is governed by XCHammer
set -e
if [[ $ACTION == "clean" ]]; then
exit 0
fi

PREV_STAT=`stat -f %c "$0"`
PREV_STAT=`stat -f %c "/Users/jerry/Projects/xchammer-github/sample/UrlGet/UrlGet.xcodeproj/XCHammerAssets/genStatus"`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you expecting absolute paths here? remove

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep we're using absolute paths, and unfortunately, they are all hardcoded to the last persons computer.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should have a better way..

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#13

/Users/jerry/Projects/xchammer-github/.build/debug/XCHammer generate /Users/jerry/Projects/xchammer-github/sample/UrlGet/XCHammer.yaml --workspace_root /Users/jerry/Projects/xchammer-github/sample/UrlGet
STAT=`stat -f %c "$0"`
STAT=`stat -f %c "/Users/jerry/Projects/xchammer-github/sample/UrlGet/UrlGet.xcodeproj/XCHammerAssets/genStatus"`
if [[ "$PREV_STAT" != "$STAT" ]]; then
echo "error: Xcode project was out-of-date so we updated it for you! Please build again."
exit 1
2 changes: 1 addition & 1 deletion sample/UrlGet/UrlGet.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Binary file modified tulsi-aspects/Utilities/post_processor
Binary file not shown.