Skip to content

Exclude removed methods in Ruby 3.4 and support erb config file #29

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

Merged
merged 4 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CONFIG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ enum:
```

## Full configuration file
[config/default.yml](config/default.yml) is used by https://github.com/ruby-go-gem/go-gem-wrapper to generate bindings for Go.
[config/default.yml.erb](config/default.yml.erb) is used by https://github.com/ruby-go-gem/go-gem-wrapper to generate bindings for Go.

## `function.include_name`, `struct.include_name`, `type.include_name`, `enum.include_name`
Return functions and structures that match the condition with a [RubyHeaderParser::Parser](lib/ruby_header_parser/parser.rb)
Expand Down
9 changes: 9 additions & 0 deletions config/default.yml → config/default.yml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ function:
# FIXME: Workaround for "undefined reference to `rb_class_descendants'" on GitHub Actions (Ubuntu 22.04)
- rb_class_descendants

<% if Gem::Version.create(RUBY_VERSION) >= Gem::Version.create("3.4.0") %>
# Removed since ruby 3.4+
- rb_data_object_make
- rb_newobj
- rb_newobj_of
- rb_st_init_existing_table_with_size
- rb_st_replace
<% end %>

pointer_hint:
RSTRING_PTR:
self: raw
Expand Down
1 change: 1 addition & 0 deletions lib/ruby_header_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require "yaml"
require "tmpdir"
require "erb"

require_relative "ruby_header_parser/version"

Expand Down
3 changes: 2 additions & 1 deletion lib/ruby_header_parser/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ class Config
#
# @note See [CONFIG.md](../file.CONFIG.html) for config file details
def initialize(config_file)
yaml = File.read(config_file)
erb = File.read(config_file)
yaml = ERB.new(erb).result
@data = YAML.safe_load(yaml, aliases: true, permitted_classes: [Regexp])
end

Expand Down
4 changes: 2 additions & 2 deletions lib/ruby_header_parser/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Parser # rubocop:disable Metrics/ClassLength
# @param include_paths [Array<String>]
# @param dist_preprocessed_header_file [String,nil] Destination path to the output of preprocessed ruby.h.
# (default: `"#{Dir.tmpdir}/ruby_preprocessed.h"`)
# @param config_file [String,nil] Path to config file (default: `config/default.yml`)
# @param config_file [String,nil] Path to config file (default: `config/default.yml.erb`)
#
# @note `dist_preprocessed_header_file` is used as the output destination for temporary files when the parser
# is executed
Expand All @@ -42,7 +42,7 @@ def initialize(dist_preprocessed_header_file: nil, header_file: DEFAULT_HEADER_F
@include_paths = include_paths
@dist_preprocessed_header_file = dist_preprocessed_header_file || File.join(Dir.tmpdir, "ruby_preprocessed.h")

config_file ||= File.expand_path("../../config/default.yml", __dir__.to_s)
config_file ||= File.expand_path("../../config/default.yml.erb", __dir__.to_s)
@config = Config.new(config_file)
end

Expand Down
4 changes: 4 additions & 0 deletions rbs_collection.lock.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ gems:
revision: '09beb2100db10cbf4773ed0e71ddf79280a2f275'
remote: https://github.com/ruby/gem_rbs_collection.git
repo_dir: gems
- name: erb
version: '0'
source:
type: stdlib
- name: fileutils
version: '0'
source:
Expand Down
1 change: 1 addition & 0 deletions rbs_collection.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ gems:

- name: yaml
- name: tmpdir
- name: erb
8 changes: 4 additions & 4 deletions spec/ruby_header_parser/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
describe "#function_arg_pointer_hint" do
subject { config.function_arg_pointer_hint(function_name:, pos:) }

context "found in config/default.yml" do
context "found in config/default.yml.erb" do
let(:function_name) { "rb_funcallv" }
let(:pos) { 4 }

it { should eq :array }
end

context "not found in config/default.yml" do
context "not found in config/default.yml.erb" do
let(:function_name) { "rb_funcallv" }
let(:pos) { 5 }

Expand All @@ -24,13 +24,13 @@
describe "#function_self_pointer_hint" do
subject { config.function_self_pointer_hint(function_name) }

context "found in default.yml" do
context "found in default.yml.erb" do
let(:function_name) { "RSTRING_PTR" }

it { should eq :raw }
end

context "not found in config/default.yml" do
context "not found in config/default.yml.erb" do
let(:function_name) { "rb_class2name" }

it { should eq :ref }
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@

# @return [String]
def default_config_file
File.expand_path("../config/default.yml", __dir__)
File.expand_path("../config/default.yml.erb", __dir__)
end
Loading