From: Luis Lavena Date: 2008-05-15T07:35:03+09:00 Subject: Can platform agnosticism be achieved? Hello List, I've been asking myself this question for quite some time, as Windows user need to break the rules and do things that don't work out of the box with Ruby. I know Ruby has it's root in posix and *nix OS, where things like drive letters don't exist and full power is just four letters away (sudo). Since last year, I've decided to spend more time helping great OSS Ruby projects to Windows users, and in doing so, I review, check and edit a lot of projects on rubyforge, github and other esoteric places. The thing is I'm a bit annoyed of adding regexp around things like sudo in Rakefiles. Yeah, it's annoying, 4 letters ends up adding 20 bytes more just to avoid typing sudo in front of the rake command you're calling. Take as example the following gem install rake tasks (from DataMapper and Merb dev): namespace :gems do desc 'Uninstall all RubyGems for this project' task :wipe do sudo = RUBY_PLATFORM =~ /win32|cygwin/ ? '' : 'sudo' sh "#{sudo} gem uninstall #{project} --all --ignore-dependencies --executables; true" end end You see a big condition for sudo there. Take out of the consideration that the regexp don't cover mingw as valid platform, or even don't consider mswin64 (build of ruby 1.9 with VC9 for 64bits). So, that regexp will become obsolete with time, at least for Windows... and the Windows folks will be required to patch it every time. What about remove sudo from there and leave up to the user to make that decision? One example: User perform some apt-get (ubuntu) tasks that requires sudo. He enters his password to confirm the operation. Under the same session, a few minutes later, he fires a rake task that uses sudo, by mistake or because is not clearly advertised what It does, he ends up messing with his gem repository, removing gems maybe he is using for other projects. So, these rake tasks are doing more than they should, taking privileges out of user hand and automating them, hiding the problem when looking answer to "what happened?". Or maybe I'm wrong, someone will say shut up or a flame war will get started... For the time being, those Windows user that don't want to patch a lot of rakefiles that: 1) ignores platforms like mingw and java under Windows (dunno how to get that), or 2) clearly ignores sudo is not usable under windows. > type sudo.bat @ECHO OFF REM REM Fake sudo for Windows REM This help avoid tools that forces usage of 'sudo' on all the REM platforms, not just *nix ones. REM REM Save this file as 'sudo.bat' and place it somewhere in your PATH REM (ruby/bin is a good place too). REM CALL %* Regards, -- Luis Lavena