Hi everybody,

Recently, there was submitted patch [1] for gem2rpm requesting to use
"gem install --build-root" option. This made me to investigate the
situation. It is actually more then one year since this option was
introduced into RubyGems [2] and the intentions is quite nice for
packaging. But there are two things:

1) Unfortunately, this option does not work on Fedora as expected, since
we never install gems into /usr/share/gems, where the RPM packaged gems
reside, but we install them either into user home or /usr/local,
depending on current user. So it might be reasonable to make the
--build-root option to work as designed (see fix-build-root.patch
attachment).

2) Once the --build-root option works, we could use it in our
macros.rubygems instead the --install-dir --bindir combo (see
enable-build-root.patch attachment). But although this would mean slight
simplification of %gem_install macro, it would break every
old/unmaintained .spec file, which still contains something like:

%install
%gem_install -n %{SOURCE0} -d %{buildroot}%{gem_dir}

i.e. the %gem_install is called in %install section.

Now the question is if the changes are worth of the effort. It does not
seem that --build-root is widely used, since nobody complained yet.
Moreover, the change in %gem_install macro might break things (although
the gems are probably unmaintained anyway, so we could get rid of them).
So what is your opinion? Should I go for (1), (1) and (2) or non?

If there is no significant response, I'll probably go for both patches.
Please let me know.


Vít


[1] https://github.com/fedora-ruby/gem2rpm/pull/51
[2] https://github.com/rubygems/rubygems/pull/965
diff --git a/operating_system.rb b/operating_system.rb
index ed653fd..4b2903d 100644
--- a/operating_system.rb
+++ b/operating_system.rb
@@ -14,11 +14,27 @@ module Gem
     private :previous_but_one_dir_to
 
     ##
+    # Detects --install-dir option specified on command line.
+
+    def opt_install_dir?
+      @opt_install_dir ||= ARGV.include?('--install-dir') || ARGV.include?('-i')
+    end
+    private :opt_install_dir?
+
+    ##
+    # Detects --build-root option specified on command line.
+
+    def opt_build_root?
+      @opt_build_root ||= ARGV.include?('--build-root')
+    end
+    private :opt_build_root?
+
+    ##
     # Tries to detect, if arguments and environment variables suggest that
     # 'gem install' is executed from rpmbuild.
 
     def rpmbuild?
-      (ARGV.include?('--install-dir') || ARGV.include?('-i')) && ENV['RPM_PACKAGE_NAME']
+      @rpmbuild ||= ENV['RPM_PACKAGE_NAME'] && (opt_install_dir? || opt_build_root?)
     end
     private :rpmbuild?
 
@@ -80,7 +96,9 @@ module Gem
     # RubyGems default overrides.
 
     def default_dir
-      if Process.uid == 0
+      if opt_build_root?
+        Gem.default_dirs[:system][:gem_dir]
+      elsif Process.uid == 0
         Gem.default_dirs[:local][:gem_dir]
       else
         Gem.user_dir
@@ -93,7 +111,9 @@ module Gem
     end
 
     def default_bindir
-      if Process.uid == 0
+      if opt_build_root?
+        Gem.default_dirs[:system][:bin_dir]
+      elsif Process.uid == 0
         Gem.default_dirs[:local][:bin_dir]
       else
         File.join [Dir.home, 'bin']
diff --git a/macros.rubygems b/macros.rubygems
index 1043c02..6d99ac3 100644
--- a/macros.rubygems
+++ b/macros.rubygems
@@ -20,8 +20,7 @@ CONFIGURE_ARGS="--with-cflags='%{optflags}' $CONFIGURE_ARGS" \\\
 gem install \\\
         -V \\\
         --local \\\
-        --install-dir %{-d*}%{!?-d:.%{gem_dir}} \\\
-        --bindir .%{_bindir} \\\
+        --build-root %{-d*}%{!?-d:.} \\\
         --force \\\
         --document=ri,rdoc \\\
         %{-n*}%{!?-n:%{gem_name}-%{version}.gem} \
_______________________________________________
ruby-sig mailing list
[email protected]
https://admin.fedoraproject.org/mailman/listinfo/ruby-sig

Reply via email to