polisher 0.7.1 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,29 +5,10 @@
5
5
 
6
6
  require 'bundler'
7
7
 
8
+ require 'polisher/git'
9
+ require 'polisher/gem'
8
10
  require 'polisher/version_checker'
9
11
 
10
- # Override bundler's gem registration
11
- module Bundler
12
- class << self
13
- attr_accessor :bundler_gems
14
-
15
- def init_gems
16
- Bundler.bundler_gems = []
17
- end
18
- end
19
-
20
- class Dsl
21
- alias :old_gem :gem
22
- def gem(name, *args)
23
- Bundler.bundler_gems ||= []
24
- version = args.first.is_a?(Hash) ? nil : args.first
25
- Bundler.bundler_gems << [name, version]
26
- old_gem(name, *args)
27
- end
28
- end
29
- end
30
-
31
12
  module Polisher
32
13
  class Gemfile
33
14
  include VersionedDependencies
@@ -45,6 +26,7 @@ module Polisher
45
26
  @version = nil
46
27
  @deps = args[:deps]
47
28
  @dev_deps = args[:dev_deps]
29
+ @definition = args[:definition]
48
30
  @file_paths = []
49
31
  end
50
32
 
@@ -52,30 +34,64 @@ module Polisher
52
34
  #
53
35
  # @param [String] path to gemfile to parse
54
36
  # @return [Polisher::Gemfile] gemfile instantiated from parsed metadata
55
- def self.parse(path)
37
+ def self.parse(path, args={})
38
+ groups = args[:groups]
39
+
40
+ definition = nil
56
41
  path,g = File.split(path)
57
42
  Dir.chdir(path){
58
- Bundler.init_gems
59
43
  begin
60
- Bundler::Definition.build(g, nil, false)
44
+ definition = Bundler::Definition.build(g, nil, false)
61
45
  rescue Bundler::GemfileNotFound
62
46
  raise ArgumentError, "invalid gemfile: #{path}"
63
47
  end
64
48
  }
49
+
65
50
  metadata = {}
66
- metadata[:deps] = Bundler.bundler_gems.collect { |n,v| n }
51
+ metadata[:deps] =
52
+ definition.dependencies.select { |d|
53
+ d.groups.include?(:default) || # dep in all groups
54
+ groups.nil? || groups.empty? || # groups not specified
55
+ groups.any? { |g| d.groups.include?(g.intern) } # dep in any group
56
+ }.collect { |d| d.name }
57
+
67
58
  metadata[:dev_deps] = [] # TODO
59
+ metadata[:definition] = definition
68
60
 
69
61
  self.new metadata
70
62
  end
71
63
 
72
- # TODO simply alias for gems in gemfile?
64
+ # Simply alias for all dependencies in Gemfile
73
65
  def vendored
66
+ deps + dev_deps
74
67
  end
75
68
 
76
- # TODO retrieve gems which differ from
69
+ # Retrieve gems which differ from
77
70
  # rubygems.org/other upstream sources
78
71
  def patched
72
+ vendored.collect do |dep|
73
+ bundler_dep = @definition ?
74
+ @definition.dependencies.find { |d| d.name == dep } : nil
75
+
76
+ # TODO right now just handling git based alternate sources,
77
+ # should be able to handle other types bundler supports
78
+ # (path and alternate rubygems src)
79
+ next unless bundler_dep && bundler_dep.source.is_a?(Bundler::Source::Git)
80
+ src = bundler_dep.source
81
+
82
+ # retrieve gem
83
+ gem = src.version ?
84
+ Polisher::Gem.new(:name => dep, :version => src.version) :
85
+ Polisher::Gem.retrieve(dep)
86
+
87
+ # retrieve dep
88
+ git = Polisher::Git::Repo.new :url => src.uri
89
+ git.clone unless git.cloned?
90
+ git.checkout src.ref if src.ref
91
+
92
+ # diff gem against git
93
+ gem.diff(git.path)
94
+ end.compact!
79
95
  end
80
96
  end # class Gemfile
81
97
  end # module Polisher
@@ -3,233 +3,6 @@
3
3
  # Licensed under the MIT license
4
4
  # Copyright (C) 2013-2014 Red Hat, Inc.
5
5
 
6
- require 'tmpdir'
7
- require 'awesome_spawn'
8
- require 'polisher/rpmspec'
9
- require 'polisher/git_cache'
10
-
11
- module Polisher
12
- # Git Repository
13
- class GitRepo
14
- # TODO use ruby git api
15
- GIT_CMD = '/usr/bin/git'
16
-
17
- attr_accessor :url
18
-
19
- def initialize(args={})
20
- @url = args[:url]
21
- end
22
-
23
- def path
24
- GitCache.path_for(@url)
25
- end
26
-
27
- def clone
28
- AwesomeSpawn.run "#{GIT_CMD} clone #{url} #{path}"
29
- end
30
-
31
- def cloned?
32
- File.directory?(path)
33
- end
34
-
35
- def in_repo
36
- Dir.chdir path do
37
- yield
38
- end
39
- end
40
-
41
- # Note be careful when invoking:
42
- def reset!
43
- in_repo { AwesomeSpawn.run "#{GIT_CMD} reset HEAD~ --hard" }
44
- self
45
- end
46
-
47
- def pull
48
- in_repo { AwesomeSpawn.run "#{GIT_CMD} pull" }
49
- self
50
- end
51
-
52
- def checkout(tgt)
53
- in_repo { AwesomeSpawn.run "#{GIT_CMD} checkout #{tgt}" }
54
- self
55
- end
56
-
57
- def commit(msg)
58
- in_repo { AwesomeSpawn.run "#{GIT_CMD} commit -m '#{msg}'" }
59
- self
60
- end
61
- end
62
-
63
- # DistGit Package Representation
64
- class GitPackage < GitRepo
65
- attr_accessor :name
66
- attr_accessor :version
67
-
68
- # TODO these should be to be configurable
69
- RPM_PREFIX = 'rubygem-'
70
- PKG_CMD = '/usr/bin/fedpkg'
71
- BUILD_CMD = '/usr/bin/koji'
72
- BUILD_TGT = 'rawhide'
73
-
74
- MD5SUM_CMD = '/usr/bin/md5sum'
75
- SED_CMD = '/usr/bin/sed'
76
- DIST_GIT_URL = 'git://pkgs.fedoraproject.org/'
77
-
78
- def initialize(args={})
79
- @name = args[:name]
80
- @version = args[:version]
81
- super(args)
82
- end
83
-
84
- # Return full rpm name of package containing optional prefix
85
- def rpm_name
86
- @rpm_name ||= "#{RPM_PREFIX}#{self.name}"
87
- end
88
-
89
- # Return full srpm file name of package
90
- def srpm
91
- @srpm ||= "#{rpm_name}-#{self.version}-1.*.src.rpm"
92
- end
93
-
94
- # Return full spec file name
95
- def spec_file
96
- @spec_path ||= "#{rpm_name}.spec"
97
- end
98
-
99
- # Return handle to instance of Polisher::RPMSpec corresponding to spec
100
- def spec
101
- @spec ||= in_repo { Polisher::RPMSpec.parse spec_file }
102
- end
103
-
104
- # Files representing pkg tracked by git
105
- def pkg_files
106
- @pkg_files ||= [spec_file, 'sources', '.gitignore']
107
- end
108
-
109
- # Override path to reference pkg name
110
- # @override
111
- def path
112
- GitCache.path_for(rpm_name)
113
- end
114
-
115
- # Alias orig clone method to git_clone
116
- alias :git_clone :clone
117
-
118
- # Override clone to use PKG_PCMD
119
- # @override
120
- def clone
121
- in_repo do
122
- AwesomeSpawn.run "#{PKG_CMD} clone #{rpm_name}"
123
- Dir.glob(rpm_name, '*').each { |f| File.move f, '.' }
124
- FileUtils.rm_rf rpm_name
125
- end
126
-
127
- self
128
- end
129
-
130
- def dead?
131
- in_repo { File.exists?('dead.package') }
132
- end
133
-
134
- # Clone / init GitPkg
135
- def fetch
136
- clone unless cloned?
137
- raise Exception, "Dead package detected" if dead?
138
- checkout 'master'
139
- reset!
140
- pull
141
-
142
- self
143
- end
144
-
145
- # Update the local spec to the specified gem version
146
- #
147
- # FIXME this should be removed and calls replaced with self.spec.update_to(gem)
148
- def update_spec_to(gem)
149
- in_repo do
150
- replace_version = "s/Version.*/Version: #{gem.version}/"
151
- replace_release = "s/Release:.*/Release: 1%{?dist}/"
152
- [replace_version, replace_release].each do |replace|
153
- AwesomeSpawn.run "#{SED_CMD} -i '#{replace}' #{spec_file}"
154
- end
155
- end
156
- end
157
-
158
- # Generate new sources file
159
- def gen_sources_for(gem)
160
- in_repo do
161
- AwesomeSpawn.run "#{MD5SUM_CMD} #{gem.name}-#{gem.version}.gem > sources"
162
- end
163
- end
164
-
165
- # Update git ignore to ignore gem
166
- def ignore(gem)
167
- File.open(".gitignore", "w") { |f| f.write "#{gem.name}-#{gem.version}.gem" }
168
- end
169
-
170
- # Update the local pkg to specified gem
171
- #
172
- # @param [Polisher::Gem] gem instance of gem containing metadata to update to
173
- def update_to(gem)
174
- update_spec_to gem
175
- gen_sources_for gem
176
- ignore gem
177
- self
178
- end
179
-
180
- # Override commit, generate a default msg, always add pkg files
181
- # @override
182
- def commit(msg=nil)
183
- in_repo { AwesomeSpawn.run "#{GIT_CMD} add #{pkg_files.join(' ')}" }
184
- super(msg.nil? ? "updated to #{version}" : msg)
185
- self
186
- end
187
-
188
- # Build the srpm
189
- def build_srpm
190
- in_repo { AwesomeSpawn.run "#{PKG_CMD} srpm" }
191
- self
192
- end
193
-
194
- # Run a scratch build
195
- def scratch_build
196
- # TODO if build fails, raise error, else return output
197
- cmd = "#{BUILD_CMD} build --scratch #{BUILD_TGT} #{srpm}"
198
- in_repo { AwesomeSpawn.run(cmd) }
199
- self
200
- end
201
-
202
- # Build the pkg
203
- def build
204
- build_srpm
205
- scratch_build
206
- self
207
- end
208
-
209
- # Retrieve list of the version of the specified package in git
210
- #
211
- # @param [String] name name of package to lookup
212
- # @param [Callable] bl optional block to invoke with version retrieved
213
- # @return [String] version retrieved, or nil if none found
214
- def self.version_for(name, &bl)
215
- version = nil
216
- gitpkg = self.new :name => name
217
- gitpkg.url = "#{DIST_GIT_URL}#{gitpkg.rpm_name}.git"
218
- gitpkg.git_clone
219
- begin
220
- version = gitpkg.spec.version
221
- rescue => e
222
- end
223
-
224
- bl.call(:git, name, [version]) unless(bl.nil?)
225
- version
226
- end
227
- end # class GitPackage
228
-
229
- # Upstream Git project representation
230
- class GitProject < GitRepo
231
- # TODO scan project for vendored components
232
- def vendored
233
- end
234
- end
235
- end # module Polisher
6
+ require 'polisher/git/repo'
7
+ require 'polisher/git/pkg'
8
+ require 'polisher/git/project'
@@ -0,0 +1,189 @@
1
+ # Polisher Git Based Package (distgit) Representation
2
+ #
3
+ # Licensed under the MIT license
4
+ # Copyright (C) 2013-2014 Red Hat, Inc.
5
+
6
+ require 'awesome_spawn'
7
+
8
+ require 'polisher/error'
9
+ require 'polisher/git/repo'
10
+ require 'polisher/rpm/spec'
11
+
12
+ module Polisher
13
+ module Git
14
+ # Git Repository
15
+ class Pkg < Repo
16
+ attr_accessor :name
17
+ attr_accessor :version
18
+
19
+ conf_attr :rpm_prefix, 'rubygem-'
20
+ conf_attr :pkg_cmd, '/usr/bin/fedpkg'
21
+ conf_attr :build_cmd, '/usr/bin/koji'
22
+ conf_attr :build_tgt, 'rawhide'
23
+ conf_attr :md5sum_cmd, '/usr/bin/md5sum'
24
+ conf_attr :dist_git_url, 'git://pkgs.fedoraproject.org/'
25
+ conf_attr :fetch_tgt, 'master'
26
+
27
+ def initialize(args={})
28
+ @name = args[:name]
29
+ @version = args[:version]
30
+ super(args)
31
+ end
32
+
33
+ # Return full rpm name of package containing optional prefix
34
+ def rpm_name
35
+ @rpm_name ||= "#{rpm_prefix}#{self.name}"
36
+ end
37
+
38
+ # Return full srpm file name of package
39
+ def srpm
40
+ @srpm ||= "#{rpm_name}-#{self.version}-1.*.src.rpm"
41
+ end
42
+
43
+ # Return full spec file name
44
+ def spec_file
45
+ @spec_path ||= "#{rpm_name}.spec"
46
+ end
47
+
48
+ # Return handle to instance of Polisher::RPM::Spec corresponding to spec
49
+ def spec
50
+ @spec ||= in_repo { Polisher::RPM::Spec.parse File.read(spec_file) }
51
+ end
52
+
53
+ # Files representing pkg tracked by git
54
+ def pkg_files
55
+ @pkg_files ||= [spec_file, 'sources', '.gitignore']
56
+ end
57
+
58
+ # Override path to reference pkg name
59
+ # @override
60
+ def path
61
+ GitCache.path_for(rpm_name)
62
+ end
63
+
64
+ # Alias orig clone method to git_clone
65
+ alias :git_clone :clone
66
+
67
+ # Override clone to use PKG_PCMD
68
+ # @override
69
+ def clone
70
+ self.clobber!
71
+ Dir.mkdir path unless File.directory? path
72
+ in_repo do
73
+ result = AwesomeSpawn.run "#{pkg_cmd} clone #{rpm_name}"
74
+ raise PolisherError,
75
+ "could not clone #{rpm_name}" unless result.exit_status == 0
76
+
77
+ # pkg_cmd will clone into the rpm_name subdir,
78
+ # move everything up a dir
79
+ Dir.foreach("#{rpm_name}/") do |f|
80
+ orig = "#{rpm_name}/#{f}"
81
+ skip = ['.', '..'].include?(f)
82
+ FileUtils.move orig, '.' unless skip
83
+ end
84
+
85
+ FileUtils.rm_rf rpm_name
86
+ end
87
+
88
+ self
89
+ end
90
+
91
+ # Return boolean indicating if package is marked as dead (retired/obsolete/etc)
92
+ def dead?
93
+ in_repo { File.exists?('dead.package') }
94
+ end
95
+
96
+ # Clone / init GitPkg
97
+ def fetch
98
+ clone unless cloned?
99
+ raise Exception, "Dead package detected" if dead?
100
+ checkout fetch_tgt
101
+ reset!
102
+ pull
103
+
104
+ self
105
+ end
106
+
107
+ # Update the local spec to the specified gem version
108
+ def update_spec_to(gem)
109
+ in_repo do
110
+ spec.update_to(gem)
111
+ File.write(spec_file, spec.to_string)
112
+ end
113
+ end
114
+
115
+ # Generate new sources file
116
+ def gen_sources_for(gem)
117
+ in_repo do
118
+ AwesomeSpawn.run "#{md5sum_cmd} #{gem.gem_path} > sources"
119
+ File.write('sources', File.read('sources').gsub("#{GemCache::DIR}/", ''))
120
+ end
121
+ end
122
+
123
+ # Update git ignore to ignore gem
124
+ def ignore(gem)
125
+ in_repo do
126
+ File.open(".gitignore", "w") { |f| f.write "#{gem.name}-#{gem.version}.gem" }
127
+ end
128
+ end
129
+
130
+ # Update the local pkg to specified gem
131
+ #
132
+ # @param [Polisher::Gem] gem instance of gem containing metadata to update to
133
+ def update_to(gem)
134
+ update_spec_to gem
135
+ gen_sources_for gem
136
+ ignore gem
137
+ self
138
+ end
139
+
140
+ # Override commit, generate a default msg, always add pkg files
141
+ # @override
142
+ def commit(msg=nil)
143
+ in_repo { AwesomeSpawn.run "#{git_cmd} add #{pkg_files.join(' ')}" }
144
+ super(msg.nil? ? "updated to #{version}" : msg)
145
+ self
146
+ end
147
+
148
+ # Build the srpm
149
+ def build_srpm
150
+ in_repo { AwesomeSpawn.run "#{pkg_cmd} srpm" }
151
+ self
152
+ end
153
+
154
+ # Run a scratch build
155
+ def scratch_build
156
+ # TODO if build fails, raise error, else return output
157
+ cmd = "#{build_cmd} build --scratch #{build_tgt} #{srpm}"
158
+ in_repo { AwesomeSpawn.run(cmd) }
159
+ self
160
+ end
161
+
162
+ # Build the pkg
163
+ def build
164
+ build_srpm
165
+ scratch_build
166
+ self
167
+ end
168
+
169
+ # Retrieve list of the version of the specified package in git
170
+ #
171
+ # @param [String] name name of package to lookup
172
+ # @param [Callable] bl optional block to invoke with version retrieved
173
+ # @return [String] version retrieved, or nil if none found
174
+ def self.version_for(name, &bl)
175
+ version = nil
176
+ gitpkg = self.new :name => name
177
+ gitpkg.url = "#{dist_git_url}#{gitpkg.rpm_name}.git"
178
+ gitpkg.git_clone
179
+ begin
180
+ version = gitpkg.spec.version
181
+ rescue => e
182
+ end
183
+
184
+ bl.call(:git, name, [version]) unless(bl.nil?)
185
+ version
186
+ end
187
+ end # module Pkg
188
+ end # module Git
189
+ end # module Polisher