canoe 0.3.2.3 → 0.3.3.2

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: '0518fcb695948644be7df59c7200eaf996a1c753bb8b575721764d36fcde61cb'
4
- data.tar.gz: 385806c9e2035fa9c0cd1caf2556ca8aba1994ca73caad835f252003bbe1c36e
3
+ metadata.gz: 74d6ddb337f4f8d2b52f18e5f6d3f2925211481dd5ad139ba555675bf434d356
4
+ data.tar.gz: 9828b9850dc35c90ba98a93f3b63a53df1ac102ba0c3c5ae41716f1f670e702d
5
5
  SHA512:
6
- metadata.gz: fe763993a442305afd7180eba5bb52fe63cd5ba9c8520c985a1cecec3ecbabb52296c5b6afd5ac7a72fa2341ebe432a6e7ca7b261145ca211dfc436f5066d22c
7
- data.tar.gz: 9eb610ca364b557e9e1999c18dd497912503cdc0580f3f403ef3abf6f4ac58803b81d5a1c352f02e5e00685d6bb1e471866f33c3da2f12651063fb4e6a5f33bc
6
+ metadata.gz: bbd6271cff5a4a5c6342918b9b9c1420216016d185a8979d7d177ce78a3e01e26d4984dc69c90aec0706824fd14e6be0dd9cfb1fb612988bad9412241e16326f
7
+ data.tar.gz: 0e39977c7d620b0cc5b8fc55ab9e6b79049c9ca01534e75ef2f856d5fd2005e56102337aeb19e34800d948058e83c6e74af54e51bf6f646fe61edbd002e14c40
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,6 +18,10 @@ 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')
@@ -43,14 +47,14 @@ module Canoe
43
47
  end
44
48
 
45
49
  def build_compiler_from_config
46
- flags = ConfigReader.extract_flags "config.json"
47
- compiler_name = flags["compiler"] ? flags["compiler"] : "clang++"
50
+ flags = ConfigReader.new('config.json').extract_flags
51
+ compiler_name = flags['compiler'] ? flags['compiler'] : 'clang++'
48
52
 
49
53
  abort_on_err "compiler #{compiler_name} not found" unless system "which #{compiler_name} > /dev/null"
50
- compiler_flags = ["-Isrc/components"]
54
+ compiler_flags = ['-Isrc/components']
51
55
  linker_flags = []
52
56
 
53
- c_flags, l_flags = flags["flags"]["compile"], flags["flags"]["link"]
57
+ c_flags, l_flags = flags['flags']['compile'], flags['flags']['link']
54
58
  build_flags(compiler_flags, c_flags)
55
59
  build_flags(linker_flags, l_flags)
56
60
 
@@ -131,7 +135,7 @@ module Canoe
131
135
  puts "#{'[BUILDING TARGET]'.magenta}..."
132
136
  target = "#{@target}/#{@name}"
133
137
  build_time = File.exist?(target) ? File.mtime(target) : Time.new(0)
134
- files = DepAnalyzer.compiling_filter target_deps, build_time, @source_suffix, @header_suffix
138
+ files = DepAnalyzer.compiling_filter(target_deps, build_time, @source_suffix, @header_suffix)
135
139
 
136
140
  if files.empty? && File.exist?(target)
137
141
  puts "nothing to do, all up to date"
@@ -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,21 +37,28 @@ module Canoe
44
37
  end
45
38
  end
46
39
 
47
- def test_single(name)
40
+ def test_single(name, args = "")
48
41
  rebuild = false;
49
42
  bin = "#{@target_short}/test_#{name}"
43
+
50
44
  rebuild ||= !File.exist?(bin)
51
-
45
+
52
46
  file = "#{@tests_short}/test_#{name}.#{@source_suffix}"
53
-
47
+ abort_on_err "No test file exists for #{name}" unless File.exist?(file)
48
+ rebuild ||= File.mtime(bin) < File.mtime(file)
49
+
54
50
  deps = fetch_all_deps
55
- extract_one_file(file, deps).push(file).each do |f|
56
- rebuild ||= File.mtime(bin) < File.mtime(f)
51
+ extract_one_file(file, deps).each do |f|
52
+ rebuild ||= File.mtime(bin) < File.mtime(f) || File.mtime(bin) < File.mtime(hdr_of_src(f))
57
53
  end
58
54
 
59
- build_compiler_from_config && build_one_test(file, deps) if rebuild
60
-
61
- issue_command bin
55
+ cmd = "#{bin} #{args}"
56
+ if rebuild
57
+ build_compiler_from_config
58
+ run_command cmd if build_one_test(file, deps)
59
+ else
60
+ run_command cmd
61
+ end
62
62
  end
63
63
 
64
64
  def fetch_all_test_files
@@ -78,26 +78,22 @@ module Canoe
78
78
  end.min
79
79
  end
80
80
 
81
- # @deps is the dependency hash for tests
82
- # cyclic dependency is not handled
83
- # compiler should first be built
84
- def compile_one_test(test_file, deps)
85
- extract_one_file(test_file, deps).each do |f|
86
- o = file_to_obj(f)
87
- next if File.exist?(o) && File.mtime(o) > File.mtime(f)
88
-
89
- compile(f, o)
90
- end
91
- compile(test_file, file_to_obj(test_file))
92
- end
93
-
94
81
  def link_one_test(test_file, deps)
95
82
  target = "#{@target_short}/#{File.basename(test_file, '.*')}"
96
83
  @compiler.link_executable target, extract_one_file_obj(test_file, deps) + [file_to_obj(test_file)]
97
84
  end
98
85
 
99
86
  def build_one_test(test_file, deps)
100
- compile_one_test(test_file, deps)
87
+ files = DepAnalyzer.compiling_filter(target_deps, Time.new(0), @source_suffix, @header_suffix)
88
+ flag = true
89
+ files << test_file
90
+
91
+ files.each do |f|
92
+ o = file_to_obj(f)
93
+ flag = false unless compile f, o
94
+ end
95
+
96
+ abort_on_err("Compiling errors encountered") unless flag;
101
97
  link_one_test(test_file, deps)
102
98
  end
103
99
 
@@ -110,7 +106,7 @@ module Canoe
110
106
 
111
107
  files.each do |f|
112
108
  printf "#{stepper.progress_as_str.green} compiling #{f} "
113
- compile_one_test(f, deps)
109
+ build_one_test(f, deps)
114
110
  stepper.step
115
111
  end
116
112
  end
@@ -127,6 +123,7 @@ module Canoe
127
123
  end
128
124
 
129
125
  def build_test
126
+ build_compiler_from_config
130
127
  puts "#{'[COMPILING TESTS]'.magenta}..."
131
128
  return unless test_build_time
132
129
 
@@ -2,7 +2,7 @@ module Canoe
2
2
  class WorkSpace
3
3
  def self.version
4
4
  puts <<~VER
5
- canoe v0.3.2.3
5
+ canoe v0.3.3.2
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.3
4
+ version: 0.3.3.2
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-18 00:00:00.000000000 Z
11
+ date: 2021-12-10 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |+
14
14
  Canoe offers project management and building facilities to C/C++ projects.