From fe35339b86c259d0466fba144ab1b4c863597b15 Mon Sep 17 00:00:00 2001 From: TSUYUSATO Kitsune Date: Sat, 8 Jul 2017 04:20:40 +0900 Subject: [PATCH] Get version number from CHANGELOG.md when cannot get it from git Fixed #4642 --- src/compiler/crystal/config.cr | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/compiler/crystal/config.cr b/src/compiler/crystal/config.cr index 29e5f62832fc..bf944d25fc66 100644 --- a/src/compiler/crystal/config.cr +++ b/src/compiler/crystal/config.cr @@ -35,8 +35,15 @@ module Crystal git_version = {{`(git describe --tags --long --always 2>/dev/null) || true`.stringify.chomp}} # Failed git and no explicit version set: "" - # We inherit the version of the compiler building us for now. - return { {{Crystal::VERSION}}, nil } if git_version.empty? + # We try to get the version from CHANGELOG.md. + # It is useful when build crystal from release archive. + # See: https://github.com/crystal-lang/crystal/issues/4642 + if git_version.empty? + changelog_version = {{`(grep -oE '[0-9]+\\.[0-9]+\\.[0-9]+' CHANGELOG.md | head -n1) || true`.stringify.chomp}} + # As final fallback, we inherit the version of the compiler building us for now. + changelog_version = {{Crystal::VERSION}} if changelog_version.empty? + return {changelog_version, nil} + end # Shallow clone with no tag in reach: abcd123 # We assume being compiled with the latest released compiler