canoe 0.3.1 → 0.3.2.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 +4 -4
- data/bin/canoe +1 -2
- data/lib/canoe.rb +23 -21
- data/lib/cmd.rb +78 -92
- data/lib/compiler.rb +44 -45
- data/lib/config_reader.rb +2 -2
- data/lib/default_files.rb +19 -36
- data/lib/dependence.rb +111 -111
- data/lib/source_files.rb +3 -3
- data/lib/util.rb +84 -0
- data/lib/workspace/add.rb +19 -17
- data/lib/workspace/build.rb +154 -97
- data/lib/workspace/clean.rb +21 -20
- data/lib/workspace/dep.rb +8 -6
- data/lib/workspace/generate.rb +8 -3
- data/lib/workspace/help.rb +14 -6
- data/lib/workspace/make.rb +227 -180
- data/lib/workspace/new.rb +27 -24
- data/lib/workspace/run.rb +10 -7
- data/lib/workspace/test.rb +133 -30
- data/lib/workspace/update.rb +5 -3
- data/lib/workspace/version.rb +15 -0
- data/lib/workspace/workspace.rb +57 -44
- metadata +5 -4
- data/lib/err.rb +0 -21
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: '0518fcb695948644be7df59c7200eaf996a1c753bb8b575721764d36fcde61cb'
|
|
4
|
+
data.tar.gz: 385806c9e2035fa9c0cd1caf2556ca8aba1994ca73caad835f252003bbe1c36e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fe763993a442305afd7180eba5bb52fe63cd5ba9c8520c985a1cecec3ecbabb52296c5b6afd5ac7a72fa2341ebe432a6e7ca7b261145ca211dfc436f5066d22c
|
|
7
|
+
data.tar.gz: 9eb610ca364b557e9e1999c18dd497912503cdc0580f3f403ef3abf6f4ac58803b81d5a1c352f02e5e00685d6bb1e471866f33c3da2f12651063fb4e6a5f33bc
|
data/bin/canoe
CHANGED
data/lib/canoe.rb
CHANGED
|
@@ -1,25 +1,27 @@
|
|
|
1
|
-
require_relative
|
|
2
|
-
require_relative
|
|
3
|
-
require_relative
|
|
1
|
+
require_relative 'workspace/workspace'
|
|
2
|
+
require_relative 'cmd'
|
|
3
|
+
require_relative 'source_files'
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
5
|
+
module Canoe
|
|
6
|
+
class Builder
|
|
7
|
+
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']
|
|
20
|
+
@cmd = CmdParser.new options
|
|
21
|
+
end
|
|
21
22
|
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
def parse(args)
|
|
24
|
+
@cmd.parse args
|
|
25
|
+
end
|
|
24
26
|
end
|
|
25
27
|
end
|
data/lib/cmd.rb
CHANGED
|
@@ -1,120 +1,106 @@
|
|
|
1
|
-
require_relative
|
|
2
|
-
require_relative
|
|
3
|
-
require_relative
|
|
1
|
+
require_relative 'workspace/workspace'
|
|
2
|
+
require_relative 'util'
|
|
3
|
+
require_relative 'config_reader'
|
|
4
4
|
|
|
5
5
|
##
|
|
6
6
|
# class CmdParser
|
|
7
7
|
# Parsing command arguments passed to canoe
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
module Canoe
|
|
9
|
+
class CmdParser
|
|
10
|
+
include Err
|
|
11
|
+
include WorkSpaceUtil
|
|
10
12
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def parse(args)
|
|
16
|
-
if args.size < 1
|
|
17
|
-
abort_on_err "please give one command among #{@options.join(", ")}"
|
|
13
|
+
def initialize(options)
|
|
14
|
+
@options = options
|
|
18
15
|
end
|
|
19
16
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
self.send "parse_#{args[0]}", args[1..]
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
private
|
|
28
|
-
|
|
29
|
-
def get_current_workspace
|
|
30
|
-
abort_on_err "not in a canoe workspace" unless File.exists? ".canoe"
|
|
31
|
-
config = ConfigReader.extract_flags("config.json")
|
|
32
|
-
|
|
33
|
-
src_sfx = config["source-suffix"] ? config["source-suffix"] : "cpp"
|
|
34
|
-
hdr_sfx = config["header-suffix"] ? config["header-suffix"] : "hpp"
|
|
17
|
+
def parse(args)
|
|
18
|
+
if args.size < 1
|
|
19
|
+
abort_on_err "please give one command among #{@options.join(", ")}"
|
|
20
|
+
end
|
|
35
21
|
|
|
36
|
-
|
|
37
|
-
|
|
22
|
+
unless @options.include?(args[0])
|
|
23
|
+
abort_on_err "unknown command #{args[0]}"
|
|
24
|
+
end
|
|
38
25
|
|
|
39
|
-
|
|
40
|
-
return WorkSpace.new(name, mode, src_sfx, hdr_sfx)
|
|
26
|
+
self.send "parse_#{args[0]}", args[1..]
|
|
41
27
|
end
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
def parse_new(args)
|
|
45
|
-
abort_on_err "not enough arguments to canoe new" if args.size < 1
|
|
46
|
-
|
|
47
|
-
name, mode = nil, "bin"
|
|
48
|
-
suffixes = ["cpp", "hpp"]
|
|
49
28
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
29
|
+
private
|
|
30
|
+
def parse_new(args)
|
|
31
|
+
abort_on_err "not enough arguments to canoe new" if args.size < 1
|
|
32
|
+
|
|
33
|
+
name, mode = nil, "bin"
|
|
34
|
+
suffixes = ["cpp", "hpp"]
|
|
35
|
+
|
|
36
|
+
args.each do |arg|
|
|
37
|
+
case arg
|
|
38
|
+
when "--bin", "--lib"
|
|
39
|
+
mode = arg[2..]
|
|
40
|
+
when /--suffix=(\w+)\:(\w+)/
|
|
41
|
+
suffixes[0], suffixes[1] = $1, $2
|
|
42
|
+
else
|
|
43
|
+
name = arg unless name
|
|
44
|
+
end
|
|
58
45
|
end
|
|
46
|
+
|
|
47
|
+
abort_on_err('please give a name to this project') unless name
|
|
48
|
+
WorkSpace.new(name, mode.to_sym, suffixes[0], suffixes[1], true).new
|
|
59
49
|
end
|
|
60
50
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
51
|
+
def parse_add(args)
|
|
52
|
+
if args.size < 1
|
|
53
|
+
abort_on_err "it's not reasonable to add a component with no name given"
|
|
54
|
+
end
|
|
64
55
|
|
|
65
|
-
|
|
66
|
-
if args.size < 1
|
|
67
|
-
abort_on_err "it's not reasonable to add a component with no name given"
|
|
56
|
+
current_workspace.add args
|
|
68
57
|
end
|
|
69
58
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
end
|
|
59
|
+
def parse_build(args)
|
|
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]
|
|
63
|
+
end
|
|
76
64
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
65
|
+
def parse_generate(args)
|
|
66
|
+
current_workspace.generate
|
|
67
|
+
end
|
|
80
68
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
69
|
+
def parse_run(args)
|
|
70
|
+
current_workspace.run args
|
|
71
|
+
end
|
|
84
72
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
73
|
+
def parse_dep(args)
|
|
74
|
+
current_workspace.dep
|
|
75
|
+
end
|
|
88
76
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
77
|
+
def parse_clean(args)
|
|
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]
|
|
84
|
+
end
|
|
92
85
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
86
|
+
def parse_test(args)
|
|
87
|
+
current_workspace.test args
|
|
88
|
+
end
|
|
96
89
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
For features in this version, please visit https://github.com/Dicridon/canoe
|
|
101
|
-
Currently, canoe can do below:
|
|
102
|
-
- project creation
|
|
103
|
-
- project auto build and run (works like Cargo for Rust)
|
|
104
|
-
- project structure management
|
|
105
|
-
by XIONG Ziwei
|
|
106
|
-
VER
|
|
107
|
-
end
|
|
90
|
+
def parse_version(args)
|
|
91
|
+
WorkSpace.version
|
|
92
|
+
end
|
|
108
93
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
94
|
+
def parse_help(args)
|
|
95
|
+
WorkSpace.help
|
|
96
|
+
end
|
|
112
97
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
98
|
+
def parse_update(args)
|
|
99
|
+
current_workspace.update
|
|
100
|
+
end
|
|
116
101
|
|
|
117
|
-
|
|
118
|
-
|
|
102
|
+
def parse_make(args)
|
|
103
|
+
current_workspace.make
|
|
104
|
+
end
|
|
119
105
|
end
|
|
120
106
|
end
|
data/lib/compiler.rb
CHANGED
|
@@ -1,50 +1,49 @@
|
|
|
1
|
+
require_relative 'util'
|
|
2
|
+
|
|
1
3
|
##
|
|
2
4
|
# class Compiler
|
|
3
5
|
# Storing compiler name in String and flags as an array
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
@
|
|
12
|
-
@
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
def inspect
|
|
47
|
-
puts "compiler name: #{name.inspect}"
|
|
48
|
-
puts "compiler flags: #{flags.inspect}"
|
|
6
|
+
module Canoe
|
|
7
|
+
class Compiler
|
|
8
|
+
include SystemCommand
|
|
9
|
+
|
|
10
|
+
attr_reader :name, :flags
|
|
11
|
+
|
|
12
|
+
##
|
|
13
|
+
# @name: String
|
|
14
|
+
# @flgs: Array of String
|
|
15
|
+
def initialize(name, compiling_flags, linking_flags)
|
|
16
|
+
@name = name
|
|
17
|
+
@linking_flags = linking_flags
|
|
18
|
+
@compiling_flags = compiling_flags
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def compiling_flags_as_str
|
|
22
|
+
@compiling_flags.join ' '
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def linking_flags_as_str
|
|
26
|
+
@linking_flags.join ' '
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def append_compiling_flag(flag)
|
|
30
|
+
@compiling_flags << flag
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def append_linking_flag(flag)
|
|
34
|
+
@linking_flags << flag
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def compile(src, out)
|
|
38
|
+
issue_command "#{name} -o #{out} #{compiling_flags_as_str} -c #{src}"
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def link_executable(out, objs)
|
|
42
|
+
issue_command "#{name} -o #{out} #{objs.join(' ')} #{linking_flags_as_str}"
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def link_shared(out, objs)
|
|
46
|
+
issue_command "#{name} -shared -o #{out}.so #{objs.join(' ')} #{linking_flags_as_str}"
|
|
47
|
+
end
|
|
49
48
|
end
|
|
50
49
|
end
|
data/lib/config_reader.rb
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
require
|
|
1
|
+
require 'json'
|
|
2
2
|
|
|
3
3
|
##
|
|
4
4
|
# class ConfigReader
|
|
5
5
|
# Just read a json file
|
|
6
6
|
class ConfigReader
|
|
7
7
|
def self.extract_flags(file)
|
|
8
|
-
abort_on_err("config file #{file} does not exsit") unless File.
|
|
8
|
+
abort_on_err("config file #{file} does not exsit") unless File.exist? file
|
|
9
9
|
JSON.parse(File.read(file))
|
|
10
10
|
end
|
|
11
11
|
end
|
data/lib/default_files.rb
CHANGED
|
@@ -5,94 +5,77 @@
|
|
|
5
5
|
class DefaultFiles
|
|
6
6
|
class << self
|
|
7
7
|
def open_file_and_write(filename, content)
|
|
8
|
-
File.open(filename,
|
|
8
|
+
File.open(filename, 'w') do |f|
|
|
9
9
|
f.write(content)
|
|
10
10
|
end
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
-
def create_config(path, src_sfx =
|
|
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
|
+
|
|
29
28
|
}
|
|
30
29
|
}
|
|
31
30
|
}
|
|
32
31
|
CONFIG
|
|
33
|
-
|
|
34
|
-
)
|
|
32
|
+
)
|
|
35
33
|
end
|
|
36
34
|
|
|
37
|
-
def create_main(path, suffix =
|
|
35
|
+
def create_main(path, suffix = 'cpp')
|
|
36
|
+
header = suffix == 'c' ? 'stdio.h' : 'iostream'
|
|
38
37
|
open_file_and_write(
|
|
39
38
|
"#{path}/main.#{suffix}",
|
|
40
39
|
<<~DOC
|
|
41
|
-
#include
|
|
40
|
+
#include <#{header}>
|
|
42
41
|
int main(int argc, char *argv[]) {
|
|
43
|
-
|
|
42
|
+
|
|
44
43
|
}
|
|
45
44
|
DOC
|
|
46
|
-
|
|
47
|
-
)
|
|
45
|
+
)
|
|
48
46
|
end
|
|
49
47
|
|
|
50
|
-
def create_lib_header(path, lib_name, suffix =
|
|
48
|
+
def create_lib_header(path, lib_name, suffix = 'hpp')
|
|
51
49
|
open_file_and_write(
|
|
52
50
|
"#{path}/#{lib_name}.#{suffix}",
|
|
53
51
|
<<~DOC
|
|
54
52
|
#ifndef __#{lib_name.upcase}__
|
|
55
53
|
#define __#{lib_name.upcase}__
|
|
56
|
-
|
|
54
|
+
|
|
57
55
|
#endif
|
|
58
56
|
DOC
|
|
59
|
-
|
|
60
|
-
)
|
|
57
|
+
)
|
|
61
58
|
end
|
|
62
59
|
|
|
63
|
-
|
|
64
|
-
# open_file_and_write(
|
|
65
|
-
# "#{path}/.dir-locals.el",
|
|
66
|
-
# <<~DOC
|
|
67
|
-
# ((nil . ((company-clang-arguments . ("-I./src/components/"
|
|
68
|
-
# "-I./components/"))))
|
|
69
|
-
# (nil . ((company-c-headers-path-user . ("./src/components/"
|
|
70
|
-
# "./components/")))))
|
|
71
|
-
# DOC
|
|
72
|
-
# )
|
|
73
|
-
# end
|
|
74
|
-
|
|
75
|
-
def create_cpp(filename, src_sfx = "cpp", hdr_sfx = "hpp")
|
|
60
|
+
def create_cpp(filename, src_sfx = 'cpp', hdr_sfx = 'hpp')
|
|
76
61
|
open_file_and_write(
|
|
77
62
|
"#{filename}.#{src_sfx}",
|
|
78
63
|
<<~DOC
|
|
79
64
|
#include "#{filename}.#{hdr_sfx}"
|
|
80
65
|
DOC
|
|
81
|
-
|
|
82
|
-
)
|
|
66
|
+
)
|
|
83
67
|
end
|
|
84
68
|
|
|
85
|
-
def create_hpp(workspace, prefix, filename, hdr_sfx =
|
|
69
|
+
def create_hpp(workspace, prefix, filename, hdr_sfx = 'hpp')
|
|
86
70
|
open_file_and_write(
|
|
87
71
|
"#{filename}.#{hdr_sfx}",
|
|
88
72
|
<<~DOC
|
|
89
73
|
#ifndef __#{workspace.upcase}__#{prefix.upcase}__#{filename.upcase}__
|
|
90
74
|
#define __#{workspace.upcase}__#{prefix.upcase}__#{filename.upcase}__
|
|
91
|
-
|
|
75
|
+
|
|
92
76
|
#endif
|
|
93
77
|
DOC
|
|
94
|
-
|
|
95
|
-
)
|
|
78
|
+
)
|
|
96
79
|
end
|
|
97
80
|
end
|
|
98
81
|
end
|