canoe 0.3.0 → 0.3.0.1

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
  SHA256:
3
- metadata.gz: f6650afffc9e3aa13bb3489b419cd7e4f2b44f1f104be6fdffa77d0b2a66d072
4
- data.tar.gz: fef3df6c97065e9274c2f95e2b2993a740d46a563e9e04b7359fbb4b69d4f95d
3
+ metadata.gz: 7c1916c0ee5ce05d67222c84f93ac7e41de04895ffb523b1a5435276c6f8e11f
4
+ data.tar.gz: f3b69717aed857c30f8154fb1f63126b8f84c42081890ef1be75c6d2a7250735
5
5
  SHA512:
6
- metadata.gz: 1c093606ffcc64c3679afc3b8998841e7e1b8e83a2315d5bc8f1ad91e2c3b36d3eac5d649dda55d27287600ba52c9880c2f65b612b65f5fb57dbeac06ddc865b
7
- data.tar.gz: 7483c43fa9d8f91c27be1b042f2b151187a867e85fd4cffc57f84b0a01c892583ef3f7d57ad6c816ad50668cabdfcb4e6c955db9c95aba8037ccf30c02eb0054
6
+ metadata.gz: adae82066e778ae3756d970b75fb87784087e25996051c9cd5dd5ad75f265c09418eeb5c4387db9b0c9c125d1b1739461f1f0a0dfc72cde9f1914a65023eb030
7
+ data.tar.gz: 7d31ba373cf0a9a7f41178a153ee8fd7f9eb442a2698ec464c5ea9ca247b9816765f2bc17db1d0902209c6e6e4ff4bc238a4d7e9fa59cf74ba29a841bf519c3b
@@ -0,0 +1,23 @@
1
+ ##
2
+ # gem Colorize is a great tool, but I don't want add dependencies to Canoe
3
+ class String
4
+ def self.define_coloring_methods
5
+ colors = {
6
+ 30 => :black,
7
+ 31 => :red,
8
+ 32 => :green,
9
+ 33 => :yellow,
10
+ 34 => :blue,
11
+ 35 => :magenta,
12
+ 36 => :cyan,
13
+ 37 => :white
14
+ }
15
+ colors.each do |k, v|
16
+ define_method v do
17
+ "\033[#{k}m#{self}\033[0m"
18
+ end
19
+ end
20
+ end
21
+
22
+ define_coloring_methods
23
+ end
@@ -5,9 +5,9 @@
5
5
  class DefaultFiles
6
6
  class << self
7
7
  def open_file_and_write(filename, content)
8
- File.open(filename, "w") {|f|
8
+ File.open(filename, "w") do |f|
9
9
  f.write(content)
10
- }
10
+ end
11
11
  end
12
12
 
13
13
  def create_config(path, src_sfx='cpp', hdr_sfx='hpp')
@@ -31,14 +31,17 @@ class DepAnalyzer
31
31
  def self.compiling_filter(deps, build_time, src_sfx='cpp', hdr_sfx='hpp')
32
32
  files = []
33
33
  @processed = {}
34
+ @recompiles = {}
34
35
  deps.keys.each do |k|
35
36
  @processed[k] = false
37
+ @recompiles[k] = false
36
38
  end
37
39
  deps.each do |k, v|
38
40
  next if k.end_with? ".#{hdr_sfx}"
39
41
  if should_recompile?(k, build_time)
40
42
  files << k
41
43
  @processed[k] = true
44
+ @recompiles[k] = true
42
45
  next
43
46
  end
44
47
  v.each do |f|
@@ -58,9 +61,12 @@ class DepAnalyzer
58
61
  return true
59
62
  else
60
63
  deps[file].each do |f|
61
- next if @processed[f]
64
+ return @recompiles[f] if @processed[f]
62
65
  @processed[f] = true
63
- return true if mark(f, build_time, deps)
66
+ if mark(f, build_time, deps)
67
+ @recompiles[f] = true
68
+ return true
69
+ end
64
70
  end
65
71
  end
66
72
  false
@@ -69,7 +75,11 @@ class DepAnalyzer
69
75
  def self.should_recompile?(file, build_time)
70
76
  judge = build_time
71
77
  if build_time == Time.new(0)
72
- objfile = "./obj/#{File.basename(file, ".*")}.o"
78
+ objfile = if file.start_with?("./src/components")
79
+ './obj/' + file.delete_suffix(File.extname(file))['./src/components/'.length..].gsub('/', '_') + '.o'
80
+ else
81
+ "./obj/#{File.basename(file, ".*")}.o"
82
+ end
73
83
  return true unless File.exists? objfile
74
84
  judge = File.mtime(objfile)
75
85
  end
data/lib/err.rb CHANGED
@@ -1,7 +1,8 @@
1
+ require_relative 'coloring'
1
2
  module Err
2
3
  def warn_on_err(err)
3
4
  puts <<~ERR
4
- Warning:
5
+ #{"Waring: ".yellow}
5
6
  #{err}
6
7
  try 'canoe help' for more information
7
8
  ERR
@@ -9,11 +10,11 @@ module Err
9
10
 
10
11
  def abort_on_err(err)
11
12
  abort <<~ERR
12
- Fatal:
13
+ #{"Fatal: ".red}
13
14
  #{err}
14
15
  try 'canoe help' for more information
15
16
  ERR
16
17
  end
17
18
 
18
19
  module_function :warn_on_err, :abort_on_err
19
- end
20
+ end
@@ -5,6 +5,7 @@ require_relative 'config_reader'
5
5
  require_relative 'default_files'
6
6
  require_relative 'err'
7
7
  require_relative 'dependence'
8
+ require_relative 'coloring'
8
9
 
9
10
  class WorkSpace
10
11
  include Err
@@ -51,8 +52,7 @@ class WorkSpace
51
52
  headers are added or removed from any file.
52
53
 
53
54
  update:
54
- this command is needed because '.canoe.deps' is actually a cache of dependency relationships so that
55
- canoe doesn't have to analyze all the files when building a project.
55
+ this command is needed because '.canoe.deps' is actually a cache of dependency relationships so that canoe doesn't have to analyze all the files when building a project.
56
56
  So when a file includes new headers or some headers are removed, users have to use 'canoe udpate'
57
57
  to update dependency relationships.
58
58
 
@@ -104,7 +104,11 @@ class WorkSpace
104
104
  end
105
105
 
106
106
  def new
107
- Dir.mkdir(@name)
107
+ begin
108
+ Dir.mkdir(@name)
109
+ rescue
110
+ abort_on_err "workspace #{@name} already exsits"
111
+ end
108
112
  Dir.mkdir(@src)
109
113
  Dir.mkdir(@components)
110
114
  Dir.mkdir("#{@workspace}/obj")
@@ -122,7 +126,7 @@ class WorkSpace
122
126
  Dir.chdir(@workspace) do
123
127
  system "git init"
124
128
  end
125
- puts "workspace #{@workspace} is created"
129
+ puts "workspace #{@workspace.blue} is created"
126
130
  end
127
131
 
128
132
  # args are commandline parameters passed to `canoe build`
@@ -134,7 +138,7 @@ class WorkSpace
134
138
  build_time = File.exist?(target) ? File.mtime(target) : Time.new(0)
135
139
  files = DepAnalyzer.compiling_filter(deps, build_time, @source_suffix, @header_suffix)
136
140
 
137
- if files.empty?
141
+ if files.empty? && File.exist?(target)
138
142
  puts "nothing to do, all up to date"
139
143
  return
140
144
  end
@@ -174,7 +178,7 @@ class WorkSpace
174
178
  unless Dir.exist? dir
175
179
  FileUtils.mkdir dir
176
180
  Dir.chdir(dir) do
177
- puts "created " + Dir.pwd
181
+ puts "created " + Dir.pwd.blue
178
182
  create_working_files prefix.join('__'), filename
179
183
  end
180
184
  end
@@ -186,8 +190,8 @@ class WorkSpace
186
190
  deps = DepAnalyzer.read_from(@deps) if File.exist?(@deps)
187
191
  deps.each do |k, v|
188
192
  unless v.empty?
189
- puts "#{k} depends on: "
190
- v.each {|f| puts " #{f}"}
193
+ puts "#{k.blue} depends on: "
194
+ v.each {|f| puts " #{f.blue}"}
191
195
  puts ""
192
196
  end
193
197
  end
@@ -241,35 +245,33 @@ class WorkSpace
241
245
  end
242
246
 
243
247
  def link_exectutable(odir, objs)
244
- puts "[100%] linking"
248
+ puts "#{"[100%]".green} linking"
245
249
  @compiler.link_executable "#{odir}/#{@name}", objs
246
250
  end
247
251
 
248
252
  def link_shared(odir, objs)
249
- puts "[100%] linking"
253
+ puts "#{"[100%]".green} linking"
250
254
  @compiler.link_shared "#{odir}/lib#{@name}", objs
251
255
  end
252
256
 
253
257
  def build_bin(files, args)
254
- return if files.empty?
258
+ # return if files.empty?
255
259
  build_compiler_from_config args
256
- if build_common(files, args)
257
- link_exectutable('./target', Dir.glob("obj/*.o"))
258
- puts "canoe: building succeeded"
260
+ if build_common(files, args) && link_exectutable('./target', Dir.glob("obj/*.o"))
261
+ puts "BUILDING SUCCEEDED".green
259
262
  else
260
- puts "canoe: building failed"
263
+ puts "building FAILED".red
261
264
  end
262
265
  end
263
266
 
264
267
  def build_lib(files, args)
265
- return if files.empty?
268
+ # return if files.empty?
266
269
  build_compiler_from_config args
267
270
  @compiler.append_compiling_flag '-fPIC'
268
- if (build_common files, args)
269
- link_shared('./target', Dir.glob("obj/*.o"))
270
- puts "canoe: building succeeded"
271
+ if (build_common files, args) && link_shared('./target', Dir.glob("obj/*.o"))
272
+ puts "BUILDING SUCCEEDED".green
271
273
  else
272
- puts "canoe: building failed"
274
+ puts "building FAILED".red
273
275
  end
274
276
  end
275
277
 
@@ -282,16 +284,16 @@ class WorkSpace
282
284
  flag = true;
283
285
  srcs.each do |f|
284
286
  progress = (compiled / total).round(2) * 100
285
- printf "[#{progress.to_i}%%] compiling #{f}: "
287
+ printf "[#{progress.to_i}%%]".green + " compiling #{f}: "
286
288
  fname = f.split("/")[-1]
287
- o = @obj_prefix + fname.delete_suffix(File.extname(fname)) + '.o'
289
+ o = @obj_prefix + File.basename(fname, ".*") + '.o'
288
290
  flag = false unless compile f, o
289
291
  compiled += 1
290
292
  end
291
293
 
292
294
  comps.each do |f|
293
295
  progress = (compiled / total).round(2) * 100
294
- printf "[#{progress.to_i}%%] compiling #{f}: "
296
+ printf "[#{progress.to_i}%%]".green + " compiling #{f}: "
295
297
  o = @obj_prefix + f.delete_suffix(File.extname(f))[@components_prefix.length..]
296
298
  .gsub('/', '_') + '.o'
297
299
  flag = false unless compile f, o
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: canoe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - XIONG Ziwei
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-10 00:00:00.000000000 Z
11
+ date: 2020-07-11 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |+
14
14
  Canoe offers project management and building facilities to C/C++ projects.
@@ -28,6 +28,7 @@ files:
28
28
  - bin/canoe
29
29
  - lib/canoe.rb
30
30
  - lib/cmd.rb
31
+ - lib/coloring.rb
31
32
  - lib/compiler.rb
32
33
  - lib/config_reader.rb
33
34
  - lib/default_files.rb