canoe 0.3.2.2 → 0.3.3.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: 50752029532b56ce10a610ae7d9705212a1c424533ed2fde71a3133505c11d0e
4
- data.tar.gz: 501d882198eb59157961a741d786dbbe5c420e9d2704d37e7b1ca9a0f651854a
3
+ metadata.gz: f306cd1daca6a05e5ed98b6bac0d638ee6c8b3deb8f033573254b40e0e111f04
4
+ data.tar.gz: 20025070fa9b8880e7702fa1560458c6c02f3bd6ef544f0c105c04c4eabbb08b
5
5
  SHA512:
6
- metadata.gz: 2da665d3e3ce5e073a207863fc2cc2f06a892d9e7889d3e0e29617c673c01d5aa503854c5effb80b34989b3cdf9743a1b8ada49c537920ba06f5ec1e5cd836c0
7
- data.tar.gz: 9d13815277a02e41a894cee4528c3742d35a6e81cbc84828a0f8dc857aae1c7356de4cc05511ca9145a2f4d2912315955746541bd47d35d949c38863d1ddecf7
6
+ metadata.gz: 57d280fbde673916e1abc93a027cb9be3eda421a9bf9e65ece2c5415d9c0be19236070575b464b09d934aad7729343afcbd9e105424105417e1ea14db50e300c
7
+ data.tar.gz: b0724750762fe724958ec732e7f701d13f8b0d7c2cfaf80f8e32c01e959b982e682594cc543cc45115e0aef0a70bfd93c0ca53cd48aa8278b905d87904f52ad7
data/lib/config_reader.rb CHANGED
@@ -1,11 +1,17 @@
1
1
  require 'json'
2
+ require_relative 'util'
2
3
 
3
4
  ##
4
5
  # class ConfigReader
5
6
  # Just read a json file
6
7
  class ConfigReader
7
- def self.extract_flags(file)
8
- abort_on_err("config file #{file} does not exsit") unless File.exist? file
9
- JSON.parse(File.read(file))
8
+ include Canoe::Err
9
+ def initialize(file)
10
+ @config_file = file
11
+ end
12
+
13
+ def extract_flags
14
+ abort_on_err("config file #{@config_file} does not exsit") unless File.exist? @config_file
15
+ JSON.parse(File.read(@config_file))
10
16
  end
11
17
  end
data/lib/source_files.rb CHANGED
@@ -30,13 +30,14 @@ class SourceFiles
30
30
  def get_all_helper(dir, &block)
31
31
  Dir.each_child(dir) do |f|
32
32
  file = "#{dir}/#{f}"
33
+ # we don't handle symlinks
33
34
  if File.file? file
34
35
  if block_given?
35
36
  @files << "#{file}" if yield(f)
36
37
  else
37
38
  @files << "#{file}"
38
39
  end
39
- else
40
+ elsif File.directory? file
40
41
  get_all_helper("#{file}", &block)
41
42
  end
42
43
  end
data/lib/util.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  require_relative 'coloring'
2
2
 
3
+ require 'English'
4
+
3
5
  module Canoe
4
6
  ##
5
7
  # Stepper record the progress of a task
@@ -25,7 +27,7 @@ module Canoe
25
27
  module WorkSpaceUtil
26
28
  def current_workspace
27
29
  abort_on_err 'not in a canoe workspace' unless File.exist? '.canoe'
28
- config = ConfigReader.extract_flags('config.json')
30
+ config = ConfigReader.new('config.json').extract_flags
29
31
 
30
32
  src_sfx = config['source-suffix'] || 'cpp'
31
33
  hdr_sfx = config['header-suffix'] || 'hpp'
@@ -60,7 +62,14 @@ module Canoe
60
62
  module SystemCommand
61
63
  def issue_command(cmd_str)
62
64
  puts cmd_str
63
- system cmd_str
65
+ system(cmd_str)
66
+ end
67
+
68
+ def run_command(cmd_str)
69
+ puts cmd_str
70
+ status = system(cmd_str)
71
+ puts $CHILD_STATUS unless status
72
+ status
64
73
  end
65
74
  end
66
75
 
@@ -18,9 +18,14 @@ module Canoe
18
18
  end
19
19
  end
20
20
 
21
+ def hdr_of_src(file)
22
+ file.gsub(".#{@source_suffix}", ".#{@header_suffix}")
23
+ end
24
+
21
25
  # args are commandline parameters passed to `canoe build`,
22
26
  # could be 'all', 'test', 'target', 'base' or empty
23
27
  def build(arg = 'target')
28
+ build_compiler_from_config
24
29
  send "build_#{arg}"
25
30
  end
26
31
 
@@ -42,14 +47,14 @@ module Canoe
42
47
  end
43
48
 
44
49
  def build_compiler_from_config
45
- flags = ConfigReader.extract_flags "config.json"
46
- compiler_name = flags["compiler"] ? flags["compiler"] : "clang++"
50
+ flags = ConfigReader.new('config.json').extract_flags
51
+ compiler_name = flags['compiler'] ? flags['compiler'] : 'clang++'
47
52
 
48
53
  abort_on_err "compiler #{compiler_name} not found" unless system "which #{compiler_name} > /dev/null"
49
- compiler_flags = ["-Isrc/components"]
54
+ compiler_flags = ['-Isrc/components']
50
55
  linker_flags = []
51
56
 
52
- c_flags, l_flags = flags["flags"]["compile"], flags["flags"]["link"]
57
+ c_flags, l_flags = flags['flags']['compile'], flags['flags']['link']
53
58
  build_flags(compiler_flags, c_flags)
54
59
  build_flags(linker_flags, l_flags)
55
60
 
@@ -132,8 +137,6 @@ module Canoe
132
137
  build_time = File.exist?(target) ? File.mtime(target) : Time.new(0)
133
138
  files = DepAnalyzer.compiling_filter target_deps, build_time, @source_suffix, @header_suffix
134
139
 
135
- build_compiler_from_config
136
-
137
140
  if files.empty? && File.exist?(target)
138
141
  puts "nothing to do, all up to date"
139
142
  return true
@@ -145,7 +148,6 @@ module Canoe
145
148
  # generate a compile_commands.json file
146
149
  def build_base
147
150
  deps = target_deps.merge tests_deps
148
- build_compiler_from_config
149
151
  database = CompilationDatabase.new
150
152
  deps.each_key do |k|
151
153
  next if k.end_with? @header_suffix
@@ -53,9 +53,10 @@ module Canoe
53
53
  build [all|test]:
54
54
  build current project, 'all' builds both target and tests, 'test' builds tests only
55
55
 
56
- test [tests]:
56
+ test [tests] [args]:
57
57
  build and run tests
58
58
  [tests]: 'all' for all tests, or a name of a test for a single test
59
+ [args]: args are passed to the single test
59
60
 
60
61
  run [options]:
61
62
  build current project with no specific compilation flags, and run this project, passing [options] as command line arguments to the binary
@@ -267,7 +267,7 @@ module Canoe
267
267
 
268
268
  class WorkSpace
269
269
  def make
270
- config = ConfigReader.extract_flags "config.json"
270
+ config = ConfigReader.new('config.json').extract_flags
271
271
 
272
272
  deps = target_deps.merge tests_deps
273
273
 
data/lib/workspace/new.rb CHANGED
@@ -8,7 +8,8 @@ module Canoe
8
8
  end
9
9
  Dir.mkdir(@src)
10
10
  Dir.mkdir(@components)
11
- Dir.mkdir("#{@workspace}/obj")
11
+ Dir.mkdir(@obj)
12
+ add_gitignore @obj
12
13
  if @mode == :bin
13
14
  DefaultFiles.create_main(@src, @source_suffix)
14
15
  else
@@ -20,12 +21,23 @@ module Canoe
20
21
 
21
22
  Dir.mkdir(@third)
22
23
  Dir.mkdir(@target)
24
+ add_gitignore @target
23
25
  Dir.mkdir(@tests)
24
26
  Dir.chdir(@workspace) do
25
- system 'git init'
26
- system 'canoe add tests'
27
+ issue_command 'git init'
28
+ issue_command 'canoe add tests'
27
29
  end
28
30
  puts "workspace #{@workspace.blue} is created"
29
31
  end
32
+
33
+ private
34
+
35
+ def add_gitignore(dir)
36
+ Dir.chdir(dir) do
37
+ File.open('.gitignore', 'w') do |f|
38
+ f.write "*\n!.gitignore\n"
39
+ end
40
+ end
41
+ end
30
42
  end
31
43
  end
data/lib/workspace/run.rb CHANGED
@@ -6,7 +6,7 @@ module Canoe
6
6
  return unless build
7
7
 
8
8
  args = args.join ' '
9
- issue_command "#{@target_short}/#{@name} #{args}"
9
+ run_command "#{@target_short}/#{@name} #{args}"
10
10
  end
11
11
  end
12
12
  end
@@ -5,20 +5,13 @@ module Canoe
5
5
  test_all
6
6
  return
7
7
  end
8
-
9
- args.each do |arg|
10
- case arg
11
- when 'all'
12
- test_all
13
- else
14
- test_single arg
15
- end
16
- end
8
+ # we don't handle spaces
9
+ test_single(args[0], args[1..].join(" "))
17
10
  end
18
11
 
19
12
  # extract one test file's dependency
20
13
  def extract_one_file(file, deps)
21
- ret = deps[file]
14
+ ret = deps[file].map { |f| f.gsub(".#{@header_suffix}", ".#{@source_suffix}") }
22
15
 
23
16
  deps[file].each do |f|
24
17
  dep = extract_one_file(f, deps)
@@ -44,13 +37,27 @@ module Canoe
44
37
  end
45
38
  end
46
39
 
47
- def test_single(name)
40
+ def test_single(name, args = "")
41
+ rebuild = false;
48
42
  bin = "#{@target_short}/test_#{name}"
43
+
44
+ rebuild ||= !File.exist?(bin)
45
+
49
46
  file = "#{@tests_short}/test_#{name}.#{@source_suffix}"
50
- abort_on_err "Can not find source file #{file.red} for test #{name.red}" unless File.exist?(file)
51
- build_one_test(file, fetch_all_deps) unless File.exist?(bin)
47
+ rebuild ||= File.mtime(bin) < File.mtime(file)
48
+
49
+ deps = fetch_all_deps
50
+ extract_one_file(file, deps).each do |f|
51
+ rebuild ||= File.mtime(bin) < File.mtime(f) || File.mtime(bin) < File.mtime(hdr_of_src(f))
52
+ end
52
53
 
53
- issue_command bin
54
+ cmd = "#{bin} #{args}"
55
+ if rebuild
56
+ build_compiler_from_config
57
+ run_command cmd if build_one_test(file, deps)
58
+ else
59
+ run_command cmd
60
+ end
54
61
  end
55
62
 
56
63
  def fetch_all_test_files
@@ -76,7 +83,7 @@ module Canoe
76
83
  def compile_one_test(test_file, deps)
77
84
  extract_one_file(test_file, deps).each do |f|
78
85
  o = file_to_obj(f)
79
- next if File.exist?(o) && File.mtime(o) > File.mtime(f)
86
+ next if File.exist?(o) && File.mtime(o) > File.mtime(f) && File.mtime(o) > File.mtime(hdr_of_src(f))
80
87
 
81
88
  compile(f, o)
82
89
  end
@@ -2,7 +2,7 @@ module Canoe
2
2
  class WorkSpace
3
3
  def self.version
4
4
  puts <<~VER
5
- canoe v0.3.2.2
5
+ canoe v0.3.3.1
6
6
  For features in this version, please visit https://github.com/Dicridon/canoe
7
7
  Currently, canoe can do below:
8
8
  - project creation
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.2.2
4
+ version: 0.3.3.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: 2021-05-17 00:00:00.000000000 Z
11
+ date: 2021-08-18 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |+
14
14
  Canoe offers project management and building facilities to C/C++ projects.