apkbuild-gem-resolver: option for updating APKBUILD files

This commit is contained in:
Kaarle Ritvanen 2015-07-09 11:32:03 +03:00
parent 8704797efe
commit feca037655

View File

@ -46,6 +46,10 @@ class Package
pkg
end
def self.save
fail unless @@augeas.save
end
def initialize name
@name = name
@depends = []
@ -61,12 +65,15 @@ class Package
def depends
for dep in @depends
# ruby-gems: workaround for v2.6
if dep.start_with?('ruby-') && dep != 'ruby-gems'
unless @@packages.has_key? dep
raise "Dependency for #{@name} does not exist: #{dep}"
end
yield @@packages[dep]
end
end
end
def users
for user in @users
@ -85,8 +92,7 @@ class Aport < Package
@path = path + '/APKBUILD/'
for dep in `echo #{get_param 'depends'}`.split
# ruby-gems: workaround for v2.6
add_dependency dep if dep.start_with?('ruby-') && dep != 'ruby-gems'
add_dependency dep
end
end
@ -98,6 +104,16 @@ class Aport < Package
get_param 'pkgver'
end
def version= version
set_param 'pkgver', version
set_param 'pkgrel', '0'
end
def del_dependency name
@depends.delete name
set_param 'depends', "\"#{@depends.join ' '}\""
end
private
def get_param name
@ -105,6 +121,10 @@ class Aport < Package
raise name + ' not defined for ' + @name unless value
value
end
def set_param name, value
@@augeas.set(@path + name, value)
end
end
class Subpackage < Package
@ -306,10 +326,14 @@ end
testing = false
update = false
OptionParser.new do |opts|
opts.on('-t', '--testing') do |t|
testing = t
end
opts.on('-u', '--update') do |u|
update = u
end
end.parse! ARGV
Package.initialize testing
@ -330,8 +354,21 @@ end
update.resolve
for pkg in update
obs = pkg[:obsolete_deps]
obs = obs.empty? ? nil : " (obsolete dependencies: #{obs.join ', '})"
obsolete = pkg[:obsolete_deps]
obs = obsolete.empty? ?
nil : " (obsolete dependencies: #{obsolete.join ', '})"
puts "#{pkg[:name]}-#{pkg[:version]}#{obs}"
if update
package = Package.get(pkg[:name])
package.version = pkg[:version]
for dep in obsolete
package.del_dependency dep
end
end
end
if update
Package.save
end