From c067ccc0601bbc4504551a824d905ec0895b2bac Mon Sep 17 00:00:00 2001 From: "Brian J. Cardiff" Date: Tue, 23 Jun 2020 14:42:20 -0300 Subject: [PATCH 1/4] Fix method to be setter Although it is not used. But that's the pattern followed in config.cr for now. --- src/config.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config.cr b/src/config.cr index 51802006..bf5adbde 100644 --- a/src/config.cr +++ b/src/config.cr @@ -84,7 +84,7 @@ module Shards end) end - def self.crystal_version(@@crystal_version : String) + def self.crystal_version=(@@crystal_version : String) end private def self.without_prerelease(version) From 42b2fac5905d74ac9818d31d421e28c9f627178c Mon Sep 17 00:00:00 2001 From: "Brian J. Cardiff" Date: Tue, 23 Jun 2020 14:41:44 -0300 Subject: [PATCH 2/4] Lookup crystal location from CRYSTAL env var Avoid requiring crystal to be available in path. This can allow wrapper scripts on shards and have a cleaner override of the CRYSTAL_VERSION to use to resolve dependencies. --- spec/support/factories.cr | 2 +- src/commands/build.cr | 5 +++-- src/config.cr | 11 +++++++++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/spec/support/factories.cr b/spec/support/factories.cr index 400cbc1a..7512f10e 100644 --- a/spec/support/factories.cr +++ b/spec/support/factories.cr @@ -226,7 +226,7 @@ module Shards::Specs def self.crystal_path # Memoize so each integration spec do not need to create this process. # If crystal is bin/crystal this also reduce the noise of Using compiled compiler at ... - @@crystal_path ||= "#{Shards::INSTALL_DIR}#{Process::PATH_DELIMITER}#{`crystal env CRYSTAL_PATH`.chomp}" + @@crystal_path ||= "#{Shards::INSTALL_DIR}#{Process::PATH_DELIMITER}#{`#{Shards.crystal_bin} env CRYSTAL_PATH`.chomp}" end end diff --git a/src/commands/build.cr b/src/commands/build.cr index 69392225..05c5c539 100644 --- a/src/commands/build.cr +++ b/src/commands/build.cr @@ -41,10 +41,11 @@ module Shards args << "--verbose" end options.each { |option| args << option } - Log.debug { "crystal #{args.join(' ')}" } + Log.debug { "#{Shards.crystal_bin} #{args.join(' ')}" } error = IO::Memory.new - status = Process.run("crystal", args: args, output: Process::Redirect::Inherit, error: error) + + status = Process.run(Shards.crystal_bin, args: args, output: Process::Redirect::Inherit, error: error) raise Error.new("Error target #{target.name} failed to compile:\n#{error}") unless status.success? end end diff --git a/src/config.cr b/src/config.cr index bf5adbde..f9c64378 100644 --- a/src/config.cr +++ b/src/config.cr @@ -66,6 +66,13 @@ module Shards def self.bin_path=(@@bin_path : String) end + def self.crystal_bin + @@crystal_bin ||= ENV.fetch("CRYSTAL", "crystal") + end + + def self.crystal_bin=(@@crystal_bin : String) + end + def self.global_override_filename ENV["SHARDS_OVERRIDE"]?.try { |p| File.expand_path(p) } end @@ -75,9 +82,9 @@ module Shards output = IO::Memory.new error = IO::Memory.new status = begin - Process.run("crystal", {"env", "CRYSTAL_VERSION"}, output: output, error: error) + Process.run(crystal_bin, {"env", "CRYSTAL_VERSION"}, output: output, error: error) rescue e - raise Error.new("Could not execute 'crystal': #{e.message}") + raise Error.new("Could not execute '#{crystal_bin}': #{e.message}") end raise Error.new("Error executing crystal:\n#{error}") unless status.success? output.to_s.strip From 5a8c7ef1fb7e300122049adf1074806d93ee3151 Mon Sep 17 00:00:00 2001 From: "Brian J. Cardiff" Date: Tue, 23 Jun 2020 15:26:18 -0300 Subject: [PATCH 3/4] Honor CRYSTAL env var in specs --- spec/integration/spec_helper.cr | 2 +- spec/integration/update_spec.cr | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/integration/spec_helper.cr b/spec/integration/spec_helper.cr index 69189b10..0f185558 100644 --- a/spec/integration/spec_helper.cr +++ b/spec/integration/spec_helper.cr @@ -106,7 +106,7 @@ private def setup_repositories create_git_release "transitive", "0.2.0", { dependencies: {version: {git: git_url(:version)}}, scripts: { - postinstall: "crystal build src/version.cr", + postinstall: %(${CRYSTAL:-crystal} build src/version.cr), }, } diff --git a/spec/integration/update_spec.cr b/spec/integration/update_spec.cr index da594903..aae8f2fd 100644 --- a/spec/integration/update_spec.cr +++ b/spec/integration/update_spec.cr @@ -240,7 +240,7 @@ describe "update" do output = run "shards update --no-color --skip-postinstall" binary = install_path("transitive", Shards::Helpers.exe("version")) File.exists?(binary).should be_false - output.should contain("Postinstall of transitive: crystal build src/version.cr (skipped)") + output.should contain("Postinstall of transitive: ${CRYSTAL:-crystal} build src/version.cr (skipped)") end end From efef2db0f94c6a9b93e250e01d21e31a9beb35f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20M=C3=BCller?= Date: Thu, 9 Dec 2021 12:11:08 +0100 Subject: [PATCH 4/4] Remove env var for win32 --- spec/integration/spec_helper.cr | 2 +- spec/integration/update_spec.cr | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/integration/spec_helper.cr b/spec/integration/spec_helper.cr index 0f185558..e1528df8 100644 --- a/spec/integration/spec_helper.cr +++ b/spec/integration/spec_helper.cr @@ -106,7 +106,7 @@ private def setup_repositories create_git_release "transitive", "0.2.0", { dependencies: {version: {git: git_url(:version)}}, scripts: { - postinstall: %(${CRYSTAL:-crystal} build src/version.cr), + postinstall: %(#{{{ flag?(:win32) ? "crystal" : "${CRYSTAL:-crystal}" }}} build src/version.cr), }, } diff --git a/spec/integration/update_spec.cr b/spec/integration/update_spec.cr index aae8f2fd..52e41c68 100644 --- a/spec/integration/update_spec.cr +++ b/spec/integration/update_spec.cr @@ -240,7 +240,7 @@ describe "update" do output = run "shards update --no-color --skip-postinstall" binary = install_path("transitive", Shards::Helpers.exe("version")) File.exists?(binary).should be_false - output.should contain("Postinstall of transitive: ${CRYSTAL:-crystal} build src/version.cr (skipped)") + output.should contain("Postinstall of transitive: #{{{ flag?(:win32) ? "crystal" : "${CRYSTAL:-crystal}" }}} build src/version.cr (skipped)") end end