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,153 +1,153 @@
1
- require 'cxxproject/buildingblocks/building_block'
2
- require 'cxxproject/buildingblocks/has_libraries_mixin'
3
- require 'cxxproject/utils/printer'
4
- require 'cxxproject/utils/process'
5
-
6
- module Cxxproject
7
- class Makefile < BuildingBlock
8
- include HasLibraries
9
-
10
- def set_target(x)
11
- @target = x
12
- self
13
- end
14
-
15
- def set_flags(x)
16
- @flags = x
17
- self
18
- end
19
-
20
- def get_flags(x)
21
- @flags
22
- end
23
-
24
-
25
- def set_makefile(x)
26
- @makefile = x
27
- self
28
- end
29
-
30
- def set_path_to(hash)
31
- @path_to = hash
32
- self
33
- end
34
-
35
- def get_makefile
36
- @makefile
37
- end
38
-
39
- def get_target
40
- @target
41
- end
42
-
43
- def initialize(mfile, mtarget)
44
- @target = mtarget != "" ? mtarget : "all"
45
- @makefile = mfile
46
- @flags = ""
47
- @path_to = {}
48
- @num = Rake.application.makefile_number
49
- super(get_task_name)
50
- end
51
-
52
- def get_task_name()
53
- "makefile (#{@num}): " + get_makefile + (get_target ? ("_"+get_target) : "")
54
- end
55
-
56
- def calc_pathes_to_projects
57
- vars = []
58
- @path_to.each do |k,v|
59
- bb = ALL_BUILDING_BLOCKS[p]
60
- if bb
61
- pref = File.rel_from_to_project(@project_dir,bb.project_dir)
62
- rex = Regexp.new "\\.\\.\\/(.*)#{p}"
63
- var = pref.scan(rex)[0]
64
- if var
65
- vars << "PATH_TO_#{p}=#{var[0]}"
66
- end
67
- else
68
- vars << "PATH_TO_#{k}=#{v}"
69
- end
70
- end
71
- vars.join(" ")
72
- end
73
-
74
- def executeCmd(cmd)
75
- Dir.chdir(@project_dir) do
76
- check_config_file
77
- puts cmd + (RakeFileUtils.verbose ? " (executed in '#{@project_dir}')" : "")
78
- cmd_result = false
79
- begin
80
- cmd_result = ProcessHelper.spawnProcess(cmd + " 2>&1")
81
- rescue
82
- end
83
- if (cmd_result == false)
84
- if Rake.application.idei
85
- err_res = ErrorDesc.new
86
- err_res.file_name = @project_dir + "/" + get_makefile()
87
- err_res.line_number = 1
88
- err_res.severity = ErrorParser::SEVERITY_ERROR
89
- if get_target != ""
90
- err_res.message = "Target \"#{get_target}\" failed"
91
- else
92
- err_res.message = "Failed"
93
- end
94
- Rake.application.idei.set_errors([err_res])
95
- end
96
- Printer.printError "Error: command \"#{cmd}\" failed" + (RakeFileUtils.verbose ? "" : " (executed in '#{@project_dir}')")
97
- raise SystemCommandFailed.new
98
- end
99
- end
100
- end
101
-
102
- def convert_to_rake()
103
- pathes_to_projects = calc_pathes_to_projects
104
-
105
- mfile = get_makefile()
106
- make = @tcs[:MAKE]
107
- cmd = remove_empty_strings_and_join([
108
- make[:COMMAND], # make
109
- get_target, # all
110
- make[:MAKE_FLAGS],
111
- @flags, # -j
112
- make[:DIR_FLAG], # -C
113
- File.dirname(mfile), # x/y
114
- make[:FILE_FLAG], # -f
115
- File.basename(mfile), # x/y/makefile
116
- pathes_to_projects
117
- ])
118
-
119
- mfileTask = task get_task_name do
120
- executeCmd(cmd)
121
- end
122
-
123
- mfileTask.immediate_output = true
124
- mfileTask.transparent_timestamp = true
125
- mfileTask.type = Rake::Task::MAKE
126
- mfileTask.enhance(@config_files)
127
-
128
- create_clean_task(@project_dir+"/"+mfile, pathes_to_projects)
129
- setup_rake_dependencies(mfileTask)
130
- mfileTask
131
- end
132
-
133
- def create_clean_task(mfile, pathes_to_projects)
134
- # generate the clean task
135
- if not Rake.application["clean"].prerequisites.include?(mfile+"Clean")
136
- cmd = remove_empty_strings_and_join([@tcs[:MAKE][:COMMAND], # make
137
- @tcs[:MAKE][:CLEAN], # clean
138
- @tcs[:MAKE][:DIR_FLAG], # -C
139
- File.dirname(mfile), # x/y
140
- @tcs[:MAKE][:FILE_FLAG], # -f
141
- File.basename(mfile), # x/y/makefile
142
- pathes_to_projects
143
- ])
144
- mfileCleanTask = task mfile+"Clean" do
145
- executeCmd(cmd)
146
- end
147
- mfileCleanTask.immediate_output = true
148
- Rake.application["clean"].enhance([mfileCleanTask])
149
- end
150
- end
151
-
152
- end
153
- end
1
+ require 'cxxproject/buildingblocks/building_block'
2
+ require 'cxxproject/buildingblocks/has_libraries_mixin'
3
+ require 'cxxproject/utils/printer'
4
+ require 'cxxproject/utils/process'
5
+
6
+ module Cxxproject
7
+ class Makefile < BuildingBlock
8
+ include HasLibraries
9
+
10
+ def set_target(x)
11
+ @target = x
12
+ self
13
+ end
14
+
15
+ def set_flags(x)
16
+ @flags = x
17
+ self
18
+ end
19
+
20
+ def get_flags(x)
21
+ @flags
22
+ end
23
+
24
+
25
+ def set_makefile(x)
26
+ @makefile = x
27
+ self
28
+ end
29
+
30
+ def set_path_to(hash)
31
+ @path_to = hash
32
+ self
33
+ end
34
+
35
+ def get_makefile
36
+ @makefile
37
+ end
38
+
39
+ def get_target
40
+ @target
41
+ end
42
+
43
+ def initialize(mfile, mtarget)
44
+ @target = mtarget != "" ? mtarget : "all"
45
+ @makefile = mfile
46
+ @flags = ""
47
+ @path_to = {}
48
+ @num = Rake.application.makefile_number
49
+ super(get_task_name)
50
+ end
51
+
52
+ def get_task_name()
53
+ "makefile (#{@num}): " + get_makefile + (get_target ? ("_"+get_target) : "")
54
+ end
55
+
56
+ def calc_pathes_to_projects
57
+ vars = []
58
+ @path_to.each do |k,v|
59
+ bb = ALL_BUILDING_BLOCKS[p]
60
+ if bb
61
+ pref = File.rel_from_to_project(@project_dir,bb.project_dir)
62
+ rex = Regexp.new "\\.\\.\\/(.*)#{p}"
63
+ var = pref.scan(rex)[0]
64
+ if var
65
+ vars << "PATH_TO_#{p}=#{var[0]}"
66
+ end
67
+ else
68
+ vars << "PATH_TO_#{k}=#{v}"
69
+ end
70
+ end
71
+ vars.join(" ")
72
+ end
73
+
74
+ def executeCmd(cmd)
75
+ Dir.chdir(@project_dir) do
76
+ check_config_file
77
+ puts cmd + (RakeFileUtils.verbose ? " (executed in '#{@project_dir}')" : "")
78
+ cmd_result = false
79
+ begin
80
+ cmd_result = ProcessHelper.spawnProcess(cmd + " 2>&1")
81
+ rescue
82
+ end
83
+ if (cmd_result == false)
84
+ if Rake.application.idei
85
+ err_res = ErrorDesc.new
86
+ err_res.file_name = @project_dir + "/" + get_makefile()
87
+ err_res.line_number = 1
88
+ err_res.severity = ErrorParser::SEVERITY_ERROR
89
+ if get_target != ""
90
+ err_res.message = "Target \"#{get_target}\" failed"
91
+ else
92
+ err_res.message = "Failed"
93
+ end
94
+ Rake.application.idei.set_errors([err_res])
95
+ end
96
+ Printer.printError "Error: command \"#{cmd}\" failed" + (RakeFileUtils.verbose ? "" : " (executed in '#{@project_dir}')")
97
+ raise SystemCommandFailed.new
98
+ end
99
+ end
100
+ end
101
+
102
+ def convert_to_rake()
103
+ pathes_to_projects = calc_pathes_to_projects
104
+
105
+ mfile = get_makefile()
106
+ make = @tcs[:MAKE]
107
+ cmd = remove_empty_strings_and_join([
108
+ make[:COMMAND], # make
109
+ get_target, # all
110
+ make[:MAKE_FLAGS],
111
+ @flags, # -j
112
+ make[:DIR_FLAG], # -C
113
+ File.dirname(mfile), # x/y
114
+ make[:FILE_FLAG], # -f
115
+ File.basename(mfile), # x/y/makefile
116
+ pathes_to_projects
117
+ ])
118
+
119
+ mfileTask = task get_task_name do
120
+ executeCmd(cmd)
121
+ end
122
+
123
+ mfileTask.immediate_output = true
124
+ mfileTask.transparent_timestamp = true
125
+ mfileTask.type = Rake::Task::MAKE
126
+ mfileTask.enhance(@config_files)
127
+
128
+ create_clean_task(@project_dir+"/"+mfile, pathes_to_projects)
129
+ setup_rake_dependencies(mfileTask)
130
+ mfileTask
131
+ end
132
+
133
+ def create_clean_task(mfile, pathes_to_projects)
134
+ # generate the clean task
135
+ if not Rake.application["clean"].prerequisites.include?(mfile+"Clean")
136
+ cmd = remove_empty_strings_and_join([@tcs[:MAKE][:COMMAND], # make
137
+ @tcs[:MAKE][:CLEAN], # clean
138
+ @tcs[:MAKE][:DIR_FLAG], # -C
139
+ File.dirname(mfile), # x/y
140
+ @tcs[:MAKE][:FILE_FLAG], # -f
141
+ File.basename(mfile), # x/y/makefile
142
+ pathes_to_projects
143
+ ])
144
+ mfileCleanTask = task mfile+"Clean" do
145
+ executeCmd(cmd)
146
+ end
147
+ mfileCleanTask.immediate_output = true
148
+ Rake.application["clean"].enhance([mfileCleanTask])
149
+ end
150
+ end
151
+
152
+ end
153
+ end
@@ -1,35 +1,35 @@
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
-
6
-
7
- # can be used as wrapper for other tasks
8
- module Cxxproject
9
- class ModuleBuildingBlock < BuildingBlock
10
-
11
- attr_accessor :contents
12
- attr_accessor :main_content
13
- attr_accessor :last_content
14
-
15
- def initialize(name)
16
- super
17
- @contents = []
18
- @last_content = self
19
- @main_content = nil
20
- end
21
-
22
- def get_task_name()
23
- name
24
- end
25
-
26
- def convert_to_rake()
27
- res = task get_task_name
28
- res.type = Rake::Task::MODULE
29
- res.transparent_timestamp = true
30
-
31
- setup_rake_dependencies(res)
32
- res
33
- end
34
- end
35
- 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
+
6
+
7
+ # can be used as wrapper for other tasks
8
+ module Cxxproject
9
+ class ModuleBuildingBlock < BuildingBlock
10
+
11
+ attr_accessor :contents
12
+ attr_accessor :main_content
13
+ attr_accessor :last_content
14
+
15
+ def initialize(name)
16
+ super
17
+ @contents = []
18
+ @last_content = self
19
+ @main_content = nil
20
+ end
21
+
22
+ def get_task_name()
23
+ name
24
+ end
25
+
26
+ def convert_to_rake()
27
+ res = task get_task_name
28
+ res.type = Rake::Task::MODULE
29
+ res.transparent_timestamp = true
30
+
31
+ setup_rake_dependencies(res)
32
+ res
33
+ end
34
+ end
35
+ end
@@ -1,33 +1,33 @@
1
- require 'cxxproject/buildingblocks/building_block'
2
- require 'cxxproject/buildingblocks/has_sources_mixin'
3
- require 'cxxproject/buildingblocks/has_includes_mixin'
4
-
5
- module Cxxproject
6
- module SingleSourceModule
7
- def get_task_name()
8
- get_sources_task_name
9
- end
10
-
11
- def convert_to_rake()
12
- objects_multitask = prepare_tasks_for_objects()
13
-
14
- if objects_multitask
15
- namespace "compile" do
16
- desc "compile sources in #{@name}-configuration"
17
- task @name => objects_multitask
18
- end
19
- objects_multitask.add_description("compile sources only")
20
- end
21
-
22
- setup_rake_dependencies(objects_multitask)
23
- objects_multitask
24
- end
25
- end
26
-
27
- class SingleSource < BuildingBlock
28
- include HasSources
29
- include HasIncludes
30
-
31
- include SingleSourceModule
32
- end
33
- end
1
+ require 'cxxproject/buildingblocks/building_block'
2
+ require 'cxxproject/buildingblocks/has_sources_mixin'
3
+ require 'cxxproject/buildingblocks/has_includes_mixin'
4
+
5
+ module Cxxproject
6
+ module SingleSourceModule
7
+ def get_task_name()
8
+ get_sources_task_name
9
+ end
10
+
11
+ def convert_to_rake()
12
+ objects_multitask = prepare_tasks_for_objects()
13
+
14
+ if objects_multitask
15
+ namespace "compile" do
16
+ desc "compile sources in #{@name}-configuration"
17
+ task @name => objects_multitask
18
+ end
19
+ objects_multitask.add_description("compile sources only")
20
+ end
21
+
22
+ setup_rake_dependencies(objects_multitask)
23
+ objects_multitask
24
+ end
25
+ end
26
+
27
+ class SingleSource < BuildingBlock
28
+ include HasSources
29
+ include HasIncludes
30
+
31
+ include SingleSourceModule
32
+ end
33
+ end
@@ -1,124 +1,124 @@
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
- module Cxxproject
9
- class SourceLibrary < BuildingBlock
10
- include HasLibraries
11
- include HasSources
12
- include HasIncludes
13
-
14
- def initialize(name)
15
- super(name)
16
- end
17
-
18
- def complete_init()
19
- if @output_dir_abs
20
- add_lib_element(HasLibraries::SEARCH_PATH, File.join(@output_dir, 'libs'), true)
21
- add_lib_element(HasLibraries::LIB, @name, true)
22
- else
23
- add_lib_element(HasLibraries::LIB_WITH_PATH, File.join(@output_dir,"lib#{@name}.a"), true)
24
- end
25
- super
26
- end
27
-
28
- def get_archive_name() # relative path
29
- return @archive_name if @archive_name
30
- parts = [@output_dir]
31
-
32
- if @output_dir_abs
33
- parts = [@output_dir_relPath] if @output_dir_relPath
34
- parts << 'libs'
35
- end
36
-
37
- parts << "lib#{@name}.a"
38
-
39
- @archive_name = File.join(parts)
40
- @archive_name
41
- end
42
-
43
- def get_task_name() # full path
44
- return @task_name if @task_name
45
-
46
- parts = [@output_dir]
47
- parts << 'libs' if @output_dir_abs
48
- parts << "lib#{@name}.a"
49
- @task_name = File.join(parts)
50
- @task_name = @project_dir + "/" + @task_name unless @output_dir_abs
51
- @task_name
52
- end
53
-
54
- # task that will link the given object files to a static lib
55
- #
56
- def convert_to_rake()
57
- object_multitask = prepare_tasks_for_objects()
58
- archiver = @tcs[:ARCHIVER]
59
-
60
- res = typed_file_task Rake::Task::LIBRARY, get_task_name => object_multitask do
61
- dir = @project_dir
62
- objs = @objects
63
- aname = get_archive_name
64
-
65
- if @output_dir_abs
66
- dir = @output_dir
67
- prefix = File.rel_from_to_project(@project_dir, @output_dir)
68
- objs.map! { |m| m[prefix.length..-1] }
69
- aname = aname[prefix.length..-1]
70
- end
71
-
72
- Dir.chdir(dir) do
73
- FileUtils.rm(aname) if File.exists?(aname)
74
- cmd = [archiver[:COMMAND]] # ar
75
- cmd += archiver[:ARCHIVE_FLAGS].split(" ")
76
- cmd += archiver[:FLAGS].split(" ") # --all_load
77
- cmd << aname # -o debug/x.exe
78
- cmd += objs
79
-
80
- if Cxxproject::Utils.old_ruby?
81
- cmd.map! {|c| ((c.include?" ") ? ("\""+c+"\"") : c )}
82
-
83
- cmdLine = cmd.join(" ")
84
- if cmdLine.length > 8000
85
- inputName = aname+".tmp"
86
- File.open(inputName,"wb") { |f| f.write(cmd[1..-1].join(" ")) }
87
- consoleOutput = `#{archiver[:COMMAND] + " @" + inputName}`
88
- else
89
- consoleOutput = `#{cmd.join(" ")} 2>&1`
90
- end
91
- else
92
- rd, wr = IO.pipe
93
- cmd << {
94
- :err=>wr,
95
- :out=>wr
96
- }
97
- sp = spawn(*cmd)
98
- cmd.pop
99
-
100
- consoleOutput = ProcessHelper.readOutput(sp, rd, wr)
101
- end
102
-
103
- process_result(cmd, consoleOutput, archiver[:ERROR_PARSER], "Creating #{aname}")
104
-
105
- check_config_file()
106
- end
107
- end
108
- enhance_with_additional_files(res)
109
- add_output_dir_dependency(get_task_name, res, true)
110
-
111
- add_grouping_tasks(get_task_name)
112
-
113
- setup_rake_dependencies(res, object_multitask)
114
- return res
115
- end
116
-
117
- def add_grouping_tasks(archive)
118
- namespace 'lib' do
119
- desc archive
120
- task @name => archive
121
- end
122
- end
123
- end
124
- 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
+
8
+ module Cxxproject
9
+ class SourceLibrary < BuildingBlock
10
+ include HasLibraries
11
+ include HasSources
12
+ include HasIncludes
13
+
14
+ def initialize(name)
15
+ super(name)
16
+ end
17
+
18
+ def complete_init()
19
+ if @output_dir_abs
20
+ add_lib_element(HasLibraries::SEARCH_PATH, File.join(@output_dir, 'libs'), true)
21
+ add_lib_element(HasLibraries::LIB, @name, true)
22
+ else
23
+ add_lib_element(HasLibraries::LIB_WITH_PATH, File.join(@output_dir,"lib#{@name}.a"), true)
24
+ end
25
+ super
26
+ end
27
+
28
+ def get_archive_name() # relative path
29
+ return @archive_name if @archive_name
30
+ parts = [@output_dir]
31
+
32
+ if @output_dir_abs
33
+ parts = [@output_dir_relPath] if @output_dir_relPath
34
+ parts << 'libs'
35
+ end
36
+
37
+ parts << "lib#{@name}.a"
38
+
39
+ @archive_name = File.join(parts)
40
+ @archive_name
41
+ end
42
+
43
+ def get_task_name() # full path
44
+ return @task_name if @task_name
45
+
46
+ parts = [@output_dir]
47
+ parts << 'libs' if @output_dir_abs
48
+ parts << "lib#{@name}.a"
49
+ @task_name = File.join(parts)
50
+ @task_name = @project_dir + "/" + @task_name unless @output_dir_abs
51
+ @task_name
52
+ end
53
+
54
+ # task that will link the given object files to a static lib
55
+ #
56
+ def convert_to_rake()
57
+ object_multitask = prepare_tasks_for_objects()
58
+ archiver = @tcs[:ARCHIVER]
59
+
60
+ res = typed_file_task Rake::Task::LIBRARY, get_task_name => object_multitask do
61
+ dir = @project_dir
62
+ objs = @objects
63
+ aname = get_archive_name
64
+
65
+ if @output_dir_abs
66
+ dir = @output_dir
67
+ prefix = File.rel_from_to_project(@project_dir, @output_dir)
68
+ objs.map! { |m| m[prefix.length..-1] }
69
+ aname = aname[prefix.length..-1]
70
+ end
71
+
72
+ Dir.chdir(dir) do
73
+ FileUtils.rm(aname) if File.exists?(aname)
74
+ cmd = [archiver[:COMMAND]] # ar
75
+ cmd += archiver[:ARCHIVE_FLAGS].split(" ")
76
+ cmd += Cxxproject::Utils::flagSplit(archiver[:FLAGS]) # --all_load
77
+ cmd << aname # -o debug/x.exe
78
+ cmd += objs
79
+
80
+ if Cxxproject::Utils.old_ruby?
81
+ cmd.map! {|c| ((c.include?" ") ? ("\""+c+"\"") : c )}
82
+
83
+ cmdLine = cmd.join(" ")
84
+ if cmdLine.length > 8000
85
+ inputName = aname+".tmp"
86
+ File.open(inputName,"wb") { |f| f.write(cmd[1..-1].join(" ")) }
87
+ consoleOutput = `#{archiver[:COMMAND] + " @" + inputName}`
88
+ else
89
+ consoleOutput = `#{cmd.join(" ")} 2>&1`
90
+ end
91
+ else
92
+ rd, wr = IO.pipe
93
+ cmd << {
94
+ :err=>wr,
95
+ :out=>wr
96
+ }
97
+ sp = spawn(*cmd)
98
+ cmd.pop
99
+
100
+ consoleOutput = ProcessHelper.readOutput(sp, rd, wr)
101
+ end
102
+
103
+ process_result(cmd, consoleOutput, archiver[:ERROR_PARSER], "Creating #{aname}")
104
+
105
+ check_config_file()
106
+ end
107
+ end
108
+ enhance_with_additional_files(res)
109
+ add_output_dir_dependency(get_task_name, res, true)
110
+
111
+ add_grouping_tasks(get_task_name)
112
+
113
+ setup_rake_dependencies(res, object_multitask)
114
+ return res
115
+ end
116
+
117
+ def add_grouping_tasks(archive)
118
+ namespace 'lib' do
119
+ desc archive
120
+ task @name => archive
121
+ end
122
+ end
123
+ end
124
+ end