diff options
Diffstat (limited to 'lang/ruby')
-rw-r--r-- | lang/ruby/files/update-gemspec.rb | 69 | ||||
-rw-r--r-- | lang/ruby/gem.mk | 21 |
2 files changed, 56 insertions, 34 deletions
diff --git a/lang/ruby/files/update-gemspec.rb b/lang/ruby/files/update-gemspec.rb index e0f017f7f38..7e2a8546996 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.4 2012/03/02 03:46:09 taca Exp $ +# $NetBSD: update-gemspec.rb,v 1.5 2013/03/07 16:42:53 taca Exp $ # -# Copyright (c) 2011, 2012 The NetBSD Foundation, Inc. +# Copyright (c) 2011, 2012, 2013 The NetBSD Foundation, Inc. # All rights reserved. # # This code is derived from software contributed to The NetBSD Foundation @@ -39,45 +39,43 @@ require 'rubygems' require 'fileutils' require 'optparse' -begin - # Since newer rubygems load psych instead of syck, don't load yaml directly. - Gem.load_yaml -rescue NoMethodError - # Older rubygems don't have load_yaml() and don't know about psych. -end - class GemSpecUpdater OrigSuffix = '.orig_gemspec' def initialize(file) @file = file - open(file) { |f| - @spec = Gem::Specification.from_yaml(f) - } + @spec = Gem::Specification.load(@file) @requirements = {} @attr = {} end # # rule should be: - # rule ::= [ dependecy_specs ] [ attr_specs ] - # dependency_specs ::= dependency_spec [ dependency_spec ] + # rule ::= dependecy_specs | attr_specs + # dependency_specs ::= dependency_spec [ SPACE 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 ] + # dependency ::= <Rubygem's dependecy operator and version string> + # attr_specs ::= ":" attr_name attr_operations + # attr_operations ::= assign_operation | array_operation + # assign_operation ::= "=" [ new_value ] + # array_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 |ru| - if /^:([a-z_]+)+/ =~ ru + if /^:([a-z_]+)=*(\S+)*/ =~ ru + key = $1 + var = $2 + @attr[key] = var + key = nil + elsif /^:([a-z_]+)+/ =~ ru key = $1 @attr[key] = [] elsif not key.nil? - @attr[key].push ru + @attr[key].push ru unless key.nil? else if /([a-z0-9_:-]+)([=!><\~][=>]*)(.*)/ =~ ru names = $1 @@ -104,7 +102,6 @@ class GemSpecUpdater def modify dependencies = @spec.instance_variable_get(:@dependencies) - dependencies.each do |dep| next if dep.type != :runtime update = @requirements[dep.name] @@ -122,24 +119,40 @@ 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 + modified = false + av = eval "@spec.#{name}" + if av.class == String + nv = @attr[name] + av = nv + modified = true + elsif 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 + if av.include? ov + av.delete ov + modified = true + end + unless av.include? nv + av.push nv + modified = true + end elsif /^([^=]+)=$/ =~ op ov = $1 - av.delete_if {|a| a == ov} - else - av.push op unless av.include? op + if av.include? ov + av.delete(ov) + modified = true + end end end end + if modified + eval "@spec.#{name} = av" + end end end @@ -147,7 +160,7 @@ class GemSpecUpdater FileUtils.cp(@file, @file + OrigSuffix, :preserve => true) open(@file, "w") { |f| - f.print YAML.dump(@spec) + "\n" + f.print @spec.to_ruby } end diff --git a/lang/ruby/gem.mk b/lang/ruby/gem.mk index bcf588e15e3..1c239c7cfca 100644 --- a/lang/ruby/gem.mk +++ b/lang/ruby/gem.mk @@ -1,4 +1,4 @@ -# $NetBSD: gem.mk,v 1.16 2012/10/03 12:58:34 asau Exp $ +# $NetBSD: gem.mk,v 1.17 2013/03/07 16:42:53 taca Exp $ # # This Makefile fragment is intended to be included by packages that build # and install Ruby gems. @@ -10,6 +10,7 @@ # # ruby18-base: none # ruby193-base: 1.8.11 +# ruby200-base: 2.0.0 # # If newer version of rubygems is resuiqred, set RUBYGEMS_REQD to # minimum version. @@ -37,7 +38,12 @@ # # OVERRIDE_GEMSPEC+= json: # -# (2) Modify files in gemspec. +# (2) Modify instance of gemspec. +# +# Example: +# Rename gem's name to "foo" (setting instance @name): +# +# OVERRIDE_GEMSPEC+= :name=foo # # Example: # Remove files (a.rb and b.rb) from 'files': @@ -163,6 +169,7 @@ DEPENDS+= ${RUBY_PKGPREFIX}-rubygems>=1.0.1:../../misc/rubygems . if defined(RUBYGEMS_REQD) RUBY193_RUBYGEMS_VERS= 1.8.11 +RUBY200_RUBYGEMS_VERS= 2.0.0 _RUBYGEMS_REQD_MAJOR= ${RUBYGEMS_REQD:C/\.[0-9\.]+$//} _RUBYGEMS_REQD_MINORS= ${RUBYGEMS_REQD:C/^([0-9]+)\.*//} @@ -170,6 +177,9 @@ _RUBYGEMS_REQD_MINORS= ${RUBYGEMS_REQD:C/^([0-9]+)\.*//} . if ${RUBY_VER} == "193" _RUBYGEMS_MAJOR= ${RUBY193_RUBYGEMS_VERS:C/\.[0-9\.]+$//} _RUBYGEMS_MINORS= ${RUBY193_RUBYGEMS_VERS:C/^([0-9]+)\.*//} +. elif ${RUBY_VER} == "200" +_RUBYGEMS_MAJOR= ${RUBY200_RUBYGEMS_VERS:C/\.[0-9\.]+$//} +_RUBYGEMS_MINORS= ${RUBY200_RUBYGEMS_VERS:C/^([0-9]+)\.*//} . else PKG_FAIL_REASON+= "Unknown Ruby version specified: ${RUBY_VER}." . endif @@ -244,11 +254,10 @@ post-extract: gem-extract gem-extract: fake-home . for _gem_ in ${DISTFILES:M*.gem} ${RUN} cd ${WRKDIR} && ${SETENV} ${MAKE_ENV} ${RUBYGEM_ENV} \ - ${RUBYGEM} unpack ${RUBYGEM_INSTALL_ROOT_OPTION} \ - ${_DISTDIR:Q}/${_gem_:Q} + ${RUBYGEM} unpack ${_DISTDIR:Q}${_gem_:Q} ${RUN} cd ${WRKDIR} && \ ${SETENV} ${MAKE_ENV} TZ=UTC ${RUBYGEM_ENV} \ - ${RUBYGEM} spec ${_DISTDIR:Q}/${_gem_:Q} > ${_gem_}spec + ${RUBYGEM} spec --ruby ${_DISTDIR:Q}${_gem_:Q} > ${_gem_}spec . endfor .endif @@ -321,7 +330,7 @@ RUBYGEM_INSTALL_ROOT_OPTION= --install-root ${RUBYGEM_INSTALL_ROOT} _gem-build-install-root: @${STEP_MSG} "Installing gem into installation root" ${RUN} ${SETENV} ${MAKE_ENV} ${RUBYGEM_ENV} \ - ${RUBYGEM} install ${RUBYGEM_OPTIONS} ${_RUBYGEM_OPTIONS} + ${RUBYGEM} install --backtrace ${RUBYGEM_OPTIONS} ${_RUBYGEM_OPTIONS} # The ``gem'' command doesn't exit with a non-zero result even if the # install of the gem failed, so we do the check and return the proper exit |