-
Notifications
You must be signed in to change notification settings - Fork 2
/
.gemspec
136 lines (109 loc) · 3.71 KB
/
.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# encoding: utf-8
require 'yaml'
metadata = YAML.load_file('.ruby')
manifest = Dir.glob('manifest{,.txt}', File::FNM_CASEFOLD).first
Gem::Specification.new do |gemspec|
scm = case
when File.directory?('.git')
:git
end
files = case
when manifest
File.readlines(manifest).
map{ |line| line.strip }.
reject{ |line| line.empty? || line[0,1] == '#' }
when scm == :git
`git ls-files -z`.split("\0")
else
Dir.glob('{**/}{.*,*}') # TODO: be more specific using standard locations ?
end.select{ |path| File.file?(path) }
patterns = {
:bin_files => 'bin/*',
:lib_files => 'lib/{**/}*.rb',
:ext_files => 'ext/{**/}extconf.rb',
:doc_files => '*.{txt,rdoc,md,markdown,tt,textile}',
:test_files => '{test/{**/}*_test.rb,spec/{**/}*_spec.rb}'
}
glob_files = lambda { |pattern|
Dir.glob(pattern).select { |path|
File.file?(path) && files.include?(path)
}
}
#files = glob_files[patterns[:files]]
executables = glob_files[patterns[:bin_files]].map do |path|
File.basename(path)
end
extensions = glob_files[patterns[:ext_files]].map do |path|
File.basename(path)
end
# build-out the gemspec
case metadata['revision']
when 0
gemspec.name = metadata['name']
gemspec.version = metadata['version']
gemspec.summary = metadata['summary']
gemspec.description = metadata['description']
metadata['authors'].each do |author|
gemspec.authors << author['name']
if author.has_key?('email')
if gemspec.email
gemspec.email << author['email']
else
gemspec.email = [author['email']]
end
end
end
gemspec.licenses = metadata['copyrights'].map{ |c| c['license'] }.compact
metadata['requirements'].each do |req|
name = req['name']
version = req['version']
groups = req['groups'] || []
case version
when /^(.*?)\+$/
version = ">= #{$1}"
when /^(.*?)\-$/
version = "< #{$1}"
when /^(.*?)\~$/
version = "~> #{$1}"
end
if groups.empty? or groups.include?('runtime')
# populate runtime dependencies
if gemspec.respond_to?(:add_runtime_dependency)
gemspec.add_runtime_dependency(name,*version)
else
gemspec.add_dependency(name,*version)
end
else
# populate development dependencies
if gemspec.respond_to?(:add_development_dependency)
gemspec.add_development_dependency(name,*version)
else
gemspec.add_dependency(name,*version)
end
end
end
# convert external dependencies into a requirements
if metadata['external_dependencies']
##gemspec.requirements = [] unless metadata['external_dependencies'].empty?
metadata['external_dependencies'].each do |req|
gemspec.requirements << req.to_s
end
end
# determine homepage from resources
homepage = metadata['resources'].find{ |key, url| key =~ /^home/ }
gemspec.homepage = homepage.last if homepage
gemspec.require_paths = metadata['load_path'] || ['lib']
gemspec.post_install_message = metadata['install_message']
# RubyGems specific metadata
gemspec.files = files
gemspec.extensions = extensions
gemspec.executables = executables
if Gem::VERSION < '1.7.'
gemspec.default_executable = gemspec.executables.first
end
gemspec.test_files = glob_files[patterns[:test_files]]
unless gemspec.files.include?('.document')
gemspec.extra_rdoc_files = glob_files[patterns[:doc_files]]
end
end
end