Skip to content

Commit

Permalink
Touch install_path and lockfile to express dependency (#444)
Browse files Browse the repository at this point in the history
* Touch install_path and lockfile to express dependency

* Write lockfile even when there are no dependencies

* Improve specs and implementation
  • Loading branch information
straight-shoota committed Jan 21, 2021
1 parent df51076 commit 4fa1a39
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 1 deletion.
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ test_integration: bin/shards phony
lib: shard.lock
mkdir -p lib/molinillo
$(SHARDS) install || (curl -L $(MOLINILLO_URL) | tar -xzf - -C lib/molinillo --strip-components=1)
touch lib

shard.lock: shard.yml
$(SHARDS) update
Expand Down
29 changes: 29 additions & 0 deletions spec/integration/install_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -1151,4 +1151,33 @@ describe "install" do
stdout.should contain(%(Using --ignore-crystal-version was not needed. All shards are already compatible with Crystal 1.1.0))
end
end

describe "mtime" do
it "mtime lib > shard.lock > shard.yml" do
metadata = {dependencies: {
web: "*",
}}
with_shard(metadata) do
run "shards install"
File.info("shard.lock").modification_time.should be <= File.info("lib").modification_time
File.info("shard.yml").modification_time.should be <= File.info("shard.lock").modification_time
run "shards install"
File.info("shard.lock").modification_time.should be <= File.info("lib").modification_time
File.info("shard.yml").modification_time.should be <= File.info("shard.lock").modification_time
end
end

it "mtime shard.lock > shard.yml even when unmodified" do
metadata = {dependencies: {
web: "*",
}}
with_shard(metadata) do
run "shards install"
File.touch("shard.yml")
run "shards install"
File.info("shard.lock").modification_time.should be <= File.info("lib").modification_time
File.info("shard.yml").modification_time.should be <= File.info("shard.lock").modification_time
end
end
end
end
29 changes: 29 additions & 0 deletions spec/integration/update_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -445,4 +445,33 @@ describe "update" do
assert_locked "d", "0.2.0"
end
end

describe "mtime" do
it "mtime lib > shard.lock > shard.yml" do
metadata = {dependencies: {
web: "*",
}}
with_shard(metadata) do
run "shards update"
File.info("shard.lock").modification_time.should be <= File.info("lib").modification_time
File.info("shard.yml").modification_time.should be <= File.info("shard.lock").modification_time
run "shards update"
File.info("shard.lock").modification_time.should be <= File.info("lib").modification_time
File.info("shard.yml").modification_time.should be <= File.info("shard.lock").modification_time
end
end

it "mtime shard.lock > shard.yml even when unmodified" do
metadata = {dependencies: {
web: "*",
}}
with_shard(metadata) do
run "shards update"
File.touch("shard.yml")
run "shards update"
File.info("shard.lock").modification_time.should be <= File.info("lib").modification_time
File.info("shard.yml").modification_time.should be <= File.info("shard.lock").modification_time
end
end
end
end
6 changes: 6 additions & 0 deletions src/commands/install.cr
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,14 @@ module Shards

if generate_lockfile?(packages)
write_lockfile(packages)
elsif !Shards.production?
# Touch lockfile so its mtime is bigger than that of shard.yml
File.touch(lockfile_path)
end

# Touch install path so its mtime is bigger than that of the lockfile
File.touch(Shards.install_path)

if ignore_crystal_version
check_ignored_crystal_version(packages)
end
Expand Down
6 changes: 6 additions & 0 deletions src/commands/update.cr
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,14 @@ module Shards

if generate_lockfile?(packages)
write_lockfile(packages)
else
# Touch lockfile so its mtime is bigger than that of shard.yml
File.touch(lockfile_path)
end

# Touch install path so its mtime is bigger than that of the lockfile
File.touch(Shards.install_path)

if ignore_crystal_version
check_ignored_crystal_version(packages)
end
Expand Down

0 comments on commit 4fa1a39

Please sign in to comment.