Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Honour CRYSTAL env var #534

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion spec/integration/spec_helper.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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: %(#{{{ flag?(:win32) ? "crystal" : "${CRYSTAL:-crystal}" }}} build src/version.cr),
},
}

Expand Down
2 changes: 1 addition & 1 deletion spec/integration/update_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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: #{{{ flag?(:win32) ? "crystal" : "${CRYSTAL:-crystal}" }}} build src/version.cr (skipped)")
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/support/factories.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 3 additions & 2 deletions src/commands/build.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 10 additions & 3 deletions src/config.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -75,16 +82,16 @@ 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
end)
end

def self.crystal_version(@@crystal_version : String)
def self.crystal_version=(@@crystal_version : String)
end

private def self.without_prerelease(version)
Expand Down