cxxproject 0.5.48 → 0.5.59

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. data/Rakefile.rb +116 -116
  2. data/bin/cxx +10 -10
  3. data/lib/cxxproject.rb +23 -23
  4. data/lib/cxxproject/buildingblocks/binary_library.rb +39 -39
  5. data/lib/cxxproject/buildingblocks/building_block.rb +251 -239
  6. data/lib/cxxproject/buildingblocks/command_line.rb +79 -79
  7. data/lib/cxxproject/buildingblocks/custom_building_block.rb +39 -41
  8. data/lib/cxxproject/buildingblocks/executable.rb +257 -249
  9. data/lib/cxxproject/buildingblocks/has_dependencies_mixin.rb +83 -83
  10. data/lib/cxxproject/buildingblocks/has_includes_mixin.rb +20 -20
  11. data/lib/cxxproject/buildingblocks/has_libraries_mixin.rb +34 -34
  12. data/lib/cxxproject/buildingblocks/has_sources_mixin.rb +371 -364
  13. data/lib/cxxproject/buildingblocks/makefile.rb +153 -153
  14. data/lib/cxxproject/buildingblocks/module.rb +35 -35
  15. data/lib/cxxproject/buildingblocks/single_source.rb +33 -33
  16. data/lib/cxxproject/buildingblocks/source_library.rb +124 -124
  17. data/lib/cxxproject/errorparser/diab_compiler_error_parser.rb +40 -40
  18. data/lib/cxxproject/errorparser/diab_linker_error_parser.rb +41 -33
  19. data/lib/cxxproject/errorparser/error_parser.rb +50 -50
  20. data/lib/cxxproject/errorparser/gcc_compiler_error_parser.rb +35 -30
  21. data/lib/cxxproject/errorparser/gcc_linker_error_parser.rb +35 -29
  22. data/lib/cxxproject/errorparser/ti_compiler_error_parser.rb +30 -30
  23. data/lib/cxxproject/errorparser/ti_linker_error_parser.rb +30 -29
  24. data/lib/cxxproject/eval_context.rb +144 -136
  25. data/lib/cxxproject/ext/file.rb +71 -71
  26. data/lib/cxxproject/ext/filelist.rb +6 -6
  27. data/lib/cxxproject/ext/progressbar.rb +20 -20
  28. data/lib/cxxproject/ext/rake.rb +419 -397
  29. data/lib/cxxproject/ext/rake_dirty.rb +30 -30
  30. data/lib/cxxproject/ext/rake_listener.rb +59 -59
  31. data/lib/cxxproject/ext/stdout.rb +44 -44
  32. data/lib/cxxproject/ext/string.rb +9 -9
  33. data/lib/cxxproject/ide_interface.rb +187 -181
  34. data/lib/cxxproject/toolchain/clang.rb +39 -39
  35. data/lib/cxxproject/toolchain/colorizing_formatter.rb +99 -99
  36. data/lib/cxxproject/toolchain/diab.rb +3 -1
  37. data/lib/cxxproject/toolchain/gcc.rb +2 -1
  38. data/lib/cxxproject/toolchain/provider.rb +131 -128
  39. data/lib/cxxproject/toolchain/toolchain.rb +38 -38
  40. data/lib/cxxproject/toolchain/toolchain_benchmark.rb +23 -23
  41. data/lib/cxxproject/torake.rb +218 -216
  42. data/lib/cxxproject/utils/cleanup.rb +20 -20
  43. data/lib/cxxproject/utils/console.rb +6 -6
  44. data/lib/cxxproject/utils/exit_helper.rb +40 -40
  45. data/lib/cxxproject/utils/graphstream.rb +154 -154
  46. data/lib/cxxproject/utils/optional.rb +16 -16
  47. data/lib/cxxproject/utils/printer.rb +50 -50
  48. data/lib/cxxproject/utils/process.rb +52 -52
  49. data/lib/cxxproject/utils/progress.rb +66 -66
  50. data/lib/cxxproject/utils/progress_helper.rb +77 -77
  51. data/lib/cxxproject/utils/rbcurse.rb +284 -284
  52. data/lib/cxxproject/utils/rbcurse_executable_ext.rb +14 -14
  53. data/lib/cxxproject/utils/rbcurse_progress.rb +71 -71
  54. data/lib/cxxproject/utils/rbcurse_tasktable.rb +51 -51
  55. data/lib/cxxproject/utils/stats.rb +60 -60
  56. data/lib/cxxproject/utils/ubigraph.rb +228 -228
  57. data/lib/cxxproject/utils/utils.rb +60 -37
  58. data/lib/cxxproject/utils/valgrind.rb +11 -11
  59. data/lib/cxxproject/version.rb +7 -7
  60. data/lib/tools/Rakefile.rb.template +10 -10
  61. data/lib/tools/project.rb.template +6 -6
  62. data/lib/tools/project_wizard.rb +66 -66
  63. data/spec/building_block_spec.rb +56 -56
  64. data/spec/cxxproject_2_rake_spec.rb +186 -186
  65. data/spec/file_ext_spec.rb +30 -30
  66. data/spec/ide_interface_spec.rb +41 -41
  67. data/spec/object_dependency_spec.rb +83 -83
  68. data/spec/project_path_spec.rb +71 -71
  69. data/spec/rake_listener_ext_spec.rb +58 -58
  70. data/spec/spec_helper.rb +18 -18
  71. data/spec/string_spec.rb +11 -11
  72. data/spec/testdata/basic/exe12/project.rb +5 -5
  73. data/spec/testdata/basic/lib1/project.rb +5 -5
  74. data/spec/testdata/basic/lib2/project.rb +8 -8
  75. data/spec/testdata/multiple_levels/libs/lib1/project.rb +5 -5
  76. data/spec/testdata/multiple_levels/libs/lib2/project.rb +19 -19
  77. data/spec/testdata/multiple_levels/mainproject/basic/project.rb +8 -8
  78. data/spec/testdata/onlyOneHeader/Rakefile.rb +4 -4
  79. data/spec/testdata/onlyOneHeader/project.rb +4 -4
  80. data/spec/toolchain_spec.rb +29 -29
  81. metadata +58 -58
data/Rakefile.rb CHANGED
@@ -1,116 +1,116 @@
1
- require 'rake/clean'
2
- require './rake_helper/spec.rb'
3
-
4
- desc "Default Task"
5
- task :default => [:install]
6
-
7
-
8
- begin
9
- require 'rubygems/package_task'
10
- spec = Gem::Specification.load('cxx.gemspec')
11
- Gem::PackageTask.new(spec){|pkg|}
12
-
13
- desc "install gem globally"
14
- task :install => [:gem] do
15
- sh "gem install pkg/#{spec.name}-#{spec.version}.gem"
16
- end
17
-
18
-
19
- begin
20
- require 'rdoc'
21
- require 'rdoc/task'
22
- RDoc::Task.new do |rd|
23
- rd.rdoc_files.include(spec.files)
24
- end
25
- rescue LoadError => e
26
- task :rdoc do
27
- puts 'please gem install rdoc'
28
- end
29
- end
30
- begin
31
- require 'roodi'
32
- require 'roodi_task'
33
- class RoodiTask
34
- def define
35
- # copied from roodi_task.rb
36
- desc "Check for design issues in: #{patterns.join(', ')}"
37
- task name do
38
- runner = Roodi::Core::Runner.new
39
- runner.config = config if config
40
- patterns.each do |pattern|
41
- Dir.glob(pattern).each { |file| runner.check_file(file) }
42
- end
43
- runner.errors.each {|error| puts error}
44
- # raise "Found #{runner.errors.size} errors." unless runner.errors.empty?
45
- end
46
- self
47
- end
48
- end
49
- RoodiTask.new('roodi', spec.files)
50
- task :gem => [:roodi]
51
- rescue LoadError # don't bail out when people do not have roodi installed!
52
- puts 'please gem install roodi'
53
- end
54
- rescue LoadError => e
55
- puts "please missing gems #{e}"
56
- end
57
-
58
- def two_digits(x)
59
- if x.length > 1
60
- x
61
- else
62
- "0#{x}"
63
- end
64
- end
65
-
66
- begin
67
- require 'grit'
68
- include Grit
69
-
70
- def git_history
71
- repo = Repo.new('.')
72
- tag_names = repo.tags.collect {|t| t.name }
73
- relevant_tags = repo.tags.reject {|t| !t.name.start_with?("v_")}
74
- sorted_tags = relevant_tags.sort_by.each do |t|
75
- /v_(?<x>\d+)\.(?<y>\d+)\.(?<z>\d+)/ =~ t.name
76
- "#{two_digits(x)}-#{two_digits(y)}-#{two_digits(z)}"
77
- end
78
-
79
- change_text = []
80
- zipped = sorted_tags[0..-2].zip(sorted_tags[1..-1])
81
- zipped.reverse.each do |a,b|
82
- change_text << ""
83
- change_text << "#{a.name} => #{b.name}"
84
- change_text << ""
85
- cs = repo.commits_between(a.commit, b.commit)
86
- cm = cs.each do |c|
87
- change_lines = c.message.lines.to_a
88
- first = change_lines.first
89
- change_text << " * " + first + "#{change_lines[1..-1].collect {|l| " #{l}"}.join("")}"
90
- end
91
- end
92
- change_text
93
- end
94
-
95
- desc 'generate version history'
96
- task :generate_history do
97
- puts git_history
98
- end
99
-
100
- desc 'generate and update version history'
101
- task :update_version_history do
102
- change_line = "## Change History:"
103
- readme = 'README.md'
104
- content = File.read(readme)
105
- File.open(readme, 'w') do |f|
106
- f.puts content.gsub(/^#{change_line}.*/m, ([change_line] << git_history).join("\n"))
107
- end
108
- end
109
-
110
- rescue LoadError => e
111
- puts 'to build the version history please gem install grit'
112
- end
113
-
114
-
115
- require './rake_helper/perftools'
116
-
1
+ require 'rake/clean'
2
+ require './rake_helper/spec.rb'
3
+
4
+ desc "Default Task"
5
+ task :default => [:install]
6
+
7
+
8
+ begin
9
+ require 'rubygems/package_task'
10
+ spec = Gem::Specification.load('cxx.gemspec')
11
+ Gem::PackageTask.new(spec){|pkg|}
12
+
13
+ desc "install gem globally"
14
+ task :install => [:gem] do
15
+ sh "gem install pkg/#{spec.name}-#{spec.version}.gem"
16
+ end
17
+
18
+
19
+ begin
20
+ require 'rdoc'
21
+ require 'rdoc/task'
22
+ RDoc::Task.new do |rd|
23
+ rd.rdoc_files.include(spec.files)
24
+ end
25
+ rescue LoadError => e
26
+ task :rdoc do
27
+ puts 'please gem install rdoc'
28
+ end
29
+ end
30
+ begin
31
+ require 'roodi'
32
+ require 'roodi_task'
33
+ class RoodiTask
34
+ def define
35
+ # copied from roodi_task.rb
36
+ desc "Check for design issues in: #{patterns.join(', ')}"
37
+ task name do
38
+ runner = Roodi::Core::Runner.new
39
+ runner.config = config if config
40
+ patterns.each do |pattern|
41
+ Dir.glob(pattern).each { |file| runner.check_file(file) }
42
+ end
43
+ runner.errors.each {|error| puts error}
44
+ # raise "Found #{runner.errors.size} errors." unless runner.errors.empty?
45
+ end
46
+ self
47
+ end
48
+ end
49
+ RoodiTask.new('roodi', spec.files)
50
+ task :gem => [:roodi]
51
+ rescue LoadError # don't bail out when people do not have roodi installed!
52
+ puts 'please gem install roodi'
53
+ end
54
+ rescue LoadError => e
55
+ puts "please missing gems #{e}"
56
+ end
57
+
58
+ def two_digits(x)
59
+ if x.length > 1
60
+ x
61
+ else
62
+ "0#{x}"
63
+ end
64
+ end
65
+
66
+ begin
67
+ require 'grit'
68
+ include Grit
69
+
70
+ def git_history
71
+ repo = Repo.new('.')
72
+ tag_names = repo.tags.collect {|t| t.name }
73
+ relevant_tags = repo.tags.reject {|t| !t.name.start_with?("v_")}
74
+ sorted_tags = relevant_tags.sort_by.each do |t|
75
+ /v_(?<x>\d+)\.(?<y>\d+)\.(?<z>\d+)/ =~ t.name
76
+ "#{two_digits(x)}-#{two_digits(y)}-#{two_digits(z)}"
77
+ end
78
+
79
+ change_text = []
80
+ zipped = sorted_tags[0..-2].zip(sorted_tags[1..-1])
81
+ zipped.reverse.each do |a,b|
82
+ change_text << ""
83
+ change_text << "#{a.name} => #{b.name}"
84
+ change_text << ""
85
+ cs = repo.commits_between(a.commit, b.commit)
86
+ cm = cs.each do |c|
87
+ change_lines = c.message.lines.to_a
88
+ first = change_lines.first
89
+ change_text << " * " + first + "#{change_lines[1..-1].collect {|l| " #{l}"}.join("")}"
90
+ end
91
+ end
92
+ change_text
93
+ end
94
+
95
+ desc 'generate version history'
96
+ task :generate_history do
97
+ puts git_history
98
+ end
99
+
100
+ desc 'generate and update version history'
101
+ task :update_version_history do
102
+ change_line = "## Change History:"
103
+ readme = 'README.md'
104
+ content = File.read(readme)
105
+ File.open(readme, 'w') do |f|
106
+ f.puts content.gsub(/^#{change_line}.*/m, ([change_line] << git_history).join("\n"))
107
+ end
108
+ end
109
+
110
+ rescue LoadError => e
111
+ puts 'to build the version history please gem install grit'
112
+ end
113
+
114
+
115
+ require './rake_helper/perftools'
116
+
data/bin/cxx CHANGED
@@ -1,10 +1,10 @@
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
+ #!/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])
data/lib/cxxproject.rb CHANGED
@@ -1,23 +1,23 @@
1
- # Just the default file wich is auto-required in the gem and which requires all needed stuff
2
- require 'rubygems'
3
- require 'yaml'
4
- require 'rake/clean'
5
-
6
- require 'cxxproject/utils/optional'
7
-
8
- require 'cxxproject/ext/string'
9
- require 'cxxproject/utils/utils'
10
- require 'cxxproject/torake'
11
- require 'cxxproject/utils/ubigraph'
12
- require 'cxxproject/utils/graphstream'
13
- require 'cxxproject/toolchain/provider'
14
-
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
-
21
- include Cxxproject::Toolchain
22
- CxxProject2Rake = Cxxproject::CxxProject2Rake
23
- BinaryLibs = Cxxproject::BinaryLibs
1
+ # Just the default file wich is auto-required in the gem and which requires all needed stuff
2
+ require 'rubygems'
3
+ require 'yaml'
4
+ require 'rake/clean'
5
+
6
+ require 'cxxproject/utils/optional'
7
+
8
+ require 'cxxproject/ext/string'
9
+ require 'cxxproject/utils/utils'
10
+ require 'cxxproject/torake'
11
+ require 'cxxproject/utils/ubigraph'
12
+ require 'cxxproject/utils/graphstream'
13
+ require 'cxxproject/toolchain/provider'
14
+
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
+
21
+ include Cxxproject::Toolchain
22
+ CxxProject2Rake = Cxxproject::CxxProject2Rake
23
+ BinaryLibs = Cxxproject::BinaryLibs
@@ -1,39 +1,39 @@
1
- require 'cxxproject/buildingblocks/building_block'
2
- require 'cxxproject/buildingblocks/has_libraries_mixin'
3
- require 'cxxproject/buildingblocks/has_includes_mixin'
4
-
5
- module Cxxproject
6
-
7
- class BinaryLibrary < BuildingBlock
8
- include HasLibraries
9
- include HasIncludes
10
-
11
- def initialize(name, useNameAsLib = true)
12
- super(name)
13
- if useNameAsLib
14
- @useNameAsLib = name
15
- add_lib_element(HasLibraries::LIB, name, true)
16
- else
17
- @useNameAsLib = nil
18
- end
19
- end
20
-
21
- def get_task_name()
22
- return @useNameAsLib if @useNameAsLib
23
- @name
24
- end
25
-
26
-
27
- def convert_to_rake()
28
- res = task get_task_name
29
- def res.needed?
30
- return false
31
- end
32
- res.transparent_timestamp = true
33
- res.type = Rake::Task::BINARY
34
- setup_rake_dependencies(res)
35
- res
36
- end
37
-
38
- end
39
- end
1
+ require 'cxxproject/buildingblocks/building_block'
2
+ require 'cxxproject/buildingblocks/has_libraries_mixin'
3
+ require 'cxxproject/buildingblocks/has_includes_mixin'
4
+
5
+ module Cxxproject
6
+
7
+ class BinaryLibrary < BuildingBlock
8
+ include HasLibraries
9
+ include HasIncludes
10
+
11
+ def initialize(name, useNameAsLib = true)
12
+ super(name)
13
+ if useNameAsLib
14
+ @useNameAsLib = name
15
+ add_lib_element(HasLibraries::LIB, name, true)
16
+ else
17
+ @useNameAsLib = nil
18
+ end
19
+ end
20
+
21
+ def get_task_name()
22
+ return @useNameAsLib if @useNameAsLib
23
+ @name
24
+ end
25
+
26
+
27
+ def convert_to_rake()
28
+ res = task get_task_name
29
+ def res.needed?
30
+ return false
31
+ end
32
+ res.transparent_timestamp = true
33
+ res.type = Rake::Task::BINARY
34
+ setup_rake_dependencies(res)
35
+ res
36
+ end
37
+
38
+ end
39
+ end
@@ -1,239 +1,251 @@
1
- require 'cxxproject/buildingblocks/has_dependencies_mixin'
2
- require 'cxxproject/utils/exit_helper'
3
- require 'cxxproject/ext/rake'
4
- require 'cxxproject/ext/file'
5
- require 'cxxproject/ide_interface'
6
- require 'cxxproject/utils/printer'
7
-
8
- # no deprecated warning for rake >= 0.9.x
9
- include Rake::DSL if defined?(Rake::DSL)
10
- module Cxxproject
11
-
12
- # stores all defined buildingblocks by name (the name should be unique)
13
- ALL_BUILDING_BLOCKS = {}
14
-
15
- trap("INT") do
16
- Rake.application.idei.set_abort(true)
17
- end
18
-
19
- class BuildingBlock
20
- include HasDependencies
21
-
22
- attr_reader :name
23
- attr_reader :config_name
24
- attr_reader :config_files
25
-
26
- attr_reader :project_dir
27
- attr_accessor :output_dir
28
- attr_accessor :pre_step
29
- attr_reader :output_dir_abs
30
-
31
- def set_name(x)
32
- @name = x
33
- self
34
- end
35
-
36
- def set_tcs(x)
37
- @tcs = x
38
- self
39
- end
40
-
41
- def has_tcs?
42
- @tcs != nil
43
- end
44
-
45
- def tcs()
46
- raise "Toolchain settings must be set before!" if @tcs.nil?
47
- @tcs
48
- end
49
-
50
- def set_config_files(x)
51
- @config_files = x
52
- @config_date = Time.now
53
- self
54
- end
55
-
56
- def set_project_dir(x)
57
- @project_dir = File.expand_path(x)
58
- if @output_dir_abs
59
- @output_dir_relPath = File.rel_from_to_project(@project_dir, @output_dir)
60
- end
61
- self
62
- end
63
-
64
- # if output dir is absolute, -L and -l is used for linker ("linux mode")
65
- def set_output_dir(x)
66
- return self if @output_dir
67
-
68
- @output_dir = x
69
- @output_dir_abs = File.is_absolute?(@output_dir)
70
- if @project_dir
71
- @output_dir_relPath = File.rel_from_to_project(@project_dir, @output_dir)
72
- end
73
- self
74
- end
75
-
76
- def complete_output_dir
77
- @complete_output_dir ||= calc_complete_output_dir
78
- end
79
-
80
- def calc_complete_output_dir
81
- if @output_dir_abs
82
- @output_dir
83
- else
84
- File.join(@project_dir, @output_dir)
85
- end
86
- end
87
-
88
- def initialize(name)
89
- @name = name
90
- @config_name = nil
91
- @config_files = []
92
- @config_date = nil
93
- @project_dir = nil
94
- @tcs = nil
95
- @output_dir = nil
96
- @output_dir_abs = false
97
- @complete_output_dir = nil
98
- @pre_step = nil
99
-
100
- if ALL_BUILDING_BLOCKS.include?(@name) and not self.instance_of?(BinaryLibrary)
101
- raise "building block already exists: #{name}"
102
- else
103
- ALL_BUILDING_BLOCKS[@name] = self
104
- end
105
- end
106
-
107
- def set_config_name(x)
108
- @config_name = x
109
- end
110
-
111
- def complete_init()
112
- if self.respond_to?(:calc_compiler_strings)
113
- calc_compiler_strings
114
- end
115
- end
116
-
117
- def get_task_name()
118
- raise "this method must be implemented by decendants"
119
- end
120
-
121
- ##
122
- # convert all dependencies of a building block to rake task prerequisites (e.g. exe needs lib)
123
- #
124
- def setup_rake_dependencies(task, multitask = nil)
125
- dependencies.reverse_each do |d|
126
- begin
127
- bb = ALL_BUILDING_BLOCKS[d]
128
- raise "Error: tried to add the dependencies of \"#{d}\" to \"#{@name}\" but such a building block could not be found!" unless bb
129
-
130
- if multitask and bb.pre_step
131
- multitask.prerequisites.unshift(bb.get_task_name)
132
- else
133
- task.prerequisites.unshift(bb.get_task_name)
134
- end
135
- rescue ExitHelperException
136
- raise
137
- rescue Exception => e
138
- Printer.printError e.message
139
- ExitHelper.exit(1)
140
- end
141
- end
142
-
143
- task
144
- end
145
-
146
- def add_output_dir_dependency(file, taskOfFile, addDirToCleanTask)
147
- d = File.dirname(file)
148
- directory d
149
- taskOfFile.enhance([d])
150
-
151
- if addDirToCleanTask
152
- CLOBBER.include(complete_output_dir)
153
- if (@output_dir_abs)
154
- CLEAN.include(file)
155
- else
156
- CLEAN.include(complete_output_dir)
157
- end
158
- end
159
- end
160
-
161
- def process_result(cmd, console_output, error_parser, alternate)
162
-
163
- hasError = ($?.success? == false)
164
-
165
- if hasError or RakeFileUtils.verbose or (alternate.nil? and not Rake::application.options.silent)
166
- exedIn = ""
167
- exedIn = " (executed in '#{@project_dir}')" if (hasError or RakeFileUtils.verbose)
168
- if cmd.is_a?(Array)
169
- puts cmd.join(' ') + exedIn
170
- else
171
- puts cmd + exedIn
172
- end
173
- else
174
- puts alternate unless Rake::application.options.silent
175
- end
176
-
177
- errorPrinted = process_console_output(console_output, error_parser)
178
-
179
- if hasError
180
- if not errorPrinted
181
- Printer.printError "Error: system command failed"
182
- res = ErrorDesc.new
183
- res.file_name = @project_dir
184
- res.line_number = 0
185
- res.message = "Unknown error, see log output. Maybe the lake error parser has to be updated..."
186
- res.severity = ErrorParser::SEVERITY_ERROR
187
- Rake.application.idei.set_errors([res])
188
- end
189
-
190
- raise SystemCommandFailed.new
191
- end
192
- end
193
-
194
- def read_file_or_empty_string(filename)
195
- begin
196
- return File.read(filename)
197
- rescue
198
- return ""
199
- end
200
- end
201
-
202
- def typed_file_task(type, *args, &block)
203
- t = file *args do
204
- block.call
205
- end
206
- t.type = type
207
- t.progress_count = 1
208
- return t
209
- end
210
-
211
- def remove_empty_strings_and_join(a, j=' ')
212
- return a.reject{|e|e.to_s.empty?}.join(j)
213
- end
214
-
215
- def catch_output(cmd)
216
- new_command = "#{cmd} 2>&1"
217
- # "/" does not work on windows with backticks, switch the separator on windows:
218
- new_command.gsub!(File::SEPARATOR, File::ALT_SEPARATOR) if File::ALT_SEPARATOR
219
- return `#{new_command}`
220
- end
221
-
222
- def check_config_file()
223
- if @config_date
224
- @config_files.each do |c|
225
- err_msg = nil
226
- if File.exists?(c) and File.mtime(c) > @config_date
227
- @config_date = File.mtime(c)
228
- begin
229
- FileUtils.touch(c)
230
- rescue Exception
231
- end
232
- end
233
- end
234
- end
235
- end
236
-
237
- end
238
-
239
- end
1
+ require 'cxxproject/buildingblocks/has_dependencies_mixin'
2
+ require 'cxxproject/utils/exit_helper'
3
+ require 'cxxproject/ext/rake'
4
+ require 'cxxproject/ext/file'
5
+ require 'cxxproject/ide_interface'
6
+ require 'cxxproject/utils/printer'
7
+
8
+ # no deprecated warning for rake >= 0.9.x
9
+ include Rake::DSL if defined?(Rake::DSL)
10
+ module Cxxproject
11
+
12
+ # stores all defined buildingblocks by name (the name should be unique)
13
+ ALL_BUILDING_BLOCKS = {}
14
+
15
+ trap("INT") do
16
+ Rake.application.idei.set_abort(true)
17
+ end
18
+
19
+ class BuildingBlock
20
+ include HasDependencies
21
+
22
+ attr_reader :name
23
+ attr_reader :config_name
24
+ attr_reader :config_files
25
+
26
+ attr_reader :project_dir
27
+ attr_accessor :output_dir
28
+ attr_accessor :pre_step
29
+ attr_reader :output_dir_abs
30
+
31
+ def set_name(x)
32
+ @name = x
33
+ self
34
+ end
35
+
36
+ def set_tcs(x)
37
+ @tcs = x
38
+ self
39
+ end
40
+
41
+ def has_tcs?
42
+ @tcs != nil
43
+ end
44
+
45
+ def tcs()
46
+ raise "Toolchain settings must be set before!" if @tcs.nil?
47
+ @tcs
48
+ end
49
+
50
+ def set_config_files(x)
51
+ @config_files = x
52
+ @config_date = Time.now
53
+ self
54
+ end
55
+
56
+ def set_project_dir(x)
57
+ @project_dir = File.expand_path(x)
58
+ if @output_dir_abs
59
+ @output_dir_relPath = File.rel_from_to_project(@project_dir, @output_dir)
60
+ end
61
+ self
62
+ end
63
+
64
+ # if output dir is absolute, -L and -l is used for linker ("linux mode")
65
+ def set_output_dir(x)
66
+ return self if @output_dir
67
+
68
+ @output_dir = x
69
+ @output_dir_abs = File.is_absolute?(@output_dir)
70
+ if @project_dir
71
+ @output_dir_relPath = File.rel_from_to_project(@project_dir, @output_dir)
72
+ end
73
+ self
74
+ end
75
+
76
+ def complete_output_dir
77
+ @complete_output_dir ||= calc_complete_output_dir
78
+ end
79
+
80
+ def calc_complete_output_dir
81
+ if @output_dir_abs
82
+ @output_dir
83
+ else
84
+ File.join(@project_dir, @output_dir)
85
+ end
86
+ end
87
+
88
+ def initialize(name)
89
+ @name = name
90
+ @config_name = nil
91
+ @config_files = []
92
+ @config_date = nil
93
+ @project_dir = nil
94
+ @tcs = nil
95
+ @output_dir = nil
96
+ @output_dir_abs = false
97
+ @complete_output_dir = nil
98
+ @pre_step = nil
99
+ @printedCmdAlternate = false
100
+ @lastCommand = nil
101
+
102
+ if ALL_BUILDING_BLOCKS.include?(@name) and not self.instance_of?(BinaryLibrary)
103
+ raise "building block already exists: #{name}"
104
+ else
105
+ ALL_BUILDING_BLOCKS[@name] = self
106
+ end
107
+ end
108
+
109
+ def set_config_name(x)
110
+ @config_name = x
111
+ end
112
+
113
+ def complete_init()
114
+ if self.respond_to?(:calc_compiler_strings)
115
+ calc_compiler_strings
116
+ end
117
+ end
118
+
119
+ def get_task_name()
120
+ raise "this method must be implemented by decendants"
121
+ end
122
+
123
+ ##
124
+ # convert all dependencies of a building block to rake task prerequisites (e.g. exe needs lib)
125
+ #
126
+ def setup_rake_dependencies(task, multitask = nil)
127
+ dependencies.reverse_each do |d|
128
+ begin
129
+ bb = ALL_BUILDING_BLOCKS[d]
130
+ raise "Error: tried to add the dependencies of \"#{d}\" to \"#{@name}\" but such a building block could not be found!" unless bb
131
+
132
+ if multitask and bb.pre_step
133
+ multitask.prerequisites.unshift(bb.get_task_name)
134
+ else
135
+ task.prerequisites.unshift(bb.get_task_name)
136
+ end
137
+ rescue ExitHelperException
138
+ raise
139
+ rescue Exception => e
140
+ Printer.printError e.message
141
+ ExitHelper.exit(1)
142
+ end
143
+ end
144
+
145
+ task
146
+ end
147
+
148
+ def add_output_dir_dependency(file, taskOfFile, addDirToCleanTask)
149
+ d = File.dirname(file)
150
+ directory d
151
+ taskOfFile.enhance([d])
152
+
153
+ if addDirToCleanTask
154
+ CLOBBER.include(complete_output_dir)
155
+ if (@output_dir_abs)
156
+ CLEAN.include(file)
157
+ else
158
+ CLEAN.include(complete_output_dir)
159
+ end
160
+ end
161
+ end
162
+
163
+ def printCmd(cmd, alternate, showPath)
164
+ @lastCommand = cmd
165
+ if showPath or RakeFileUtils.verbose or (alternate.nil? and not Rake::application.options.silent)
166
+ @printedCmdAlternate = false
167
+ exedIn = ""
168
+ exedIn = " (executed in '#{@project_dir}')" if (showPath or RakeFileUtils.verbose)
169
+ puts "" if Rake::application.addEmptyLine
170
+ if cmd.is_a?(Array)
171
+ puts cmd.join(' ') + exedIn
172
+ else
173
+ puts cmd + exedIn
174
+ end
175
+ else
176
+ @printedCmdAlternate = true
177
+ puts alternate unless Rake::application.options.silent
178
+ end
179
+ @lastCommand = cmd
180
+ end
181
+
182
+
183
+ def process_result(cmd, console_output, error_parser, alternate)
184
+ hasError = ($?.success? == false)
185
+ if (cmd != @lastCommand) or (@printedCmdAlternate and hasError)
186
+ printCmd(cmd, alternate, hasError)
187
+ end
188
+ errorPrinted = process_console_output(console_output, error_parser)
189
+
190
+ if hasError
191
+ if not errorPrinted
192
+ Printer.printError "Error: system command failed"
193
+ res = ErrorDesc.new
194
+ res.file_name = @project_dir
195
+ res.line_number = 0
196
+ res.message = "Unknown error, see log output. Maybe the lake error parser has to be updated..."
197
+ res.severity = ErrorParser::SEVERITY_ERROR
198
+ Rake.application.idei.set_errors([res])
199
+ end
200
+ end
201
+ if hasError or errorPrinted
202
+ raise SystemCommandFailed.new
203
+ end
204
+ end
205
+
206
+ def read_file_or_empty_string(filename)
207
+ begin
208
+ return File.read(filename)
209
+ rescue
210
+ return ""
211
+ end
212
+ end
213
+
214
+ def typed_file_task(type, *args, &block)
215
+ t = file *args do
216
+ block.call
217
+ end
218
+ t.type = type
219
+ t.progress_count = 1
220
+ return t
221
+ end
222
+
223
+ def remove_empty_strings_and_join(a, j=' ')
224
+ return a.reject{|e|e.to_s.empty?}.join(j)
225
+ end
226
+
227
+ def catch_output(cmd)
228
+ new_command = "#{cmd} 2>&1"
229
+ # "/" does not work on windows with backticks, switch the separator on windows:
230
+ new_command.gsub!(File::SEPARATOR, File::ALT_SEPARATOR) if File::ALT_SEPARATOR
231
+ return `#{new_command}`
232
+ end
233
+
234
+ def check_config_file()
235
+ if @config_date
236
+ @config_files.each do |c|
237
+ err_msg = nil
238
+ if File.exists?(c) and File.mtime(c) > @config_date
239
+ @config_date = File.mtime(c)
240
+ begin
241
+ FileUtils.touch(c)
242
+ rescue Exception
243
+ end
244
+ end
245
+ end
246
+ end
247
+ end
248
+
249
+ end
250
+
251
+ end