Skip to content

Commit 045cbae

Browse files
committed
Add build tag conditon when build tag isn't passed
1 parent 1e78dcb commit 045cbae

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

_tools/ruby_h_to_go/lib/ruby_h_to_go/go_util.rb

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,35 @@ def self.snake_to_camel(str)
1616
def self.generate_initial_go_file(go_file_path)
1717
return if File.exist?(go_file_path)
1818

19-
ruby_build_tag = GoGem::Util.ruby_minor_version_build_tag
20-
21-
File.binwrite(go_file_path, <<~GO)
19+
header = +<<~GO
2220
// THE AUTOGENERATED LICENSE. ALL THE RIGHTS ARE RESERVED BY ROBOTS.
2321
2422
// WARNING: This file has automatically been generated
2523
// Code generated by ruby_h_to_go. DO NOT EDIT.
2624
27-
//go:build #{ruby_build_tag}
25+
GO
26+
27+
ruby_build_tag = GoGem::Util.ruby_minor_version_build_tag
28+
29+
header <<
30+
if ruby_build_tag == RubyHToGo.config.default_tag
31+
other_tags = RubyHToGo.config.available_tags - [RubyHToGo.config.default_tag]
32+
condition = other_tags.map { |tag| "!#{tag}" }.join(" && ")
2833

34+
<<~GO
35+
// FIXME: https://pkg.go.dev/ doesn't support custom build tag.
36+
// Therefore, if no build tag is passed, treat it as the default tag
37+
//go:build #{ruby_build_tag} || (#{condition})
38+
39+
GO
40+
else
41+
<<~GO
42+
//go:build #{ruby_build_tag}
43+
44+
GO
45+
end
46+
47+
header << <<~GO
2948
package ruby
3049
3150
/*
@@ -38,6 +57,8 @@ def self.generate_initial_go_file(go_file_path)
3857
)
3958
4059
GO
60+
61+
File.binwrite(go_file_path, header)
4162
end
4263

4364
C_TYPE_TO_GO_TYPE = {

0 commit comments

Comments
 (0)