Skip to content

Commit b55a827

Browse files
Fix install non-.exe executables on Windows (#593)
1 parent eac9adf commit b55a827

File tree

3 files changed

+39
-5
lines changed

3 files changed

+39
-5
lines changed

spec/integration/install_spec.cr

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -836,13 +836,28 @@ describe "install" do
836836
foobar = File.join(application_path, "bin", Shards::Helpers.exe("foobar"))
837837
baz = File.join(application_path, "bin", Shards::Helpers.exe("baz"))
838838
foo = File.join(application_path, "bin", Shards::Helpers.exe("foo"))
839+
crystal = File.join(application_path, "bin", "crystal.cr")
839840

840841
File.exists?(foobar).should be_true # "Expected to have installed bin/foobar executable"
841842
File.exists?(baz).should be_true # "Expected to have installed bin/baz executable"
842843
File.exists?(foo).should be_false # "Expected not to have installed bin/foo executable"
844+
File.exists?(crystal).should be_true
843845

844846
`#{Process.quote(foobar)}`.should eq("OK")
845847
`#{Process.quote(baz)}`.should eq("KO")
848+
File.read(crystal).should eq %(puts "crystal")
849+
end
850+
851+
it "errors on missing executable" do
852+
metadata = {
853+
dependencies: {"executable_missing": "*"},
854+
}
855+
with_shard(metadata) do
856+
ex = expect_raises(FailedCommand) { run "shards install --no-color" }
857+
ex.stdout.should contain <<-ERROR
858+
E: Could not find executable "nonexistent"
859+
ERROR
860+
end
846861
end
847862

848863
it "skips installing executables" do

spec/integration/spec_helper.cr

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,14 @@ private def setup_repositories
127127
create_git_repository "binary"
128128
create_executable "binary", "bin/foobar", %(print "OK")
129129
create_executable "binary", "bin/baz", %(print "KO")
130-
create_git_release "binary", "0.1.0", {executables: ["foobar", "baz"]}
130+
create_file "binary", "bin/crystal.cr", %(puts "crystal")
131+
create_git_release "binary", "0.1.0", {executables: ["foobar", "baz", "crystal.cr"]}
131132
create_executable "binary", "bin/foo", %(print "FOO")
132133
create_git_release "binary", "0.2.0", {executables: ["foobar", "baz", "foo"]}
133134

135+
create_git_repository "executable_missing"
136+
create_git_release "executable_missing", "0.1.0", {executables: ["nonexistent"]}
137+
134138
create_git_repository "c"
135139
create_git_release "c", "0.1.0", {dependencies: {d: {git: git_url(:d), version: "0.1.0"}}}
136140
create_git_release "c", "0.2.0", {dependencies: {d: {git: git_url(:d), version: "0.2.0"}}}

src/package.cr

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,13 @@ module Shards
106106
Dir.mkdir_p(Shards.bin_path)
107107

108108
spec.executables.each do |name|
109-
exe_name = Shards::Helpers.exe(name)
110-
Log.debug { "Install bin/#{exe_name}" }
111-
source = File.join(install_path, "bin", exe_name)
112-
destination = File.join(Shards.bin_path, exe_name)
109+
exe_name = find_executable_file(Path[install_path], name)
110+
unless exe_name
111+
raise Shards::Error.new("Could not find executable #{name.inspect}")
112+
end
113+
Log.debug { "Install #{exe_name}" }
114+
source = File.join(install_path, exe_name)
115+
destination = File.join(Shards.bin_path, File.basename(exe_name))
113116

114117
if File.exists?(destination)
115118
next if File.same?(destination, source)
@@ -124,6 +127,18 @@ module Shards
124127
end
125128
end
126129

130+
def find_executable_file(install_path, name)
131+
each_executable_path(name) do |path|
132+
return path if File.exists?(install_path.join(path))
133+
end
134+
end
135+
136+
private def each_executable_path(name)
137+
exe = Shards::Helpers.exe(name)
138+
yield Path["bin", exe]
139+
yield Path["bin", name] unless name == exe
140+
end
141+
127142
def to_yaml(builder)
128143
Dependency.new(name, resolver, version).to_yaml(builder)
129144
end

0 commit comments

Comments
 (0)