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

Use CRYSTAL_OPTS env variable as default compiler options #8900

Merged
merged 1 commit into from
Mar 12, 2020

Conversation

bcardiff
Copy link
Member

This PR make the compiler read the CRYSTAL_OPTS environment variable and use is as additional compiler flags in some commands: build, eval, run, spec and .

This is handy to configure the compiler to be more pedantic regarding deprecations for example. The compiler is sometimes used in postinstall tasks where injecting flags is not possible.

With this and #8899 we should be able to checks deprecation along all the source code used to build and app.

@asterite
Copy link
Member

Just bikesheddding, but why CRYSTAL_OPTS and not CRYSTAL_OPTIONS?

@bcardiff
Copy link
Member Author

No special reasons. I'm happy to change it.

@asterite
Copy link
Member

I'm fine with that name too, I was just curious.

@bcardiff bcardiff added this to the 0.34.0 milestone Mar 12, 2020
@bcardiff bcardiff merged commit 14df86e into crystal-lang:master Mar 12, 2020
@bcardiff bcardiff deleted the feature/default-opts branch March 12, 2020 16:41
@@ -585,4 +590,8 @@ class Crystal::Command
@color = false if ARGV.includes?("--no-color") || ENV["TERM"]? == "dumb"
Crystal.error msg, @color, exit_code: exit_code
end

private def use_crystal_opts
@options = ENV.fetch("CRYSTAL_OPTS", "").split.concat(options)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a declaration that nobody will ever need to use spaces within options to Crystal compiler?

Would be nice to support shell quoting.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Definitely an improvement.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a safe already way to split that respecting shell quoting?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. We'd need to port this from Ruby: https://ruby-doc.org/stdlib-2.5.1/libdoc/shellwords/rdoc/Shellwords.html (or do something similar)

makenowjust added a commit to makenowjust/crystal that referenced this pull request Jun 20, 2020
Fixed crystal-lang#9509
Ref crystal-lang#8900 (comment)

This commit adds `Process.split`, which works as like `Shellwords.split`
in Ruby.
And, this is used to parse `CRYSTAL_OPTS`.

I'm not sure `Process.split` is good naming. However I have no idea of
better name.
And also, I'm not sure Windows version of `Process.split` is needed.
bcardiff added a commit that referenced this pull request Jun 23, 2020
* Fix `CRYSTAL_OPTS` parsing

Fixed #9509
Ref #8900 (comment)

This commit adds `Process.split`, which works as like `Shellwords.split`
in Ruby.
And, this is used to parse `CRYSTAL_OPTS`.

I'm not sure `Process.split` is good naming. However I have no idea of
better name.
And also, I'm not sure Windows version of `Process.split` is needed.

* Rename `Process.split` to `parse_arguments`

* Use `in?` instead of `includes?`

Co-authored-by: Sijawusz Pur Rahnama <sija@sija.pl>

* Let `Process.parse_arguments` raise an error against unclosed quote

This also fix backslash behavior in double quote as POSIX.

* Handle error on `CRYSTAL_OPTS` parsing

Co-authored-by: Jonne Haß <me@jhass.eu>

* Remove debug output from example

Co-authored-by: Brian J. Cardiff <bcardiff@gmail.com>

* Fix method name in example

Co-authored-by: Sijawusz Pur Rahnama <sija@sija.pl>
Co-authored-by: Jonne Haß <me@jhass.eu>
Co-authored-by: Brian J. Cardiff <bcardiff@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants