-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Driver] Move some string definitions around (NFC) #4493
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
modocache
merged 1 commit into
swiftlang:master
from
modocache:driver-compilation-record
Sep 2, 2016
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
//===--- CompilationRecord.h ------------------------------------*- C++ -*-===// | ||
// | ||
// This source file is part of the Swift.org open source project | ||
// | ||
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors | ||
// Licensed under Apache License v2.0 with Runtime Library Exception | ||
// | ||
// See http://swift.org/LICENSE.txt for license information | ||
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef SWIFT_DRIVER_COMPILATIONRECORD_H | ||
#define SWIFT_DRIVER_COMPILATIONRECORD_H | ||
|
||
#include "swift/Driver/Action.h" | ||
|
||
namespace swift { | ||
namespace driver { | ||
namespace compilation_record { | ||
|
||
/// Compilation record files (.swiftdeps files) are YAML files composed of these | ||
/// top-level keys. | ||
enum class TopLevelKey { | ||
/// The key for the Swift compiler version used to produce the compilation | ||
/// record. | ||
Version, | ||
/// The key for the list of arguments passed to the Swift compiler when | ||
/// producing the compilation record. | ||
Options, | ||
/// The key for the time at which the build that produced the compilation | ||
/// record started. | ||
BuildTime, | ||
/// The key for the list of inputs to the compilation that produced the | ||
/// compilation record. | ||
Inputs, | ||
}; | ||
|
||
/// \returns A string representation of the given key. | ||
inline static StringRef getName(TopLevelKey Key) { | ||
switch (Key) { | ||
case TopLevelKey::Version: return "version"; | ||
case TopLevelKey::Options: return "options"; | ||
case TopLevelKey::BuildTime: return "build_time"; | ||
case TopLevelKey::Inputs: return "inputs"; | ||
} | ||
} | ||
|
||
/// \returns The string identifier used to represent the given status in a | ||
/// compilation record file (.swiftdeps file). | ||
/// | ||
/// \note Not every InputInfo::Status has a unique identifier. For example, | ||
/// both NewlyAdded and NeedsCascadingBuild are represented as "!dirty". | ||
/// Therefore, this will not cleanly round-trip between InputInfo::Status and | ||
/// string identifiers. | ||
inline static StringRef | ||
getIdentifierForInputInfoStatus(CompileJobAction::InputInfo::Status Status) { | ||
switch (Status) { | ||
case CompileJobAction::InputInfo::UpToDate: | ||
return ""; | ||
case CompileJobAction::InputInfo::NewlyAdded: | ||
case CompileJobAction::InputInfo::NeedsCascadingBuild: | ||
return "!dirty"; | ||
case CompileJobAction::InputInfo::NeedsNonCascadingBuild: | ||
return "!private"; | ||
} | ||
} | ||
|
||
/// \returns The status corresponding to the string identifier used in a | ||
/// compilation record file (.swiftdeps file). | ||
inline static Optional<CompileJobAction::InputInfo::Status> | ||
getInfoStatusForIdentifier(StringRef Identifier) { | ||
return llvm::StringSwitch<Optional< | ||
CompileJobAction::InputInfo::Status>>(Identifier) | ||
.Case("", CompileJobAction::InputInfo::UpToDate) | ||
.Case("!dirty", CompileJobAction::InputInfo::NeedsCascadingBuild) | ||
.Case("!private", CompileJobAction::InputInfo::NeedsNonCascadingBuild) | ||
.Default(None); | ||
} | ||
|
||
} // end namespace compilation_record | ||
} // end namespace driver | ||
} // end namespace swift | ||
|
||
#endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Last nitpick: can you add a note here pointing out that this will not round-trip?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I was actually confused when you mentioned that earlier. By "not round-trip", you mean that
getInfoStatusForIdentifier(getIdentifierForInputInfoStatus(Status)) != Status
, is that right? Since the left-hand side would be anOptional<Status>
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a note to the function below, based on my interpretation of "round trip" 😇
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, no, I mostly meant that there was no dedicated identifier for NewlyAdded, and that in general not every input status will necessarily have a unique compilation record identifier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aha, gotcha. My bad! Updating now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done! Let me know if that's what you had in mind.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works for me. Thanks, Brian!