Skip to content

Commit

Permalink
Bump required crystal to 0.35 (#424)
Browse files Browse the repository at this point in the history
* Bump requirement for Crystal >= 0.35

* Update shard.lock to version 2.0

Otherwise make lib target will trigger on CI because the shard.lock version is overwritten by shards install _after_ the creation of lib folder.

Since Crystal 0.35 ships with shards 0.11 which supports lock version 2.0, and required crystal was bumped in previous commit we can make this change now.

* Test nightly on every commit also

* Memoize crystal_path in specs
  • Loading branch information
Brian J. Cardiff committed Jul 24, 2020
1 parent 6febcec commit 371d15a
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 48 deletions.
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ workflows:
jobs:
- test
- test-on-osx
- test-on-nightly
nightly:
triggers:
- schedule:
Expand Down
4 changes: 2 additions & 2 deletions shard.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
version: 1.0
version: 2.0
shards:
molinillo:
github: crystal-lang/crystal-molinillo
git: https://github.com/crystal-lang/crystal-molinillo.git
version: 0.1.0

2 changes: 1 addition & 1 deletion shard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ targets:
shards:
main: src/shards.cr

crystal: 0.34.0
crystal: 0.35.0

license: Apache-2.0
10 changes: 9 additions & 1 deletion spec/support/factories.cr
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@ module Shards::Specs
path
end
end

@@crystal_path : String?

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}:#{`crystal env CRYSTAL_PATH`.chomp}"
end
end

def tmp_path
Expand All @@ -130,7 +138,7 @@ end

def run(command, *, env = nil)
cmd_env = {
"CRYSTAL_PATH" => "#{Shards::INSTALL_DIR}:#{`crystal env CRYSTAL_PATH`.chomp}",
"CRYSTAL_PATH" => Shards::Specs.crystal_path,
}
cmd_env.merge!(env) if env
output, error = IO::Memory.new, IO::Memory.new
Expand Down
6 changes: 1 addition & 5 deletions src/errors.cr
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,7 @@ module Shards
end

filename = self.filename
{% if compare_versions(Crystal::VERSION, "0.35.0-0") > 0 %}
filename = Path[filename].relative_to Dir.current
{% else %}
filename = filename.lchop(Dir.current + "/")
{% end %}
filename = Path[filename].relative_to Dir.current

io.puts "#{filename}: #{message}"
io.puts
Expand Down
45 changes: 11 additions & 34 deletions src/logger.cr
Original file line number Diff line number Diff line change
Expand Up @@ -9,51 +9,28 @@ module Shards
end
end

{% if compare_versions(Crystal::VERSION, "0.35.0-0") > 0 %}
Log.setup_from_env(
default_sources: "shards.*",
backend: Log::IOBackend.new(formatter: Shards::FORMATTER)
)
{% else %}
Log.setup_from_env(
level: ENV.fetch("LOG_LEVEL", "INFO"),
sources: "shards.*",
backend: Log::IOBackend.new.tap do |backend|
backend.formatter = Shards::FORMATTER
end
)
{% end %}
Log.setup_from_env(
default_sources: "shards.*",
backend: Log::IOBackend.new(formatter: Shards::FORMATTER)
)

module Shards
Log = ::Log.for(self)

def self.set_warning_log_level
{% if compare_versions(Crystal::VERSION, "0.35.0-0") > 0 %}
Log.level = ::Log::Severity::Warn
{% else %}
Log.level = ::Log::Severity::Warning
{% end %}
Log.level = ::Log::Severity::Warn
end

def self.set_debug_log_level
Log.level = ::Log::Severity::Debug
end

{% if compare_versions(Crystal::VERSION, "0.35.0-0") > 0 %}
LOGGER_COLORS = {
::Log::Severity::Error => :red,
::Log::Severity::Warn => :yellow,
::Log::Severity::Info => :green,
::Log::Severity::Debug => :light_gray,
}
{% else %}
LOGGER_COLORS = {
::Log::Severity::Error => :red,
::Log::Severity::Warning => :yellow,
::Log::Severity::Info => :green,
::Log::Severity::Debug => :light_gray,
}
{% end %}
LOGGER_COLORS = {
::Log::Severity::Error => :red,
::Log::Severity::Warn => :yellow,
::Log::Severity::Info => :green,
::Log::Severity::Debug => :light_gray,
}

FORMATTER = ::Log::Formatter.new do |entry, io|
message = entry.message
Expand Down
6 changes: 1 addition & 5 deletions src/requirement.cr
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@ module Shards
end

def to_s(io)
{% if compare_versions(Crystal::VERSION, "0.35.0-0") > 0 %}
patterns.join(io, ", ")
{% else %}
patterns.join(", ", io)
{% end %}
patterns.join(io, ", ")
end

def to_yaml(yaml)
Expand Down

0 comments on commit 371d15a

Please sign in to comment.