Skip to content

Commit

Permalink
New search path: install whole dependency folder
Browse files Browse the repository at this point in the history
refs #123
  • Loading branch information
ysbaddaden committed Sep 25, 2016
1 parent eec0bab commit f4fcf5f
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 24 deletions.
11 changes: 2 additions & 9 deletions src/resolvers/git.cr
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,11 @@ module Shards
cleanup_install_directory
Dir.mkdir_p(install_path)

if file_exists?(refs, SPEC_FILENAME)
run "git archive --format=tar #{refs} #{SPEC_FILENAME} | tar -x -f - -C #{FileUtils.escape install_path}"
else
unless file_exists?(refs, SPEC_FILENAME)
File.write(File.join(install_path, "shard.yml"), read_spec(version))
end

# TODO: search for LICENSE* files
if file_exists?(refs, "LICENSE")
run "git archive --format=tar #{refs} 'LICENSE' | tar -x -f - -C #{FileUtils.escape install_path}"
end

run "git archive --format=tar --prefix= #{refs}:src/ | tar -x -f - -C #{FileUtils.escape install_path}"
run "git archive --format=tar --prefix= #{refs} | tar -x -f - -C #{FileUtils.escape install_path}"

if version =~ RELEASE_VERSION
File.delete(sha1_path) if File.exists?(sha1_path)
Expand Down
9 changes: 4 additions & 5 deletions src/resolvers/path.cr
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,12 @@ module Shards
end

def install(version = nil)
path = File.expand_path(local_path)
raise Error.new("Failed no such path: #{path}") unless Dir.exists?(path)

cleanup_install_directory
Dir.mkdir_p(File.dirname(install_path))

src_path = File.expand_path(File.join(local_path, "src"))
raise Error.new("Failed no such path: #{local_path}") unless Dir.exists?(src_path)

File.symlink(src_path, install_path)
File.symlink(path, install_path)
end
end

Expand Down
9 changes: 4 additions & 5 deletions test/git_resolver_test.cr
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,11 @@ module Shards
assert_equal "name: library\nversion: 0.1.1\n", resolver("library").read_spec("0.1.1")
end

# TODO: test that LICENSE was installed
def test_install
library, legacy = resolver("library"), resolver("legacy")

library.install("0.1.2")
assert File.exists?(install_path("library", "library.cr"))
assert File.exists?(install_path("library", "src/library.cr"))
assert File.exists?(install_path("library", "shard.yml"))
assert_equal "0.1.2", library.installed_spec.not_nil!.version
#assert File.exists?(install_path("library", "LICENSE"))
Expand All @@ -47,11 +46,11 @@ module Shards
assert_equal "0.2.0", library.installed_spec.not_nil!.version

legacy.install
assert File.exists?(install_path("legacy", "legacy.cr"))
assert File.exists?(install_path("legacy", "src/legacy.cr"))
assert File.exists?(install_path("legacy", "shard.yml"))

legacy.install("1.0.0")
assert File.exists?(install_path("legacy", "legacy.cr"))
assert File.exists?(install_path("legacy", "src/legacy.cr"))
assert File.exists?(install_path("legacy", "shard.yml"))
assert_equal "1.0.0", legacy.installed_spec.not_nil!.version
end
Expand All @@ -64,7 +63,7 @@ module Shards
empty = resolver("empty")

empty.install # HEAD
assert File.exists?(install_path("empty", "empty.cr"))
assert File.exists?(install_path("empty", "src/empty.cr"))
assert File.exists?(install_path("empty", "shard.yml"))

spec = empty.installed_spec.not_nil!
Expand Down
4 changes: 2 additions & 2 deletions test/integration_helper.cr
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ class Minitest::Test
create_git_commit "empty", "initial release"

create_git_repository "post"
create_file "post", "src/Makefile", "all:\n\ttouch made.txt\n"
create_file "post", "Makefile", "all:\n\ttouch made.txt\n"
create_git_release "post", "0.1.0", "name: post\nversion: 0.1.0\nscripts:\n postinstall: make\n"

create_git_repository "fails"
create_file "fails", "src/Makefile", "all:\n\ttest -n ''\n"
create_file "fails", "Makefile", "all:\n\ttest -n ''\n"
create_git_release "fails", "0.1.0", "name: fails\nversion: 0.1.0\nscripts:\n postinstall: make\n"

create_path_repository "foo"
Expand Down
6 changes: 3 additions & 3 deletions test/path_resolver_test.cr
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ module Shards
def test_install
resolver("library").tap do |library|
library.install
assert File.exists?(install_path("library", "library.cr"))
refute File.exists?(install_path("library", "shard.yml"))
assert File.exists?(install_path("library", "src/library.cr"))
assert File.exists?(install_path("library", "shard.yml"))
assert_equal "1.2.3", library.installed_spec.not_nil!.version
end

resolver("legacy").tap do |legacy|
legacy.install
assert File.exists?(install_path("legacy", "legacy.cr"))
assert File.exists?(install_path("legacy", "src/legacy.cr"))
refute File.exists?(install_path("legacy", "shard.yml"))
assert_equal DEFAULT_VERSION, legacy.installed_spec.not_nil!.version
end
Expand Down

0 comments on commit f4fcf5f

Please sign in to comment.