canoe 0.3.2.4 → 0.3.3.3

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: 18aa4cddd71a6a2b06ea69ea320de7e75b5a9155685d5f4918b5047faf9a83af
4
- data.tar.gz: 488a487b6b2cb872fed7b81e604756c7676e279a3b750e720f3c219aa1f29210
3
+ metadata.gz: e7002afc65c5738fb7929e1b81cc491b9d7a7196b2ada01f3b6f580ccfe25133
4
+ data.tar.gz: 48632ed95d610599712de7f84fbfb8108c1195d9460cf1a96b8b22cccb59891c
5
5
  SHA512:
6
- metadata.gz: c0e5a956513c53ecee63750c6d13b2ff5ebba51716e72e6631aed667962d5df5e0ea3eee064ba0435a6d3f37ebf3cc2d6128bc5fce0145d6952500ef39eac0e4
7
- data.tar.gz: 1cf7cd8b486bb92f32c646fa0eebebf94288a97c00362e6af749814c352305a2b3903e4df2ffde3689365d90020522eb681e5e07d9ed486b3a0871a49edb16e7
6
+ metadata.gz: fa9c3ccf050acd66acd89bdc4b7f4fc280c68e926be7d027cfbb44cecf9f89b51aa7b61b44269f6f7d4a2c2524f4b67e65ba507a074824bba7018940dfb19d82
7
+ data.tar.gz: 23f4cd1c8e5bb9e57d8bda28974366d7486efca3a5d7c275c1042a27a7c039dd80e699d792330417647a72b3615ba164aba502c7e16097a549fd16b41fc45135
data/lib/canoe.rb CHANGED
@@ -3,20 +3,11 @@ require_relative 'cmd'
3
3
  require_relative 'source_files'
4
4
 
5
5
  module Canoe
6
+ ##
7
+ # Main class for building a canoe project
6
8
  class Builder
7
9
  def initialize
8
- options = ['new',
9
- 'add',
10
- 'build',
11
- 'generate',
12
- 'make',
13
- 'run',
14
- 'dep',
15
- 'clean',
16
- 'version',
17
- 'help',
18
- 'update',
19
- 'test']
10
+ options = %w[new add build generate make run dep clean version help update test]
20
11
  @cmd = CmdParser.new options
21
12
  end
22
13
 
data/lib/dependence.rb CHANGED
@@ -1,19 +1,17 @@
1
1
  require_relative 'source_files'
2
2
  require_relative 'util'
3
- ##
4
- # class DepAnalyzer
5
- # This class is the key component of canoe, which offers file dependency analysis functionality.
6
- # A DepAnalyzer takes a directory as input, sources files and corresponding header files in this
7
- # directory should have same name, e.g. test.cpp and test.hpp.
8
- # DepAnalyzer would read every source file and recursively process user header files included in this source file to
9
- # find out all user header files this source file depends on.
10
- # Based on dependencies built in previous stage, DepAnalyzer determines which files should be recompiled and return
11
- # these files to caller.
12
- #
13
- # Dependencies could be written to a file to avoid wasting time parsing all files, Depanalyzer would read from
14
- # this file to construct dependencies. But if sources files included new headers or included headers are revmoed,
15
- # Depanalyzer should rebuild the whole dependencies.
16
3
  module Canoe
4
+ ##
5
+ # This class is the key component of canoe, which offers file dependency analysis functionality.
6
+ #
7
+ # A DepAnalyzer takes a directory as input, sources files and corresponding header files in this
8
+ # directory should have same name, e.g. test.cpp and test.hpp. DepAnalyzer would read every source file and
9
+ # recursively process user header files included in this source file to find out all user header files this
10
+ # source file depends on. Based on dependencies built in previous stage, DepAnalyzer determines which files
11
+ # should be recompiled and return these files to caller. Dependencies could be written to a file to avoid
12
+ # wasting time parsing all files, Depanalyzer would read from this file to construct dependencies. But if
13
+ # sources files included new headers or included headers are revmoed, Depanalyzer should rebuild the whole
14
+ # dependencies.
17
15
  class DepAnalyzer
18
16
  include Err
19
17
  include SystemCommand
data/lib/source_files.rb CHANGED
@@ -13,13 +13,11 @@ class SourceFiles
13
13
  @files = []
14
14
  Dir.each_child(dir) do |f|
15
15
  file = "#{dir}/#{f}"
16
- if File.file? file
17
- if block_given?
18
- @files << file.to_s if yield(f)
19
- else
20
- @files << file.to_s
21
- end
22
- end
16
+ next unless File.file?(file)
17
+
18
+ add = true
19
+ add = yield(f) if block_given?
20
+ @files << file.to_s if add
23
21
  end
24
22
 
25
23
  @files
@@ -30,14 +28,13 @@ class SourceFiles
30
28
  def get_all_helper(dir, &block)
31
29
  Dir.each_child(dir) do |f|
32
30
  file = "#{dir}/#{f}"
31
+ # we don't handle symlinks
33
32
  if File.file? file
34
- if block_given?
35
- @files << "#{file}" if yield(f)
36
- else
37
- @files << "#{file}"
38
- end
39
- else
40
- get_all_helper("#{file}", &block)
33
+ add = true
34
+ add = yield(f) if block_given?
35
+ @files << file if add
36
+ elsif File.directory? file
37
+ get_all_helper(file, &block)
41
38
  end
42
39
  end
43
40
  end
data/lib/util.rb CHANGED
@@ -1,5 +1,8 @@
1
+ # Many useful classes to record compiling progress, change file's name and issueing system commands
1
2
  require_relative 'coloring'
2
3
 
4
+ require 'English'
5
+
3
6
  module Canoe
4
7
  ##
5
8
  # Stepper record the progress of a task
@@ -57,13 +60,24 @@ module Canoe
57
60
  end
58
61
  end
59
62
 
63
+ ##
64
+ # issueing system commands by accepting a command string
60
65
  module SystemCommand
61
66
  def issue_command(cmd_str)
62
67
  puts cmd_str
63
- system cmd_str
68
+ system(cmd_str)
69
+ end
70
+
71
+ def run_command(cmd_str)
72
+ puts cmd_str
73
+ status = system(cmd_str)
74
+ puts $CHILD_STATUS unless status
75
+ status
64
76
  end
65
77
  end
66
-
78
+
79
+ ##
80
+ # Colorized error messages with abortion
67
81
  module Err
68
82
  def warn_on_err(err)
69
83
  puts <<~ERR
data/lib/workspace/add.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  module Canoe
2
+ # WorkSpace implementation
2
3
  class WorkSpace
3
4
  def add(args)
4
5
  args.each do |i|
@@ -135,7 +135,7 @@ module Canoe
135
135
  puts "#{'[BUILDING TARGET]'.magenta}..."
136
136
  target = "#{@target}/#{@name}"
137
137
  build_time = File.exist?(target) ? File.mtime(target) : Time.new(0)
138
- 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)
139
139
 
140
140
  if files.empty? && File.exist?(target)
141
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
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,24 +37,27 @@ 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}"
47
+ abort_on_err "No test file exists for #{name}" unless File.exist?(file)
53
48
  rebuild ||= File.mtime(bin) < File.mtime(file)
54
-
49
+
55
50
  deps = fetch_all_deps
56
51
  extract_one_file(file, deps).each do |f|
57
52
  rebuild ||= File.mtime(bin) < File.mtime(f) || File.mtime(bin) < File.mtime(hdr_of_src(f))
58
53
  end
59
54
 
55
+ cmd = "#{bin} #{args}"
60
56
  if rebuild
61
57
  build_compiler_from_config
62
- issue_command bin if build_one_test(file, deps)
58
+ run_command cmd if build_one_test(file, deps)
63
59
  else
64
- issue_command bin
60
+ run_command cmd
65
61
  end
66
62
  end
67
63
 
@@ -82,26 +78,22 @@ module Canoe
82
78
  end.min
83
79
  end
84
80
 
85
- # @deps is the dependency hash for tests
86
- # cyclic dependency is not handled
87
- # compiler should first be built
88
- def compile_one_test(test_file, deps)
89
- extract_one_file(test_file, deps).each do |f|
90
- o = file_to_obj(f)
91
- next if File.exist?(o) && File.mtime(o) > File.mtime(f) && File.mtime(o) > File.mtime(hdr_of_src(f))
92
-
93
- compile(f, o)
94
- end
95
- compile(test_file, file_to_obj(test_file))
96
- end
97
-
98
81
  def link_one_test(test_file, deps)
99
82
  target = "#{@target_short}/#{File.basename(test_file, '.*')}"
100
83
  @compiler.link_executable target, extract_one_file_obj(test_file, deps) + [file_to_obj(test_file)]
101
84
  end
102
85
 
103
86
  def build_one_test(test_file, deps)
104
- 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 &= compile f, o
94
+ end
95
+
96
+ abort_on_err("Compiling errors encountered") unless flag;
105
97
  link_one_test(test_file, deps)
106
98
  end
107
99
 
@@ -114,7 +106,7 @@ module Canoe
114
106
 
115
107
  files.each do |f|
116
108
  printf "#{stepper.progress_as_str.green} compiling #{f} "
117
- compile_one_test(f, deps)
109
+ build_one_test(f, deps)
118
110
  stepper.step
119
111
  end
120
112
  end
@@ -131,6 +123,7 @@ module Canoe
131
123
  end
132
124
 
133
125
  def build_test
126
+ build_compiler_from_config
134
127
  puts "#{'[COMPILING TESTS]'.magenta}..."
135
128
  return unless test_build_time
136
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.4
5
+ canoe v0.3.3.3
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.4
4
+ version: 0.3.3.3
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-06-21 00:00:00.000000000 Z
11
+ date: 2021-12-13 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |+
14
14
  Canoe offers project management and building facilities to C/C++ projects.