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 +4 -4
- data/lib/config_reader.rb +9 -3
- data/lib/source_files.rb +2 -1
- data/lib/util.rb +11 -2
- data/lib/workspace/build.rb +9 -5
- data/lib/workspace/help.rb +2 -1
- data/lib/workspace/make.rb +1 -1
- data/lib/workspace/new.rb +15 -3
- data/lib/workspace/run.rb +1 -1
- data/lib/workspace/test.rb +31 -34
- data/lib/workspace/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 74d6ddb337f4f8d2b52f18e5f6d3f2925211481dd5ad139ba555675bf434d356
|
|
4
|
+
data.tar.gz: 9828b9850dc35c90ba98a93f3b63a53df1ac102ba0c3c5ae41716f1f670e702d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
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.
|
|
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
|
|
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
|
|
data/lib/workspace/build.rb
CHANGED
|
@@ -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.
|
|
47
|
-
compiler_name = flags[
|
|
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 = [
|
|
54
|
+
compiler_flags = ['-Isrc/components']
|
|
51
55
|
linker_flags = []
|
|
52
56
|
|
|
53
|
-
c_flags, l_flags = flags[
|
|
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
|
|
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"
|
data/lib/workspace/help.rb
CHANGED
|
@@ -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/make.rb
CHANGED
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(
|
|
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
|
-
|
|
26
|
-
|
|
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
data/lib/workspace/test.rb
CHANGED
|
@@ -5,20 +5,13 @@ module Canoe
|
|
|
5
5
|
test_all
|
|
6
6
|
return
|
|
7
7
|
end
|
|
8
|
-
|
|
9
|
-
args.
|
|
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).
|
|
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
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
data/lib/workspace/version.rb
CHANGED
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
|
+
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-
|
|
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.
|