Skip to content

Commit

Permalink
[Basic] Revise version printing
Browse files Browse the repository at this point in the history
Now that we use the LLVM mono-repo, we don't need to worry about clang's
version number. Also, git has the ability to estimate the safe number of
digits a hash can be truncated to and now git estimates that large
projects like LLVM and Linux "require" 12 digits for safe commit hash
abbreviation. Let's stay a little ahead of the curve and statically
truncate to 15.
  • Loading branch information
davezarzycki committed Jun 16, 2020
1 parent 542721b commit aefeab8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 18 deletions.
1 change: 0 additions & 1 deletion lib/Basic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ function(generate_revision_inc revision_inc_var name dir)
endfunction()

generate_revision_inc(llvm_revision_inc LLVM "${LLVM_MAIN_SRC_DIR}")
generate_revision_inc(clang_revision_inc Clang "${CLANG_MAIN_SRC_DIR}")
generate_revision_inc(swift_revision_inc Swift "${SWIFT_SOURCE_DIR}")

add_swift_host_library(swiftBasic STATIC
Expand Down
24 changes: 7 additions & 17 deletions lib/Basic/Version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,34 +45,25 @@
#endif

#include "LLVMRevision.inc"
#include "ClangRevision.inc"
#include "SwiftRevision.inc"

namespace swift {
namespace version {

/// Print a string of the form "LLVM xxxxx, Clang yyyyy, Swift zzzzz",
/// where each placeholder is the revision for the associated repository.
/// Print a string of the form "LLVM xxxxx, Swift zzzzz", where each placeholder
/// is the revision for the associated repository.
static void printFullRevisionString(raw_ostream &out) {
// Arbitrarily truncate to 10 characters. This should be enough to unique
// Git hashes for the time being, and certainly enough for SVN revisions,
// while keeping the version string from being ridiculously long.
// Arbitrarily truncate to 15 characters. This should be enough to unique Git
// hashes while keeping the REPL version string from overflowing 80 columns.
#if defined(LLVM_REVISION)
out << "LLVM " << StringRef(LLVM_REVISION).slice(0, 10);
# if defined(CLANG_REVISION) || defined(SWIFT_REVISION)
out << ", ";
# endif
#endif

#if defined(CLANG_REVISION)
out << "Clang " << StringRef(CLANG_REVISION).slice(0, 10);
out << "LLVM " << StringRef(LLVM_REVISION).slice(0, 15);
# if defined(SWIFT_REVISION)
out << ", ";
# endif
#endif

#if defined(SWIFT_REVISION)
out << "Swift " << StringRef(SWIFT_REVISION).slice(0, 10);
out << "Swift " << StringRef(SWIFT_REVISION).slice(0, 15);
#endif
}

Expand Down Expand Up @@ -424,8 +415,7 @@ std::string getSwiftFullVersion(Version effectiveVersion) {
OS << " clang-" CLANG_COMPILER_VERSION;
#endif
OS << ")";
#elif defined(LLVM_REVISION) || defined(CLANG_REVISION) || \
defined(SWIFT_REVISION)
#elif defined(LLVM_REVISION) || defined(SWIFT_REVISION)
OS << " (";
printFullRevisionString(OS);
OS << ")";
Expand Down

0 comments on commit aefeab8

Please sign in to comment.