ucc 2.0.1 → 2.0.2
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/lib/ucc.rb +32 -6
- data/lib/ucc/version.rb +1 -1
- metadata +2 -2
data/lib/ucc.rb
CHANGED
@@ -2,12 +2,16 @@ require "ucc/version"
|
|
2
2
|
require "optparse"
|
3
3
|
|
4
4
|
module Ucc
|
5
|
+
# Are we on windows?
|
5
6
|
WINDOWS = !!((`uname` rescue "") =~ /^$|windows/)
|
7
|
+
|
8
|
+
# What executable was used to run ucc?
|
6
9
|
CURRENT_EXECUTABLE = File.basename($0)
|
7
10
|
|
8
11
|
class Runner
|
9
12
|
attr_reader :source_files
|
10
13
|
|
14
|
+
# Herewe pass the compiler (to be able to choose between gcc or g++)
|
11
15
|
def initialize(compiler)
|
12
16
|
@compiler = compiler
|
13
17
|
raise "Compiler must be specified" unless @compiler
|
@@ -18,6 +22,7 @@ module Ucc
|
|
18
22
|
# Variables
|
19
23
|
# =========
|
20
24
|
|
25
|
+
# Defines options for ucc
|
21
26
|
def optparse
|
22
27
|
@optparse ||= OptionParser.new do |opts|
|
23
28
|
opts.banner = "Usage: #{CURRENT_EXECUTABLE} [options] file..."
|
@@ -36,23 +41,30 @@ module Ucc
|
|
36
41
|
opts.on( '-V', '--valgrind', 'Run the app in valgrind' ) do
|
37
42
|
options[:memcheck] = true
|
38
43
|
end
|
44
|
+
|
45
|
+
options[:verbose] = false
|
46
|
+
opts.on( '--verbose', 'Enable debug messages' ) do
|
47
|
+
options[:verbose] = true
|
48
|
+
end
|
39
49
|
|
40
|
-
opts.
|
50
|
+
opts.on_tail( '-v', '--version', 'Show app version' ) do
|
41
51
|
puts "#{CURRENT_EXECUTABLE} #{VERSION}"
|
42
52
|
exit
|
43
53
|
end
|
44
54
|
|
45
|
-
opts.
|
55
|
+
opts.on_tail( '-h', '--help', 'Display this screen' ) do
|
46
56
|
puts opts
|
47
57
|
exit
|
48
58
|
end
|
49
59
|
end
|
50
60
|
end
|
51
61
|
|
62
|
+
# Options array accessor
|
52
63
|
def options
|
53
64
|
@options ||= {}
|
54
65
|
end
|
55
66
|
|
67
|
+
# Filename to use when executing compiled app
|
56
68
|
def app_filename
|
57
69
|
return @app_filename if @app_filename
|
58
70
|
@app_filename = source_files[0].sub(/\.\w+$/, '')
|
@@ -62,6 +74,7 @@ module Ucc
|
|
62
74
|
# Main logic
|
63
75
|
# ==========
|
64
76
|
|
77
|
+
# Does option parsing using `optparse`
|
65
78
|
def parse_options
|
66
79
|
begin
|
67
80
|
optparse.parse!
|
@@ -73,24 +86,37 @@ module Ucc
|
|
73
86
|
# Here we have already parsed ARGV
|
74
87
|
@source_files = ARGV
|
75
88
|
if @source_files.empty?
|
76
|
-
#puts optparse
|
77
89
|
puts "#{CURRENT_EXECUTABLE}: no input files"
|
78
90
|
exit(1)
|
79
91
|
end
|
80
92
|
end
|
81
93
|
|
94
|
+
# Everything special goes here
|
82
95
|
def work
|
83
|
-
compilation_params = %Q[#{@compiler} -Wall -o "#{app_filename}" #{source_files.map{ |f|
|
96
|
+
compilation_params = %Q[#{@compiler} -Wall -o "#{app_filename}" #{source_files.map{ |f| enquote(f) }.join(" ")}]
|
84
97
|
compilation_params = "#{compilation_params} #{options[:compileopts]}" if options[:compileopts]
|
98
|
+
trace compilation_params
|
85
99
|
exit unless system compilation_params
|
86
100
|
|
87
|
-
exec_params =
|
101
|
+
exec_params = enquote(app_filename)
|
88
102
|
exec_params = "./#{exec_params}" unless WINDOWS
|
89
103
|
exec_params = "#{exec_params} #{options[:runopts]}" if options[:runopts]
|
90
104
|
exec_params = "valgrind #{exec_params}" if options[:memcheck]
|
105
|
+
trace exec_params
|
91
106
|
puts "=== Compiled successfully, executing... === "
|
92
107
|
exec exec_params
|
93
108
|
end
|
94
|
-
|
109
|
+
|
110
|
+
# Prints text if verbose mode is on
|
111
|
+
def trace(text)
|
112
|
+
puts "[ucc] Debug: #{text}" if options[:verbose]
|
113
|
+
end
|
114
|
+
|
115
|
+
# Enquotes param if needed, also pre-escapes quotes that already are inside the param
|
116
|
+
def enquote(param)
|
117
|
+
param = param.gsub(/(["'])/, '\\\\\\1')
|
118
|
+
param = %Q["#{param}"] if param =~ /\s/
|
119
|
+
param
|
120
|
+
end
|
95
121
|
end
|
96
122
|
end
|
data/lib/ucc/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ucc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-10-
|
12
|
+
date: 2011-10-20 00:00:00.000000000Z
|
13
13
|
dependencies: []
|
14
14
|
description: This gem makes it easy to compile small apps using gcc or g++, you even
|
15
15
|
don't need a makefile!
|