rubber-generate 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
data/README.textile CHANGED
@@ -20,6 +20,9 @@ functions and some rudimentary understanding of C code.
20
20
 
21
21
  h3. Changes
22
22
 
23
+ * 0.0.10 - 27th Apr 2011
24
+ - Add --install flag
25
+
23
26
  * 0.0.9 - 31st May 2010
24
27
  - Add support for --build-dir <DIR> switch to specify output directory
25
28
 
data/bin/rubber-generate CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  if FileTest.symlink?(__FILE__)
4
- file = File::readlink(__FILE__)
4
+ file = File.readlink(__FILE__)
5
5
  else
6
6
  file = __FILE__
7
7
  end
@@ -9,12 +9,10 @@ end
9
9
  require 'rbconfig'
10
10
  require 'ftools'
11
11
 
12
- dir = File::dirname(file)
12
+ dir = File.dirname(File.expand_path(file))
13
13
  $:.unshift(dir)
14
- #puts dir
14
+
15
15
  require 'strscan'
16
- #require 'rubygems'
17
- #require_gem 'rubber'
18
16
  require 'rubber/codegen'
19
17
  require 'rubber/mkextconf'
20
18
  require 'rubber/scanner'
@@ -23,55 +21,67 @@ require 'rubber/autord'
23
21
  require 'optparse'
24
22
  require 'ostruct'
25
23
 
26
- Args = OpenStruct.new
24
+ Args = OpenStruct.new
27
25
  Args.build_dir = Config::CONFIG['sitearch']
28
26
  Args.configure = false
29
- Args.build = false
30
-
27
+ Args.build = false
28
+ Args.install = false
31
29
 
32
30
 
33
31
  OptionParser.new { |opts|
34
- opts.banner = "Usage: rubber-generate [options] file"
35
- opts.on("--build-dir DIR", 'Directory for generating/building extension') do |dir|
36
- Args.build_dir = dir
37
- end
38
- opts.on('--configure', 'Run generated extconf.rb') do
39
- Args.configure = true
40
- end
41
- opts.on('--build', 'Build extension') do
42
- Args.build = true
43
- end
32
+ opts.banner = "Usage: rubber-generate [options] file"
33
+ opts.on("--build-dir DIR", 'Directory for generating/building extension') do |dir|
34
+ Args.build_dir = dir
35
+ end
36
+ opts.on('--configure', 'Run generated extconf.rb') do
37
+ Args.configure = true
38
+ end
39
+ opts.on('--build', 'Build extension') do
40
+ Args.build = true
41
+ end
42
+ opts.on('--install', 'Install') do
43
+ Args.install = true
44
+ end
44
45
  }.parse!(ARGV)
45
46
 
46
47
 
47
- args = ARGV#.select { |i| i[0] != ?- }
48
- #switches = ARGV.select { |i| i[0] == ?- }
49
- (args.size > 0 && args || Dir.glob('*.cr')).each { |file|
48
+ (ARGV.size > 0 && ARGV || Dir.glob('*.cr')).each do |file|
50
49
 
51
50
  file = File.expand_path(file)
51
+ FileUtils.mkdir_p(Args.build_dir)
52
52
 
53
- File.mkpath(Args.build_dir)
54
53
  Dir.chdir(Args.build_dir) do
54
+
55
+ scanner = Rubber::CRScanner.new(file)
56
+ scanner.scan(nil)
57
+
58
+ File.open(scanner.ext + ".c", 'w') do |out|
59
+ File.open(scanner.ext + ".rd", 'w') do |doc|
60
+ File.open('extconf.rb', 'w') do |extconf|
61
+ Rubber.generate_extconf(scanner, extconf)
62
+ Rubber.generate_c_source(scanner, out)
63
+ Rubber.generate_rd(scanner, doc)
64
+ end
65
+ end
66
+ end
67
+
68
+ system('ruby','extconf.rb') if Args.configure
69
+
70
+ system('make') if Args.build
71
+
72
+ if Args.install
73
+ if Process.uid.zero?
74
+ system('make', 'install')
75
+ else
76
+ if system('sudo', '-k', '-n', 'make')
77
+ # System is setup to allow make to be run without password
78
+ system('sudo', 'make', 'install')
79
+ else
80
+ # Password required
81
+ system('sudo', '-k', '-p', 'Enter password to install: ', 'make', 'install')
82
+ end
83
+ end
84
+ end
55
85
 
56
-
57
- scanner = Rubber::CRScanner.new(file)
58
- scanner.scan(nil)
59
-
60
- out = File.open(scanner.ext + ".c", 'w')
61
- doc = File.open(scanner.ext + ".rd", 'w')
62
-
63
- extconf = File.open('extconf.rb', 'w')
64
- Rubber.generate_extconf(scanner, extconf)
65
- Rubber.generate_c_source(scanner, out)
66
- Rubber.generate_rd(scanner, doc)
67
-
68
-
69
- doc.close
70
- out.close
71
- extconf.close
72
-
73
- system('ruby','extconf.rb') if Args.configure
74
- system('make') if Args.build
75
86
  end
76
- }
77
- #out.close
87
+ end
@@ -1,6 +1,6 @@
1
1
  require 'rubber/struct'
2
2
  module Rubber
3
- VERSION = [0,0,9]
3
+ VERSION = [0,0,10]
4
4
  class ScanState
5
5
  define_members(:in_code, :in_class, :in_func, :braces)
6
6
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubber-generate
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
4
+ hash: 11
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 9
10
- version: 0.0.9
9
+ - 10
10
+ version: 0.0.10
11
11
  platform: ruby
12
12
  authors:
13
13
  - Geoff Youngs
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-06-04 00:00:00 +01:00
18
+ date: 2011-04-27 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies: []
21
21