Skip to content

Commit

Permalink
add support for ruby 3
Browse files Browse the repository at this point in the history
  • Loading branch information
g-arjones committed Jan 15, 2024
1 parent e10dd92 commit c11aeb9
Show file tree
Hide file tree
Showing 23 changed files with 161 additions and 76 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:

strategy:
matrix:
ruby-version: ["2.7", "2.6", "2.5"]
ruby-version: ["3.0", "2.7"]

steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:

strategy:
matrix:
ruby-version: ["2.7", "2.6", "2.5"]
ruby-version: ["3.0", "2.7"]

steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
source "https://rubygems.org"

gem "autobuild", git: "https://github.com/rock-core/autobuild", branch: "master"
gem "rubygems-server" unless RUBY_VERSION < "3"

group :dev do
gem "rubocop", "~> 1.28.0"
Expand All @@ -14,4 +15,5 @@ group :vscode do
gem "ruby-debug-ide", ">= 0.6.0"
gem "solargraph"
end

gemspec
2 changes: 1 addition & 1 deletion autoproj.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Gem::Specification.new do |s|
s.add_runtime_dependency "utilrb", "~> 3.0.0", ">= 3.0.0"
s.add_runtime_dependency "xdg", "= 2.2.5"
s.add_development_dependency "aruba", "~> 2.1.0"
s.add_development_dependency "flexmock", "~> 2.0", ">= 2.0.0"
s.add_development_dependency "flexmock"
s.add_development_dependency "minitest", "~> 5.0", ">= 5.0"
s.add_development_dependency "simplecov"
s.add_development_dependency "timecop"
Expand Down
19 changes: 11 additions & 8 deletions lib/autoproj/cli/main_doc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ def report(report_options = Hash.new)
desc: "controls whether the dependencies of the packages given on the command line should be enabled as well (the default is not)"
def enable(*packages)
require "autoproj/cli/doc"
options = self.options.merge(parent_options)
report(silent: true) do
cli = Doc.new
args = cli.validate_options(packages, options)
cli.enable(*args)
*args, options = cli.validate_options(packages, options)
cli.enable(*args, **options)
end
end

Expand All @@ -40,10 +41,11 @@ def enable(*packages)
desc: "controls whether the dependencies of the packages given on the command line should be disabled as well (the default is not)"
def disable(*packages)
require "autoproj/cli/doc"
options = self.options.merge(parent_options)
report(silent: true) do
cli = Doc.new
args = cli.validate_options(packages, options)
cli.disable(*args)
*args, options = cli.validate_options(packages, options)
cli.disable(*args, **options)
end
end

Expand All @@ -52,10 +54,11 @@ def disable(*packages)
desc: "controls whether the dependencies of the packages given on the command line should be disabled as well (the default is not)"
def list(*packages)
require "autoproj/cli/doc"
options = self.options.merge(parent_options)
report(silent: true) do
cli = Doc.new
args = cli.validate_options(packages, options)
cli.list(*args)
*args, options = cli.validate_options(packages, options)
cli.list(*args, **options)
end
end

Expand All @@ -78,8 +81,8 @@ def exec(*packages)
report do |extra_options|
cli = Doc.new
options.delete(:tool)
args = cli.validate_options(packages, options.merge(extra_options))
cli.run(*args)
*args, options = cli.validate_options(packages, options.merge(extra_options))
cli.run(*args, **options)
end
end
end
Expand Down
19 changes: 11 additions & 8 deletions lib/autoproj/cli/main_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ def enable(*packages)
require "autoproj/cli/test"
report(silent: true) do
cli = Test.new
args = cli.validate_options(packages, options)
cli.enable(*args)
options = self.options.merge(parent_options)
*args, options = cli.validate_options(packages, options)
cli.enable(*args, **options)
end
end

Expand All @@ -57,8 +58,9 @@ def disable(*packages)
require "autoproj/cli/test"
report(silent: true) do
cli = Test.new
args = cli.validate_options(packages, options)
cli.disable(*args)
options = self.options.merge(parent_options)
*args, options = cli.validate_options(packages, options)
cli.disable(*args, **options)
end
end

Expand All @@ -69,8 +71,9 @@ def list(*packages)
require "autoproj/cli/test"
report(silent: true) do
cli = Test.new
args = cli.validate_options(packages, options)
cli.list(*args)
options = self.options.merge(parent_options)
*args, options = cli.validate_options(packages, options)
cli.list(*args, **options)
end
end

Expand Down Expand Up @@ -101,8 +104,8 @@ def exec(*packages)
Autobuild.ignore_errors = options.delete(:keep_going)
Autobuild::TestUtility.coverage_enabled = options.delete(:coverage)
options.delete(:tool)
args = cli.validate_options(packages, options.merge(extra_options))
cli.run(*args)
*args, options = cli.validate_options(packages, options.merge(extra_options))
cli.run(*args, **options)
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions lib/autoproj/cli/utility.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def default(enabled)
ws.config.save
end

def enable(user_selection, options = {})
def enable(user_selection, **options)
if user_selection.empty?
ws.load_config
ws.config.utility_enable_all(utility_name)
Expand All @@ -33,7 +33,7 @@ def enable(user_selection, options = {})
ws.config.save
end

def disable(user_selection, options = {})
def disable(user_selection, **options)
if user_selection.empty?
ws.load_config
ws.config.utility_disable_all(utility_name)
Expand All @@ -49,7 +49,7 @@ def disable(user_selection, options = {})
ws.config.save
end

def list(user_selection, options = {})
def list(user_selection, **options)
initialize_and_load
resolved_selection, = finalize_setup(
user_selection,
Expand All @@ -75,7 +75,7 @@ def list(user_selection, options = {})
end
end

def run(user_selection, options = {})
def run(user_selection, **options)
options[:parallel] ||= ws.config.parallel_build_level
initialize_and_load

Expand Down
3 changes: 2 additions & 1 deletion lib/autoproj/ops/cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ def create_or_update_gems(keep_going: true, compile_force: false, compile: [])

platform_suffix = "-#{Gem::Platform.local}.gem"
failed = []
compile.each do |gem_name, artifacts: []|
compile.each do |gem_name, options = {}|
artifacts = options[:artifacts] || []
Dir.glob(File.join(cache_dir, "#{gem_name}*.gem")) do |gem|
next if gem.end_with?(platform_suffix)

Expand Down
1 change: 1 addition & 0 deletions lib/autoproj/vcs_definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ def self.raw_spec_to_s(spec)
# @raise ArgumentError if the raw specification does not match an
# expected format
def self.from_raw(spec, from: nil, raw: [], history: [])
# spec = spec_str || spec_hash
normalized_spec = normalize_vcs_hash(spec)
unless (type = normalized_spec.delete(:type))
raise ArgumentError,
Expand Down
3 changes: 2 additions & 1 deletion test/cli/test_build.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ module CLI
describe "-n" do
it "turns dependencies off" do
flexmock(Update).new_instances
.should_receive(:run).with([], hsh(deps: false)).once
.should_receive(:run).with([])
.with_kw_args(hsh(deps: false)).once
in_ws do
Main.start(["build", "-n", "--silent"])
end
Expand Down
25 changes: 23 additions & 2 deletions test/cli/test_doc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,33 @@ module CLI
end
end

%w[enable disable list exec].each do |subcommand|
describe "--deps" do
it "turns dependencies on" do
meth = subcommand
meth = "run" if subcommand == "exec"

flexmock(Doc).new_instances
.should_receive(meth.to_sym)
.with(%w[pkg1 pkg2])
.with_kw_args(hsh(deps: true))
.once
in_ws do
Main.start(["doc", subcommand, "--deps", "pkg1", "pkg2"])
end
end
end
end

describe "-n" do
it "turns dependencies off" do
flexmock(Doc).new_instances
.should_receive(:run).with([], hsh(deps: false)).once
.should_receive(:run)
.with(%w[pkg1 pkg2])
.with_kw_args(hsh(deps: false))
.once
in_ws do
Main.start(["doc", "-n"])
Main.start(["doc", "-n", "pkg1", "pkg2"])
end
end
end
Expand Down
3 changes: 2 additions & 1 deletion test/cli/test_status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ module CLI
describe "-n" do
it "turns dependencies off" do
flexmock(Status).new_instances
.should_receive(:run).with([], hsh(deps: false)).once
.should_receive(:run).with([])
.with_kw_args(hsh(deps: false)).once
in_ws do
Main.start(["status", "-n"])
end
Expand Down
19 changes: 19 additions & 0 deletions test/cli/test_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require "autoproj/test"
require "autoproj/cli/main"
require "autoproj/cli/test"
require "timecop"

Expand Down Expand Up @@ -42,6 +43,24 @@ module CLI
end
end

%w[enable disable list exec].each do |subcommand|
describe "--deps" do
it "turns dependencies on" do
meth = subcommand
meth = "run" if subcommand == "exec"

flexmock(Test).new_instances
.should_receive(meth.to_sym)
.with(%w[pkg1 pkg2])
.with_kw_args(hsh(deps: true))
.once
in_ws do
Main.start(["test", subcommand, "--deps", "pkg1", "pkg2"])
end
end
end
end

describe "#apply_to_packages" do
after do
Timecop.return
Expand Down
14 changes: 8 additions & 6 deletions test/cli/test_update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ module CLI
describe "-n" do
it "turns dependencies off" do
flexmock(Update).new_instances
.should_receive(:run).with([], hsh(deps: false)).once
.should_receive(:run).with([])
.with_kw_args(hsh(deps: false)).once
in_ws do
Main.start(["update", "-n", "--silent"])
end
Expand Down Expand Up @@ -189,12 +190,12 @@ module CLI

it "updates the configuration in checkout_only mode with config: false" do
flexmock(ws).should_receive(:load_package_sets)
.with(hsh(checkout_only: true)).once
.with_kw_args(hsh(checkout_only: true)).once
cli.run([], config: false)
end
it "updates the configuration in checkout_only mode if checkout_only is set" do
flexmock(ws).should_receive(:load_package_sets)
.with(hsh(checkout_only: true)).once
.with_kw_args(hsh(checkout_only: true)).once
cli.run([], checkout_only: true)
end
it "properly sets up packages while updating configuration only" do
Expand All @@ -207,7 +208,8 @@ module CLI
it "passes options to the osdep installer for package import" do
flexmock(Ops::Import).new_instances
.should_receive(:import_packages)
.with(PackageSelection, hsh(checkout_only: true, install_vcs_packages: Hash[install_only: true]))
.with(PackageSelection)
.with_kw_args(hsh(checkout_only: true, install_vcs_packages: Hash[install_only: true]))
.once
.and_return([[], []])
cli.run([], packages: true, checkout_only: true, osdeps: true)
Expand Down Expand Up @@ -316,7 +318,7 @@ def mock_package_failure(*errors, **options)
flexmock(Ops::Import).new_instances.should_receive(:import_packages)
.and_return([[], ["test"]])
flexmock(ws).should_receive(:install_os_packages).once
.with(["test"], Hash)
.with(["test"]).with_any_kw_args
assert_raises(pkg_set_failure) do
cli.run([], keep_going: true, packages: true, osdeps: true)
end
Expand All @@ -325,7 +327,7 @@ def mock_package_failure(*errors, **options)
it "performs osdep import based on the value encoded in the import failure exception if the package import failed" do
mock_package_failure(osdep_packages: ["test"])
flexmock(ws).should_receive(:install_os_packages).once
.with(["test"], Hash)
.with(["test"]).with_any_kw_args
assert_raises(pkg_failure) do
cli.run([], keep_going: true, packages: true, osdeps: true)
end
Expand Down
Loading

0 comments on commit c11aeb9

Please sign in to comment.