canoe 0.3.2.1 → 0.3.2.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/cmd.rb +16 -9
- data/lib/default_files.rb +6 -6
- data/lib/util.rb +10 -7
- data/lib/workspace/build.rb +50 -10
- data/lib/workspace/clean.rb +2 -10
- data/lib/workspace/make.rb +10 -11
- data/lib/workspace/new.rb +2 -2
- data/lib/workspace/run.rb +1 -1
- data/lib/workspace/version.rb +1 -1
- data/lib/workspace/workspace.rb +2 -0
- 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: 50752029532b56ce10a610ae7d9705212a1c424533ed2fde71a3133505c11d0e
|
|
4
|
+
data.tar.gz: 501d882198eb59157961a741d786dbbe5c420e9d2704d37e7b1ca9a0f651854a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2da665d3e3ce5e073a207863fc2cc2f06a892d9e7889d3e0e29617c673c01d5aa503854c5effb80b34989b3cdf9743a1b8ada49c537920ba06f5ec1e5cd836c0
|
|
7
|
+
data.tar.gz: 9d13815277a02e41a894cee4528c3742d35a6e81cbc84828a0f8dc857aae1c7356de4cc05511ca9145a2f4d2912315955746541bd47d35d949c38863d1ddecf7
|
data/lib/cmd.rb
CHANGED
|
@@ -53,31 +53,38 @@ module Canoe
|
|
|
53
53
|
abort_on_err "it's not reasonable to add a component with no name given"
|
|
54
54
|
end
|
|
55
55
|
|
|
56
|
-
|
|
56
|
+
current_workspace.add args
|
|
57
57
|
end
|
|
58
58
|
|
|
59
59
|
def parse_build(args)
|
|
60
|
-
|
|
60
|
+
options = {[] => 'target', ['all'] => 'all', ['test'] => 'test', ['base'] => 'base'}
|
|
61
|
+
abort_on_err "Unkown subcommand #{args.join(" ").red}" unless options.include?(args)
|
|
62
|
+
current_workspace.build options[args]
|
|
61
63
|
end
|
|
62
64
|
|
|
63
65
|
def parse_generate(args)
|
|
64
|
-
|
|
66
|
+
current_workspace.generate
|
|
65
67
|
end
|
|
66
68
|
|
|
67
69
|
def parse_run(args)
|
|
68
|
-
|
|
70
|
+
current_workspace.run args
|
|
69
71
|
end
|
|
70
72
|
|
|
71
73
|
def parse_dep(args)
|
|
72
|
-
|
|
74
|
+
current_workspace.dep
|
|
73
75
|
end
|
|
74
76
|
|
|
75
77
|
def parse_clean(args)
|
|
76
|
-
|
|
78
|
+
options = {
|
|
79
|
+
[] => 'all', ['all'] => 'all',
|
|
80
|
+
['target'] => 'target', ['tests'] => 'tests', ['obj'] => 'obj'
|
|
81
|
+
}
|
|
82
|
+
abort_on_err "Unkown subcommand #{args.join(" ").red}" unless options.include?(args)
|
|
83
|
+
current_workspace.clean options[args]
|
|
77
84
|
end
|
|
78
85
|
|
|
79
86
|
def parse_test(args)
|
|
80
|
-
|
|
87
|
+
current_workspace.test args
|
|
81
88
|
end
|
|
82
89
|
|
|
83
90
|
def parse_version(args)
|
|
@@ -89,11 +96,11 @@ module Canoe
|
|
|
89
96
|
end
|
|
90
97
|
|
|
91
98
|
def parse_update(args)
|
|
92
|
-
|
|
99
|
+
current_workspace.update
|
|
93
100
|
end
|
|
94
101
|
|
|
95
102
|
def parse_make(args)
|
|
96
|
-
|
|
103
|
+
current_workspace.make
|
|
97
104
|
end
|
|
98
105
|
end
|
|
99
106
|
end
|
data/lib/default_files.rb
CHANGED
|
@@ -10,19 +10,18 @@ class DefaultFiles
|
|
|
10
10
|
end
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
-
def create_config(path, src_sfx = 'cpp', hdr_sfx = 'hpp')
|
|
13
|
+
def create_config(path, compiler = 'clang++', src_sfx = 'cpp', hdr_sfx = 'hpp')
|
|
14
14
|
open_file_and_write(
|
|
15
15
|
"#{path}/config.json",
|
|
16
16
|
<<~CONFIG
|
|
17
17
|
{
|
|
18
|
-
"compiler": "
|
|
18
|
+
"compiler": "#{compiler}",
|
|
19
19
|
"header-suffix": "#{hdr_sfx}",
|
|
20
20
|
"source-suffix": "#{src_sfx}",
|
|
21
21
|
"flags": {
|
|
22
22
|
"compile": {
|
|
23
23
|
"opt": "-O2",
|
|
24
|
-
"debug": "-g"
|
|
25
|
-
"std": "-std=c++17"
|
|
24
|
+
"debug": "-g"
|
|
26
25
|
},
|
|
27
26
|
"link": {
|
|
28
27
|
|
|
@@ -34,12 +33,13 @@ class DefaultFiles
|
|
|
34
33
|
end
|
|
35
34
|
|
|
36
35
|
def create_main(path, suffix = 'cpp')
|
|
36
|
+
header = suffix == 'c' ? 'stdio.h' : 'iostream'
|
|
37
37
|
open_file_and_write(
|
|
38
38
|
"#{path}/main.#{suffix}",
|
|
39
39
|
<<~DOC
|
|
40
|
-
#include
|
|
40
|
+
#include <#{header}>
|
|
41
41
|
int main(int argc, char *argv[]) {
|
|
42
|
-
|
|
42
|
+
|
|
43
43
|
}
|
|
44
44
|
DOC
|
|
45
45
|
)
|
data/lib/util.rb
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
require_relative 'coloring'
|
|
2
2
|
|
|
3
3
|
module Canoe
|
|
4
|
+
##
|
|
5
|
+
# Stepper record the progress of a task
|
|
6
|
+
# progress is obtained via #'progress_as_str
|
|
4
7
|
class Stepper
|
|
5
8
|
def initialize(total, togo)
|
|
6
9
|
@total = total.to_f
|
|
@@ -16,11 +19,11 @@ module Canoe
|
|
|
16
19
|
@togo -= 1 if @togo.positive?
|
|
17
20
|
end
|
|
18
21
|
end
|
|
19
|
-
|
|
22
|
+
|
|
20
23
|
##
|
|
21
24
|
# wrapping workspace related functionality to expose to other modules
|
|
22
25
|
module WorkSpaceUtil
|
|
23
|
-
def
|
|
26
|
+
def current_workspace
|
|
24
27
|
abort_on_err 'not in a canoe workspace' unless File.exist? '.canoe'
|
|
25
28
|
config = ConfigReader.extract_flags('config.json')
|
|
26
29
|
|
|
@@ -34,23 +37,23 @@ module Canoe
|
|
|
34
37
|
end
|
|
35
38
|
|
|
36
39
|
def src_to_obj(src)
|
|
37
|
-
|
|
40
|
+
current_workspace.src_to_obj(src)
|
|
38
41
|
end
|
|
39
42
|
|
|
40
43
|
def comp_to_obj(comp)
|
|
41
|
-
|
|
44
|
+
current_workspace.comp_to_obj(comp)
|
|
42
45
|
end
|
|
43
46
|
|
|
44
47
|
def file_to_obj(file)
|
|
45
|
-
|
|
48
|
+
current_workspace.file_to_obj(file)
|
|
46
49
|
end
|
|
47
50
|
|
|
48
51
|
def extract_one_file(file, deps)
|
|
49
|
-
|
|
52
|
+
current_workspace.extract_one_file(file, deps)
|
|
50
53
|
end
|
|
51
54
|
|
|
52
55
|
def extract_one_file_obj(file, deps)
|
|
53
|
-
|
|
56
|
+
current_workspace.extract_one_file_obj(file, deps)
|
|
54
57
|
end
|
|
55
58
|
end
|
|
56
59
|
|
data/lib/workspace/build.rb
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
require 'json'
|
|
1
2
|
module Canoe
|
|
2
3
|
class WorkSpace
|
|
3
4
|
def src_to_obj(src)
|
|
@@ -18,14 +19,9 @@ module Canoe
|
|
|
18
19
|
end
|
|
19
20
|
|
|
20
21
|
# args are commandline parameters passed to `canoe build`,
|
|
21
|
-
# could be 'all', 'test', 'target' or empty
|
|
22
|
-
def build(
|
|
23
|
-
|
|
24
|
-
if options.include?(args)
|
|
25
|
-
send "build_#{options[args]}"
|
|
26
|
-
else
|
|
27
|
-
abort_on_err "Unkown subcommand #{args.join(" ").red}"
|
|
28
|
-
end
|
|
22
|
+
# could be 'all', 'test', 'target', 'base' or empty
|
|
23
|
+
def build(arg = 'target')
|
|
24
|
+
send "build_#{arg}"
|
|
29
25
|
end
|
|
30
26
|
|
|
31
27
|
private
|
|
@@ -132,10 +128,9 @@ module Canoe
|
|
|
132
128
|
|
|
133
129
|
def build_target
|
|
134
130
|
puts "#{'[BUILDING TARGET]'.magenta}..."
|
|
135
|
-
deps = get_deps @deps, @src, [@src_short, @components_short]
|
|
136
131
|
target = "#{@target}/#{@name}"
|
|
137
132
|
build_time = File.exist?(target) ? File.mtime(target) : Time.new(0)
|
|
138
|
-
files = DepAnalyzer.compiling_filter
|
|
133
|
+
files = DepAnalyzer.compiling_filter target_deps, build_time, @source_suffix, @header_suffix
|
|
139
134
|
|
|
140
135
|
build_compiler_from_config
|
|
141
136
|
|
|
@@ -146,5 +141,50 @@ module Canoe
|
|
|
146
141
|
|
|
147
142
|
self.send "build_#{@mode.to_s}", files
|
|
148
143
|
end
|
|
144
|
+
|
|
145
|
+
# generate a compile_commands.json file
|
|
146
|
+
def build_base
|
|
147
|
+
deps = target_deps.merge tests_deps
|
|
148
|
+
build_compiler_from_config
|
|
149
|
+
database = CompilationDatabase.new
|
|
150
|
+
deps.each_key do |k|
|
|
151
|
+
next if k.end_with? @header_suffix
|
|
152
|
+
c = @compiler.name.end_with?('++') ? 'c++' : 'c'
|
|
153
|
+
|
|
154
|
+
arg = [c] + @compiler.compiling_flags_as_str.split + [k] + [file_to_obj(k)] + ['-c', '-o']
|
|
155
|
+
database.add_command_object(@workspace, arg, k)
|
|
156
|
+
end
|
|
157
|
+
File.open('compile_commands.json', 'w') do |f|
|
|
158
|
+
f.puts database.pretty_to_s
|
|
159
|
+
end
|
|
160
|
+
end
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
class CompilationDatabase
|
|
164
|
+
attr_reader :database
|
|
165
|
+
def initialize
|
|
166
|
+
@database = []
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
def add_command_object(dir, arguments, file)
|
|
170
|
+
temp = {
|
|
171
|
+
"arguments" => arguments,
|
|
172
|
+
"directory" => dir,
|
|
173
|
+
"file" => file
|
|
174
|
+
}
|
|
175
|
+
@database << temp
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
def to_s
|
|
179
|
+
@database.to_s
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
def pretty_to_s
|
|
183
|
+
JSON.pretty_generate(@database)
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
def to_json
|
|
187
|
+
@database.to_json
|
|
188
|
+
end
|
|
149
189
|
end
|
|
150
190
|
end
|
data/lib/workspace/clean.rb
CHANGED
|
@@ -1,16 +1,8 @@
|
|
|
1
1
|
module Canoe
|
|
2
2
|
class WorkSpace
|
|
3
3
|
# valid options: none, 'all', 'target', 'tests'
|
|
4
|
-
def clean(
|
|
5
|
-
|
|
6
|
-
[] => 'all', ['all'] => 'all',
|
|
7
|
-
['target'] => 'target', ['tests'] => 'tests', ['obj'] => 'obj'
|
|
8
|
-
}
|
|
9
|
-
if options.include?(args)
|
|
10
|
-
send "clean_#{options[args]}"
|
|
11
|
-
else
|
|
12
|
-
abort_on_err "Unkown subcommand #{args.join(' ').red}"
|
|
13
|
-
end
|
|
4
|
+
def clean(arg = 'all')
|
|
5
|
+
send "clean_#{arg}"
|
|
14
6
|
end
|
|
15
7
|
|
|
16
8
|
private
|
data/lib/workspace/make.rb
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# If the project has circular dependency, this command would fail
|
|
2
2
|
module Canoe
|
|
3
|
-
|
|
3
|
+
##
|
|
4
|
+
# CanoeMakefile is used to offer makefile generation utilities
|
|
5
|
+
class CanoeMakefile
|
|
4
6
|
include WorkSpaceUtil
|
|
5
7
|
def initialize(workspace)
|
|
6
8
|
@workspace = workspace
|
|
@@ -208,25 +210,23 @@ module Canoe
|
|
|
208
210
|
|
|
209
211
|
def make_obj_rules(makefile, deps)
|
|
210
212
|
cmplr = cxx?(get_compiler) ? 'CXX' : 'CC'
|
|
211
|
-
makefile.puts("all: OUT\n")
|
|
212
|
-
makefile.puts ''
|
|
213
213
|
|
|
214
214
|
@all_names.each do |n|
|
|
215
|
-
makefile.puts("$(OBJ_#{n}): $(#{n}_DEP)\n\t$(#{cmplr}) $(#{cmplr}FLAGS) -o $@ -c $(SRC_#{n})")
|
|
216
|
-
makefile.puts ''
|
|
215
|
+
makefile.puts("$(OBJ_#{n}): $(#{n}_DEP)\n\t$(#{cmplr}) $(#{cmplr}FLAGS) -o $@ -c $(SRC_#{n})\n\n")
|
|
217
216
|
end
|
|
218
|
-
|
|
219
217
|
end
|
|
220
218
|
|
|
221
219
|
def make_out_rules(makefile, deps)
|
|
222
220
|
cmplr = cxx?(get_compiler) ? 'CXX' : 'CC'
|
|
223
221
|
if @workspace.mode == :bin
|
|
224
|
-
makefile.puts("
|
|
222
|
+
makefile.puts("out: $(OUT_OBJS)\n\t$(#{cmplr}) $(#{cmplr}FLAGS) -o $(TARGET) $(OUT_OBJS) $(LDFLAGS) $(LDLIBS)")
|
|
225
223
|
else
|
|
226
|
-
makefile.puts("
|
|
224
|
+
makefile.puts("out: $(OUT_OBJS)\n\t$(#{cmplr}) $(#{cmplr}FLAGS) -shared -o $(TARGET) $(OUT_OBJS) -fPIC $(LDFLAGS) $(LDLIBS)")
|
|
227
225
|
end
|
|
228
226
|
makefile.puts ''
|
|
229
227
|
makefile.puts("test: $(TESTS)")
|
|
228
|
+
makefile.puts ''
|
|
229
|
+
makefile.puts("all: out test")
|
|
230
230
|
end
|
|
231
231
|
|
|
232
232
|
def make_tests_rules(makefile, deps)
|
|
@@ -256,10 +256,9 @@ module Canoe
|
|
|
256
256
|
def make_rules(makefile, deps)
|
|
257
257
|
make_dependencies makefile, deps
|
|
258
258
|
makefile.puts ''
|
|
259
|
-
make_obj_rules makefile, deps
|
|
260
|
-
makefile.puts ''
|
|
261
259
|
make_out_rules makefile, deps
|
|
262
260
|
makefile.puts ''
|
|
261
|
+
make_obj_rules makefile, deps
|
|
263
262
|
make_tests_rules makefile, deps
|
|
264
263
|
makefile.puts ''
|
|
265
264
|
make_clean makefile
|
|
@@ -272,7 +271,7 @@ module Canoe
|
|
|
272
271
|
|
|
273
272
|
deps = target_deps.merge tests_deps
|
|
274
273
|
|
|
275
|
-
makefile =
|
|
274
|
+
makefile = CanoeMakefile.new self
|
|
276
275
|
makefile.configure config
|
|
277
276
|
makefile.make! deps
|
|
278
277
|
end
|
data/lib/workspace/new.rb
CHANGED
|
@@ -15,8 +15,8 @@ module Canoe
|
|
|
15
15
|
DefaultFiles.create_lib_header(@src, @name, @header_suffix)
|
|
16
16
|
end
|
|
17
17
|
File.new("#{@workspace}/.canoe", 'w')
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
compiler = @source_suffix == 'c' ? 'clang' : 'clang++'
|
|
19
|
+
DefaultFiles.create_config @workspace, compiler, @source_suffix, @header_suffix
|
|
20
20
|
|
|
21
21
|
Dir.mkdir(@third)
|
|
22
22
|
Dir.mkdir(@target)
|
data/lib/workspace/run.rb
CHANGED
data/lib/workspace/version.rb
CHANGED
data/lib/workspace/workspace.rb
CHANGED
|
@@ -11,6 +11,8 @@ module Canoe
|
|
|
11
11
|
##
|
|
12
12
|
# A workspace resents a C/C++ project
|
|
13
13
|
# This class is responsible for the main functionality of canoe, such as building and cleaning
|
|
14
|
+
# TODO
|
|
15
|
+
# add a command to generate compile_commands.json so users won't have to install bear
|
|
14
16
|
class WorkSpace
|
|
15
17
|
include Err
|
|
16
18
|
include SystemCommand
|
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.2.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-
|
|
11
|
+
date: 2021-05-17 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: |+
|
|
14
14
|
Canoe offers project management and building facilities to C/C++ projects.
|