diff options
-rw-r--r-- | lang/ruby/files/update-gemspec.rb | 156 | ||||
-rw-r--r-- | lang/ruby/gem.mk | 35 |
2 files changed, 189 insertions, 2 deletions
diff --git a/lang/ruby/files/update-gemspec.rb b/lang/ruby/files/update-gemspec.rb new file mode 100644 index 00000000000..73886faf9d2 --- /dev/null +++ b/lang/ruby/files/update-gemspec.rb @@ -0,0 +1,156 @@ +#!/usr/pkg/bin/ruby +# -*- coding: utf-8 -*- +# +# $NetBSD: update-gemspec.rb,v 1.1 2011/08/12 14:35:34 taca Exp $ +# +# Copyright (c) 2011 The NetBSD Foundation, Inc. +# All rights reserved. +# +# This code is derived from software contributed to The NetBSD Foundation +# by Takahiro Kambe. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# + +# +# This is a quick and dirty tool which updates gemspec file: +# +require 'rubygems' +require 'yaml' +require 'fileutils' +require 'optparse' + +class Gem::Specification + def get_dependencies + return @dependencies + end +end + +class Gem::Requirement + def get_requirement + return @requirement + end +end + +class GemSpecUpdater + OrigSuffix = '.orig_gemspec' + + def initialize(file) + @file = file + open(file) { |f| + @spec = Gem::Specification.from_yaml(f) + } + @requirements = {} + end + + # + # rule should be: + # rule ::= name_spec op version + # name_sec ::= name [ : new_name ] + # + def parse_rules(rules) + rules.each do |s| + s.split.each do |dep| + names = op = ver = nil + if /([a-z0-9_:-]+)([=!><\~][=>]*)(.*)/ =~ dep + names = $1 + op = $2 + ver = $3 + end + r = Gem::Version.new ver + name, new_name = names.split(/:/, 2) + @requirements[name] = { :op => op, :version => r, :name => new_name } + end + end + end + + def modify + dependencies = @spec.runtime_dependencies + + dependencies.each do |dep| + name = dep.name + update = @requirements[name] + unless update.nil? + r = dep.requirement.requirements + r[0][0] = update[:op] + r[0][1] = update[:version] + unless update[:name].nil? + dep.name = update[:name] + end + end + end + end + + def update + FileUtils.cp(@file, @file + OrigSuffix, :preserve => true) + + open(@file, "w") { |f| + f.print YAML.dump(@spec) + "\n" + } + end + + def dump_dependency + dependencies = @spec.runtime_dependencies + + dependencies.each do |dep| + puts "#{dep.name} #{dep.requirement}" + end + end +end + +def usage + $stderr.puts <<"EOF" +#{$0}: [-n] [-o] [-h] gemspec [rules ...] + Update gemspec with as version patterns. + Options: + -h Show this help. + -n Don't update gemspec file. + -o Don't update gemspec file and show original dependency. + +EOF + exit +end + +ENV['TZ'] = 'UTC' + +show = false +update = true + +opt = OptionParser.new +opt.on('-n') { show = true } +opt.on('-o') { show = true; update = false } +opt.on('-h') { usage } + +opt.parse!(ARGV) + +file = ARGV.shift +rules = ARGV + +updater = GemSpecUpdater.new file +updater.parse_rules rules +updater.modify if update +if show + updater.dump_dependency +else + updater.update +end diff --git a/lang/ruby/gem.mk b/lang/ruby/gem.mk index 769afdd17f1..26d7cc30f50 100644 --- a/lang/ruby/gem.mk +++ b/lang/ruby/gem.mk @@ -1,4 +1,4 @@ -# $NetBSD: gem.mk,v 1.6 2011/05/10 13:31:49 taca Exp $ +# $NetBSD: gem.mk,v 1.7 2011/08/12 14:35:34 taca Exp $ # # This Makefile fragment is intended to be included by packages that build # and install Ruby gems. @@ -12,6 +12,24 @@ # # Default: not defined # +# OVERRIDE_GEMSPEC +# Fix version of depending gem. Specify as gem and dependency +# pattern as usual pkgsrc's one. +# +# Example: +# When gemspec contains "json~>1.4.6" as runtime dependency and +# if you want to relax dependency to "json>=1.4.6" then use: +# +# OVERRIDE_GEMSPEC+= json>=1.4.7 +# +# or +# +# OVERRIDE_GEMSPEC+= json:json_pure>=1.4.7 +# +# With latter case, depending gem's name will be renamed, too. +# +# Default: (empty) +# # BUILD_TARGET # The Rakefile target that creates a local gem if using the # ``rake'' GEM_BUILD method. @@ -70,6 +88,12 @@ REPLACE_RUBY_PAT?= * # Default to using rake to build the local gem from the unpacked files. GEM_BUILD?= gemspec +OVERRIDE_GEMSPEC?= # default is empty + +.if !empty(OVERRIDE_GEMSPEC) +UPDATE_GEMSPEC= ../../lang/ruby/files/update-gemspec.rb +.endif + .if ${GEM_BUILD} == "rake" USE_RAKE= YES .endif @@ -199,7 +223,12 @@ PKG_FAIL_REASON= "GEM_CLEANBUILD must be relative to "${PREFIX}/${GEM_LIBDIR:Q}" do-build: _gem-pre-build gem-build _gem-pre-build: - @${STEP_MSG} "Removing backup files of patch before build " +.if !empty(OVERRIDE_GEMSPEC) + @${STEP_MSG} Override gemspec dependency + @${RUBY} ${.CURDIR}/${UPDATE_GEMSPEC} ${WRKDIR}/${GEM_NAME}.gemspec \ + ${OVERRIDE_GEMSPEC:Q} +.endif + @${STEP_MSG} "Removing backup files of patch before build" @find ${WRKSRC} -name \*.orig -exec rm {} \; gem-build: _gem-${GEM_BUILD}-build @@ -235,7 +264,9 @@ _RUBYGEM_OPTIONS+= --no-ri .if !empty(RUBY_BUILD_RDOC:M[nN][oO]) _RUBYGEM_OPTIONS+= --no-rdoc .endif +.if !empty(CONFIGURE_ARGS) _RUBYGEM_OPTIONS+= -- --build-args ${CONFIGURE_ARGS} +.endif RUBYGEM_INSTALL_ROOT_OPTION= --install-root ${RUBYGEM_INSTALL_ROOT} |