cxxproject 0.6.9 → 0.6.10

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile.rb CHANGED
@@ -25,8 +25,6 @@ begin
25
25
  end
26
26
  end
27
27
 
28
-
29
-
30
28
  begin
31
29
  require 'rdoc'
32
30
  require 'rdoc/task'
@@ -1,7 +1,6 @@
1
-
2
1
  module Cxxproject
3
2
  module Context
4
-
3
+
5
4
  def check_hash(hash,allowed)
6
5
  hash.keys.map do |k|
7
6
  error_string = ["error while evaluating \"#{@current_working_dir}/#{@current_project_file}\"",
@@ -3,25 +3,29 @@ require 'rubygems'
3
3
  require 'yaml'
4
4
  require 'rake/clean'
5
5
 
6
- require 'cxxproject/utils/optional'
7
6
 
8
7
  require 'cxxproject/ext/string'
8
+ require 'cxxproject/ext/hash'
9
+
10
+ require 'cxxproject/utils/optional'
9
11
  require 'cxxproject/utils/utils'
10
- require 'cxxproject/torake'
11
- require 'cxxproject/utils/ubigraph'
12
- require 'cxxproject/utils/graphstream'
12
+ require 'cxxproject/utils/stats'
13
+
13
14
  require 'cxxproject/toolchain/provider'
14
15
 
15
- require 'cxxproject/utils/progress'
16
- require 'cxxproject/utils/rbcurse'
17
- require 'cxxproject/utils/progress'
18
- require 'cxxproject/utils/rbcurse'
19
- require 'cxxproject/utils/stats'
20
16
  require 'cxxproject/version'
21
17
 
18
+ require 'cxxproject/plugin_context'
19
+
20
+ require 'frazzle/frazzle'
21
+ registry = Frazzle::Registry.new('cxxproject', '_', '')
22
+
23
+ toolchain_plugins = registry.get_plugins('toolchain')
24
+ toolchain_plugins.each do |toolchain_plugin|
25
+ registry.load_plugin(toolchain_plugin, Cxxproject::PluginContext.new(nil, nil, nil))
26
+ end
27
+
22
28
  include Cxxproject::Toolchain
23
- CxxProject2Rake = Cxxproject::CxxProject2Rake
24
- BinaryLibs = Cxxproject::BinaryLibs
25
29
 
26
30
  def version_info
27
31
  Cxxproject::Version.cxxproject
@@ -0,0 +1,12 @@
1
+ class Hash
2
+ def method_missing(m, *args, &block)
3
+ if m.to_s =~ /(.*)=$/ # was assignment
4
+ self[$1] = args[0]
5
+ else
6
+ fetch(m.to_s, nil)
7
+ end
8
+ end
9
+ def recursive_merge(h)
10
+ self.merge!(h) {|key, _old, _new| if _old.class == Hash then _old.recursive_merge(_new) else _new end }
11
+ end
12
+ end
@@ -34,13 +34,13 @@ module Cxxproject
34
34
  # * :command
35
35
  def toolchain(name, tc)
36
36
  raise "not a tc" unless tc.is_a?(Hash)
37
- check_hash(tc,Provider.default.keys)
37
+ check_hash(tc, Cxxproject::Toolchain::Provider.default.keys)
38
38
  check_compiler(tc[:COMPILER]) if tc[:COMPILER]
39
39
  check_linker(tc[:LINKER]) if tc[:LINKER]
40
40
  check_archiver(tc[:ARCHIVER]) if tc[:ARCHIVER]
41
41
  PluginContext::expand(tc)
42
- Provider.add(name)
43
- Provider.merge(Provider[name], tc)
42
+ Cxxproject::Toolchain::Provider.add(name)
43
+ Cxxproject::Toolchain::Provider.merge(Cxxproject::Toolchain::Provider[name], tc)
44
44
  end
45
45
 
46
46
  def self.expand(toolchain)
@@ -50,7 +50,7 @@ module Cxxproject
50
50
  to_expand = find_toolchain_subhash(toolchain)
51
51
  from = find_toolchain_element(toolchain,to_expand[:BASED_ON])
52
52
  to_expand.delete(:BASED_ON)
53
- Cxxproject::Toolchain::Provider.merge(to_expand,from,false)
53
+ Cxxproject::Toolchain::Provider.merge(to_expand, from, false)
54
54
  end
55
55
  return toolchain
56
56
  end
@@ -60,7 +60,7 @@ module Cxxproject
60
60
  tc.each do |k,v|
61
61
  if k == :BASED_ON
62
62
  res = true
63
- elsif v.is_a?(Hash)
63
+ elsif v.is_a?(Hash)
64
64
  res = needs_expansion(v)
65
65
  end
66
66
  if res
@@ -76,7 +76,7 @@ module Cxxproject
76
76
  tc.each do |k,v|
77
77
  if(k == :BASED_ON)
78
78
  res << tc
79
- elsif v.is_a?(Hash)
79
+ elsif v.is_a?(Hash)
80
80
  loop.call(res,v)
81
81
  end
82
82
  end
@@ -84,7 +84,7 @@ module Cxxproject
84
84
  loop.call(res,tc)
85
85
  return res[0] if res.length > 0
86
86
  end
87
-
87
+
88
88
 
89
89
  def self.find_toolchain_element(tc,name)
90
90
  res = []
@@ -104,21 +104,20 @@ module Cxxproject
104
104
 
105
105
  def check_compiler(hash)
106
106
  raise "not a hash" unless hash.is_a?(Hash)
107
- check_hash(hash,Provider.default[:COMPILER].keys)
108
-
109
- check_hash(hash[:CPP],Provider.default[:COMPILER][:CPP].keys << :BASED_ON) if hash[:CPP]
110
- check_hash(hash[:C],Provider.default[:COMPILER][:C].keys << :BASED_ON) if hash[:C]
111
- check_hash(hash[:ASM],Provider.default[:COMPILER][:ASM].keys << :BASED_ON) if hash[:ASM]
107
+ check_hash(hash, Cxxproject::Toolchain::Provider.default[:COMPILER].keys)
108
+ check_hash(hash[:CPP], Cxxproject::Toolchain::Provider.default[:COMPILER][:CPP].keys << :BASED_ON) if hash[:CPP]
109
+ check_hash(hash[:C], Cxxproject::Toolchain::Provider.default[:COMPILER][:C].keys << :BASED_ON) if hash[:C]
110
+ check_hash(hash[:ASM], Cxxproject::Toolchain::Provider.default[:COMPILER][:ASM].keys << :BASED_ON) if hash[:ASM]
112
111
  end
113
112
 
114
113
  def check_linker(hash)
115
114
  raise "not a hash" unless hash.is_a?(Hash)
116
- check_hash(hash,Provider.default[:LINKER].keys)
115
+ check_hash(hash, Cxxproject::Toolchain::Provider.default[:LINKER].keys)
117
116
  end
118
117
 
119
118
  def check_archiver(hash)
120
119
  raise "not a hash" unless hash.is_a?(Hash)
121
- check_hash(hash,Provider.default[:ARCHIVER].keys)
120
+ check_hash(hash, Cxxproject::Toolchain::Provider.default[:ARCHIVER].keys)
122
121
  end
123
122
 
124
123
  # will use the content of the plugin.rb file and evaluate it
@@ -1,19 +1,5 @@
1
1
  require 'yaml'
2
2
 
3
- class Hash
4
- def method_missing(m, *args, &block)
5
- if m.to_s =~ /(.*)=$/ # was assignment
6
- self[$1] = args[0]
7
- else
8
- fetch(m.to_s, nil)
9
- end
10
- end
11
- def recursive_merge(h)
12
- self.merge!(h) {|key, _old, _new| if _old.class == Hash then _old.recursive_merge(_new) else _new end }
13
- end
14
-
15
- end
16
-
17
3
  class Toolchain
18
4
  attr_reader :toolchain
19
5
  def initialize(toolchain_file)
@@ -26,13 +12,13 @@ class Toolchain
26
12
  basechain = YAML::load(File.open(File.join(File.dirname(__FILE__),"#{@based_on}.json")))
27
13
  @toolchain = basechain.recursive_merge(@toolchain)
28
14
  end
29
- def method_missing(m, *args, &block)
15
+ def method_missing(m, *args, &block)
30
16
  if @toolchain[m.to_s]
31
17
  self.class.send(:define_method, m) { @toolchain[m.to_s] }
32
18
  @toolchain[m.to_s]
33
19
  else
34
20
  return super
35
21
  end
36
- end
22
+ end
37
23
 
38
24
  end
@@ -1,7 +1,7 @@
1
1
  module Cxxproject
2
2
  class Version
3
3
  def self.cxxproject
4
- '0.6.9'
4
+ '0.6.10'
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: cxxproject
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.6.9
5
+ version: 0.6.10
6
6
  platform: ruby
7
7
  authors:
8
8
  - oliver mueller
@@ -10,21 +10,21 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-07-11 00:00:00 Z
13
+ date: 2012-07-12 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
- name: highline
16
+ name: colored
17
17
  requirement: &id001 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ">="
21
21
  - !ruby/object:Gem::Version
22
- version: 1.6.0
22
+ version: "0"
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: *id001
26
26
  - !ruby/object:Gem::Dependency
27
- name: colored
27
+ name: frazzle
28
28
  requirement: &id002 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
@@ -34,21 +34,10 @@ dependencies:
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: *id002
37
- - !ruby/object:Gem::Dependency
38
- name: progressbar
39
- requirement: &id003 !ruby/object:Gem::Requirement
40
- none: false
41
- requirements:
42
- - - ">="
43
- - !ruby/object:Gem::Version
44
- version: "0"
45
- type: :runtime
46
- prerelease: false
47
- version_requirements: *id003
48
37
  description: " Some more high level building blocks for cpp projects.\n"
49
38
  email: oliver.mueller@gmail.com
50
- executables:
51
- - cxx
39
+ executables: []
40
+
52
41
  extensions: []
53
42
 
54
43
  extra_rdoc_files: []
@@ -68,7 +57,6 @@ files:
68
57
  - lib/cxxproject/utils/rbcurse_executable_ext.rb
69
58
  - lib/cxxproject/utils/utils.rb
70
59
  - lib/cxxproject/utils/rbcurse_tasktable.rb
71
- - lib/cxxproject/utils/console.rb
72
60
  - lib/cxxproject/utils/progress.rb
73
61
  - lib/cxxproject/utils/graphstream.rb
74
62
  - lib/cxxproject/toolchain/provider.rb
@@ -82,11 +70,11 @@ files:
82
70
  - lib/cxxproject/ext/rake.rb
83
71
  - lib/cxxproject/ext/progressbar.rb
84
72
  - lib/cxxproject/ext/stdout.rb
73
+ - lib/cxxproject/ext/hash.rb
85
74
  - lib/cxxproject/ext/rake_dirty.rb
86
75
  - lib/cxxproject/ext/file.rb
87
76
  - lib/cxxproject/context.rb
88
77
  - lib/cxxproject/plugin_context.rb
89
- - lib/cxxproject/torake.rb
90
78
  - lib/cxxproject/buildingblocks/building_block.rb
91
79
  - lib/cxxproject/buildingblocks/has_libraries_mixin.rb
92
80
  - lib/cxxproject/buildingblocks/custom_building_block.rb
@@ -101,8 +89,7 @@ files:
101
89
  - lib/cxxproject/buildingblocks/source_library.rb
102
90
  - lib/cxxproject/buildingblocks/command_line.rb
103
91
  - lib/cxxproject/eval_context.rb
104
- - lib/tools/project_wizard.rb
105
- - lib/cxxproject.rb
92
+ - lib/cxxproject/cxxproject.rb
106
93
  - Rakefile.rb
107
94
  - spec/string_spec.rb
108
95
  - spec/project_path_spec.rb
@@ -124,9 +111,6 @@ files:
124
111
  - spec/cxxproject_2_rake_spec.rb
125
112
  - spec/toolchain_spec.rb
126
113
  - spec/rake_listener_ext_spec.rb
127
- - lib/tools/Rakefile.rb.template
128
- - lib/tools/project.rb.template
129
- - bin/cxx
130
114
  homepage: https://github.com/marcmo/cxxproject
131
115
  licenses: []
132
116
 
@@ -140,7 +124,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
140
124
  requirements:
141
125
  - - ">="
142
126
  - !ruby/object:Gem::Version
143
- hash: -1123746913238393195
127
+ hash: -240781837461888490
144
128
  segments:
145
129
  - 0
146
130
  version: "0"
data/bin/cxx DELETED
@@ -1,10 +0,0 @@
1
- #!/usr/bin/env ruby
2
- $:.unshift File.join(File.dirname(__FILE__),"..","lib")
3
-
4
- require 'tools/project_wizard'
5
-
6
- if ARGV.size < 1
7
- puts "usage: cxx project-dir"
8
- exit 0
9
- end
10
- prepare_project(ARGV[0])
@@ -1,257 +0,0 @@
1
- require 'logger'
2
- require 'pp'
3
- require 'pathname'
4
- require 'cxxproject/ext/rake'
5
- require 'cxxproject/buildingblocks/module'
6
- require 'cxxproject/buildingblocks/makefile'
7
- require 'cxxproject/buildingblocks/executable'
8
- require 'cxxproject/buildingblocks/source_library'
9
- require 'cxxproject/buildingblocks/single_source'
10
- require 'cxxproject/buildingblocks/binary_library'
11
- require 'cxxproject/buildingblocks/custom_building_block'
12
- require 'cxxproject/buildingblocks/command_line'
13
- require 'cxxproject/toolchain/colorizing_formatter'
14
- require 'cxxproject/eval_context'
15
- require 'cxxproject/plugin_context'
16
-
17
- require 'rubygems'
18
-
19
- module Cxxproject
20
-
21
- class CxxProject2Rake
22
- attr_accessor :base_dir, :all_tasks
23
-
24
- def initialize(projects, build_dir, toolchain_name, base_dir='.', &option_block)
25
- load_toolchain_plugins
26
- option_block.call if option_block
27
- toolchain = Provider[toolchain_name]
28
- raise "no provider with name \"#{toolchain_name}\" found" unless toolchain
29
- @base_dir = base_dir
30
- cd(@base_dir, :verbose => false) do
31
- @projects = projects.to_a
32
- end
33
-
34
- # TODO: this should be cleaned up somehow...
35
- if Utils::OS.linux?
36
- toolchain[:LINKER][:LIB_PREFIX_FLAGS] = "-Wl,--whole-archive"
37
- toolchain[:LINKER][:LIB_POSTFIX_FLAGS] = "-Wl,--no-whole-archive"
38
- end
39
-
40
- Rake::application.deriveIncludes = true
41
-
42
- initialize_logging(build_dir)
43
- @all_tasks = instantiate_tasks(toolchain, build_dir)
44
-
45
- create_generic_tasks
46
- create_console_colorization
47
- create_multitask
48
- create_dont_bail_on_first_task
49
- describe_clean_task
50
- create_console_task
51
-
52
- load_nontoolchain_plugins
53
- end
54
-
55
- def find_gems
56
- latest = Gem::Specification.latest_specs
57
- latest.select do |gem|
58
- yield(gem)
59
- end
60
- end
61
-
62
- def load_toolchain_plugins
63
- toolchains = find_gems do |gem|
64
- Regexp.new('cxxproject_(.+)toolchain').match(gem.name)
65
- end
66
- load_gems(toolchains)
67
- end
68
-
69
- def load_nontoolchain_plugins
70
- cxx = Regexp.new('cxxproject_(.+)')
71
- no_toolchain = Regexp.new('.*toolchain.*')
72
- gems_to_load = find_gems do |gem|
73
- cxx.match(gem.name) && !(no_toolchain.match(gem.name))
74
- end
75
- load_gems(gems_to_load)
76
- end
77
-
78
- def load_gems(gems)
79
- context = PluginContext.new(self, ALL_BUILDING_BLOCKS, @log)
80
- gems.each do |gem|
81
- load_plugin(gem, context)
82
- end
83
- end
84
-
85
- def load_plugin(gem, pluginContext)
86
- begin
87
- path = File.join(gem.full_gem_path, 'lib', 'plugin.rb')
88
- content = File.read(path)
89
- pluginContext.eval_plugin(content)
90
- rescue Exception => e
91
- puts "problems with gem #{gem} in dir: #{path}: #{e}"
92
- raise e
93
- end
94
- end
95
-
96
- def create_console_task
97
- require 'cxxproject/utils/console'
98
- end
99
-
100
- def initialize_logging(build_dir)
101
- @log = Logger.new(STDOUT)
102
- @log.formatter = proc { |severity, datetime, progname, msg|
103
- "#{severity}: #{msg}\n"
104
- }
105
- # Logger loglevels: fatal, error, warn, info, debug
106
- # Rake --verbose -> info
107
- # Rake --trace -> debug
108
- @log.level = Logger::ERROR
109
- @log.level = Logger::INFO if RakeFileUtils.verbose == true
110
- @log.level = Logger::DEBUG if Rake::application.options.trace
111
- @log.debug "initializing for build_dir: \"#{build_dir}\", base_dir: \"#{@base_dir}\""
112
- end
113
-
114
- def describe_clean_task
115
- Rake::Task[:clean].add_description('clean')
116
- end
117
-
118
- def create_dont_bail_on_first_task
119
- desc 'dont bail on first error'
120
- task :dont_bail_on_first_error do
121
- Rake::Task.bail_on_first_error = false
122
- end
123
- end
124
-
125
- def create_multitask
126
- desc 'set parallelization of multitask'
127
- task :multitask, :threads do |t, args|
128
- arg = args.threads
129
- if arg
130
- Rake::application.max_parallel_tasks = arg.to_i
131
- end
132
- end
133
- end
134
-
135
- def create_console_colorization
136
- # default is on
137
- Cxxproject::ColorizingFormatter.enabled = true
138
- desc 'Toggle colorization of console output (use true|t|yes|y|1|on for true ... everything else is false)'
139
- task :toggle_colorize, :on_off do |t, args|
140
- arg = args[:on_off] || 'false'
141
- on_off = arg.match(/(true|t|yes|y|1|on)$/) != nil
142
- Cxxproject::ColorizingFormatter.enabled = on_off
143
- end
144
- end
145
-
146
- def create_generic_tasks
147
- tasks = [:lib, :exe, :run]
148
- tasks << nil
149
- tasks.each { |i| create_filter_task_with_namespace(i) }
150
- end
151
-
152
- def create_filter_task_with_namespace(basename)
153
- if basename
154
- desc "invoke #{basename} with filter"
155
- namespace basename do
156
- create_filter_task("#{basename}:")
157
- end
158
- else
159
- desc 'invoke with filter'
160
- create_filter_task('')
161
- end
162
- end
163
-
164
- def create_filter_task(basename)
165
- task :filter, :filter do |t, args|
166
- filter = ".*"
167
- if args[:filter]
168
- filter = "#{args[:filter]}"
169
- end
170
- filter = Regexp.new("#{basename}#{filter}")
171
- Rake::Task.tasks.each do |to_check|
172
- name = to_check.name
173
- if ("#{basename}:filter" != name)
174
- match = filter.match(name)
175
- if match
176
- to_check.invoke
177
- end
178
- end
179
- end
180
- end
181
- end
182
-
183
- def instantiate_tasks(toolchain, build_dir)
184
- check_for_project_configs
185
-
186
- if @log.debug?
187
- @log.debug "project_configs:"
188
- @projects.each { |c| @log.debug " * #{c}" }
189
- end
190
- register_projects()
191
- ALL_BUILDING_BLOCKS.values.each do |block|
192
- prepare_block(block, toolchain, build_dir)
193
- end
194
- ALL_BUILDING_BLOCKS.values.inject([]) do |memo,block|
195
- @log.debug "creating tasks for block: #{block.name}/taskname: #{block.get_task_name} (#{block})"
196
- memo << block.convert_to_rake()
197
- end
198
- end
199
-
200
- def check_for_project_configs
201
- cd(@base_dir, :verbose => false) do
202
- @projects.each do |p|
203
- abort "project config #{p} cannot be found!" unless File.exists?(p)
204
- end
205
- end
206
- end
207
-
208
- def prepare_block(block, toolchain, build_dir)
209
- block.set_tcs(toolchain) unless block.has_tcs?
210
- block.set_output_dir(Dir.pwd + "/" + build_dir)
211
- block.complete_init()
212
- end
213
-
214
- def register_projects()
215
- cd(@base_dir,:verbose => false) do |b|
216
- @projects.each_with_index do |project_file, i|
217
- @log.debug "register project #{project_file}"
218
- dirname = File.dirname(project_file)
219
- @log.debug "dirname for project was: #{dirname}"
220
- cd(dirname,:verbose => false) do | base_dir |
221
- @log.debug "register project #{project_file} from within directory: #{Dir.pwd}"
222
- eval_file(b, File.basename(project_file))
223
- end
224
- end
225
- end
226
- end
227
-
228
- def eval_file(b, project_file)
229
- loadContext = EvalContext.new
230
- begin
231
- loadContext.eval_project(File.read(File.basename(project_file)), project_file, Dir.pwd)
232
- rescue Exception => e
233
- puts "problems with #{File.join(b, project_file)} in dir: #{Dir.pwd}"
234
- raise e
235
- end
236
-
237
- loadContext.all_blocks.each do |block|
238
- block.
239
- set_project_dir(Dir.pwd).
240
- set_config_files([Dir.pwd + "/" + project_file])
241
- if block.respond_to?(:sources) && block.sources.instance_of?(Rake::FileList)
242
- block.set_sources(block.sources.to_a)
243
- end
244
- end
245
- end
246
-
247
- def define_project_info_task
248
- desc "shows your defined projects"
249
- task :project_info do
250
- ALL_BUILDING_BLOCKS.each_value do |bb|
251
- pp bb
252
- end
253
- end
254
- end
255
-
256
- end
257
- end
@@ -1,6 +0,0 @@
1
- desc 'start a rake console'
2
- task :console do
3
- require 'irb'
4
- ARGV.clear
5
- IRB.start
6
- end
@@ -1,10 +0,0 @@
1
- require 'cxxproject'
2
- BuildDir = "BuildDir"
3
-
4
- unittest_flags = {
5
- :DEFINES => ['UNIT_TEST','CPPUNIT_MAIN=main'],
6
- :FLAGS => "-O0 -g3 -Wall"
7
- }
8
- toolchain = Provider.modify_cpp_compiler("<%= toolchain %>", unittest_flags)
9
- dependent_projects = ['./project.rb']
10
- CxxProject2Rake.new(dependent_projects, BuildDir, toolchain, './')
@@ -1,6 +0,0 @@
1
- cxx_configuration do
2
- <%= building_block %> "<%= name %>",
3
- :sources => FileList['**/*.cpp'],
4
- :includes => ['include'],
5
- :dependencies => []
6
- end
@@ -1,113 +0,0 @@
1
- require 'rake'
2
- require 'erb'
3
- require 'rubygems'
4
-
5
- def prepare_project(dir_name)
6
- begin
7
- require 'highline/import'
8
-
9
- say "This will create a new cxx-project in directory: '#{dir_name}'"
10
- if confirm("Are you sure you want to continue") then
11
- building_block = choose_building_block
12
- generate_makefile = confirm("Do you also whant to generate a rakefile", building_block.eql?("exe"))
13
-
14
- toolchain = nil
15
- if generate_makefile then
16
- toolchain = choose_toolchain
17
- return unless toolchain
18
- end
19
-
20
- create_project(dir_name, building_block, toolchain, generate_makefile)
21
- say "Completed project-setup ;-)"
22
- else
23
- say "Stopped project-setup!"
24
- end
25
-
26
- rescue Interrupt
27
- say "\nStopped project-setup!"
28
- rescue LoadError
29
- say "Please run 'gem install highline'"
30
- end
31
- end
32
-
33
- def choose_building_block
34
- res = nil
35
- choose do |menu|
36
- say "What building-block do you whant to create?"
37
- menu.choice(:exe) { res = "exe" }
38
- menu.choice(:lib) { res = "source_lib" }
39
- menu.prompt = "Select a building-block: "
40
- end
41
- res
42
- end
43
-
44
- def choose_toolchain
45
- res = nil
46
- toolchains = []
47
- toolchain_pattern = /cxxproject_(.*)toolchain/
48
- Gem::Specification.find_all do |gem|
49
- if gem.name =~ toolchain_pattern then
50
- toolchains << $1
51
- end
52
- end
53
- if toolchains.length > 0 then
54
- choose do |menu|
55
- say "What toolchain do you whant to use?"
56
- toolchains.each do |toolchain|
57
- menu.choice(toolchain.to_sym) { res = toolchain }
58
- end
59
- menu.prompt = "Select a toolchain: "
60
- end
61
- else
62
- say "No toolchains installed!"
63
- candidates = `gem list --remote "cxxproject_.*toolchain"`
64
- say "You need at least one toolchain-plugin,- candidates are:\n#{candidates}"
65
- end
66
- res
67
- end
68
-
69
- def create_project(dir_name, building_block, toolchain, generate_rakefile)
70
- rakefile_template = IO.read(File.join(File.dirname(__FILE__),"..","tools","Rakefile.rb.template"))
71
- project_template = IO.read(File.join(File.dirname(__FILE__),"..","tools","project.rb.template"))
72
- binding = create_binding("new-item", building_block, toolchain)
73
-
74
- if !File.directory?(dir_name) then
75
- mkdir_p(dir_name, :verbose => false)
76
- end
77
-
78
- rakefile_file = "#{dir_name}/Rakefile.rb"
79
- if generate_rakefile && (!File.exists?(rakefile_file) || confirm("Override existing '#{rakefile_file}'")) then
80
- write_template(rakefile_file, rakefile_template, binding)
81
- end
82
-
83
- project_file = "#{dir_name}/project.rb"
84
- if !File.exists?(project_file) || confirm("Override existing '#{project_file}'") then
85
- write_template(project_file, project_template, binding)
86
- end
87
- end
88
-
89
- def create_binding(name, building_block, toolchain)
90
- return binding()
91
- end
92
-
93
- def write_template(file_name, template, binding)
94
- say "...write: '#{file_name}'"
95
- File.open(file_name, 'w') do |f|
96
- f.write ERB.new(template).result(binding)
97
- end
98
- end
99
-
100
- def confirm(question, default = true)
101
- res = nil
102
- while res == nil
103
- confirm = ask("#{question}? ") { |q| q.default = default ? "Y/n" : "y/N" }
104
- if confirm.eql?("Y/n") || confirm.downcase.eql?("yes") || confirm.downcase.eql?("y") then
105
- res = true
106
- elsif confirm.eql?("y/N") || confirm.downcase.eql?("no") || confirm.downcase.eql?("n") then
107
- res = false
108
- else
109
- say "Please enter \"yes\" or \"no\"."
110
- end
111
- end
112
- return res
113
- end