gem-exefy 1.2.0-universal-mingw32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.autotest +23 -0
- data/History.rdoc +18 -0
- data/Manifest.txt +11 -0
- data/README.rdoc +115 -0
- data/Rakefile +29 -0
- data/lib/exefy.rb +187 -0
- data/lib/exefy/version.rb +3 -0
- data/lib/rubygems/commands/exefy_command.rb +70 -0
- data/lib/rubygems_plugin.rb +86 -0
- data/templates/gem_exe.c +87 -0
- data/templates/gem_exe.rc.erb +40 -0
- metadata +146 -0
data/.autotest
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'autotest/restart'
|
4
|
+
|
5
|
+
# Autotest.add_hook :initialize do |at|
|
6
|
+
# at.extra_files << "../some/external/dependency.rb"
|
7
|
+
#
|
8
|
+
# at.libs << ":../some/external"
|
9
|
+
#
|
10
|
+
# at.add_exception 'vendor'
|
11
|
+
#
|
12
|
+
# at.add_mapping(/dependency.rb/) do |f, _|
|
13
|
+
# at.files_matching(/test_.*rb$/)
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# %w(TestA TestB).each do |klass|
|
17
|
+
# at.extra_class_map[klass] = "test/test_misc.rb"
|
18
|
+
# end
|
19
|
+
# end
|
20
|
+
|
21
|
+
# Autotest.add_hook :run_command do |at|
|
22
|
+
# system "rake build"
|
23
|
+
# end
|
data/History.rdoc
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
=== 1.2.0 / 2012-09-11
|
2
|
+
|
3
|
+
* Enhancements
|
4
|
+
|
5
|
+
* Added support for x64 Ruby versions (https://github.com/bosko/gem-exefy/issues/12)
|
6
|
+
|
7
|
+
=== 1.1.0 / 2012-08-15
|
8
|
+
|
9
|
+
* Enhancements
|
10
|
+
|
11
|
+
* Dropped support for Ruby versions less than 1.9.2 (@luislavena)
|
12
|
+
|
13
|
+
=== 1.0.0 / 2012-06-25
|
14
|
+
|
15
|
+
* 1 major enhancement
|
16
|
+
|
17
|
+
* Birthday!
|
18
|
+
|
data/Manifest.txt
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
= gem-exefy
|
2
|
+
|
3
|
+
code :: http://github.com/bosko/gem-exefy
|
4
|
+
bugs :: http://github.com/bosko/gem-exefy/issues
|
5
|
+
|
6
|
+
== DESCRIPTION:
|
7
|
+
|
8
|
+
GemExefy is RubyGems plugin aimed to replace batch files (.bat) with
|
9
|
+
executables with the same name. This gem will work only on
|
10
|
+
RubyInstaller Ruby installation and it requires RubyInstaller DevKit.
|
11
|
+
|
12
|
+
Reason for such replaceming batch files with executable stubs is
|
13
|
+
twofold. When execution of batch file is interrupted with Ctrl-C key
|
14
|
+
combination, user is faced with the confusing question
|
15
|
+
|
16
|
+
"Terminate batch job (Y/N)?"
|
17
|
+
|
18
|
+
which is avoided after replacement.
|
19
|
+
|
20
|
+
Second reason is appearance of processes in Task manager (or Process
|
21
|
+
Explorer). In the case of batch files all processes are visible as
|
22
|
+
ruby.exe. In order to distinguish between them, program arguments must
|
23
|
+
be examined. In addition, having one process name makes it hard to
|
24
|
+
define firewall rules. Having executable versions instead of batch
|
25
|
+
files will facilitate process identification in task list as well as
|
26
|
+
defining firewall rules. Moreover it makes it possible to create
|
27
|
+
selective firewall rules for different Ruby gems. Installing Ruby
|
28
|
+
applications as Windows services should be also much easer when
|
29
|
+
executable stub is used instead of batch file.
|
30
|
+
|
31
|
+
=== How does it work?
|
32
|
+
|
33
|
+
If GemExefy is installed prior to other gems installation it will
|
34
|
+
automatically install executable stub instead of each batch file that
|
35
|
+
is normally created during gem installation. GemExefy enables
|
36
|
+
replacement for existing gems too. Either all or one by one gem can be
|
37
|
+
processed. Finally GemExefy can revert all changes and return all
|
38
|
+
batch files instead of executable stubs if needed.
|
39
|
+
|
40
|
+
== FEATURES/PROBLEMS:
|
41
|
+
|
42
|
+
* No known problems at the moment
|
43
|
+
|
44
|
+
== SYNOPSIS:
|
45
|
+
|
46
|
+
Exefying single gem:
|
47
|
+
|
48
|
+
C:\> gem exefy <gem_name>
|
49
|
+
|
50
|
+
Exefying all installed gems on the system:
|
51
|
+
|
52
|
+
C:\> gem exefy --all
|
53
|
+
|
54
|
+
Reverting batch file for single gem:
|
55
|
+
|
56
|
+
C:\> gem exefy <gem_name> --revert
|
57
|
+
|
58
|
+
Reverting batch files for all previously processed gems:
|
59
|
+
|
60
|
+
C:\> gem exefy --all --revert
|
61
|
+
|
62
|
+
== REQUIREMENTS:
|
63
|
+
|
64
|
+
* RubyInstaller Ruby version
|
65
|
+
* RubyInstaller's DevKit
|
66
|
+
|
67
|
+
== INSTALL:
|
68
|
+
|
69
|
+
* gem install gem-exefy
|
70
|
+
|
71
|
+
== DEVELOPERS:
|
72
|
+
|
73
|
+
After checking out the source, run:
|
74
|
+
|
75
|
+
$ rake newb
|
76
|
+
|
77
|
+
This task will install any missing dependencies, run the tests/specs,
|
78
|
+
and generate the RDoc.
|
79
|
+
|
80
|
+
GemExefy searches following directories for batch files
|
81
|
+
|
82
|
+
- Gem.bindir
|
83
|
+
- Gem.path
|
84
|
+
|
85
|
+
Since Gem::path array contains directories pointing to the top level
|
86
|
+
directory and executables are saved in the Gem#bindir folder, GemExefy
|
87
|
+
concatenates directory from Gem.path with value of Gem#bindir (bin
|
88
|
+
directory defined in the target Gem) and name from Gem#executables
|
89
|
+
array with .bat extension. If such file is found it is replaced with
|
90
|
+
corresponding executable file with same name and .exe extension.
|
91
|
+
|
92
|
+
== LICENSE:
|
93
|
+
|
94
|
+
(The MIT License)
|
95
|
+
|
96
|
+
Copyright (c) 2012 Boško Ivanišević
|
97
|
+
|
98
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
99
|
+
a copy of this software and associated documentation files (the
|
100
|
+
'Software'), to deal in the Software without restriction, including
|
101
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
102
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
103
|
+
permit persons to whom the Software is furnished to do so, subject to
|
104
|
+
the following conditions:
|
105
|
+
|
106
|
+
The above copyright notice and this permission notice shall be
|
107
|
+
included in all copies or substantial portions of the Software.
|
108
|
+
|
109
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
110
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
111
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
112
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
113
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
114
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
115
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# -*- ruby -*-
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'hoe'
|
6
|
+
require './lib/exefy/version'
|
7
|
+
|
8
|
+
Hoe.spec 'gem-exefy' do
|
9
|
+
developer('Boško Ivanišević', 'bosko.ivanisevic@gmail.com')
|
10
|
+
|
11
|
+
self.urls = {"GitHub repository" => "http://github.com/bosko/gem-exefy"}
|
12
|
+
self.readme_file = 'README.rdoc'
|
13
|
+
self.history_file = 'History.rdoc'
|
14
|
+
self.extra_rdoc_files = FileList['*.rdoc']
|
15
|
+
self.require_rubygems_version(">= 1.8.0")
|
16
|
+
self.version = Exefy::VERSION
|
17
|
+
spec_extras[:platform] = Gem::Platform.new("universal-mingw32")
|
18
|
+
spec_extras[:required_ruby_version] = ">= 1.9.3"
|
19
|
+
self.post_install_message = %Q{**************************************************
|
20
|
+
* *
|
21
|
+
* Thank you for installing #{self.name}-#{self.version}! *
|
22
|
+
* *
|
23
|
+
* This gem will work only on RubyInstaller *
|
24
|
+
* versions of Ruby with installed DevKit. *
|
25
|
+
* *
|
26
|
+
**************************************************}
|
27
|
+
end
|
28
|
+
|
29
|
+
# vim: syntax=ruby
|
data/lib/exefy.rb
ADDED
@@ -0,0 +1,187 @@
|
|
1
|
+
module Exefy
|
2
|
+
require 'rubygems'
|
3
|
+
require 'rubygems/user_interaction'
|
4
|
+
require 'tmpdir'
|
5
|
+
require 'rbconfig'
|
6
|
+
require 'erb'
|
7
|
+
require 'exefy/version'
|
8
|
+
|
9
|
+
def self.process_existing_gem(gem, revert)
|
10
|
+
generator = GeneratorFromBatch.new(gem)
|
11
|
+
revert ? generator.revert_gem : generator.exefy_gem
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.process_gem_install(target_path)
|
15
|
+
generator = Generator.new(target_path)
|
16
|
+
generator.exefy_gem
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.executable
|
20
|
+
return @executable if defined?(@executable)
|
21
|
+
|
22
|
+
gem_root = File.expand_path("../..", __FILE__)
|
23
|
+
ruby_version = RbConfig::CONFIG["ruby_version"]
|
24
|
+
|
25
|
+
@executable = File.join(gem_root, "data", ruby_version, "gemstub.exe")
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.devkit_needed?
|
29
|
+
!File.executable?(Exefy.executable)
|
30
|
+
end
|
31
|
+
|
32
|
+
class Generator
|
33
|
+
include Gem::UserInteraction
|
34
|
+
|
35
|
+
def initialize(target_path)
|
36
|
+
@exe_target = target_path
|
37
|
+
end
|
38
|
+
|
39
|
+
def exefy_gem
|
40
|
+
process
|
41
|
+
end
|
42
|
+
|
43
|
+
def process
|
44
|
+
install_executable_stub(@exe_target)
|
45
|
+
end
|
46
|
+
|
47
|
+
def install_executable_stub(target)
|
48
|
+
unless File.executable?(Exefy.executable)
|
49
|
+
generate_executable
|
50
|
+
end
|
51
|
+
|
52
|
+
log_message "Creating executable as '#{File.basename(target)}'"
|
53
|
+
FileUtils.install Exefy.executable, target
|
54
|
+
end
|
55
|
+
|
56
|
+
def generate_executable
|
57
|
+
log_message "Generating executable '#{Exefy.executable}'..."
|
58
|
+
|
59
|
+
gem_root = File.expand_path("../..", __FILE__)
|
60
|
+
template = File.join(gem_root, "templates", "gem_exe.c")
|
61
|
+
res_template = File.join(gem_root, "templates", "gem_exe.rc.erb")
|
62
|
+
|
63
|
+
Dir.mktmpdir do |build_dir|
|
64
|
+
base = File.basename(template)
|
65
|
+
res_base = File.basename(res_template)
|
66
|
+
|
67
|
+
obj = File.join(build_dir, base.gsub(".c", ".o"))
|
68
|
+
res_src = File.join(build_dir, res_base.gsub(".erb", ""))
|
69
|
+
res_obj = File.join(build_dir, res_base.gsub(".erb", ".o"))
|
70
|
+
exe = File.join(build_dir, base.gsub(".c", ".exe"))
|
71
|
+
|
72
|
+
compile(template, obj)
|
73
|
+
compile_resources(res_template, res_src, res_obj)
|
74
|
+
link([obj, res_obj].join(" "), exe)
|
75
|
+
|
76
|
+
# verify target directory first exists
|
77
|
+
FileUtils.mkdir_p File.dirname(Exefy.executable)
|
78
|
+
|
79
|
+
FileUtils.install exe, Exefy.executable
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def compile(source, target)
|
84
|
+
cflags = RbConfig::CONFIG["CFLAGS"]
|
85
|
+
cppflags = RbConfig::CONFIG["CPPFLAGS"]
|
86
|
+
|
87
|
+
hdr_dir = RbConfig::CONFIG["rubyhdrdir"] || RbConfig::CONFIG["includedir"]
|
88
|
+
arch_dir = RbConfig::CONFIG["arch"]
|
89
|
+
|
90
|
+
include_dirs = "-I#{hdr_dir}/#{arch_dir} -I#{hdr_dir}"
|
91
|
+
|
92
|
+
cc = ENV.fetch("CC", RbConfig::CONFIG["CC"])
|
93
|
+
|
94
|
+
system "#{cc} -c #{source} -o #{target} #{cflags} #{cppflags} #{include_dirs}"
|
95
|
+
end
|
96
|
+
|
97
|
+
def compile_resources(template, source, target)
|
98
|
+
binary_version = VERSION.gsub('.', ',') + ",0"
|
99
|
+
File.open source, "w" do |file|
|
100
|
+
erb = ERB.new File.read(template)
|
101
|
+
file.puts erb.result(binding)
|
102
|
+
end
|
103
|
+
|
104
|
+
system "windres #{source} -o #{target}"
|
105
|
+
end
|
106
|
+
|
107
|
+
def link(objs, target)
|
108
|
+
libruby_dir = RbConfig::CONFIG["libdir"]
|
109
|
+
libruby = RbConfig::CONFIG["LIBRUBYARG"]
|
110
|
+
|
111
|
+
libs = RbConfig::CONFIG["LIBS"]
|
112
|
+
libs_dir = "-L#{libruby_dir} #{libruby} #{libs}"
|
113
|
+
|
114
|
+
cc = ENV.fetch("CC", RbConfig::CONFIG["CC"])
|
115
|
+
system "#{cc} #{objs} -o #{target} #{libs_dir}"
|
116
|
+
system "strip #{target}"
|
117
|
+
end
|
118
|
+
|
119
|
+
def log_message(message)
|
120
|
+
say message if Gem.configuration.really_verbose
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
class GeneratorFromBatch < Generator
|
125
|
+
def initialize(gem)
|
126
|
+
@gem = gem
|
127
|
+
end
|
128
|
+
|
129
|
+
def exefy_gem
|
130
|
+
batch_files(@gem).each do |list|
|
131
|
+
process(list)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
def revert_gem
|
136
|
+
require "rubygems/installer"
|
137
|
+
|
138
|
+
return if @gem.executables.nil? or @gem.executables.empty?
|
139
|
+
|
140
|
+
# Instantiate Gem::Installer object with no additional options
|
141
|
+
# WARNING!!! at the moment RubyGems do not handle additional
|
142
|
+
# install options correctly (--install-dir or --bindir). Once
|
143
|
+
# gem is installed in non-default location it becomes unusable.
|
144
|
+
# We cannot get path to its .bat files nor path where it is
|
145
|
+
# installed (https://github.com/rubygems/rubygems/issues/342).
|
146
|
+
# Therefore we will, for now, process gems as they are always
|
147
|
+
# installed in default locations.
|
148
|
+
@gem.executables.each do |filename|
|
149
|
+
filename.untaint
|
150
|
+
exe_file = File.join(Gem.bindir, "#{filename}.exe")
|
151
|
+
if File.exist? exe_file
|
152
|
+
Gem::Installer.new(@gem).generate_windows_script(filename, Gem.bindir)
|
153
|
+
if File.exist? exe_file.gsub(".exe", ".bat")
|
154
|
+
log_message "Removing #{exe_file}"
|
155
|
+
File.unlink exe_file
|
156
|
+
else
|
157
|
+
log_message "Reverting batch file failed. Executable file will remain in bin directory."
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
def process(batch_files)
|
164
|
+
batch_files.each do |bf|
|
165
|
+
target = bf.gsub(".bat", ".exe")
|
166
|
+
install_executable_stub(target)
|
167
|
+
|
168
|
+
log_message "Removing batch file '#{File.basename(bf)}'"
|
169
|
+
File.unlink bf
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
def batch_files(gem)
|
174
|
+
bf = {}
|
175
|
+
test_paths = Gem.path.map {|gp| File.join(gp, gem.bindir)}.
|
176
|
+
unshift(Gem.bindir).uniq
|
177
|
+
|
178
|
+
gem.executables.each do |executable|
|
179
|
+
test_paths.map {|tp| File.join(tp, "#{executable}.bat")}.each do |bat|
|
180
|
+
bf[executable] = [] unless bf[executable]
|
181
|
+
bf[executable] << bat if File.exist?(bat)
|
182
|
+
end
|
183
|
+
end
|
184
|
+
bf.values
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require "rubygems/command"
|
2
|
+
|
3
|
+
module Gem
|
4
|
+
module Commands
|
5
|
+
class ExefyCommand < Gem::Command
|
6
|
+
def initialize
|
7
|
+
super 'exefy', "Replaces a Gem's batch script with a Windows executable"
|
8
|
+
|
9
|
+
add_option('--all', 'Replaces batch files with executable file',
|
10
|
+
'for all installed gems') do |value, options|
|
11
|
+
options[:process_all_gems] = value
|
12
|
+
end
|
13
|
+
|
14
|
+
add_option('--revert', 'Restores batch files for given gem',
|
15
|
+
'or all gems if --all option is used') do |value, options|
|
16
|
+
options[:revert] = value
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def arguments
|
21
|
+
"GEMNAME name of gem to exefy (unless --all)"
|
22
|
+
end
|
23
|
+
|
24
|
+
def usage # :nodoc:
|
25
|
+
"#{program_name} [GEMNAME]"
|
26
|
+
end
|
27
|
+
|
28
|
+
def description # :nodoc:
|
29
|
+
<<-EOS
|
30
|
+
The exefy command replaces the default gem batch(.bat) script runner with
|
31
|
+
a Windows executable(.exe) stub. Exefy also includes hooks that will
|
32
|
+
automatically do this for all new Gem installs and will remove the
|
33
|
+
executable with a Gem uninstall.
|
34
|
+
|
35
|
+
Requires a RubyInstaller Ruby installation and the RubyInstaller DevKit.
|
36
|
+
EOS
|
37
|
+
end
|
38
|
+
|
39
|
+
def execute
|
40
|
+
unless RUBY_PLATFORM =~ /mingw/
|
41
|
+
say "This command can be executed only on RubyInstaller Windows OS installation"
|
42
|
+
return
|
43
|
+
end
|
44
|
+
|
45
|
+
begin
|
46
|
+
require "exefy"
|
47
|
+
require "devkit" if !options[:revert] && Exefy.devkit_needed?
|
48
|
+
rescue ::LoadError => load_error
|
49
|
+
say "You must have DevKit installed in order to exefy gems"
|
50
|
+
return
|
51
|
+
end
|
52
|
+
|
53
|
+
gem_specs = if options[:process_all_gems] then
|
54
|
+
Gem::Specification
|
55
|
+
else
|
56
|
+
begin
|
57
|
+
gem_name = get_one_gem_name
|
58
|
+
Gem::Specification.find_all_by_name(gem_name)
|
59
|
+
rescue Gem::LoadError => e
|
60
|
+
say "Cannot exefy. Gem #{name} not found"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
gem_specs.each do |gem_spec|
|
65
|
+
Exefy.process_existing_gem(gem_spec, options[:revert])
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require "rubygems/command_manager"
|
2
|
+
|
3
|
+
Gem::CommandManager.instance.register_command :exefy
|
4
|
+
|
5
|
+
Gem.pre_install do |installer|
|
6
|
+
class << installer
|
7
|
+
def generate_exe_file(filename, bindir)
|
8
|
+
if RUBY_PLATFORM =~ /mingw/
|
9
|
+
begin
|
10
|
+
require "exefy"
|
11
|
+
require "devkit" if Exefy.devkit_needed?
|
12
|
+
|
13
|
+
exe_name = filename + ".exe"
|
14
|
+
exe_path = File.join bindir, File.basename(exe_name)
|
15
|
+
Exefy.process_gem_install(exe_path)
|
16
|
+
|
17
|
+
say "Installed #{exe_path} executable" if Gem.configuration.really_verbose
|
18
|
+
rescue LoadError
|
19
|
+
puts "You must have DevKit installed in order to exefy gems"
|
20
|
+
generate_batch_file(filename, bindir)
|
21
|
+
end
|
22
|
+
else
|
23
|
+
generate_batch_file(filename, bindir)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
alias_method :generate_batch_file, :generate_windows_script
|
28
|
+
alias_method :generate_windows_script, :generate_exe_file
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
Gem.pre_uninstall do |uninstaller|
|
33
|
+
class << uninstaller
|
34
|
+
def remove_executables_and_exe_file(spec)
|
35
|
+
return if spec.nil? or spec.executables.empty?
|
36
|
+
|
37
|
+
list = Gem::Specification.find_all { |s|
|
38
|
+
s.name == spec.name && s.version != spec.version
|
39
|
+
}
|
40
|
+
|
41
|
+
executables = spec.executables.clone
|
42
|
+
|
43
|
+
list.each do |s|
|
44
|
+
s.executables.each do |exe_name|
|
45
|
+
executables.delete exe_name
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
return if executables.empty?
|
50
|
+
|
51
|
+
executables = executables.map { |exec| formatted_program_filename exec }
|
52
|
+
|
53
|
+
remove = if @force_executables.nil? then
|
54
|
+
ask_yes_no("Remove executables:\n" \
|
55
|
+
"\t#{executables.join ', '}\n\n" \
|
56
|
+
"in addition to the gem?",
|
57
|
+
true)
|
58
|
+
else
|
59
|
+
@force_executables
|
60
|
+
end
|
61
|
+
|
62
|
+
unless remove then
|
63
|
+
say "Executables and scripts will remain installed."
|
64
|
+
else
|
65
|
+
bin_dir = @bin_dir || Gem.bindir(spec.base_dir)
|
66
|
+
|
67
|
+
raise Gem::FilePermissionError, bin_dir unless File.writable? bin_dir
|
68
|
+
|
69
|
+
executables.each do |exe_name|
|
70
|
+
say "Removing #{exe_name}"
|
71
|
+
|
72
|
+
exe_file = File.join bin_dir, exe_name
|
73
|
+
|
74
|
+
FileUtils.rm_f exe_file
|
75
|
+
batch_file = "#{exe_file}.bat"
|
76
|
+
FileUtils.rm_f batch_file if File.exist?(batch_file)
|
77
|
+
generic_exe = "#{exe_file}.exe"
|
78
|
+
FileUtils.rm_f generic_exe if File.exist?(generic_exe)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
alias_method :remove_executables_orig, :remove_executables
|
84
|
+
alias_method :remove_executables, :remove_executables_and_exe_file
|
85
|
+
end
|
86
|
+
end
|
data/templates/gem_exe.c
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
#include "ruby.h"
|
2
|
+
#include <stdlib.h>
|
3
|
+
|
4
|
+
#ifdef HAVE_LOCALE_H
|
5
|
+
#include <locale.h>
|
6
|
+
#endif
|
7
|
+
|
8
|
+
#ifndef MAXPATHLEN
|
9
|
+
# define MAXPATHLEN 1024
|
10
|
+
#endif
|
11
|
+
|
12
|
+
void
|
13
|
+
dump_args(int argc, char **argv)
|
14
|
+
{
|
15
|
+
int i;
|
16
|
+
printf("Number of arguments: %d\n", argc);
|
17
|
+
|
18
|
+
for (i = 0; i < argc; ++i)
|
19
|
+
printf("Argument %d: %s\n", i, argv[i]);
|
20
|
+
|
21
|
+
printf("=================\n");
|
22
|
+
}
|
23
|
+
|
24
|
+
int
|
25
|
+
main(int argc, char **argv)
|
26
|
+
{
|
27
|
+
int i;
|
28
|
+
int myargc;
|
29
|
+
char** myargv;
|
30
|
+
char script_path[MAXPATHLEN];
|
31
|
+
char* dump_val;
|
32
|
+
DWORD attr;
|
33
|
+
|
34
|
+
#ifdef HAVE_LOCALE_H
|
35
|
+
setlocale(LC_CTYPE, "");
|
36
|
+
#endif
|
37
|
+
|
38
|
+
dump_val = getenv("EXEFY_DUMP");
|
39
|
+
|
40
|
+
if (GetModuleFileName(NULL, script_path, MAXPATHLEN)) {
|
41
|
+
for (i = strlen(script_path) - 1; i >= 0; --i) {
|
42
|
+
if (*(script_path + i) == '.') {
|
43
|
+
*(script_path + i) = '\0';
|
44
|
+
break;
|
45
|
+
}
|
46
|
+
}
|
47
|
+
|
48
|
+
attr = GetFileAttributes(script_path);
|
49
|
+
if (attr == INVALID_FILE_ATTRIBUTES) {
|
50
|
+
printf("Script %s is missing!", script_path);
|
51
|
+
return -1;
|
52
|
+
}
|
53
|
+
// Let Ruby initialize program arguments
|
54
|
+
ruby_sysinit(&argc, &argv);
|
55
|
+
|
56
|
+
// Change arguments by inserting path to script file
|
57
|
+
// as second argument (first argument is always executable
|
58
|
+
// name) and copying arguments from command line after it.
|
59
|
+
myargc = argc + 1;
|
60
|
+
myargv = (char**)xmalloc(sizeof(char*) * (myargc + 1));
|
61
|
+
if (NULL != myargv) {
|
62
|
+
memset(myargv, 0, sizeof(char*) * (myargc + 1));
|
63
|
+
*myargv = *argv;
|
64
|
+
*(myargv + 1) = &script_path[0];
|
65
|
+
|
66
|
+
for (i = 1; i < argc; ++i) {
|
67
|
+
*(myargv + i + 1) = *(argv + i);
|
68
|
+
}
|
69
|
+
|
70
|
+
if (NULL != dump_val) {
|
71
|
+
dump_args(myargc, myargv);
|
72
|
+
}
|
73
|
+
|
74
|
+
{
|
75
|
+
RUBY_INIT_STACK;
|
76
|
+
ruby_init();
|
77
|
+
return ruby_run_node(ruby_options(myargc, myargv));
|
78
|
+
}
|
79
|
+
}
|
80
|
+
else {
|
81
|
+
printf("Not enough memory to continue. Exiting...");
|
82
|
+
}
|
83
|
+
}
|
84
|
+
|
85
|
+
// Return an error when nothing works
|
86
|
+
return -1;
|
87
|
+
}
|
@@ -0,0 +1,40 @@
|
|
1
|
+
//#include "resource.h"
|
2
|
+
#include <winver.h>
|
3
|
+
|
4
|
+
/////////////////////////////////////////////////////////////////////////////
|
5
|
+
//
|
6
|
+
// Version
|
7
|
+
//
|
8
|
+
|
9
|
+
VS_VERSION_INFO VERSIONINFO
|
10
|
+
FILEVERSION <%= binary_version %>
|
11
|
+
PRODUCTVERSION <%= binary_version %>
|
12
|
+
FILEFLAGSMASK 0x17L
|
13
|
+
#ifdef _DEBUG
|
14
|
+
FILEFLAGS 0x1L
|
15
|
+
#else
|
16
|
+
FILEFLAGS 0x0L
|
17
|
+
#endif
|
18
|
+
FILEOS VOS_NT
|
19
|
+
FILETYPE VFT_APP
|
20
|
+
FILESUBTYPE VFT2_UNKNOWN
|
21
|
+
BEGIN
|
22
|
+
BLOCK "StringFileInfo"
|
23
|
+
BEGIN
|
24
|
+
BLOCK "040904b0"
|
25
|
+
BEGIN
|
26
|
+
VALUE "FileDescription", "Gem Executable Stub is built for <%= RUBY_DESCRIPTION %>"
|
27
|
+
VALUE "Comments", "Stub is built for <%= RUBY_DESCRIPTION %> version."
|
28
|
+
VALUE "FileVersion", "<%= VERSION %>"
|
29
|
+
VALUE "InternalName", "Gem ExeStub"
|
30
|
+
VALUE "LegalCopyright", "Copyright (C) 2012 Bosko Ivanisevic"
|
31
|
+
VALUE "OriginalFilename", "gemstub.exe"
|
32
|
+
VALUE "ProductName", "Gem Exefy"
|
33
|
+
VALUE "ProductVersion", "<%= VERSION %>"
|
34
|
+
END
|
35
|
+
END
|
36
|
+
BLOCK "VarFileInfo"
|
37
|
+
BEGIN
|
38
|
+
VALUE "Translation", 0x409, 1200
|
39
|
+
END
|
40
|
+
END
|
metadata
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gem-exefy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.2.0
|
5
|
+
prerelease:
|
6
|
+
platform: universal-mingw32
|
7
|
+
authors:
|
8
|
+
- Boško Ivanišević
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-09-11 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rdoc
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '3.10'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.10'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: hoe
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '3.0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '3.0'
|
46
|
+
description: ! 'GemExefy is RubyGems plugin aimed to replace batch files (.bat) with
|
47
|
+
|
48
|
+
executables with the same name. This gem will work only on
|
49
|
+
|
50
|
+
RubyInstaller Ruby installation and it requires RubyInstaller DevKit.
|
51
|
+
|
52
|
+
|
53
|
+
Reason for such replaceming batch files with executable stubs is
|
54
|
+
|
55
|
+
twofold. When execution of batch file is interrupted with Ctrl-C key
|
56
|
+
|
57
|
+
combination, user is faced with the confusing question
|
58
|
+
|
59
|
+
|
60
|
+
"Terminate batch job (Y/N)?"
|
61
|
+
|
62
|
+
|
63
|
+
which is avoided after replacement.
|
64
|
+
|
65
|
+
|
66
|
+
Second reason is appearance of processes in Task manager (or Process
|
67
|
+
|
68
|
+
Explorer). In the case of batch files all processes are visible as
|
69
|
+
|
70
|
+
ruby.exe. In order to distinguish between them, program arguments must
|
71
|
+
|
72
|
+
be examined. In addition, having one process name makes it hard to
|
73
|
+
|
74
|
+
define firewall rules. Having executable versions instead of batch
|
75
|
+
|
76
|
+
files will facilitate process identification in task list as well as
|
77
|
+
|
78
|
+
defining firewall rules. Moreover it makes it possible to create
|
79
|
+
|
80
|
+
selective firewall rules for different Ruby gems. Installing Ruby
|
81
|
+
|
82
|
+
applications as Windows services should be also much easer when
|
83
|
+
|
84
|
+
executable stub is used instead of batch file.'
|
85
|
+
email:
|
86
|
+
- bosko.ivanisevic@gmail.com
|
87
|
+
executables: []
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files:
|
90
|
+
- History.rdoc
|
91
|
+
- Manifest.txt
|
92
|
+
- README.rdoc
|
93
|
+
files:
|
94
|
+
- .autotest
|
95
|
+
- History.rdoc
|
96
|
+
- Manifest.txt
|
97
|
+
- README.rdoc
|
98
|
+
- Rakefile
|
99
|
+
- lib/rubygems/commands/exefy_command.rb
|
100
|
+
- lib/rubygems_plugin.rb
|
101
|
+
- lib/exefy.rb
|
102
|
+
- lib/exefy/version.rb
|
103
|
+
- templates/gem_exe.c
|
104
|
+
- templates/gem_exe.rc.erb
|
105
|
+
homepage: http://github.com/bosko/gem-exefy
|
106
|
+
licenses: []
|
107
|
+
post_install_message: ! '**************************************************
|
108
|
+
|
109
|
+
* *
|
110
|
+
|
111
|
+
* Thank you for installing gem-exefy-1.2.0! *
|
112
|
+
|
113
|
+
* *
|
114
|
+
|
115
|
+
* This gem will work only on RubyInstaller *
|
116
|
+
|
117
|
+
* versions of Ruby with installed DevKit. *
|
118
|
+
|
119
|
+
* *
|
120
|
+
|
121
|
+
**************************************************'
|
122
|
+
rdoc_options:
|
123
|
+
- --main
|
124
|
+
- README.rdoc
|
125
|
+
require_paths:
|
126
|
+
- lib
|
127
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
128
|
+
none: false
|
129
|
+
requirements:
|
130
|
+
- - ! '>='
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: 1.9.3
|
133
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
|
+
none: false
|
135
|
+
requirements:
|
136
|
+
- - ! '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 1.8.0
|
139
|
+
requirements: []
|
140
|
+
rubyforge_project: gem-exefy
|
141
|
+
rubygems_version: 1.8.24
|
142
|
+
signing_key:
|
143
|
+
specification_version: 3
|
144
|
+
summary: GemExefy is RubyGems plugin aimed to replace batch files (.bat) with executables
|
145
|
+
with the same name
|
146
|
+
test_files: []
|