Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: crystal-lang/crystal
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: f23a126de287
Choose a base ref
...
head repository: crystal-lang/crystal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: a214c8da0530
Choose a head ref
  • 2 commits
  • 2 files changed
  • 2 contributors

Commits on Sep 18, 2017

  1. Introduce crystal --stdin-filename source flag to compile source from…

    … STDIN, closes #4561.
    
    Synopsys:
    
    ```bash
    cat src/math/math.cr | ./bin/crystal build --no-codegen --no-color -o /dev/null -f
    json --stdin-filename src/math/math.cr
    ```
    akzhan committed Sep 18, 2017
    Copy the full SHA
    7085f3c View commit details

Commits on Sep 21, 2017

  1. Merge pull request #4571 from akzhan/introduce-crystal-compiler-flag-…

    …--fake-source-source-path
    
    Introduce crystal --stdin-filename source flag
    asterite authored Sep 21, 2017
    Copy the full SHA
    a214c8d View commit details
Showing with 15 additions and 2 deletions.
  1. +2 −0 man/crystal.1
  2. +13 −2 src/compiler/crystal/command.cr
2 changes: 2 additions & 0 deletions man/crystal.1
Original file line number Diff line number Diff line change
@@ -137,6 +137,8 @@ Maximum number of threads to use for code generation. The default is 8 threads.
Enable target triple; intended to use for cross-compilation. See llvm documentation for more information about target triple.
.It Fl -verbose
Display the commands executed by the system.
.It Fl -stdin-filename Ar FILENAME
Source file name to be read from STDIN.
.El

.Pp
15 changes: 13 additions & 2 deletions src/compiler/crystal/command.cr
Original file line number Diff line number Diff line change
@@ -285,6 +285,8 @@ class Crystal::Command
compiler = Compiler.new
compiler.progress_tracker = @progress_tracker
link_flags = [] of String
filenames = [] of String
has_stdin_filename = false
opt_filenames = nil
opt_arguments = nil
opt_output_filename = nil
@@ -417,6 +419,11 @@ class Crystal::Command
end
end

opts.on("--stdin-filename ", "Source file name to be read from STDIN") do |stdin_filename|
has_stdin_filename = true
filenames << stdin_filename
end

opts.unknown_args do |before, after|
opt_filenames = before
opt_arguments = after
@@ -426,7 +433,7 @@ class Crystal::Command
compiler.link_flags = link_flags.join(" ") unless link_flags.empty?

output_filename = opt_output_filename
filenames = opt_filenames.not_nil!
filenames += opt_filenames.not_nil!
arguments = opt_arguments.not_nil!

if single_file && filenames.size > 1
@@ -439,7 +446,11 @@ class Crystal::Command
exit 1
end

sources = gather_sources(filenames)
sources = [] of Compiler::Source
if has_stdin_filename
sources << Compiler::Source.new(filenames.shift, STDIN.gets_to_end)
end
sources += gather_sources(filenames)
first_filename = sources.first.filename
first_file_ext = File.extname(first_filename)
original_output_filename = File.basename(first_filename, first_file_ext)