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

crystal build without spepecified program files #3538

Closed
wants to merge 1 commit into from
Closed
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
7 changes: 7 additions & 0 deletions spec/compiler/compiler_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,11 @@ describe "Compiler" do
`#{tempfile.path}`.should eq("Hello!")
end
end

it "build a project without specified sources" do
Dir.cd "#{__DIR__}/data/" do
Crystal::Command.run ["build"]
File.delete("dummy-proj")
end
end
end
1 change: 1 addition & 0 deletions spec/compiler/data/shard.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
name: dummy-proj
Empty file.
24 changes: 22 additions & 2 deletions src/compiler/crystal/command.cr
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# an executable.

require "json"
require "yaml"
require "./command/*"

class Crystal::Command
Expand Down Expand Up @@ -388,8 +389,17 @@ class Crystal::Command
end

if filenames.size == 0 || (cursor_command && cursor_location.nil?)
puts option_parser
exit 1
unless shard_yml_exists?
puts option_parser
exit 1
else
if shard_proj_name.is_a?(String)
filenames << "./src/#{shard_proj_name}.cr"
else
error "\'name\' key is missing in shard.yml"
exit 1
end
end
end

sources = gather_sources(filenames)
Expand Down Expand Up @@ -457,6 +467,16 @@ class Crystal::Command
values
end

private def shard_yml_exists?
return true if File.exists?("shard.yml") && File.file?("shard.yml")
false
end

private def shard_proj_name
config = YAML.parse(File.read("shard.yml")).as_h
config["name"].to_s if config.has_key?("name")
end

private def error(msg, exit_code = 1)
# This is for the case where the main command is wrong
@color = false if ARGV.includes?("--no-color")
Expand Down