cxxproject 0.6.26 → 0.6.27

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -3,3 +3,4 @@ gem 'rspec'
3
3
  gem 'grit'
4
4
  gem 'roodi'
5
5
  gem 'builder'
6
+ gem 'frazzle'
data/Gemfile.lock CHANGED
@@ -3,6 +3,7 @@ GEM
3
3
  specs:
4
4
  builder (3.0.0)
5
5
  diff-lcs (1.1.3)
6
+ frazzle (0.1.3)
6
7
  grit (2.5.0)
7
8
  diff-lcs (~> 1.1)
8
9
  mime-types (~> 1.15)
@@ -28,6 +29,7 @@ PLATFORMS
28
29
 
29
30
  DEPENDENCIES
30
31
  builder
32
+ frazzle
31
33
  grit
32
34
  roodi
33
35
  rspec
@@ -66,7 +66,7 @@ module Cxxproject
66
66
  ret
67
67
  end
68
68
 
69
- def adaptPath(v, d, prefix)
69
+ def adapt_path(v, d, prefix)
70
70
  tmp = nil
71
71
  if File.is_absolute?(v)
72
72
  tmp = v
@@ -77,48 +77,47 @@ module Cxxproject
77
77
  [tmp, prefix]
78
78
  end
79
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)
80
+ def linker_lib_string(linker)
81
+ lib_path_set = Set.new
82
+ deps = collect_dependencies
87
83
  res = []
88
- return res if @dep_set.include?(d)
89
- @dep_set << d
90
-
91
- if HasLibraries === d
92
- prefix = nil
93
- linker = @tcs[:LINKER]
94
-
95
- d.lib_elements.each do |elem|
96
- case elem[0]
84
+ deps.each do |d|
85
+ handle_whole_archive(d, res, linker, :START_OF_WHOLE_ARCHIVE)
86
+ if HasLibraries === d
87
+ d.lib_elements.each do |elem|
88
+ case elem[0]
97
89
  when HasLibraries::LIB
98
- res << "#{linker[:LIB_FLAG]}#{elem[1]}"
90
+ res.push("#{linker[:LIB_FLAG]}#{elem[1]}")
99
91
  when HasLibraries::USERLIB
100
- res << "#{linker[:USER_LIB_FLAG]}#{elem[1]}"
92
+ res.push("#{linker[:USER_LIB_FLAG]}#{elem[1]}")
101
93
  when HasLibraries::LIB_WITH_PATH
102
- tmp, prefix = adaptPath(elem[1], d, prefix)
103
- res << tmp
94
+ tmp, prefix = adapt_path(elem[1], d, prefix)
95
+ res.push(tmp)
104
96
  when HasLibraries::SEARCH_PATH
105
- tmp, prefix = adaptPath(elem[1], d, prefix)
106
- if not @lib_path_set.include?(tmp)
107
- @lib_path_set << tmp
108
- res << "#{linker[:LIB_PATH_FLAG]}#{tmp}"
109
- end
110
- when HasLibraries::DEPENDENCY
111
- if ALL_BUILDING_BLOCKS.include?(elem[1])
112
- bb = ALL_BUILDING_BLOCKS[elem[1]]
113
- res += calc_linker_lib_string_recursive(bb)
97
+ tmp, prefix = adapt_path(elem[1], d, prefix)
98
+ if not lib_path_set.include?(tmp)
99
+ lib_path_set << tmp
100
+ res.push("#{linker[:LIB_PATH_FLAG]}#{tmp}")
114
101
  end
102
+ end
115
103
  end
116
104
  end
105
+ handle_whole_archive(d, res, linker, :END_OF_WHOLE_ARCHIVE)
117
106
  end
118
-
119
107
  res
120
108
  end
121
109
 
110
+ # res the array with command line arguments that is used as result
111
+ # linker the linker hash
112
+ # sym the symbol that is used to fish out a value from the linker
113
+ def handle_whole_archive(building_block, res, linker, sym)
114
+ if building_block.instance_of?(SourceLibrary)
115
+ if building_block.whole_archive
116
+ res.push(linker[sym]) if linker[sym]
117
+ end
118
+ end
119
+ end
120
+
122
121
  # create a task that will link an executable from a set of object files
123
122
  #
124
123
  def convert_to_rake()
@@ -138,9 +137,9 @@ module Cxxproject
138
137
  cmd << linker[:SCRIPT] if @linker_script # -T
139
138
  cmd << @linker_script if @linker_script # xy/xy.dld
140
139
  cmd << linker[:MAP_FILE_FLAG] if @mapfile # -Wl,-m6
141
- cmd += linker[:LIB_PREFIX_FLAGS].split(" ") # "-Wl,--whole-archive "
142
- cmd += linker_lib_string
143
- cmd += linker[:LIB_POSTFIX_FLAGS].split(" ") # "-Wl,--no-whole-archive "
140
+ cmd += linker[:LIB_PREFIX_FLAGS].split(" ") # TODO ... is this still needed e.g. for diab
141
+ cmd += linker_lib_string(@tcs[:LINKER])
142
+ cmd += linker[:LIB_POSTFIX_FLAGS].split(" ") # TODO ... is this still needed e.g. for diab
144
143
 
145
144
  mapfileStr = @mapfile ? " >#{@mapfile}" : ""
146
145
  if Cxxproject::Utils.old_ruby?
@@ -9,7 +9,7 @@ module Cxxproject
9
9
  @helper_dependencies ||= []
10
10
  end
11
11
 
12
- def set_dependencies(deps)
12
+ def set_dependencies(deps)
13
13
  @dependencies = deps.map { |dep| dep.instance_of?(String) ? dep : dep.name }
14
14
  self
15
15
  end
@@ -53,6 +53,32 @@ module Cxxproject
53
53
  @direct_deps
54
54
  end
55
55
 
56
+ def collect_dependencies()
57
+ # puts "collect for #{name}"
58
+ res = []
59
+ res << self
60
+ todo = dependencies
61
+ while not todo.empty?
62
+ # p todo
63
+ bb = resolve_by_name(todo.pop)
64
+ add_unique(res, bb)
65
+ todo += bb.dependencies
66
+ end
67
+ # puts "result of collect for #{name} -> #{res}"
68
+ res
69
+ end
70
+
71
+ def add_unique(res, bb)
72
+ res.delete(bb)
73
+ res.push(bb)
74
+ end
75
+
76
+ def resolve_by_name(name)
77
+ res = ALL_BUILDING_BLOCKS[name]
78
+ raise "BuildingBlock #{name} not defined" unless res
79
+ res
80
+ end
81
+
56
82
  def all_dependencies()
57
83
  return @all_dependencies if @all_deps_calculated
58
84
 
@@ -76,9 +76,13 @@ module Cxxproject
76
76
  all_dependencies.each_with_index do |d,i|
77
77
  next if not HasIncludes === d
78
78
  next if i == 0
79
- prefix = File.rel_from_to_project(@project_dir,d.project_dir)
80
- next if not prefix
81
- @incArray.concat(d.includes.map {|inc| File.add_prefix(prefix,inc)})
79
+ if BinaryLibrary === d
80
+ @incArray.concat(d.includes)
81
+ else
82
+ prefix = File.rel_from_to_project(@project_dir,d.project_dir)
83
+ next if not prefix
84
+ @incArray.concat(d.includes.map {|inc| File.add_prefix(prefix,inc)})
85
+ end
82
86
  end
83
87
  @incArray.uniq!
84
88
  end
@@ -94,7 +98,11 @@ module Cxxproject
94
98
  end
95
99
 
96
100
  def get_define_string(tcs, type)
97
- tcs[:COMPILER][type][:DEFINES].map {|k| "#{tcs[:COMPILER][type][:DEFINE_FLAG]}#{k}"}
101
+ if (has_tcs?)
102
+ return tcs[:COMPILER][type][:DEFINES].map {|k| "#{tcs[:COMPILER][type][:DEFINE_FLAG]}#{k}"}
103
+ else
104
+ return 'only needed for spec'
105
+ end
98
106
  end
99
107
 
100
108
  def get_object_file(sourceRel)
@@ -167,7 +175,6 @@ module Cxxproject
167
175
  end
168
176
 
169
177
  def create_object_file_tasks()
170
-
171
178
  sources_to_build = {}
172
179
 
173
180
  exclude_files = Set.new
@@ -11,8 +11,11 @@ module Cxxproject
11
11
  include HasSources
12
12
  include HasIncludes
13
13
 
14
- def initialize(name)
14
+ attr_reader :whole_archive
15
+
16
+ def initialize(name, whole_archive=false)
15
17
  super(name)
18
+ @whole_archive = whole_archive
16
19
  end
17
20
 
18
21
  def complete_init()
@@ -73,7 +73,9 @@ module Cxxproject
73
73
  :FLAGS => [],
74
74
  :MAP_FILE_FLAG => "",
75
75
  :OUTPUT_ENDING => ".exe", # or .elf
76
- :ERROR_PARSER => nil
76
+ :ERROR_PARSER => nil,
77
+ :START_OF_WHOLE_ARCHIVE => '',
78
+ :END_OF_WHOLE_ARCHIVE => ''
77
79
  },
78
80
 
79
81
  :MAKE =>
@@ -1,5 +1,5 @@
1
1
  module Cxxproject
2
- VERSION = "0.6.26"
2
+ VERSION = '0.6.27'
3
3
 
4
4
  class Version
5
5
  def self.cxxproject
@@ -10,26 +10,35 @@ describe Cxxproject::BuildingBlock do
10
10
  before(:each) do
11
11
  Cxxproject::Utils.cleanup_rake
12
12
  end
13
+
13
14
  after(:each) do
14
15
  Cxxproject::Utils.cleanup_rake
15
16
  end
16
17
 
17
- it 'should build the right dependency-chain' do
18
+ it 'should collect the dependencies for a single lib' do
19
+ lib1 = Cxxproject::SourceLibrary.new('1')
20
+ lib1.collect_dependencies().should == [lib1]
21
+ end
22
+
23
+ it 'should collect the dependencies for a single lib with one dep' do
18
24
  lib1 = Cxxproject::SourceLibrary.new('1')
19
25
  lib2 = Cxxproject::SourceLibrary.new('2').set_dependencies(['1'])
20
- lib3 = Cxxproject::SourceLibrary.new('3').set_dependencies(['1'])
21
- lib4 = Cxxproject::SourceLibrary.new('4').set_dependencies(['2', '3'])
22
- deps = lib4.all_dependencies.map { |d| d.name }
23
- deps.should == ['4', '2', '3', '1']
26
+ lib2.collect_dependencies().should == [lib2, lib1]
27
+ end
28
+
29
+ it 'should build the right dependency-chain' do
30
+ lib1 = Cxxproject::SourceLibrary.new('1').set_dependencies(['2'])
31
+ lib2 = Cxxproject::SourceLibrary.new('2')
32
+ lib3 = Cxxproject::SourceLibrary.new('3').set_dependencies(['2', '1'])
33
+ lib3.collect_dependencies().should == [lib3, lib1, lib2]
24
34
  end
25
35
 
26
36
  it 'should build the right dependency-chain for custom blocks' do
27
37
  lib1 = Cxxproject::SourceLibrary.new('1')
28
- lib2 = Cxxproject::CustomBuildingBlock.new('2').set_dependencies(['1'])
29
- lib3 = Cxxproject::SourceLibrary.new('3').set_dependencies(['1'])
30
- lib4 = Cxxproject::CustomBuildingBlock.new('4').set_dependencies(['2', '3'])
31
- deps = lib4.all_dependencies.map { |d| d.name }
32
- deps.should == ['4', '2', '3', '1']
38
+ lib2 = Cxxproject::SourceLibrary.new('2').set_dependencies(['1'])
39
+ lib3 = Cxxproject::SourceLibrary.new('3').set_dependencies(['1', '2'])
40
+ lib4 = Cxxproject::SourceLibrary.new('4').set_dependencies(['1', '2', '3'])
41
+ lib4.collect_dependencies().should == [lib4, lib3, lib2, lib1]
33
42
  end
34
43
 
35
44
  it 'should generate an error if building block names conflict' do
@@ -51,6 +60,22 @@ describe Cxxproject::BuildingBlock do
51
60
  }.should raise_exception
52
61
  end
53
62
 
63
+ it 'should handle whole archive' do
64
+ # TODO ... clean up api and also this test
65
+ l1 = Cxxproject::SourceLibrary.new('1', true)
66
+ l1.output_dir = 'out'
67
+ l1.complete_init
68
+ l2 = Cxxproject::SourceLibrary.new('2', true)
69
+ l2.output_dir = 'out'
70
+ l2.complete_init
71
+ exe = Cxxproject::Executable.new('test')
72
+ deps = ['1', '2']
73
+ exe.set_dependencies(deps)
74
+ exe.complete_init
75
+ exe.linker_lib_string({:START_OF_WHOLE_ARCHIVE => 'start', :END_OF_WHOLE_ARCHIVE => 'end'}).should == ['start', 'out/lib2.a', 'end', 'start', 'out/lib1.a', 'end']
76
+ # TODO add a test for recursive whole archive libs a lib that should be whole and that has dependencies to whole libs
77
+ end
78
+
54
79
  =begin
55
80
  it 'should have the right output-directory' do
56
81
  lib1 = Cxxproject::SourceLibrary.new('lib1').set_sources(['test.cc'])
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cxxproject
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.26
4
+ version: 0.6.27
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-06 00:00:00.000000000 Z
12
+ date: 2012-09-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: colored
@@ -220,7 +220,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
220
220
  version: '0'
221
221
  segments:
222
222
  - 0
223
- hash: -4608833184588443303
223
+ hash: -319442458633377301
224
224
  required_rubygems_version: !ruby/object:Gem::Requirement
225
225
  none: false
226
226
  requirements: