From cafec080114265413d19b9d45ca6c9103cd0b4cc Mon Sep 17 00:00:00 2001 From: Will Leinweber Date: Fri, 31 Mar 2023 16:12:09 +0200 Subject: [PATCH 1/5] Add more customizations to Crystal::Config.description * Allow passing in git sha and date to Makefile * Remove empty parens when date is "" * Add message when compiler was not compiled in release mode When building in a nix derivation, there is no git directory, so you have to pass in the sha manually. Also, all the file modification times are set to epcoh, and I think it'd be nicer to just have the builds not have a date rather than the obviously wrong 1970-01-01. I don't think we need to always have release mode information, but it would be useful I think to have a way to see when you're working with a non-release compiler. --- Makefile | 4 ++-- src/compiler/crystal/config.cr | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index fe714d2ba393..c15648d7fc37 100644 --- a/Makefile +++ b/Makefile @@ -39,9 +39,9 @@ override FLAGS += -D strict_multi_assign -D preview_overload_order $(if $(releas SPEC_WARNINGS_OFF := --exclude-warnings spec/std --exclude-warnings spec/compiler --exclude-warnings spec/primitives SPEC_FLAGS := $(if $(verbose),-v )$(if $(junit_output),--junit_output $(junit_output) )$(if $(order),--order=$(order) ) CRYSTAL_CONFIG_LIBRARY_PATH := '$$ORIGIN/../lib/crystal' -CRYSTAL_CONFIG_BUILD_COMMIT := $(shell git rev-parse --short HEAD 2> /dev/null) +CRYSTAL_CONFIG_BUILD_COMMIT ?= $(shell git rev-parse --short HEAD 2> /dev/null) CRYSTAL_CONFIG_PATH := '$$ORIGIN/../share/crystal/src' -SOURCE_DATE_EPOCH := $(shell (git show -s --format=%ct HEAD || stat -c "%Y" Makefile || stat -f "%m" Makefile) 2> /dev/null) +SOURCE_DATE_EPOCH ?= $(shell (git show -s --format=%ct HEAD || stat -c "%Y" Makefile || stat -f "%m" Makefile) 2> /dev/null) ifeq ($(shell command -v ld.lld >/dev/null && uname -s),Linux) EXPORT_CC ?= CC="$(CC) -fuse-ld=lld" endif diff --git a/src/compiler/crystal/config.cr b/src/compiler/crystal/config.cr index eb77b9e8886f..5165eecfff99 100644 --- a/src/compiler/crystal/config.cr +++ b/src/compiler/crystal/config.cr @@ -16,11 +16,14 @@ module Crystal def self.description formatted_sha = "[#{build_commit}] " if build_commit + formatted_date = "(#{date})" unless date.empty? + release_msg = "\nRelease mode: false" unless release_mode + <<-DOC - Crystal #{version} #{formatted_sha}(#{date}) + Crystal #{version} #{formatted_sha}#{formatted_date} LLVM: #{llvm_version} - Default target: #{self.host_target} + Default target: #{self.host_target}#{release_msg} DOC end @@ -40,6 +43,14 @@ module Crystal end end + def self.release_mode + {% if flag?(:release) %} + true + {% else %} + false + {% end %} + end + @@host_target : Crystal::Codegen::Target? def self.host_target : Crystal::Codegen::Target From a0b4f18cfb605e91fe1350deb0be6ec7a55255b0 Mon Sep 17 00:00:00 2001 From: Will Leinweber Date: Fri, 31 Mar 2023 17:27:06 +0200 Subject: [PATCH 2/5] fixup! Add more customizations to Crystal::Config.description --- src/compiler/crystal/config.cr | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/compiler/crystal/config.cr b/src/compiler/crystal/config.cr index 5165eecfff99..32b307e80c27 100644 --- a/src/compiler/crystal/config.cr +++ b/src/compiler/crystal/config.cr @@ -17,13 +17,13 @@ module Crystal def self.description formatted_sha = "[#{build_commit}] " if build_commit formatted_date = "(#{date})" unless date.empty? - release_msg = "\nRelease mode: false" unless release_mode <<-DOC Crystal #{version} #{formatted_sha}#{formatted_date} LLVM: #{llvm_version} - Default target: #{self.host_target}#{release_msg} + Default target: #{self.host_target} + Release mode: #{self.release_mode} DOC end @@ -44,11 +44,7 @@ module Crystal end def self.release_mode - {% if flag?(:release) %} - true - {% else %} - false - {% end %} + {{ flag?(:release) }} end @@host_target : Crystal::Codegen::Target? From 710f87cdee7a175fb48996dfe9e98296adfead2c Mon Sep 17 00:00:00 2001 From: Will Leinweber Date: Fri, 31 Mar 2023 17:27:51 +0200 Subject: [PATCH 3/5] fixup! Add more customizations to Crystal::Config.description --- src/compiler/crystal/config.cr | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/compiler/crystal/config.cr b/src/compiler/crystal/config.cr index 32b307e80c27..639d146b6cf7 100644 --- a/src/compiler/crystal/config.cr +++ b/src/compiler/crystal/config.cr @@ -15,15 +15,17 @@ module Crystal end def self.description - formatted_sha = "[#{build_commit}] " if build_commit - formatted_date = "(#{date})" unless date.empty? + details = [version] + details << "[#{build_commit}]" if build_commit + details << "(#{date})" unless date.empty? + + development_msg = "\n\nThe compiler was not built in release mode." unless release_mode? <<-DOC - Crystal #{version} #{formatted_sha}#{formatted_date} + Crystal #{details.join(" ")} LLVM: #{llvm_version} - Default target: #{self.host_target} - Release mode: #{self.release_mode} + Default target: #{self.host_target}#{development_msg} DOC end @@ -43,7 +45,7 @@ module Crystal end end - def self.release_mode + def self.release_mode? {{ flag?(:release) }} end From 4b672b6716b4de7b8a3c4a9cfaf959011b56b1c7 Mon Sep 17 00:00:00 2001 From: Will Leinweber Date: Fri, 7 Apr 2023 10:03:55 +0200 Subject: [PATCH 4/5] fixup! Add more customizations to Crystal::Config.description --- src/compiler/crystal/config.cr | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/compiler/crystal/config.cr b/src/compiler/crystal/config.cr index 639d146b6cf7..ae61fa28ca61 100644 --- a/src/compiler/crystal/config.cr +++ b/src/compiler/crystal/config.cr @@ -15,18 +15,17 @@ module Crystal end def self.description - details = [version] - details << "[#{build_commit}]" if build_commit - details << "(#{date})" unless date.empty? + String.build do |io| + io << "Crystal " << version + io << " [" << build_commit << "]" if build_commit + io << " (" << date << ")" unless date.empty? - development_msg = "\n\nThe compiler was not built in release mode." unless release_mode? + io << "\n\nLLVM: " << llvm_version + io << "\nDefault target: " << host_target - <<-DOC - Crystal #{details.join(" ")} - - LLVM: #{llvm_version} - Default target: #{self.host_target}#{development_msg} - DOC + io << "\n\nThe compiler was not built in release mode." unless release_mode? + io << "\n" + end end def self.build_commit From 54b1d85a0f2df9f88e014778e2cfce069ef310a7 Mon Sep 17 00:00:00 2001 From: Will Leinweber Date: Fri, 7 Apr 2023 14:58:51 +0200 Subject: [PATCH 5/5] fixup! Add more customizations to Crystal::Config.description --- src/compiler/crystal/config.cr | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compiler/crystal/config.cr b/src/compiler/crystal/config.cr index ae61fa28ca61..2f71aa49815c 100644 --- a/src/compiler/crystal/config.cr +++ b/src/compiler/crystal/config.cr @@ -20,10 +20,10 @@ module Crystal io << " [" << build_commit << "]" if build_commit io << " (" << date << ")" unless date.empty? + io << "\n\nThe compiler was not built in release mode." unless release_mode? + io << "\n\nLLVM: " << llvm_version io << "\nDefault target: " << host_target - - io << "\n\nThe compiler was not built in release mode." unless release_mode? io << "\n" end end