-
Notifications
You must be signed in to change notification settings - Fork 3
/
cppjieba_rb.gemspec
63 lines (53 loc) · 2.44 KB
/
cppjieba_rb.gemspec
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# frozen_string_literal: true
lib = File.expand_path('lib', __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'cppjieba_rb/version'
# Recursive function to handle submodules and their submodules
def collect_submodule_files(spec, relative_path, submodule_dir)
Dir.chdir(submodule_dir) do
submodule_relative_path = submodule_dir.gsub(relative_path, '')
# Get all files in the current submodule
submodule_files = `git ls-files -z`.split("\x0")
submodule_files.each do |file|
# Add the relative submodule path to each file
spec.files << File.join(submodule_relative_path, file)
end
# Recurse into any submodules of the current submodule
nested_submodules = `git submodule foreach --quiet pwd`.split("\n")
nested_submodules.each do |nested_submodule_path|
if (ENV['OS'] == 'Windows_NT') && nested_submodule_path.start_with?('/')
# Handle cygwin-style paths on Windows
nested_submodule_path = nested_submodule_path[1..] # Remove leading slash
nested_submodule_path.insert(1, ':') # Add drive letter (e.g., C:)
end
collect_submodule_files(spec, relative_path, nested_submodule_path)
end
end
end
Gem::Specification.new do |spec|
spec.name = 'cppjieba_rb'
spec.version = CppjiebaRb::VERSION
spec.authors = ['Erick Guan']
spec.email = ['[email protected]']
spec.summary = 'cppjieba binding for ruby'
spec.description = 'cppjieba binding for ruby. Mainly used by Discourse.'
spec.homepage = 'https://github.com/erickguan/cppjieba_rb'
spec.required_ruby_version = '>=2.7.0'
spec.license = 'MIT'
spec.extensions = ['ext/cppjieba_rb/extconf.rb']
spec.files = `git ls-files -z`.split("\x0")
relative_path = "#{File.expand_path(__dir__)}/"
# Collect files from all submodules recursively
submodules = `git submodule foreach --quiet pwd`.split("\n")
submodules.each do |submodule_path|
if (ENV['OS'] == 'Windows_NT') && submodule_path.start_with?('/')
# Handle cygwin-style paths on Windows
submodule_path = submodule_path[1..] # Remove leading slash
submodule_path.insert(1, ':') # Add drive letter (e.g., C:)
end
collect_submodule_files(spec, relative_path, submodule_path)
end
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.require_paths = ['lib'] # to pick up the compiled shared library.
spec.metadata['rubygems_mfa_required'] = 'true'
end