destination 0.0.3 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4c87ef0e4945f33c116ac74e001422db220c1aca
4
- data.tar.gz: 8336a56d52f70ef36106a36a63bdc8ac1530568a
3
+ metadata.gz: 097b24f39873e393a93fa196eafaa61f65ca1d11
4
+ data.tar.gz: 311237b8696731bda8c796a5dac78850f0cd686e
5
5
  SHA512:
6
- metadata.gz: 6b48cd003dcdd853ca26f1c658dfb88af252dffce21ec4a68ca7456d81bebc5f51152da73e85cbf7d8e005ca6254adda1851cd4d922228a2e6ee45155827c340
7
- data.tar.gz: 0dfe14f2586733f1b48046c9bcfe5cb68e3bccab138a02c78381aba9c667d86210d900463d9ef0be77f9ffa5ca82775622fda7db50eb0d706a057038e9b32eb1
6
+ metadata.gz: c025dcd871e7f0927cfdf4d4159c947a4695ba5950ae8677aa52d6a556434565b478683325a20a161a80758186114bdf663825de0b402d7075c3f1060dc51fb3
7
+ data.tar.gz: 20f46d9dc5b690c67e7b1f08fe3e10bd3809766e9944dddc34515dcc8b57a0fc3bb738eccfdef2ee8f85089d66c0dc33621589064994d61f4724dd9bf2d66816
data/.gitignore CHANGED
@@ -2,3 +2,6 @@
2
2
 
3
3
  *.gem
4
4
  **/*.bc
5
+
6
+ # Binaries
7
+ test/project/project
@@ -0,0 +1,32 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ dest (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.2.5)
10
+ rake (10.3.2)
11
+ rspec (3.0.0)
12
+ rspec-core (~> 3.0.0)
13
+ rspec-expectations (~> 3.0.0)
14
+ rspec-mocks (~> 3.0.0)
15
+ rspec-core (3.0.3)
16
+ rspec-support (~> 3.0.0)
17
+ rspec-expectations (3.0.3)
18
+ diff-lcs (>= 1.2.0, < 2.0)
19
+ rspec-support (~> 3.0.0)
20
+ rspec-mocks (3.0.3)
21
+ rspec-support (~> 3.0.0)
22
+ rspec-support (3.0.3)
23
+
24
+ PLATFORMS
25
+ ruby
26
+
27
+ DEPENDENCIES
28
+ bundler (~> 1.5)
29
+ dest!
30
+ rake
31
+ rspec
32
+ rspec-expectations
@@ -5,4 +5,7 @@ require 'dest/version'
5
5
  require 'dest/project/base'
6
6
 
7
7
  module Dest
8
+ module Util
9
+ XCODE_FRAMEWORKS = File.join(`xcode-select -p`.strip, 'Library', 'Frameworks')
10
+ end
8
11
  end
@@ -6,12 +6,22 @@ module Dest
6
6
  end
7
7
 
8
8
  class Base
9
- attr_accessor :dir, :frameworks, :sources, :target
9
+ attr_accessor :dir, :frameworks, :sources, :target, :compile_flags, :link_flags, :main
10
+ # Testing stuff
11
+ attr_accessor :test_frameworks, :test_target, :test_sources
12
+
10
13
  def initialize dir
11
14
  @dir = dir
12
15
  @frameworks = ['Foundation']
13
16
  @sources = []
14
17
  @target = guess_target
18
+ @compile_flags = ''
19
+ @link_flags = ''
20
+ @main = guess_main
21
+
22
+ @test_frameworks = []
23
+ @test_target = nil
24
+ @test_sources = []
15
25
  end
16
26
  # def scan_sources
17
27
  # src = Dir[File.join(@dir, 'src', '**/*.m')]
@@ -21,13 +31,28 @@ module Dest
21
31
  def add_source fn
22
32
  @sources << File.expand_path(fn)
23
33
  end
34
+ alias :add_source_file :add_source
24
35
  def add_source_directory dir
25
- Dir[File.join dir, '**/*.m'].map {|fn| File.expand_path fn }.each {|fn| @sources << fn }
36
+ glob_sources(dir).each {|fn| @sources << fn }
37
+ end
38
+ def add_test_directory dir
39
+ glob_sources(dir).each {|fn| @test_sources << fn }
40
+ end
41
+
42
+ # Handy utility method to pull in special Xcode frameworks needed for
43
+ # testing and the like.
44
+ def include_xcode_frameworks!
45
+ @compile_flags << "-F #{Dest::Util::XCODE_FRAMEWORKS}"
46
+ @link_flags << "-F #{Dest::Util::XCODE_FRAMEWORKS} -Wl,-rpath,#{Dest::Util::XCODE_FRAMEWORKS}"
26
47
  end
48
+
27
49
  def guess_target
28
50
  # Turns '/a/b/c' into just 'c'
29
51
  File.basename dir
30
52
  end
53
+ def guess_main
54
+ File.join(@dir, 'main.m')
55
+ end
31
56
 
32
57
  def self.setup dir=nil, &block
33
58
  unless dir
@@ -37,6 +62,12 @@ module Dest
37
62
  Dest::Project.current = proj
38
63
  block.call proj
39
64
  end
65
+
66
+ private
67
+ def glob_sources dir
68
+ Dir[File.join dir, '**/*.m'].map {|fn| File.expand_path fn }
69
+ end
70
+
40
71
  end
41
72
  end
42
73
  end
@@ -25,6 +25,9 @@ module Dest
25
25
  flags << '-Wall' # All warnings
26
26
  flags << '-emit-llvm'
27
27
  flags << '-fobjc-arc'
28
+ if project.compile_flags
29
+ flags << project.compile_flags
30
+ end
28
31
  @flags = flags.join ' '
29
32
  end
30
33
 
@@ -33,13 +36,18 @@ module Dest
33
36
  dir = File.dirname object
34
37
  FileUtils.mkdir_p dir
35
38
  # Then build
36
- system "clang #{source} #{flags} -o #{object}"
39
+ sh "clang #{source} #{flags} -o #{object}"
40
+ end
41
+
42
+ def time_action name
43
+ start = Time.now
44
+ yield
45
+ diff = ((Time.now - start) * 1000).round
46
+ puts name + " (#{diff.to_s} ms)".light_black
37
47
  end
38
48
 
39
49
  # Set up rake hooks
40
50
  def setup
41
- # puts project.sources.inspect
42
- # puts project.target
43
51
  @build_dir = File.join project.dir, 'build'
44
52
  unless Dir.exists? @build_dir
45
53
  Dir.mkdir @build_dir
@@ -52,52 +60,94 @@ module Dest
52
60
  puts "Built #{File.basename project.target}".green
53
61
  end
54
62
 
55
- # Build the sources into their objects via the rule below
56
- file project.target => project.sources.map {|fn| objectsify fn } do |t|
57
- # Then build the target file from the sources
58
- target = t.name
59
- objects = t.prerequisites
60
- # Little message
61
- time_action "Linking #{File.basename target} from #{objects.length.to_s} objects" do
62
- # Then figure out our frameworks and objects
63
- objects = objects.join ' '
64
- frameworks = project.frameworks.map {|f| "-framework #{f}" }.join ' '
65
- system "clang #{objects} -lobjc #{frameworks} -o #{target}"
66
- end
63
+ self.setup_target
64
+ self.setup_source_files
65
+
66
+ if project.test_target
67
+ self.setup_test_target
68
+ self.setup_test_files
67
69
  end
68
70
 
69
- def time_action name
70
- start = Time.now
71
- yield
72
- diff = ((Time.now - start) * 1000).round
73
- puts name + " (#{diff.to_s} ms)".light_black
71
+ desc 'Clean up build artifacts and target'
72
+ task 'clean' do
73
+ sh "rm -f #{project.target}"
74
+ project.sources.each do |fn|
75
+ fn = objectsify fn
76
+ sh "rm -f #{fn}"
77
+ end
78
+ end
79
+
80
+ namespace 'test' do
81
+ desc 'Build the test target'
82
+ task 'build' => project.test_target do
83
+ puts "Built #{File.basename project.test_target}".green
84
+ end
85
+ desc 'Clean test build artifacts'
86
+ task 'clean' do
87
+ sh "rm -f #{project.test_target}"
88
+ project.test_sources.each do |fn|
89
+ fn = objectsify fn
90
+ sh "rm -f #{fn}"
91
+ end
92
+ end
74
93
  end
94
+
95
+ end#setup
96
+
97
+ # Build the target file from the sources
98
+ def setup_target
99
+ link_target_task project.target, (project.sources + [project.main]).map {|fn| objectsify fn }
100
+ end
75
101
 
76
- # Set up a file task for every source file to catch changes
102
+ # Set up a file task for every source file
103
+ def setup_source_files
77
104
  project.sources.each do |src|
78
105
  # Figure out where stuff should come from and go to
79
106
  source_file = src
80
107
  object_file = objectsify src
81
-
82
- file object_file => source_file do |t|
83
- # Try to strip off the leading directory
84
- fn = src.sub project.dir+'/', ''
85
- time_action "Compiling #{fn}" do
86
- compile source_file, object_file
87
- end
88
- end
108
+ compile_task object_file, source_file
89
109
  end#project.sources.each
110
+ end#setup_source_files
111
+
112
+ # Set up test source files and test target tasks
113
+ def setup_test_files
114
+ project.test_sources.each do |src|
115
+ compile_task objectsify(src), src
116
+ end
117
+ end
118
+ def setup_test_target
119
+ link_target_task project.test_target,
120
+ (project.sources + project.test_sources).map {|fn| objectsify fn },
121
+ :frameworks => project.test_frameworks
122
+ end
90
123
 
91
- desc 'Clean up build artifacts and target'
92
- task 'clean' do
93
- system "rm -f #{project.target}"
94
- project.sources.each do |fn|
95
- fn = objectsify fn
96
- system "rm -f #{fn}"
124
+ private
125
+ def compile_task object, source
126
+ file object => source do |t|
127
+ # Try to strip off the leading directory
128
+ fn = source.sub project.dir+'/', ''
129
+ time_action "Compiling #{fn}" do
130
+ compile source, object
97
131
  end
98
132
  end
99
-
100
- end#setup
133
+ end
134
+ def link_target_task target, objects, opts = {}
135
+ file target => objects do |t|
136
+ # Little message
137
+ time_action "Linking #{File.basename target} from #{objects.length.to_s} objects" do
138
+ # Then figure out our frameworks and objects
139
+ objects = objects.join ' '
140
+ frameworks = project.frameworks
141
+ if opts[:frameworks]
142
+ opts[:frameworks].each {|f| frameworks << f }
143
+ end
144
+ # Concatenate all the frameworks together
145
+ frameworks = frameworks.map {|f| "-framework #{f}" }.join ' '
146
+ flags = project.link_flags || ''
147
+ sh "clang #{objects} -lobjc #{frameworks} #{flags} -o #{target}"
148
+ end
149
+ end
150
+ end#link_target_task
101
151
 
102
152
  end#Rake
103
153
  end#Dest
@@ -1,3 +1,3 @@
1
1
  module Dest
2
- VERSION = "0.0.3"
2
+ VERSION = "0.1.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: destination
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dirk Gadsden
@@ -102,6 +102,7 @@ files:
102
102
  - ".gitignore"
103
103
  - ".rspec"
104
104
  - Gemfile
105
+ - Gemfile.lock
105
106
  - LICENSE
106
107
  - README.md
107
108
  - dest.gemspec