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

CLI option for override steep command at spawn worker #511

Merged
merged 3 commits into from
Mar 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/steep/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/steep/drivers/check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def run
steepfile: project.steepfile_path,
args: command_line_patterns,
delay_shutdown: true,
steep_command: steep_command,
count: jobs_count
)

Expand Down
4 changes: 2 additions & 2 deletions lib/steep/drivers/langserver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions lib/steep/drivers/stats.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ def run
steepfile: project.steepfile_path,
delay_shutdown: true,
args: command_line_patterns,
steep_command: steep_command,
count: jobs_count
)

Expand Down
2 changes: 1 addition & 1 deletion lib/steep/drivers/utils/jobs_count.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/steep/drivers/watch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 5 additions & 4 deletions lib/steep/server/worker_process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ 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)
args << "--log-output=#{Steep.log_output}"
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
Expand All @@ -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)
Expand Down
25 changes: 25 additions & 0 deletions test/cli_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down