diff --git a/lib/steep/cli.rb b/lib/steep/cli.rb index 1931fddb9..598ec35aa 100644 --- a/lib/steep/cli.rb +++ b/lib/steep/cli.rb @@ -72,6 +72,11 @@ def handle_jobs_option(command, opts, modifier = 0) opts.on("-j N", "--jobs=N", "Specify the number of type check workers (defaults: #{default})") do |count| command.jobs_count = Integer(count) if Integer(count) > 0 end + + command.steep_command = "steep" + opts.on("--steep-command=COMMAND", "Specify command to exec Steep CLI for worker (defaults: steep)") do |cmd| + command.steep_command = cmd + end end def process_init diff --git a/lib/steep/drivers/check.rb b/lib/steep/drivers/check.rb index abf55e2fb..291c8db7a 100644 --- a/lib/steep/drivers/check.rb +++ b/lib/steep/drivers/check.rb @@ -39,6 +39,7 @@ def run steepfile: project.steepfile_path, args: command_line_patterns, delay_shutdown: true, + steep_command: steep_command, count: jobs_count ) diff --git a/lib/steep/drivers/langserver.rb b/lib/steep/drivers/langserver.rb index 0cf851887..2aea0591b 100644 --- a/lib/steep/drivers/langserver.rb +++ b/lib/steep/drivers/langserver.rb @@ -37,8 +37,8 @@ def project def run @project = load_config() - interaction_worker = Server::WorkerProcess.spawn_worker(:interaction, name: "interaction", steepfile: project.steepfile_path) - typecheck_workers = Server::WorkerProcess.spawn_typecheck_workers(steepfile: project.steepfile_path, args: [], count: jobs_count) + interaction_worker = Server::WorkerProcess.spawn_worker(:interaction, name: "interaction", steepfile: project.steepfile_path, steep_command: steep_command) + typecheck_workers = Server::WorkerProcess.spawn_typecheck_workers(steepfile: project.steepfile_path, args: [], steep_command: steep_command, count: jobs_count) master = Server::Master.new( project: project, diff --git a/lib/steep/drivers/stats.rb b/lib/steep/drivers/stats.rb index 4d7475635..03ff7c981 100644 --- a/lib/steep/drivers/stats.rb +++ b/lib/steep/drivers/stats.rb @@ -129,6 +129,7 @@ def run steepfile: project.steepfile_path, delay_shutdown: true, args: command_line_patterns, + steep_command: steep_command, count: jobs_count ) diff --git a/lib/steep/drivers/utils/jobs_count.rb b/lib/steep/drivers/utils/jobs_count.rb index f676bacd5..6c09dfcf4 100644 --- a/lib/steep/drivers/utils/jobs_count.rb +++ b/lib/steep/drivers/utils/jobs_count.rb @@ -2,7 +2,7 @@ module Steep module Drivers module Utils module JobsCount - attr_accessor :jobs_count + attr_accessor :jobs_count, :steep_command end end end diff --git a/lib/steep/drivers/watch.rb b/lib/steep/drivers/watch.rb index 44591b585..a147ca30f 100644 --- a/lib/steep/drivers/watch.rb +++ b/lib/steep/drivers/watch.rb @@ -41,7 +41,7 @@ def run() server_reader = LanguageServer::Protocol::Transport::Io::Reader.new(server_read) server_writer = LanguageServer::Protocol::Transport::Io::Writer.new(server_write) - typecheck_workers = Server::WorkerProcess.spawn_typecheck_workers(steepfile: project.steepfile_path, args: dirs.map(&:to_s), count: jobs_count) + typecheck_workers = Server::WorkerProcess.spawn_typecheck_workers(steepfile: project.steepfile_path, args: dirs.map(&:to_s), steep_command: steep_command, count: jobs_count) master = Server::Master.new( project: project, diff --git a/lib/steep/server/worker_process.rb b/lib/steep/server/worker_process.rb index e37870db9..a538afed5 100644 --- a/lib/steep/server/worker_process.rb +++ b/lib/steep/server/worker_process.rb @@ -18,7 +18,7 @@ def initialize(reader:, writer:, stderr:, wait_thread:, name:, index: nil) @index = index end - def self.spawn_worker(type, name:, steepfile:, options: [], delay_shutdown: false, index: nil) + def self.spawn_worker(type, name:, steepfile:, steep_command: "steep", options: [], delay_shutdown: false, index: nil) args = ["--name=#{name}", "--steepfile=#{steepfile}"] args << (%w(debug info warn error fatal unknown)[Steep.logger.level].yield_self {|log_level| "--log-level=#{log_level}" }) if Steep.log_output.is_a?(String) @@ -26,9 +26,9 @@ def self.spawn_worker(type, name:, steepfile:, options: [], delay_shutdown: fals end command = case type when :interaction - ["steep", "worker", "--interaction", *args, *options] + [steep_command, "worker", "--interaction", *args, *options] when :typecheck - ["steep", "worker", "--typecheck", *args, *options] + [steep_command, "worker", "--typecheck", *args, *options] else raise "Unknown type: #{type}" end @@ -46,11 +46,12 @@ def self.spawn_worker(type, name:, steepfile:, options: [], delay_shutdown: fals new(reader: reader, writer: writer, stderr: stderr, wait_thread: thread, name: name, index: index) end - def self.spawn_typecheck_workers(steepfile:, args:, count: [Etc.nprocessors - 1, 1].max, delay_shutdown: false) + def self.spawn_typecheck_workers(steepfile:, args:, steep_command: "steep", count: [Etc.nprocessors - 1, 1].max, delay_shutdown: false) count.times.map do |i| spawn_worker(:typecheck, name: "typecheck@#{i}", steepfile: steepfile, + steep_command: steep_command, options: ["--max-index=#{count}", "--index=#{i}", *args], delay_shutdown: delay_shutdown, index: i) diff --git a/test/cli_test.rb b/test/cli_test.rb index fa8903afa..7e09c0f25 100644 --- a/test/cli_test.rb +++ b/test/cli_test.rb @@ -48,6 +48,31 @@ def test_jobs_count sub_test.call("check", %w(-j -1)) end + def test_steep_command_option + in_tmpdir do + (current_dir + "Steepfile").write(<<-EOF) +target :app do + check "foo.rb" +end + EOF + + (current_dir + "foo.rb").write(<<-EOF) +1 + 2 + EOF + + (current_dir + "wrap-steep.sh").write(<<-EOF) +echo "This is Wrap!" +steep $@ + EOF + FileUtils.chmod("u+x", current_dir + "wrap-steep.sh") + + stdout, status = sh(*steep, "check", "--steep-command=./wrap-steep.sh") + + assert_predicate status, :success?, stdout + assert_match /No type error detected\./, stdout + end + end + def test_check_success in_tmpdir do (current_dir + "Steepfile").write(<<-EOF)