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
@@ -1,79 +1,79 @@
1
- require 'cxxproject/buildingblocks/building_block'
2
- require 'cxxproject/utils/process'
3
-
4
- module Cxxproject
5
-
6
- class CommandLine < BuildingBlock
7
-
8
- def set_command_line(x)
9
- @line = x
10
- self
11
- end
12
-
13
- def get_command_line
14
- @line
15
- end
16
-
17
- def set_defined_in_file(x)
18
- @defined_in_file = x
19
- self
20
- end
21
-
22
- def get_defined_in_file
23
- @defined_in_file
24
- end
25
-
26
- def set_defined_in_line(x)
27
- @defined_in_line = x
28
- self
29
- end
30
-
31
- def get_defined_in_line
32
- @defined_in_line
33
- end
34
-
35
- def initialize(name)
36
- set_command_line(name)
37
- @num = Rake.application.command_line_number
38
- super(get_task_name)
39
- end
40
-
41
- def get_task_name()
42
- "command line (#{@num}): " + get_command_line
43
- end
44
-
45
- def convert_to_rake()
46
- res = task get_task_name do
47
- Dir.chdir(@project_dir) do
48
- check_config_file
49
- cmd = get_command_line
50
- puts cmd + (RakeFileUtils.verbose ? " (executed in '#{@project_dir}')" : "")
51
- cmd_result = false
52
- begin
53
- cmd_result = ProcessHelper.spawnProcess(cmd + " 2>&1")
54
- rescue
55
- end
56
- if (cmd_result == false)
57
- if Rake.application.idei
58
- err_res = ErrorDesc.new
59
- err_res.file_name = (@defined_in_file ? @defined_in_file : @project_dir)
60
- err_res.line_number = (@defined_in_line ? @defined_in_line : 0)
61
- err_res.severity = ErrorParser::SEVERITY_ERROR
62
- err_res.message = "Command \"#{get_command_line}\" failed"
63
- Rake.application.idei.set_errors([err_res])
64
- end
65
- Printer.printError "Error: command \"#{get_command_line}\" failed" + (RakeFileUtils.verbose ? "" : " (executed in '#{@project_dir}')")
66
- raise SystemCommandFailed.new
67
- end
68
- end
69
- end
70
- res.immediate_output = true
71
- res.transparent_timestamp = true
72
- res.type = Rake::Task::COMMANDLINE
73
- setup_rake_dependencies(res)
74
- res
75
- end
76
-
77
-
78
- end
79
- end
1
+ require 'cxxproject/buildingblocks/building_block'
2
+ require 'cxxproject/utils/process'
3
+
4
+ module Cxxproject
5
+
6
+ class CommandLine < BuildingBlock
7
+
8
+ def set_command_line(x)
9
+ @line = x
10
+ self
11
+ end
12
+
13
+ def get_command_line
14
+ @line
15
+ end
16
+
17
+ def set_defined_in_file(x)
18
+ @defined_in_file = x
19
+ self
20
+ end
21
+
22
+ def get_defined_in_file
23
+ @defined_in_file
24
+ end
25
+
26
+ def set_defined_in_line(x)
27
+ @defined_in_line = x
28
+ self
29
+ end
30
+
31
+ def get_defined_in_line
32
+ @defined_in_line
33
+ end
34
+
35
+ def initialize(name)
36
+ set_command_line(name)
37
+ @num = Rake.application.command_line_number
38
+ super(get_task_name)
39
+ end
40
+
41
+ def get_task_name()
42
+ "command line (#{@num}): " + get_command_line
43
+ end
44
+
45
+ def convert_to_rake()
46
+ res = task get_task_name do
47
+ Dir.chdir(@project_dir) do
48
+ check_config_file
49
+ cmd = get_command_line
50
+ puts cmd + (RakeFileUtils.verbose ? " (executed in '#{@project_dir}')" : "")
51
+ cmd_result = false
52
+ begin
53
+ cmd_result = ProcessHelper.spawnProcess(cmd + " 2>&1")
54
+ rescue
55
+ end
56
+ if (cmd_result == false)
57
+ if Rake.application.idei
58
+ err_res = ErrorDesc.new
59
+ err_res.file_name = (@defined_in_file ? @defined_in_file : @project_dir)
60
+ err_res.line_number = (@defined_in_line ? @defined_in_line : 0)
61
+ err_res.severity = ErrorParser::SEVERITY_ERROR
62
+ err_res.message = "Command \"#{get_command_line}\" failed"
63
+ Rake.application.idei.set_errors([err_res])
64
+ end
65
+ Printer.printError "Error: command \"#{get_command_line}\" failed" + (RakeFileUtils.verbose ? "" : " (executed in '#{@project_dir}')")
66
+ raise SystemCommandFailed.new
67
+ end
68
+ end
69
+ end
70
+ res.immediate_output = true
71
+ res.transparent_timestamp = true
72
+ res.type = Rake::Task::COMMANDLINE
73
+ setup_rake_dependencies(res)
74
+ res
75
+ end
76
+
77
+
78
+ end
79
+ end
@@ -1,41 +1,39 @@
1
- require 'cxxproject/buildingblocks/building_block'
2
-
3
- # todo...
4
- module Cxxproject
5
-
6
- class CustomBuildingBlock < BuildingBlock
7
- attr_reader :custom_command, :actions
8
-
9
- def set_custom_command(c)
10
- @custom_command = c
11
- self
12
- end
13
-
14
- def get_task_name()
15
- name
16
- end
17
-
18
- def set_actions(actions)
19
- if actions.kind_of?(Array)
20
- @actions = actions
21
- else
22
- @actions = [actions]
23
- end
24
- end
25
-
26
- def convert_to_rake()
27
- desc get_task_name
28
- res = task get_task_name do
29
- actions.each do |a|
30
- a.call
31
- end
32
- end
33
- res.type = Rake::Task::CUSTOM
34
- setup_rake_dependencies(res)
35
- res
36
- end
37
-
38
-
39
-
40
- end
41
- end
1
+ require 'cxxproject/buildingblocks/building_block'
2
+
3
+ # todo...
4
+ module Cxxproject
5
+
6
+ class CustomBuildingBlock < BuildingBlock
7
+ attr_reader :custom_command, :actions
8
+
9
+ def set_custom_command(c)
10
+ @custom_command = c
11
+ self
12
+ end
13
+
14
+ def get_task_name()
15
+ name
16
+ end
17
+
18
+ def set_actions(actions)
19
+ if actions.kind_of?(Array)
20
+ @actions = actions
21
+ else
22
+ @actions = [actions]
23
+ end
24
+ end
25
+
26
+ def convert_to_rake()
27
+ desc get_task_name
28
+ res = task get_task_name do
29
+ actions.each do |a|
30
+ a.call
31
+ end
32
+ end
33
+ res.type = Rake::Task::CUSTOM
34
+ setup_rake_dependencies(res)
35
+ res
36
+ end
37
+
38
+ end
39
+ end
@@ -1,249 +1,257 @@
1
- require 'cxxproject/buildingblocks/building_block'
2
- require 'cxxproject/buildingblocks/has_libraries_mixin'
3
- require 'cxxproject/buildingblocks/has_sources_mixin'
4
- require 'cxxproject/buildingblocks/has_includes_mixin'
5
- require 'cxxproject/utils/process'
6
- require 'cxxproject/utils/utils'
7
-
8
- require 'tmpdir'
9
- require 'set'
10
- require 'etc'
11
-
12
- module Cxxproject
13
-
14
- class Executable < BuildingBlock
15
- include HasLibraries
16
- include HasSources
17
- include HasIncludes
18
-
19
- def set_linker_script(x)
20
- @linker_script = x
21
- self
22
- end
23
-
24
- def set_mapfile(x)
25
- @mapfile = x
26
- self
27
- end
28
-
29
- def initialize(name)
30
- super(name)
31
- @linker_script = nil
32
- @mapfile = nil
33
- end
34
-
35
- def set_executable_name(name) # ensure it's relative
36
- @exe_name = name
37
- end
38
-
39
- def get_executable_name() # relative path
40
- return @exe_name if @exe_name
41
-
42
- parts = [@output_dir]
43
-
44
- if @output_dir_abs
45
- parts = [@output_dir_relPath] if @output_dir_relPath
46
- end
47
-
48
- parts << "#{@name}#{@tcs[:LINKER][:OUTPUT_ENDING]}"
49
-
50
- @exe_name = File.join(parts)
51
- @exe_name
52
- end
53
-
54
- def get_task_name() # full path
55
- @project_dir + "/" + get_executable_name
56
- end
57
-
58
- def collect_unique(array, set)
59
- ret = []
60
- array.each do |v|
61
- if set.add?(v)
62
- ret << v
63
- end
64
- end
65
- ret
66
- end
67
-
68
- def adaptPath(v, d, prefix)
69
- tmp = nil
70
- if File.is_absolute?(v)
71
- tmp = v
72
- else
73
- prefix ||= File.rel_from_to_project(@project_dir,d.project_dir)
74
- tmp = File.add_prefix(prefix, v)
75
- end
76
- tmp = "\"" + tmp + "\"" if tmp.include?(" ")
77
- [tmp, prefix]
78
- end
79
-
80
- def linker_lib_string()
81
- @lib_path_set = Set.new
82
- @dep_set = Set.new
83
- calc_linker_lib_string_recursive(self)
84
- end
85
-
86
- def calc_linker_lib_string_recursive(d)
87
- res = []
88
-
89
- return res if @dep_set.include?d
90
- @dep_set << d
91
-
92
- if HasLibraries === d
93
- prefix = nil
94
- linker = @tcs[:LINKER]
95
-
96
- d.lib_elements.each do |elem|
97
- case elem[0]
98
- when HasLibraries::LIB
99
- res << "#{linker[:LIB_FLAG]}#{elem[1]}"
100
- when HasLibraries::USERLIB
101
- res << "#{linker[:USER_LIB_FLAG]}#{elem[1]}"
102
- when HasLibraries::LIB_WITH_PATH
103
- tmp, prefix = adaptPath(elem[1], d, prefix)
104
- res << tmp
105
- when HasLibraries::SEARCH_PATH
106
- tmp, prefix = adaptPath(elem[1], d, prefix)
107
- if not @lib_path_set.include?tmp
108
- @lib_path_set << tmp
109
- res << "#{linker[:LIB_PATH_FLAG]}#{tmp}"
110
- end
111
- when HasLibraries::DEPENDENCY
112
- if ALL_BUILDING_BLOCKS.include?elem[1]
113
- bb = ALL_BUILDING_BLOCKS[elem[1]]
114
- res += calc_linker_lib_string_recursive(bb)
115
- end
116
- end
117
- end
118
- end
119
-
120
- res
121
- end
122
-
123
- # create a task that will link an executable from a set of object files
124
- #
125
- def convert_to_rake()
126
- object_multitask = prepare_tasks_for_objects()
127
-
128
- linker = @tcs[:LINKER]
129
-
130
- res = typed_file_task Rake::Task::EXECUTABLE, get_task_name => object_multitask do
131
- Dir.chdir(@project_dir) do
132
-
133
- cmd = [linker[:COMMAND]] # g++
134
- cmd += linker[:MUST_FLAGS].split(" ")
135
- cmd += linker[:FLAGS].gsub(/\"/,"").split(" ") # double quotes within string do not work on windows...
136
- cmd << linker[:EXE_FLAG]
137
- cmd << get_executable_name # -o debug/x.exe
138
- cmd += @objects
139
- cmd << linker[:SCRIPT] if @linker_script # -T
140
- cmd << @linker_script if @linker_script # xy/xy.dld
141
- cmd << linker[:MAP_FILE_FLAG] if @mapfile # -Wl,-m6
142
- cmd += linker[:LIB_PREFIX_FLAGS].split(" ") # "-Wl,--whole-archive "
143
- cmd += linker_lib_string
144
- cmd += linker[:LIB_POSTFIX_FLAGS].split(" ") # "-Wl,--no-whole-archive "
145
-
146
- mapfileStr = @mapfile ? " >#{@mapfile}" : ""
147
- if Cxxproject::Utils.old_ruby?
148
- cmd.map! {|c| ((c.include?(" ")) ? ("\""+c+"\"") : c )}
149
-
150
- # TempFile used, because some compilers, e.g. diab, uses ">" for piping to map files:
151
- cmdLine = cmd.join(" ") + " 2>" + get_temp_filename
152
- if cmdLine.length > 8000
153
- inputName = get_executable_name+".tmp"
154
- File.open(inputName,"wb") { |f| f.write(cmd[1..-1].join(" ")) }
155
- inputName = "\""+inputName+"\"" if inputName.include?" "
156
- consoleOutput = `#{linker[:COMMAND] + " @" + inputName + mapfileStr + " 2>" + get_temp_filename}`
157
- else
158
- consoleOutput = `#{cmd.join(" ") + mapfileStr + " 2>" + get_temp_filename}`
159
- end
160
- consoleOutput.concat(read_file_or_empty_string(get_temp_filename))
161
- else
162
- rd, wr = IO.pipe
163
- cmd << {
164
- :out=> @mapfile ? "#{@mapfile}" : wr, # > xy.map
165
- :err=>wr
166
- }
167
- sp = spawn(*cmd)
168
- cmd.pop
169
-
170
- # for console print
171
- cmd << " >#{@mapfile}" if @mapfile
172
- consoleOutput = ProcessHelper.readOutput(sp, rd, wr)
173
- end
174
-
175
- process_result(cmd, consoleOutput, linker[:ERROR_PARSER], "Linking #{get_executable_name}")
176
-
177
- check_config_file()
178
- end
179
- end
180
- res.enhance(@config_files)
181
- res.enhance([@project_dir + "/" + @linker_script]) if @linker_script
182
-
183
- add_output_dir_dependency(get_task_name, res, true)
184
- add_grouping_tasks(get_task_name)
185
- setup_rake_dependencies(res, object_multitask)
186
-
187
- # check that all source libs are checked even if they are not a real rake dependency (can happen if "build this project only")
188
- begin
189
- libChecker = task get_task_name+"LibChecker" do
190
- if File.exists?(get_task_name) # otherwise the task will be executed anyway
191
- all_dependencies.each do |bb|
192
- if bb and SourceLibrary === bb
193
- f = bb.get_task_name # = abs path of library
194
- if not File.exists?(f) or File.mtime(f) > File.mtime(get_task_name)
195
- def res.needed?
196
- true
197
- end
198
- break
199
- end
200
- end
201
- end
202
- end
203
- end
204
- rescue
205
- def res.needed?
206
- true
207
- end
208
- end
209
- libChecker.transparent_timestamp = true
210
- res.enhance([libChecker])
211
-
212
- return res
213
- end
214
-
215
- def add_grouping_tasks(executable)
216
- namespace 'exe' do
217
- desc executable
218
- task @name => executable
219
- end
220
- create_run_task(executable, @name)
221
- end
222
-
223
- def create_run_task(executable, name)
224
- namespace 'run' do
225
- desc "run executable #{executable}"
226
- res = task name => executable do |t|
227
- sh executable
228
- end
229
- res.type = Rake::Task::RUN
230
- res
231
- end
232
- if Valgrind::available?
233
- namespace 'valgrind' do
234
- desc "run executable #{executable} with valgrind"
235
- res = task name => executable do |t|
236
- sh "valgrind #{executable}"
237
- end
238
- res.type = Rake::Task::RUN
239
- res
240
- end
241
- end
242
- end
243
-
244
- def get_temp_filename
245
- Dir.tmpdir + "/lake.tmp"
246
- end
247
-
248
- end
249
- end
1
+ require 'cxxproject/buildingblocks/building_block'
2
+ require 'cxxproject/buildingblocks/has_libraries_mixin'
3
+ require 'cxxproject/buildingblocks/has_sources_mixin'
4
+ require 'cxxproject/buildingblocks/has_includes_mixin'
5
+ require 'cxxproject/utils/process'
6
+ require 'cxxproject/utils/utils'
7
+ require 'cxxproject/ext/stdout'
8
+ require 'cxxproject/utils/valgrind'
9
+
10
+ require 'tmpdir'
11
+ require 'set'
12
+ require 'etc'
13
+
14
+ module Cxxproject
15
+
16
+ class Executable < BuildingBlock
17
+ include HasLibraries
18
+ include HasSources
19
+ include HasIncludes
20
+
21
+ def set_linker_script(x)
22
+ @linker_script = x
23
+ self
24
+ end
25
+
26
+ def set_mapfile(x)
27
+ @mapfile = x
28
+ self
29
+ end
30
+
31
+ def initialize(name)
32
+ super(name)
33
+ @linker_script = nil
34
+ @mapfile = nil
35
+ end
36
+
37
+ def set_executable_name(name) # ensure it's relative
38
+ @exe_name = name
39
+ end
40
+
41
+ def get_executable_name() # relative path
42
+ return @exe_name if @exe_name
43
+
44
+ parts = [@output_dir]
45
+
46
+ if @output_dir_abs
47
+ parts = [@output_dir_relPath] if @output_dir_relPath
48
+ end
49
+
50
+ parts << "#{@name}#{@tcs[:LINKER][:OUTPUT_ENDING]}"
51
+
52
+ @exe_name = File.join(parts)
53
+ @exe_name
54
+ end
55
+
56
+ def get_task_name() # full path
57
+ @project_dir + "/" + get_executable_name
58
+ end
59
+
60
+ def collect_unique(array, set)
61
+ ret = []
62
+ array.each do |v|
63
+ if set.add?(v)
64
+ ret << v
65
+ end
66
+ end
67
+ ret
68
+ end
69
+
70
+ def adaptPath(v, d, prefix)
71
+ tmp = nil
72
+ if File.is_absolute?(v)
73
+ tmp = v
74
+ else
75
+ prefix ||= File.rel_from_to_project(@project_dir,d.project_dir)
76
+ tmp = File.add_prefix(prefix, v)
77
+ end
78
+ tmp = "\"" + tmp + "\"" if tmp.include?(" ")
79
+ [tmp, prefix]
80
+ end
81
+
82
+ def linker_lib_string()
83
+ @lib_path_set = Set.new
84
+ @dep_set = Set.new
85
+ calc_linker_lib_string_recursive(self)
86
+ end
87
+
88
+ def calc_linker_lib_string_recursive(d)
89
+ res = []
90
+
91
+ return res if @dep_set.include?d
92
+ @dep_set << d
93
+
94
+ if HasLibraries === d
95
+ prefix = nil
96
+ linker = @tcs[:LINKER]
97
+
98
+ d.lib_elements.each do |elem|
99
+ case elem[0]
100
+ when HasLibraries::LIB
101
+ res << "#{linker[:LIB_FLAG]}#{elem[1]}"
102
+ when HasLibraries::USERLIB
103
+ res << "#{linker[:USER_LIB_FLAG]}#{elem[1]}"
104
+ when HasLibraries::LIB_WITH_PATH
105
+ tmp, prefix = adaptPath(elem[1], d, prefix)
106
+ res << tmp
107
+ when HasLibraries::SEARCH_PATH
108
+ tmp, prefix = adaptPath(elem[1], d, prefix)
109
+ if not @lib_path_set.include?tmp
110
+ @lib_path_set << tmp
111
+ res << "#{linker[:LIB_PATH_FLAG]}#{tmp}"
112
+ end
113
+ when HasLibraries::DEPENDENCY
114
+ if ALL_BUILDING_BLOCKS.include?elem[1]
115
+ bb = ALL_BUILDING_BLOCKS[elem[1]]
116
+ res += calc_linker_lib_string_recursive(bb)
117
+ end
118
+ end
119
+ end
120
+ end
121
+
122
+ res
123
+ end
124
+
125
+ # create a task that will link an executable from a set of object files
126
+ #
127
+ def convert_to_rake()
128
+ object_multitask = prepare_tasks_for_objects()
129
+
130
+ linker = @tcs[:LINKER]
131
+
132
+ res = typed_file_task Rake::Task::EXECUTABLE, get_task_name => object_multitask do
133
+ Dir.chdir(@project_dir) do
134
+
135
+ cmd = [linker[:COMMAND]] # g++
136
+ cmd += linker[:MUST_FLAGS].split(" ")
137
+ cmd += Cxxproject::Utils::flagSplit(linker[:FLAGS])
138
+ cmd << linker[:EXE_FLAG]
139
+ cmd << get_executable_name # -o debug/x.exe
140
+ cmd += @objects
141
+ cmd << linker[:SCRIPT] if @linker_script # -T
142
+ cmd << @linker_script if @linker_script # xy/xy.dld
143
+ cmd << linker[:MAP_FILE_FLAG] if @mapfile # -Wl,-m6
144
+ cmd += Cxxproject::Utils::flagSplit(linker[:LIB_PREFIX_FLAGS]) # "-Wl,--whole-archive "
145
+ cmd += linker_lib_string
146
+ cmd += Cxxproject::Utils::flagSplit(linker[:LIB_POSTFIX_FLAGS]) # "-Wl,--no-whole-archive "
147
+
148
+ mapfileStr = @mapfile ? " >#{@mapfile}" : ""
149
+ if Cxxproject::Utils.old_ruby?
150
+ cmd.map! {|c| ((c.include?(" ")) ? ("\""+c+"\"") : c )}
151
+
152
+ # TempFile used, because some compilers, e.g. diab, uses ">" for piping to map files:
153
+ cmdLinePrint = cmd.join(" ")
154
+ cmdLine = cmdLinePrint + " 2>" + get_temp_filename
155
+ if cmdLine.length > 8000
156
+ inputName = get_executable_name+".tmp"
157
+ File.open(inputName,"wb") { |f| f.write(cmd[1..-1].join(" ")) }
158
+ inputName = "\""+inputName+"\"" if inputName.include?" "
159
+ strCmd = "#{linker[:COMMAND] + " @" + inputName + mapfileStr + " 2>" + get_temp_filename}"
160
+ else
161
+ strCmd = "#{cmd.join(" ") + mapfileStr + " 2>" + get_temp_filename}"
162
+ end
163
+ printCmd(cmdLinePrint, "Linking #{get_executable_name}", false)
164
+ consoleOutput = `#{strCmd}`
165
+ consoleOutput.concat(read_file_or_empty_string(get_temp_filename))
166
+ else
167
+ rd, wr = IO.pipe
168
+ cmdLinePrint = cmd
169
+ printCmd(cmdLinePrint, "Linking #{get_executable_name}", false)
170
+ cmd << {
171
+ :out=> @mapfile ? "#{@mapfile}" : wr, # > xy.map
172
+ :err=>wr
173
+ }
174
+ sp = spawn(*cmd)
175
+ cmd.pop
176
+
177
+ # for console print
178
+ cmd << " >#{@mapfile}" if @mapfile
179
+ consoleOutput = ProcessHelper.readOutput(sp, rd, wr)
180
+ end
181
+
182
+ process_result(cmdLinePrint, consoleOutput, linker[:ERROR_PARSER], nil)
183
+
184
+ check_config_file()
185
+ end
186
+ end
187
+ res.immediate_output = true
188
+ res.enhance(@config_files)
189
+ res.enhance([@project_dir + "/" + @linker_script]) if @linker_script
190
+
191
+ add_output_dir_dependency(get_task_name, res, true)
192
+ add_grouping_tasks(get_task_name)
193
+ setup_rake_dependencies(res, object_multitask)
194
+
195
+ # check that all source libs are checked even if they are not a real rake dependency (can happen if "build this project only")
196
+ begin
197
+ libChecker = task get_task_name+"LibChecker" do
198
+ if File.exists?(get_task_name) # otherwise the task will be executed anyway
199
+ all_dependencies.each do |bb|
200
+ if bb and SourceLibrary === bb
201
+ f = bb.get_task_name # = abs path of library
202
+ if not File.exists?(f) or File.mtime(f) > File.mtime(get_task_name)
203
+ def res.needed?
204
+ true
205
+ end
206
+ break
207
+ end
208
+ end
209
+ end
210
+ end
211
+ end
212
+ rescue
213
+ def res.needed?
214
+ true
215
+ end
216
+ end
217
+ libChecker.transparent_timestamp = true
218
+ res.enhance([libChecker])
219
+
220
+ return res
221
+ end
222
+
223
+ def add_grouping_tasks(executable)
224
+ namespace 'exe' do
225
+ desc executable
226
+ task @name => executable
227
+ end
228
+ create_run_task(executable, @name)
229
+ end
230
+
231
+ def create_run_task(executable, name)
232
+ namespace 'run' do
233
+ desc "run executable #{executable}"
234
+ res = task name => executable do |t|
235
+ sh executable
236
+ end
237
+ res.type = Rake::Task::RUN
238
+ res
239
+ end
240
+ if Valgrind::available?
241
+ namespace 'valgrind' do
242
+ desc "run executable #{executable} with valgrind"
243
+ res = task name => executable do |t|
244
+ sh "valgrind #{executable}"
245
+ end
246
+ res.type = Rake::Task::RUN
247
+ res
248
+ end
249
+ end
250
+ end
251
+
252
+ def get_temp_filename
253
+ Dir.tmpdir + "/lake.tmp"
254
+ end
255
+
256
+ end
257
+ end