diff options
author | taca <taca@pkgsrc.org> | 2012-03-02 03:46:09 +0000 |
---|---|---|
committer | taca <taca@pkgsrc.org> | 2012-03-02 03:46:09 +0000 |
commit | d6b93da3722c7c1daa4cd7b480e681396c448433 (patch) | |
tree | ffbe999ae4e7438047a37c975adae3868e0c4e76 /lang/ruby | |
parent | fa2d32e52a793dd3f7498ee098c1b5ac75e80cbe (diff) | |
download | pkgsrc-d6b93da3722c7c1daa4cd7b480e681396c448433.tar.gz |
o Now OVERRIDE_GEMSPEC can modify files in gemspec.
o Protect multiple inclusion.
Nothing should affect current packages.
Diffstat (limited to 'lang/ruby')
-rw-r--r-- | lang/ruby/files/update-gemspec.rb | 93 | ||||
-rw-r--r-- | lang/ruby/gem.mk | 50 |
2 files changed, 102 insertions, 41 deletions
diff --git a/lang/ruby/files/update-gemspec.rb b/lang/ruby/files/update-gemspec.rb index 5bfa8cd4553..e0f017f7f38 100644 --- a/lang/ruby/files/update-gemspec.rb +++ b/lang/ruby/files/update-gemspec.rb @@ -1,9 +1,9 @@ #!/usr/pkg/bin/ruby # -*- coding: utf-8 -*- # -# $NetBSD: update-gemspec.rb,v 1.3 2011/11/07 11:56:25 taca Exp $ +# $NetBSD: update-gemspec.rb,v 1.4 2012/03/02 03:46:09 taca Exp $ # -# Copyright (c) 2011 The NetBSD Foundation, Inc. +# Copyright (c) 2011, 2012 The NetBSD Foundation, Inc. # All rights reserved. # # This code is derived from software contributed to The NetBSD Foundation @@ -55,34 +55,48 @@ class GemSpecUpdater @spec = Gem::Specification.from_yaml(f) } @requirements = {} + @attr = {} end # # rule should be: - # rule ::= name_spec op version - # name_sec ::= name [ : new_name ] + # rule ::= [ dependecy_specs ] [ attr_specs ] + # dependency_specs ::= dependency_spec [ dependency_spec ] + # dependency_spec ::= name_spec [ dependency ] + # name_spec ::= name [ ":" new_name ] + # dependency ::= "pkgsrc's dependecy operator and version string" + # command ::= ":" attr_name" attr_operations + # attr_operations ::= attr_op [ attr_op ] + # attr_op ::= new | old=new | old= # def parse_rules(rules) + key = nil rules.each do |s| - s.split.each do |dep| - method = names = op = ver = nil - if /([a-z0-9_:-]+)([=!><\~][=>]*)(.*)/ =~ dep - names = $1 - op = $2 - ver = $3 - r = Gem::Version.new ver - name, new_name = names.split(/:/, 2) - @requirements[name] = { - :method => :update, - :op => op, - :version => r, - :name => new_name - } - elsif /([a-z0-9_-]+):$/ =~ dep - name = $1 - @requirements[name] = { - :method => :delete, - } + s.split.each do |ru| + if /^:([a-z_]+)+/ =~ ru + key = $1 + @attr[key] = [] + elsif not key.nil? + @attr[key].push ru + else + if /([a-z0-9_:-]+)([=!><\~][=>]*)(.*)/ =~ ru + names = $1 + op = $2 + ver = $3 + r = Gem::Version.new ver + name, new_name = names.split(/:/, 2) + @requirements[name] = { + :method => :update, + :op => op, + :version => r, + :name => new_name + } + elsif /([a-z0-9_-]+):$/ =~ ru + name = $1 + @requirements[name] = { + :method => :delete, + } + end end end end @@ -108,11 +122,30 @@ class GemSpecUpdater update = @requirements[dep.name] not update.nil? and update[:method] == :delete } + @attr.keys.each do |name| + av = @spec.instance_variable_get('@' + name) + if av.class == Array + operation = @attr[name] + operation.each do |op| + if /^([^=]+)=([^=]+)$/ =~ op + ov = $1 + nv = $2 + av.delete_if {|a| a == ov} + av.push nv unless av.include? nv + elsif /^([^=]+)=$/ =~ op + ov = $1 + av.delete_if {|a| a == ov} + else + av.push op unless av.include? op + end + end + end + end end def update FileUtils.cp(@file, @file + OrigSuffix, :preserve => true) - + open(@file, "w") { |f| f.print YAML.dump(@spec) + "\n" } @@ -127,9 +160,9 @@ class GemSpecUpdater end end -def usage +def usage(status) $stderr.puts <<"EOF" -#{$0}: [-n] [-o] [-h] gemspec [rules ...] +#{File.basename($0)}: [-n] [-o] [-h] gemspec [rules ...] Update gemspec with as version patterns. Options: -h Show this help. @@ -137,7 +170,7 @@ def usage -o Don't update gemspec file and show original dependency. EOF - exit + Process.exit status end ENV['TZ'] = 'UTC' @@ -148,7 +181,11 @@ update = true opt = OptionParser.new opt.on('-n') { show = true } opt.on('-o') { show = true; update = false } -opt.on('-h') { usage } +opt.on('-h') { usage 0 } + +if ARGV.size < 1 + usage 1 +end opt.parse!(ARGV) diff --git a/lang/ruby/gem.mk b/lang/ruby/gem.mk index e96db684e7f..557c9cc42ec 100644 --- a/lang/ruby/gem.mk +++ b/lang/ruby/gem.mk @@ -1,4 +1,4 @@ -# $NetBSD: gem.mk,v 1.11 2012/01/12 08:43:22 obache Exp $ +# $NetBSD: gem.mk,v 1.12 2012/03/02 03:46:09 taca Exp $ # # This Makefile fragment is intended to be included by packages that build # and install Ruby gems. @@ -18,24 +18,44 @@ # Default: not defined # # OVERRIDE_GEMSPEC -# Fix version of depending gem. Specify as gem and dependency -# pattern as usual pkgsrc's one. +# Fix version of depending gem or modify files in gemspec. # -# Example: -# When gemspec contains "json~>1.4.7" as runtime dependency -# (i.e. json>=1.4.7<1.5) and if you want to relax it to -# "json>=1.4.6" then use: +# (1) Specify as gem and dependency pattern as usual pkgsrc's one. +# +# Example: +# When gemspec contains "json~>1.4.7" as runtime dependency +# (i.e. json>=1.4.7<1.5) and if you want to relax it to +# "json>=1.4.6" then use: +# +# OVERRIDE_GEMSPEC+= json>=1.4.6 +# +# If you want to change depending gem to "json_pure>=1.4.6" +# then use: +# +# OVERRIDE_GEMSPEC+= json:json_pure>=1.4.6 +# +# You can also remove dependency: +# +# OVERRIDE_GEMSPEC+= json: +# +# (2) Modify files in gemspec. +# +# Example: +# Remove files (a.rb and b.rb) from 'files': # -# OVERRIDE_GEMSPEC+= json>=1.4.6 +# OVERRIDE_GEMSPEC+= :files a.rb= b.rb= # -# If you want to change depending gem to "json_pure>=1.4.6" -# then use: +# Example: +# Add a file (exec.rb) to 'executables': # -# OVERRIDE_GEMSPEC+= json:json_pure>=1.4.6 +# OVERRIDE_GEMSPEC+= :executables exec.rb # -# You can also remove dependency: +# Example: +# Rename a file (from 'ruby' to 'ruby193') in 'files': # -# OVERRIDE_GEMSPEC+= json: +# OVERRIDE_GEMSPEC+= :files ruby=ruby193 +# +# Note: Because of limited parser, argumetns for (1) must preceed to (2). # # Default: (empty) # @@ -86,6 +106,8 @@ # RUBYGEM # The path to the rubygems ``gem'' script. # +.if !defined(_RUBYGEM_MK) +_RUBYGEM_MK= # defined # By default, assume that gems are capable of user-destdir installation. PKG_DESTDIR_SUPPORT?= user-destdir @@ -378,3 +400,5 @@ _gem-install: @${STEP_MSG} "gem install" ${RUN} cd ${RUBYGEM_INSTALL_ROOT}${PREFIX} && \ pax -rwpe . ${DESTDIR}${PREFIX} + +.endif |