| 1 |
# THIS FILE WAS AUTOGENERATED, DO NOT EDIT |
| 2 |
abort 'Use the rake task or esr-gem-builder to build the gem' if $0 =~ /gem$/ && $*.first == 'build' |
| 3 |
require 'yaml' |
| 4 |
|
| 5 |
Class.new do |
| 6 |
|
| 7 |
def initialize |
| 8 |
@project_path = File.dirname(__FILE__) |
| 9 |
@project_config_path = File.join(File.dirname(__FILE__), 'Project.yaml') |
| 10 |
@project_config = YAML.load(File.read(@project_config_path)) |
| 11 |
end |
| 12 |
|
| 13 |
def rubies |
| 14 |
(@project_config['rubies'] || ['2.3']).map(&:to_s) |
| 15 |
end |
| 16 |
|
| 17 |
def platforms |
| 18 |
@project_config['platforms'] || %w(x86_64-linux x64-mingw32) |
| 19 |
end |
| 20 |
|
| 21 |
def exclude_files |
| 22 |
@project_config['exclude_files'] || [] |
| 23 |
end |
| 24 |
|
| 25 |
def encrypt_sources |
| 26 |
@project_config['encrypt_sources'].nil? ? true : @project_config['encrypt_sources'] |
| 27 |
end |
| 28 |
|
| 29 |
def extensions |
| 30 |
@project_config['extensions'] || |
| 31 |
Hash[Dir.glob(File.join(@project_path, 'ext', '*')).select { |f| File.directory?(f) }.map { |f| [File.basename(f).to_sym, f] }] |
| 32 |
end |
| 33 |
|
| 34 |
def common_native_binary_paths |
| 35 |
@project_config['common_native_binary_paths'] |
| 36 |
end |
| 37 |
|
| 38 |
def native_library_artifacts |
| 39 |
@project_config['native_library_artifacts'] |
| 40 |
end |
| 41 |
|
| 42 |
def common_native_binary_artifacts |
| 43 |
@project_config['common_native_binary_artifacts'] || {} |
| 44 |
end |
| 45 |
|
| 46 |
def extensions_target_path |
| 47 |
@project_config['extensions_target_path'] || File.join('lib', 'native') |
| 48 |
end |
| 49 |
|
| 50 |
# All extension artifact path list |
| 51 |
def native_library_artifact_paths(only_platforms = nil) |
| 52 |
platforms_list = only_platforms.nil? ? platforms : only_platforms |
| 53 |
extensions.keys.flat_map do |name| |
| 54 |
rubies.flat_map do |ruby| |
| 55 |
platforms_list.flat_map do |platform| |
| 56 |
if native_library_artifacts && native_library_artifacts[name.to_s] |
| 57 |
native_library_artifacts[name.to_s].map do |artifact_platform, artifacts| |
| 58 |
next unless platform == artifact_platform.to_s |
| 59 |
artifacts.map { |a| File.join(extensions_target_path, name.to_s, ruby, platform, a) } |
| 60 |
end |
| 61 |
elsif @project_config['native_artifacts'] && @project_config['native_artifacts'][name.to_s] # backward compatibility (e.g. esr-licensing <0.3) |
| 62 |
@project_config['native_artifacts'][name.to_s].map do |artifact| |
| 63 |
next unless platform == platform.to_s |
| 64 |
File.join(extensions_target_path, name.to_s, ruby.to_s, platform, artifact) |
| 65 |
end |
| 66 |
else |
| 67 |
[File.join(extensions_target_path, name.to_s, ruby.to_s, platform, name.to_s + '.so')] |
| 68 |
end |
| 69 |
end |
| 70 |
end |
| 71 |
end |
| 72 |
end |
| 73 |
|
| 74 |
def common_native_binary_path(name, platform = nil) |
| 75 |
path = common_native_binary_paths[name] unless common_native_binary_paths.nil? |
| 76 |
path = path[platform || RUBY_PLATFORM] if path.is_a?(Hash) |
| 77 |
path || File.join('native', name) |
| 78 |
end |
| 79 |
|
| 80 |
def common_native_binary_artifact_paths(only_platforms = nil) |
| 81 |
common_native_binary_artifacts.flat_map do |name, info| |
| 82 |
info.flat_map do |platform, binaries| |
| 83 |
next if only_platforms && !only_platforms.include?(platform.to_s) |
| 84 |
binaries.map { |binary| File.join(common_native_binary_path(name, platform), binary) } |
| 85 |
end |
| 86 |
end.compact |
| 87 |
end |
| 88 |
|
| 89 |
def native_artifact_paths(only_platforms = nil) |
| 90 |
native_library_artifact_paths(only_platforms) + common_native_binary_artifact_paths(only_platforms) |
| 91 |
end |
| 92 |
|
| 93 |
def gemspec |
| 94 |
Gem::Specification.new do |s| |
| 95 |
s.name = @project_config['name'] |
| 96 |
s.version = @project_config['version'] |
| 97 |
s.authors = @project_config['authors'] |
| 98 |
s.homepage = @project_config['homepage'] |
| 99 |
s.summary = @project_config['summary'] |
| 100 |
s.description = @project_config['description'] |
| 101 |
s.licenses = @project_config['licenses'] |
| 102 |
s.bindir = @project_config['bindir'] || 'bin' |
| 103 |
s.executables = @project_config['executables'] |
| 104 |
s.extra_rdoc_files = @project_config['extra_rdoc_files'] |
| 105 |
s.rdoc_options.push(*@project_config['rdoc_options']) if @project_config['rdoc_options'] |
| 106 |
include_patterns = (@project_config['include_files'] || []) + ["lib/**/*.rb", "Project.yaml"] |
| 107 |
include = include_patterns.reject { |i| i.include?('*') } + |
| 108 |
include_patterns.select { |i| i.include?('*') }.flat_map { |i| Dir.glob(File.join(@project_path, i)) } |
| 109 |
include.push(*native_artifact_paths) |
| 110 |
include << "lib/rubyencoder.lic" if encrypt_sources |
| 111 |
exclude_files_expanded = exclude_files.reject { |i| i.include?('*') } |
| 112 |
exclude = [exclude_files_expanded] + |
| 113 |
exclude_files.select { |i| i.include?('*') }.flat_map { |i| Dir.glob(File.join(@project_path, i)) } |
| 114 |
s.files = include - exclude |
| 115 |
(@project_config['dependencies'] || {}).flat_map do |_, deps| |
| 116 |
deps.map do |d| |
| 117 |
if d.is_a?(String) |
| 118 |
s.add_dependency(d) |
| 119 |
else |
| 120 |
dep_args = [d['name']] |
| 121 |
dep_args.concat(if d['version'].nil?; []; else d['version'].is_a?(String) ? [d['version']] : d['version'] end) |
| 122 |
if d['development'] |
| 123 |
s.add_development_dependency(*dep_args) |
| 124 |
else |
| 125 |
s.add_dependency(*dep_args) |
| 126 |
end |
| 127 |
end |
| 128 |
end |
| 129 |
end |
| 130 |
end |
| 131 |
end |
| 132 |
|
| 133 |
end.new.gemspec |