Skip to content

Commit

Permalink
Update to Ruby 3
Browse files Browse the repository at this point in the history
Currently the SDK doesn't build or work with Ruby 3:

- The code generator needs at least Weld 3 in order to work with Java
  11.

- The versions of `rake`, `rubocop` and `webrick` need to be udpated to
  work with Ruby 3.

- The C code needs to be udpated to use the `rb_thread_call_with_gvl`
  only when the code doesn't already hold the GVL. This is probably
  due to changes in `libcurl`.

This patch contains fixes for all those issues.

Signed-off-by: Juan Hernandez <[email protected]>
  • Loading branch information
jhernand authored and sandrobonazzola committed Mar 27, 2024
1 parent 9355e4f commit 9df97fc
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 9 deletions.
4 changes: 2 additions & 2 deletions generator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ limitations under the License.
<!-- The generator runs in a CDI environment, implemented by Weld: -->
<dependency>
<groupId>org.jboss.weld.se</groupId>
<artifactId>weld-se</artifactId>
<version>2.3.0.Final</version>
<artifactId>weld-se-core</artifactId>
<version>3.1.9.Final</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
Expand Down
20 changes: 19 additions & 1 deletion sdk/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Style/DateTime:
# to itself. Rubocop doesn't like these tests, but we want them anyhow,
# so we exclude that spec.
#
Lint/UselessComparison:
Lint/BinaryOperatorWithIdenticalOperands:
Exclude:
- 'spec/type_spec.rb'
Style/NilComparison:
Expand All @@ -95,3 +95,21 @@ AllCops:
- 'lib/ovirtsdk4/version.rb'
- 'pkg/**/*'
- 'tmp/**/*'

#
# This things used to work fine before upgrading Rubocop, and we don't want
# to address them now. At some point we should remove these lines, check the
# result and fix the code accordingly.
#
Style/RedundantFileExtensionInRequire:
Enabled: False
Style/OptionalBooleanParameter:
Enabled: False
Naming/VariableNumber:
Enabled: False
Style/AccessorGrouping:
Enabled: False
Style/SingleArgumentDig:
Enabled: False
Style/ZeroLengthPredicate:
Enabled: False
2 changes: 1 addition & 1 deletion sdk/examples/vm_backup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
system_service = connection.system_service

# Get the reference to the service that we will use to send events to the audit log:
events_service = system_service.events_service()
events_service = system_service.events_service

# In order to send events we need to also send unique integer ids. These should usually come from an external
# database, but in this example we # will just generate them from the current time in seconds since Jan 1st 1970.
Expand Down
12 changes: 10 additions & 2 deletions sdk/ext/ovirtsdk4c/ov_http_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -490,12 +490,20 @@ static int ov_http_client_debug_function(CURL* handle, curl_infotype type, char*
/* Get the pointer to the transfer: */
ov_http_transfer_ptr(transfer, transfer_ptr);

/* Execute the debug code with the global interpreter lock acquired, as it needs to call Ruby methods: */
/* The global interpreter lock may be acquired or not, so we need to check and either call the task directly
or else call it after acquiring the lock. Note that the `ruby_thread_has_gvl_p` function that we ue to
check if the GVL is acquired is marked as experimental, and not defined in `thread.h`, so it may be
removed at any time, but I didn't find any other way to check if the GVL is acquired. */
context.client = transfer_ptr->client;
context.type = type;
context.data = data;
context.size = size;
rb_thread_call_with_gvl(ov_http_client_debug_task, &context);
if (ruby_thread_has_gvl_p()) {
ov_http_client_debug_task(&context);
}
else {
rb_thread_call_with_gvl(ov_http_client_debug_task, &context);
}
return 0;
}

Expand Down
7 changes: 4 additions & 3 deletions sdk/ovirt-engine-sdk.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ Gem::Specification.new do |spec|
spec.required_ruby_version = '>= 2.5'

# Build time dependencies:
spec.add_development_dependency('rake', '~> 12.3')
spec.add_development_dependency('rake-compiler', '~> 1.0')
spec.add_development_dependency('rake', '~> 13.1')
spec.add_development_dependency('rake-compiler', '~> 1.2')
spec.add_development_dependency('rspec', '~> 3.7')
spec.add_development_dependency('rubocop', '0.79.0')
spec.add_development_dependency('rubocop', '1.60.2')
spec.add_development_dependency('webrick', '~> 1.8')
spec.add_development_dependency('yard', '~> 0.9', '>= 0.9.12')

# Run time dependencies:
Expand Down

0 comments on commit 9df97fc

Please sign in to comment.