Adds initial support for external commands#14953
Adds initial support for external commands#14953bcardiff merged 7 commits intocrystal-lang:masterfrom
Conversation
|
git doesn't document it for some reason, but homebrew does - here's their docs: https://docs.brew.sh/External-Commands (https://github.com/Homebrew/brew/blob/master/docs/External-Commands.md) |
|
git offers a way to list all supported commands via Another alternative would be to have a registry in the compiler of known external commands with some minimal description and in case the command is missing we can point the user to install it. |
|
Nice work @bcardiff !!! 👏
I thought about this when working on But as you said, that might be too much and maybe for another PR. As long Amazing work! |
|
Regarding specs, I think we can run the compiler being testd with a command that matches an executable that we put in with_tempfile "subcommand" do |path|
File.write(path, <<-SH
#!/bin/sh
echo $@
SH
File.chmod(path, 0700)
process = Process.new(ENV["CRYSTAL_SPEC_COMPILER_BIN"]? || "bin/crystal", ["subcommand", "foo", "bar"], output: :pipe, env: {"PATH" => File.dirname(path)})
output = process.output.gets_to_end
status = process.wait
status.success?.should be_true
output.should eq "foo bar"
end |
|
@bcardiff and @straight-shoota, reminder to wrap the subcommand executable script in a non-win32 setup, or use a Crystal application instead, as we encountered the same thing for |
Co-authored-by: Johannes Müller <straightshoota@gmail.com>
89b248b to
9e4d2bd
Compare
|
Rebased on master just in case CI failures were due to outdated branch |
|
@straight-shoota CI is failing because compiler_spec is running without the the binary being compiled. From what I gather (and remember) bin/ci used to do that. But GitHub workflows don't, or I'm reading things incorrectly. What should be the current way to make this to pass? Should I guard the spec with a |
|
Hm, yeah |
|
Note that |
|
@ysbaddaden but the Command.run to call the external tool will perform a I think I will need to add an skip if interpreter in the current state to make CI happy. I don't fully understand why compiler_spec does not run with a recently build compiler (at least in some workflows), and I see that having a separate integration_specs would be a good fit. But we can defer that for later. |
|
It seems CI is happy enough with that last skip_file 🤞 |
LGTM |
Add support for external commands. Inspired by git and cabal.
When running
crystal ext foo barifextis not a built-in command, it will look up forcrystal-extexecutable in thePATHand run that program. The current compiler location is passed as theCRYSTALenv variable, this can be used to run the compiler from the external commands or access additional information present incrystal env.This will help to shrink the compiler, but also open the game for external commands.
What kind of spec should be added on the CI for this change? A manual one? Because callingCrystal::Command.runas the rest of the compiler specs will end up callingexec.I'm not sure how/if git and cabal list external commands in the help. I would like to offer some discoverability with some description if possible, but that could be deferred for a later PR probably once we are certain we want this.