-
-
Notifications
You must be signed in to change notification settings - Fork 103
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
Added a feature shards build
#136
Conversation
Related to #110 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for taking the time to work on this!
That being said, I would like the feature to be as minimal as possible, and we sadly lacked a proper design beforehand, merely a few random ideas tossed in an issue comment. So, I would like to make many changes, sorry.
- the target name is meant to be the name of the resulting binary, which should be installed into the
bin
directory; also themain
must be a complete path (it could be outside thesrc
folder); the command should thus be:["crystal", "build", target.main, "-o", File.join("bin", target.name)]
. - let's simplify the command, since
default
andall
won't work as expected (it's the target binary name), so it becomesshards build [options] [target, ...]
meaning that:shards build
will build all configured targets; erroring if none are found (no targets configured);shards build one two three
will build theone
, thentwo
thenthree
targets, one after the other; erroring if a target doesn't exist (missing target foo).
- please drop the
options
Array. I don't think there is much need for it for the time being; options could be passed via the command for example (e.g.shards build --release
); - no need to check for the presence of the
crystal
binary. Let the command fail, and print it with the error message; BTW maybe we'd like to honor anENV["CRYSTAL"]
variable that would default tocrystal
? - the
build
command should check the dependencies and install them before trying to build.
Last but not least, thank you for writing integration tests, and taking of your time to work on this feature!
case pull.read_scalar | ||
when "main" | ||
target.main = pull.read_scalar | ||
when "options" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's avoid options
for now; they could be passed as options to the command for example:
$ shards build --release
getter spec_path : String | ||
getter lockfile_path : String | ||
|
||
@spec : Spec? | ||
@locks : Array(Dependency)? | ||
|
||
def initialize(path) | ||
def initialize(path, @sub = nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is sub
? Can we avoid it?
@options = [] of String | ||
end | ||
|
||
def cmd |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about shell_command
? Thought the model shouldn't have to deal with the invocation. Command::Build should be the one generating the command.
property options : Array(String) | ||
|
||
def initialize(@name) | ||
super() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not needed: there are no superclass.
Dir.cd(application_path) do | ||
File.open "mock.cr", "w" | ||
ex = assert_raises(FailedCommand) { run "shards build mock_fake" } | ||
assert_match "\e[31mTarget\e[0m 'mock_fake' is not found\n", ex.stdout |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please pass --no-color
to the command.
Thanks for your review! We set
Then
One thing that I have to say is that it is quite difficult to know whether an argument is a "target" or "option"
In this case, shards cannot decide bbb is a value of "-aaa" or a target.
I can hard code For now, I took first approach.(Regarding the input after the argument with "-" prefix as options) As a supplement, I don't understand why the test/cli.cr parses a hash manually. |
Thanks! I'll correctly review this when I have some free time. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After tbrand@58fc34f there are some unused changes i think.
@@ -5,6 +5,7 @@ require "../spec" | |||
module Shards | |||
abstract class Command | |||
getter path : String | |||
getter sub : String | Nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unused?
@@ -24,8 +25,8 @@ module Shards | |||
|
|||
abstract def run | |||
|
|||
def self.run(path) | |||
new(path).run | |||
def self.run(path, sub = nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unused change? It should be rolledback probably.
parse_args | ||
# mkdir bin | ||
mkdir_bin | ||
if @targets.size == 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if @targets.empty?
:)
def parse_args | ||
is_option? = false | ||
@@args.each do |arg| | ||
is_option? = true if arg.starts_with?("-") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use Char
here: '-'
Squashed and merged as 82fef4d. Thank you! |
You meant you keep |
Hi all,
This PR is based on crystal-lang/crystal#3538.
I added a
build
command forshards
.In shard.yml, we set
Then,
Thanks for your review!