From 9afe5859a3e428b259a306c36a860e4d82dbb4bb Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Thu, 31 Dec 2020 16:41:24 -0700 Subject: [PATCH 1/3] Revert "Remove 'g' prefix from commit hash in Zig semver" This reverts commit 02438aabe3a04ac8ca2a2e0b2501ba18885652e3. --- CMakeLists.txt | 2 +- build.zig | 10 ++-------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 291a2f7839..c74ba7fca8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,7 +46,7 @@ if("${ZIG_VERSION}" STREQUAL "") if(NOT GIT_TAG VERSION_EQUAL ZIG_VERSION) message(SEND_ERROR "Zig version (${ZIG_VERSION}) does not match Git tag (${GIT_TAG}).") endif() - elseif(GIT_DESCRIBE MATCHES "^v?([0-9]+\\.[0-9]+\\.[0-9]+)-([0-9]+)-g(.+)$") + elseif(GIT_DESCRIBE MATCHES "^v?([0-9]+\\.[0-9]+\\.[0-9]+)-([0-9]+)-(.+)$") # Untagged pre-release. The Zig version is updated to include the number of commits # since the last tagged version and the commit hash. The version is formatted in # accordance with the https://semver.org specification. diff --git a/build.zig b/build.zig index fe588ea2cb..197dd0bbed 100644 --- a/build.zig +++ b/build.zig @@ -256,17 +256,11 @@ pub fn build(b: *Builder) !void { std.process.exit(1); } - // Check that the commit hash is prefixed with a 'g' (a Git convention). - if (commit_id.len < 1 or commit_id[0] != 'g') { - std.debug.print("Unexpected `git describe` output: {}\n", .{git_describe}); - break :v version_string; - } - // The version is reformatted in accordance with the https://semver.org specification. - break :v b.fmt("{}-dev.{}+{}", .{ version_string, commit_height, commit_id[1..] }); + break :v b.fmt("{}-dev.{}+{}", .{ version_string, commit_height, commit_id }); }, else => { - std.debug.print("Unexpected `git describe` output: {}\n", .{git_describe}); + std.debug.print("Failed to parse `git describe` output: {}\n", .{git_describe}); break :v version_string; }, } From e8810f579406673edad0c9780c9d990f3034717a Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Thu, 31 Dec 2020 16:41:35 -0700 Subject: [PATCH 2/3] Revert "stage2: SemVer compliance for development builds" This reverts commit 4af763d401b48f7186650335c8e42e8fe29751bf. --- CMakeLists.txt | 4 ++-- build.zig | 48 +++++++++++++++-------------------------------- src/config.zig.in | 7 ++++++- 3 files changed, 23 insertions(+), 36 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c74ba7fca8..e023777dd9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,7 +44,7 @@ if("${ZIG_VERSION}" STREQUAL "") # Tagged release version. set(GIT_TAG ${CMAKE_MATCH_1}) if(NOT GIT_TAG VERSION_EQUAL ZIG_VERSION) - message(SEND_ERROR "Zig version (${ZIG_VERSION}) does not match Git tag (${GIT_TAG}).") + message(SEND_ERROR "Configured Zig version (${ZIG_VERSION}) does not match Git tag (${GIT_TAG}).") endif() elseif(GIT_DESCRIBE MATCHES "^v?([0-9]+\\.[0-9]+\\.[0-9]+)-([0-9]+)-(.+)$") # Untagged pre-release. The Zig version is updated to include the number of commits @@ -54,7 +54,7 @@ if("${ZIG_VERSION}" STREQUAL "") set(GIT_COMMITS_AFTER_TAG ${CMAKE_MATCH_2}) set(GIT_COMMIT ${CMAKE_MATCH_3}) if(NOT ZIG_VERSION VERSION_GREATER GIT_TAG) - message(SEND_ERROR "Zig version (${ZIG_VERSION}) must be greater than tagged ancestor (${GIT_TAG}).") + message(SEND_ERROR "Configured Zig version (${ZIG_VERSION}) must be greater than tagged ancestor (${GIT_TAG}).") endif() set(ZIG_VERSION "${ZIG_VERSION}-dev.${GIT_COMMITS_AFTER_TAG}+${GIT_COMMIT}") else() diff --git a/build.zig b/build.zig index 197dd0bbed..bef3b3b58f 100644 --- a/build.zig +++ b/build.zig @@ -11,7 +11,7 @@ const fs = std.fs; const InstallDirectoryOptions = std.build.InstallDirectoryOptions; const assert = std.debug.assert; -const zig_version = std.builtin.Version{ .major = 0, .minor = 8, .patch = 0 }; +const zig_version = std.builtin.Version{ .major = 0, .minor = 7, .patch = 1 }; pub fn build(b: *Builder) !void { b.setPreferredReleaseMode(.ReleaseFast); @@ -227,42 +227,24 @@ pub fn build(b: *Builder) !void { const version_string = b.fmt("{}.{}.{}", .{ zig_version.major, zig_version.minor, zig_version.patch }); var code: u8 = undefined; - const git_describe_untrimmed = b.execAllowFail(&[_][]const u8{ - "git", "-C", b.build_root, "describe", "--match", "*.*.*", "--tags", + const git_sha_untrimmed = b.execAllowFail(&[_][]const u8{ + "git", "-C", b.build_root, "name-rev", "HEAD", + "--tags", "--name-only", "--no-undefined", "--always", }, &code, .Ignore) catch { break :v version_string; }; - const git_describe = mem.trim(u8, git_describe_untrimmed, " \n\r"); + const git_sha_trimmed = mem.trim(u8, git_sha_untrimmed, " \n\r"); - switch (mem.count(u8, git_describe, "-")) { - 0 => { - // Tagged release version (e.g. 0.7.0). - if (!mem.eql(u8, git_describe, version_string)) { - std.debug.print("Zig version '{}' does not match Git tag '{}'\n", .{ version_string, git_describe }); - std.process.exit(1); - } - break :v version_string; - }, - 2 => { - // Untagged development build (e.g. 0.7.0-684-gbbe2cca1a). - var it = mem.split(git_describe, "-"); - const tagged_ancestor = it.next() orelse unreachable; - const commit_height = it.next() orelse unreachable; - const commit_id = it.next() orelse unreachable; - - const ancestor_ver = try std.builtin.Version.parse(tagged_ancestor); - if (zig_version.order(ancestor_ver) != .gt) { - std.debug.print("Zig version '{}' must be greater than tagged ancestor '{}'\n", .{ zig_version, ancestor_ver }); - std.process.exit(1); - } - - // The version is reformatted in accordance with the https://semver.org specification. - break :v b.fmt("{}-dev.{}+{}", .{ version_string, commit_height, commit_id }); - }, - else => { - std.debug.print("Failed to parse `git describe` output: {}\n", .{git_describe}); - break :v version_string; - }, + // This will look like e.g. "0.7.0^0" for a tag commit. + if (mem.endsWith(u8, git_sha_trimmed, "^0")) { + const git_ver_string = git_sha_trimmed[0 .. git_sha_trimmed.len - 2]; + if (!mem.eql(u8, git_ver_string, version_string)) { + std.debug.print("Expected git tag '{}', found '{}'\n", .{ version_string, git_ver_string }); + std.process.exit(1); + } + break :v b.fmt("{}", .{version_string}); + } else { + break :v b.fmt("{}+{}", .{ version_string, git_sha_trimmed }); } }; exe.addBuildOption([:0]const u8, "version", try b.allocator.dupeZ(u8, version)); diff --git a/src/config.zig.in b/src/config.zig.in index 9d16cf3824..871c6e9abf 100644 --- a/src/config.zig.in +++ b/src/config.zig.in @@ -1,6 +1,11 @@ pub const have_llvm = true; pub const version: [:0]const u8 = "@ZIG_VERSION@"; -pub const semver = try @import("std").SemanticVersion.parse(version); +pub const semver: @import("std").SemanticVersion = .{ + .major = @ZIG_VERSION_MAJOR@, + .minor = @ZIG_VERSION_MINOR@, + .patch = @ZIG_VERSION_PATCH@, + .build = "@ZIG_GIT_REV@", +}; pub const log_scopes: []const []const u8 = &[_][]const u8{}; pub const zir_dumps: []const []const u8 = &[_][]const u8{}; pub const enable_tracy = false; From d96d8639e592b4bb4b2e330c4bd7412256b297d2 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Thu, 31 Dec 2020 16:41:42 -0700 Subject: [PATCH 3/3] Revert "Comply with semantic versioning pre-release format" This reverts commit bbe2cca1ae32af322abcf4cc4a6d6bee671bf5b8. --- CMakeLists.txt | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e023777dd9..a9dc38b40b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,8 +25,8 @@ project(zig C CXX) set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH}) set(ZIG_VERSION_MAJOR 0) -set(ZIG_VERSION_MINOR 8) -set(ZIG_VERSION_PATCH 0) +set(ZIG_VERSION_MINOR 7) +set(ZIG_VERSION_PATCH 1) set(ZIG_VERSION "" CACHE STRING "Override Zig version string. Default is to find out with git.") if("${ZIG_VERSION}" STREQUAL "") @@ -34,31 +34,18 @@ if("${ZIG_VERSION}" STREQUAL "") find_program(GIT_EXE NAMES git) if(GIT_EXE) execute_process( - COMMAND ${GIT_EXE} -C ${CMAKE_SOURCE_DIR} describe --match *.*.* --tags + COMMAND ${GIT_EXE} -C ${CMAKE_SOURCE_DIR} name-rev HEAD --tags --name-only --no-undefined --always RESULT_VARIABLE EXIT_STATUS - OUTPUT_VARIABLE GIT_DESCRIBE + OUTPUT_VARIABLE ZIG_GIT_REV OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET) if(EXIT_STATUS EQUAL "0") - if(GIT_DESCRIBE MATCHES "^v?([0-9]+\\.[0-9]+\\.[0-9]+)$") - # Tagged release version. - set(GIT_TAG ${CMAKE_MATCH_1}) - if(NOT GIT_TAG VERSION_EQUAL ZIG_VERSION) - message(SEND_ERROR "Configured Zig version (${ZIG_VERSION}) does not match Git tag (${GIT_TAG}).") + if(ZIG_GIT_REV MATCHES "\\^0$") + if(NOT("${ZIG_GIT_REV}" STREQUAL "${ZIG_VERSION}^0")) + message("WARNING: Tag does not match configured Zig version") endif() - elseif(GIT_DESCRIBE MATCHES "^v?([0-9]+\\.[0-9]+\\.[0-9]+)-([0-9]+)-(.+)$") - # Untagged pre-release. The Zig version is updated to include the number of commits - # since the last tagged version and the commit hash. The version is formatted in - # accordance with the https://semver.org specification. - set(GIT_TAG ${CMAKE_MATCH_1}) - set(GIT_COMMITS_AFTER_TAG ${CMAKE_MATCH_2}) - set(GIT_COMMIT ${CMAKE_MATCH_3}) - if(NOT ZIG_VERSION VERSION_GREATER GIT_TAG) - message(SEND_ERROR "Configured Zig version (${ZIG_VERSION}) must be greater than tagged ancestor (${GIT_TAG}).") - endif() - set(ZIG_VERSION "${ZIG_VERSION}-dev.${GIT_COMMITS_AFTER_TAG}+${GIT_COMMIT}") else() - message(WARNING "Failed to parse version from output of `git describe`.") + set(ZIG_VERSION "${ZIG_VERSION}+${ZIG_GIT_REV}") endif() endif() endif()