canoe 0.2.4 → 0.3.1.1
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 -0
- data/lib/canoe.rb +14 -12
- data/lib/cmd.rb +27 -22
- data/lib/coloring.rb +23 -0
- data/lib/compiler.rb +28 -15
- data/lib/config_reader.rb +4 -1
- data/lib/default_files.rb +89 -73
- data/lib/dependence.rb +56 -17
- data/lib/err.rb +5 -3
- data/lib/source_files.rb +7 -4
- data/lib/workspace/add.rb +27 -0
- data/lib/workspace/build.rb +131 -0
- data/lib/workspace/clean.rb +27 -0
- data/lib/workspace/dep.rb +12 -0
- data/lib/workspace/generate.rb +5 -0
- data/lib/workspace/help.rb +76 -0
- data/lib/workspace/make.rb +233 -0
- data/lib/workspace/new.rb +28 -0
- data/lib/workspace/run.rb +9 -0
- data/lib/workspace/test.rb +41 -0
- data/lib/workspace/update.rb +5 -0
- data/lib/workspace/version.rb +13 -0
- data/lib/workspace/workspace.rb +53 -0
- metadata +17 -4
- data/lib/workspace.rb +0 -296
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
# If the project has circular dependency, this command would fail
|
|
2
|
+
class Makefile
|
|
3
|
+
def initialize(workspace)
|
|
4
|
+
@workspace = workspace
|
|
5
|
+
@all_names = []
|
|
6
|
+
@common_variables = {}
|
|
7
|
+
@src_variables = {}
|
|
8
|
+
@hdr_variables = {}
|
|
9
|
+
@obj_variables = {}
|
|
10
|
+
@config = {}
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def configure(config)
|
|
14
|
+
@config = config
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def make!(deps)
|
|
18
|
+
File.open("Makefile", "w") do |f|
|
|
19
|
+
if cxx?(get_compiler)
|
|
20
|
+
make_cxx(f, deps)
|
|
21
|
+
else
|
|
22
|
+
make_c(f, deps)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
private
|
|
28
|
+
|
|
29
|
+
def get_compiler
|
|
30
|
+
@config["compiler"]
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def get_header_suffix
|
|
34
|
+
@workspace.header_suffix
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def get_source_suffix
|
|
38
|
+
@workspace.source_suffix
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def get_compiling_flags
|
|
42
|
+
flags = @config["flags"]["compile"].values.join " "
|
|
43
|
+
flags + " -I./src/components"
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def get_ldflags
|
|
47
|
+
@config["flags"]["link"].values.select { |v| v.start_with?("-L") }.join " "
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def get_ldlibs
|
|
51
|
+
(@config["flags"]["link"].values - (get_ldflags.split)).join " "
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def cxx?(name)
|
|
55
|
+
return get_compiler.end_with? "++"
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def make_cxx(makefile, deps)
|
|
59
|
+
make_common(makefile, "CXX", deps)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def make_c(makefile, deps)
|
|
63
|
+
make_common(makefile, "CC", deps)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def make_common(makefile, compiler_prefix, deps)
|
|
67
|
+
make_compiling_info(makefile, compiler_prefix)
|
|
68
|
+
define_variables(makefile, deps)
|
|
69
|
+
make_rules(makefile, deps)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def make_compiling_info(makefile, compiler_prefix)
|
|
73
|
+
makefile.puts("#{compiler_prefix}=#{get_compiler}")
|
|
74
|
+
makefile.puts("#{compiler_prefix}FLAGS=#{get_compiling_flags}")
|
|
75
|
+
makefile.puts("LDFLAGS=#{get_ldflags}")
|
|
76
|
+
makefile.puts("LDLIBS=#{get_ldlibs}")
|
|
77
|
+
makefile.puts ""
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def define_variables(makefile, deps)
|
|
81
|
+
define_dirs(makefile)
|
|
82
|
+
|
|
83
|
+
src_files = deps.keys.select { |f| f.end_with? get_source_suffix }
|
|
84
|
+
generate_all_names(src_files)
|
|
85
|
+
define_srcs(makefile, src_files)
|
|
86
|
+
makefile.puts ""
|
|
87
|
+
define_hdrs(makefile, src_files)
|
|
88
|
+
makefile.puts ""
|
|
89
|
+
define_objs(makefile, src_files)
|
|
90
|
+
makefile.puts ""
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def extract_name(name, prefix)
|
|
94
|
+
if name.start_with?(prefix)
|
|
95
|
+
name.delete_suffix(File.extname(name))[prefix.length..].gsub("/", "_")
|
|
96
|
+
else
|
|
97
|
+
File.basename(name.split("/")[-1], ".*")
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def generate_all_names(files)
|
|
102
|
+
files.each do |f|
|
|
103
|
+
name = extract_name(f, @workspace.components_prefix).upcase
|
|
104
|
+
@all_names << name
|
|
105
|
+
@src_variables[name] = f
|
|
106
|
+
@hdr_variables[name] = f.gsub(@workspace.source_suffix, @workspace.header_suffix)
|
|
107
|
+
@obj_variables[name] = @workspace.obj_prefix + extract_name(f, @workspace.components_prefix) + ".o"
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def define_dirs(makefile)
|
|
112
|
+
makefile.puts("TARGET_DIR=./target")
|
|
113
|
+
if @workspace.mode == :bin
|
|
114
|
+
makefile.puts("TARGET=$(TARGET_DIR)/#{@workspace.name}")
|
|
115
|
+
else
|
|
116
|
+
makefile.puts("TARGET=$(TARGET_DIR)/lib#{@workspace.name.downcase}.so")
|
|
117
|
+
end
|
|
118
|
+
# note the ending slash
|
|
119
|
+
makefile.puts("OBJ_DIR=#{@workspace.obj_prefix[..-2]}")
|
|
120
|
+
makefile.puts("SRC_DIR=#{@workspace.src_prefix[..-2]}")
|
|
121
|
+
makefile.puts("COMPONENTS_DIR=#{@workspace.components_prefix[..-2]}")
|
|
122
|
+
makefile.puts ""
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def define_srcs(makefile, files)
|
|
126
|
+
@src_variables.each do |k, v|
|
|
127
|
+
makefile.puts("SRC_#{k}=#{v}")
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def define_hdrs(makefile, files)
|
|
132
|
+
@hdr_variables.each do |k, v|
|
|
133
|
+
next if k == "MAIN"
|
|
134
|
+
makefile.puts("HDR_#{k}=#{v}")
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def define_objs(makefile, files)
|
|
139
|
+
@obj_variables.each do |k, v|
|
|
140
|
+
makefile.puts("OBJ_#{k}=#{v}")
|
|
141
|
+
end
|
|
142
|
+
objs = @obj_variables.keys.map { |k| "$(OBJ_#{k})" }.join " "
|
|
143
|
+
makefile.puts("OBJS=#{objs}")
|
|
144
|
+
makefile.puts ""
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
def get_all_dep_name(file_name, deps)
|
|
148
|
+
dep = deps[file_name]
|
|
149
|
+
if dep.empty?
|
|
150
|
+
[]
|
|
151
|
+
else
|
|
152
|
+
tmp = dep.map { |n| extract_name(n, @workspace.components_prefix).upcase }
|
|
153
|
+
dep.each do |d|
|
|
154
|
+
tmp += get_all_dep_name(d, deps)
|
|
155
|
+
end
|
|
156
|
+
tmp
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
def emit_dependencies(makefile, name, deps)
|
|
161
|
+
as_str = deps.map do |n|
|
|
162
|
+
if n == name
|
|
163
|
+
["$(SRC_#{n})"] + ["$(HDR_#{n})"] * (name == "MAIN" ? 0 : 1)
|
|
164
|
+
else
|
|
165
|
+
"$(#{n}_DEP)"
|
|
166
|
+
end
|
|
167
|
+
end.flatten.join " "
|
|
168
|
+
makefile.puts("#{name}_DEP=#{as_str}")
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
def make_dependencies(makefile, deps)
|
|
172
|
+
dep_variables = Hash[@all_names.map { |n| [n, []] }]
|
|
173
|
+
reference = Hash[@all_names.map { |n| [n, []] }]
|
|
174
|
+
@all_names.each do |n|
|
|
175
|
+
dep_variables[n] = ([n] + get_all_dep_name(@src_variables[n], deps)).uniq
|
|
176
|
+
reference[n] = ([n] + get_all_dep_name(@src_variables[n], deps)).uniq
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
# deduplication
|
|
180
|
+
dep_variables.each do |k, v|
|
|
181
|
+
v.each do |n|
|
|
182
|
+
next if n == k
|
|
183
|
+
v = v - reference[n] + [n] if v.include? n
|
|
184
|
+
end
|
|
185
|
+
dep_variables[k] = v
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
dep_variables.each do |k, v|
|
|
189
|
+
emit_dependencies(makefile, k, v)
|
|
190
|
+
end
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
def make_rules(makefile, deps)
|
|
194
|
+
make_dependencies(makefile, deps)
|
|
195
|
+
makefile.puts ""
|
|
196
|
+
makefile.puts("all: BIN\n")
|
|
197
|
+
makefile.puts ""
|
|
198
|
+
cmplr = cxx?(get_compiler) ? "CXX" : "CC"
|
|
199
|
+
@all_names.each do |n|
|
|
200
|
+
makefile.puts("$(OBJ_#{n}): $(#{n}_DEP)\n\t$(#{cmplr}) $(#{cmplr}FLAGS) -o $(OBJ_#{n}) -c $(SRC_#{n})")
|
|
201
|
+
makefile.puts ""
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
if @workspace.mode == :bin
|
|
205
|
+
makefile.puts("BIN: $(OBJS)\n\t$(#{cmplr}) $(#{cmplr}FLAGS) -o $(TARGET) $(wildcard ./obj/*.o) $(LDFLAGS) $(LDLIBS)")
|
|
206
|
+
else
|
|
207
|
+
makefile.puts("LIB: $(OBJS)\n\t$(#{cmplr}) $(#{cmplr}FLAGS) -shared -o $(TARGET) $(wildcard ./obj/*.o) -fPIC $(LDFLAGS) $(LDLIBS)")
|
|
208
|
+
end
|
|
209
|
+
makefile.puts ""
|
|
210
|
+
|
|
211
|
+
clean = <<~DOC
|
|
212
|
+
.PHONY: clean
|
|
213
|
+
clean:
|
|
214
|
+
\trm $(TARGET)
|
|
215
|
+
\trm ./obj/*.o
|
|
216
|
+
DOC
|
|
217
|
+
makefile.puts(clean)
|
|
218
|
+
end
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
class WorkSpace
|
|
222
|
+
def make
|
|
223
|
+
config = ConfigReader.extract_flags "config.json"
|
|
224
|
+
|
|
225
|
+
deps = File.exist?(@deps) ?
|
|
226
|
+
DepAnalyzer.read_from(@deps) :
|
|
227
|
+
DepAnalyzer.new("./src").build_to_file(["./src", "./src/components"], @deps)
|
|
228
|
+
|
|
229
|
+
makefile = Makefile.new(self)
|
|
230
|
+
makefile.configure(config)
|
|
231
|
+
makefile.make!(deps)
|
|
232
|
+
end
|
|
233
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
class WorkSpace
|
|
2
|
+
def new
|
|
3
|
+
begin
|
|
4
|
+
Dir.mkdir(@name)
|
|
5
|
+
rescue
|
|
6
|
+
abort_on_err "workspace #{@name} already exsits"
|
|
7
|
+
end
|
|
8
|
+
Dir.mkdir(@src)
|
|
9
|
+
Dir.mkdir(@components)
|
|
10
|
+
Dir.mkdir("#{@workspace}/obj")
|
|
11
|
+
if @mode == :bin
|
|
12
|
+
DefaultFiles.create_main(@src, @source_suffix)
|
|
13
|
+
else
|
|
14
|
+
DefaultFiles.create_lib_header(@src, @name, @header_suffix)
|
|
15
|
+
end
|
|
16
|
+
File.new("#{@workspace}/.canoe", "w")
|
|
17
|
+
DefaultFiles.create_config @workspace, @source_suffix, @header_suffix
|
|
18
|
+
# DefaultFiles.create_emacs_dir_local @workspace
|
|
19
|
+
|
|
20
|
+
Dir.mkdir(@third)
|
|
21
|
+
Dir.mkdir(@target)
|
|
22
|
+
Dir.mkdir(@tests)
|
|
23
|
+
Dir.chdir(@workspace) do
|
|
24
|
+
system "git init"
|
|
25
|
+
end
|
|
26
|
+
puts "workspace #{@workspace.blue} is created"
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
class WorkSpace
|
|
2
|
+
public
|
|
3
|
+
|
|
4
|
+
def test(args)
|
|
5
|
+
if args.empty?
|
|
6
|
+
test_all
|
|
7
|
+
return
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
args.each do |arg|
|
|
11
|
+
case arg
|
|
12
|
+
when "all"
|
|
13
|
+
test_all
|
|
14
|
+
else
|
|
15
|
+
test_single arg
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
private
|
|
21
|
+
|
|
22
|
+
def test_all
|
|
23
|
+
puts "tests all"
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def test_single(name)
|
|
27
|
+
puts "#{@tests}/bin/test_#{name}"
|
|
28
|
+
# system "./#{@tests}/bin/test_#{name}"
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
##
|
|
32
|
+
# how to build:
|
|
33
|
+
# each test file tests one or more components, indicated by included headers
|
|
34
|
+
# find corresponding object file in ../obj and link them to test file
|
|
35
|
+
# TODO
|
|
36
|
+
def build_test
|
|
37
|
+
build
|
|
38
|
+
deps = DepAnalyzer.new("./tests").build_to_file(["./src", "./src/components", "./tests", "./tests/common"], "./tests/.canoe.deps")
|
|
39
|
+
puts deps
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
class WorkSpace
|
|
2
|
+
def self.version
|
|
3
|
+
puts <<~VER
|
|
4
|
+
canoe v0.3.1.1
|
|
5
|
+
For features in this version, please visit https://github.com/Dicridon/canoe
|
|
6
|
+
Currently, canoe can do below:
|
|
7
|
+
- project creation
|
|
8
|
+
- project auto build and run (works like Cargo for Rust)
|
|
9
|
+
- project structure management
|
|
10
|
+
by XIONG Ziwei
|
|
11
|
+
VER
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
require "fileutils"
|
|
2
|
+
require_relative "../source_files"
|
|
3
|
+
require_relative "../compiler"
|
|
4
|
+
require_relative "../config_reader"
|
|
5
|
+
require_relative "../default_files"
|
|
6
|
+
require_relative "../err"
|
|
7
|
+
require_relative "../dependence"
|
|
8
|
+
require_relative "../coloring"
|
|
9
|
+
|
|
10
|
+
class WorkSpace
|
|
11
|
+
include Err
|
|
12
|
+
attr_reader :name, :cwd, :src_prefix, :components_prefix, :obj_prefix, :source_suffix, :header_suffix, :mode
|
|
13
|
+
|
|
14
|
+
def initialize(name, mode, src_suffix = "cpp", hdr_suffix = "hpp")
|
|
15
|
+
@name = name
|
|
16
|
+
@compiler = Compiler.new "clang++", ["-Isrc/components"], []
|
|
17
|
+
@cwd = Dir.new(Dir.pwd)
|
|
18
|
+
@workspace = "#{Dir.pwd}/#{@name}"
|
|
19
|
+
@src = "#{@workspace}/src"
|
|
20
|
+
@components = "#{@src}/components"
|
|
21
|
+
@obj = "#{@workspace}/obj"
|
|
22
|
+
@third = "#{@workspace}/third-party"
|
|
23
|
+
@target = "#{@workspace}/target"
|
|
24
|
+
@tests = "#{@workspace}/tests"
|
|
25
|
+
@mode = mode
|
|
26
|
+
@deps = ".canoe.deps"
|
|
27
|
+
|
|
28
|
+
@src_prefix = "./src/"
|
|
29
|
+
@components_prefix = "./src/components/"
|
|
30
|
+
@obj_prefix = "./obj/"
|
|
31
|
+
|
|
32
|
+
@source_suffix = src_suffix
|
|
33
|
+
@header_suffix = hdr_suffix
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def inspect
|
|
37
|
+
puts "name is #{@name}"
|
|
38
|
+
puts "name is #{@workspace}"
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
require_relative "help"
|
|
43
|
+
require_relative "version"
|
|
44
|
+
require_relative "new"
|
|
45
|
+
require_relative "add"
|
|
46
|
+
require_relative "build"
|
|
47
|
+
require_relative "generate"
|
|
48
|
+
require_relative "run"
|
|
49
|
+
require_relative "dep"
|
|
50
|
+
require_relative "clean"
|
|
51
|
+
require_relative "update"
|
|
52
|
+
require_relative "test"
|
|
53
|
+
require_relative "make"
|
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.
|
|
4
|
+
version: 0.3.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- XIONG Ziwei
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2021-02-25 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: |+
|
|
14
14
|
Canoe offers project management and building facilities to C/C++ projects.
|
|
@@ -28,13 +28,26 @@ files:
|
|
|
28
28
|
- bin/canoe
|
|
29
29
|
- lib/canoe.rb
|
|
30
30
|
- lib/cmd.rb
|
|
31
|
+
- lib/coloring.rb
|
|
31
32
|
- lib/compiler.rb
|
|
32
33
|
- lib/config_reader.rb
|
|
33
34
|
- lib/default_files.rb
|
|
34
35
|
- lib/dependence.rb
|
|
35
36
|
- lib/err.rb
|
|
36
37
|
- lib/source_files.rb
|
|
37
|
-
- lib/workspace.rb
|
|
38
|
+
- lib/workspace/add.rb
|
|
39
|
+
- lib/workspace/build.rb
|
|
40
|
+
- lib/workspace/clean.rb
|
|
41
|
+
- lib/workspace/dep.rb
|
|
42
|
+
- lib/workspace/generate.rb
|
|
43
|
+
- lib/workspace/help.rb
|
|
44
|
+
- lib/workspace/make.rb
|
|
45
|
+
- lib/workspace/new.rb
|
|
46
|
+
- lib/workspace/run.rb
|
|
47
|
+
- lib/workspace/test.rb
|
|
48
|
+
- lib/workspace/update.rb
|
|
49
|
+
- lib/workspace/version.rb
|
|
50
|
+
- lib/workspace/workspace.rb
|
|
38
51
|
homepage: https://github.com/Dicridon/canoe
|
|
39
52
|
licenses:
|
|
40
53
|
- MIT
|
|
@@ -54,7 +67,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
54
67
|
- !ruby/object:Gem::Version
|
|
55
68
|
version: '0'
|
|
56
69
|
requirements: []
|
|
57
|
-
rubygems_version: 3.
|
|
70
|
+
rubygems_version: 3.2.3
|
|
58
71
|
signing_key:
|
|
59
72
|
specification_version: 4
|
|
60
73
|
summary: a C/C++ project management and building tool
|
data/lib/workspace.rb
DELETED
|
@@ -1,296 +0,0 @@
|
|
|
1
|
-
require 'fileutils'
|
|
2
|
-
require 'open3'
|
|
3
|
-
require_relative 'source_files'
|
|
4
|
-
require_relative 'compiler'
|
|
5
|
-
require_relative 'config_reader'
|
|
6
|
-
require_relative 'default_files'
|
|
7
|
-
require_relative 'err'
|
|
8
|
-
require_relative 'dependence'
|
|
9
|
-
|
|
10
|
-
class WorkSpace
|
|
11
|
-
include Err
|
|
12
|
-
attr_reader :name, :cwd
|
|
13
|
-
def self.help
|
|
14
|
-
info = <<~INFO
|
|
15
|
-
canoe is a C/C++ project manager, inspired by Rust cargo.
|
|
16
|
-
usage:
|
|
17
|
-
canoe new tada: create a project named 'tada' in current directory
|
|
18
|
-
|
|
19
|
-
canoe build: compile current project (execute this command in project directory)
|
|
20
|
-
|
|
21
|
-
canoe generate: generate dependency relationships and store it in '.canoe.deps' file. Alias: update
|
|
22
|
-
|
|
23
|
-
canoe update: udpate dependency relationships and store it in '.canoe.deps' file.
|
|
24
|
-
|
|
25
|
-
canoe run: compile and execute current project (execute this command in project directory)
|
|
26
|
-
|
|
27
|
-
canoe clean: remove all generated object files and binary files
|
|
28
|
-
|
|
29
|
-
canoe help: show this help message
|
|
30
|
-
|
|
31
|
-
canoe add tada: add a folder named tada under workspace/components,
|
|
32
|
-
|
|
33
|
-
canoe dep: show current dependency relationships of current project
|
|
34
|
-
|
|
35
|
-
canoe verion: version information
|
|
36
|
-
|
|
37
|
-
new project_name [mode] [suffixes]:
|
|
38
|
-
create a new project with project_name.
|
|
39
|
-
In this project, four directories obj, src, target and third-party will be generated in project directory.
|
|
40
|
-
in src, directory 'components' will be generated if [mode] is '--lib', an extra main.cpp will be generated if [mode] is '--bin'
|
|
41
|
-
|
|
42
|
-
[mode]: --lib for a library and --bin for executable binaries
|
|
43
|
-
[suffixes]: should be in 'source_suffix:header_suffix" format, notice the ':' between two suffixes
|
|
44
|
-
add component_name:
|
|
45
|
-
add a folder named tada under workspace/components.
|
|
46
|
-
two files tada.hpp and tada.cpp would be craeted and intialized. File suffix may differ according users' specifications.
|
|
47
|
-
if component_name is a path separated by '/', then canoe would create folders and corresponding files recursively.
|
|
48
|
-
|
|
49
|
-
generate:
|
|
50
|
-
generate dependence relationship for each file, this may accelarate
|
|
51
|
-
`canoe buid` command. It's recommanded to execute this command everytime
|
|
52
|
-
headers are added or removed from any file.
|
|
53
|
-
|
|
54
|
-
update:
|
|
55
|
-
this command is needed because '.canoe.deps' is actually a cache of dependency relationships so that
|
|
56
|
-
canoe doesn't have to analyze all the files when building a project.
|
|
57
|
-
So when a file includes new headers or some headers are removed, users have to use 'canoe udpate'
|
|
58
|
-
to update dependency relationships.
|
|
59
|
-
|
|
60
|
-
build [options]:
|
|
61
|
-
build current project, arguments in [options] will be passed to C++ compiler
|
|
62
|
-
|
|
63
|
-
run [options]:
|
|
64
|
-
build current project with no specific compilation flags, and run this project, passing [options] as command line arguments to the binary
|
|
65
|
-
|
|
66
|
-
clean:
|
|
67
|
-
remove all generated object files and binary files
|
|
68
|
-
|
|
69
|
-
help:
|
|
70
|
-
show this help message
|
|
71
|
-
|
|
72
|
-
verion:
|
|
73
|
-
display version information
|
|
74
|
-
|
|
75
|
-
dep:
|
|
76
|
-
display file dependencies in a better readable way
|
|
77
|
-
|
|
78
|
-
@author: written by XIONG Ziwei, ICT, CAS
|
|
79
|
-
@contact: noahxiong@outlook.com
|
|
80
|
-
INFO
|
|
81
|
-
puts info
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
def initialize(name, mode, src_suffix='cpp', hdr_suffix='hpp')
|
|
86
|
-
@name = name
|
|
87
|
-
@compiler = Compiler.new 'clang++', '-Isrc/components'
|
|
88
|
-
@cwd = Dir.new(Dir.pwd)
|
|
89
|
-
@workspace = "#{Dir.pwd}/#{@name}"
|
|
90
|
-
@src = "#{@workspace}/src"
|
|
91
|
-
@components = "#{@src}/components"
|
|
92
|
-
@obj = "#{@workspace}/obj"
|
|
93
|
-
@third = "#{@workspace}/third-party"
|
|
94
|
-
@target = "#{@workspace}/target"
|
|
95
|
-
@mode = mode
|
|
96
|
-
@deps = '.canoe.deps'
|
|
97
|
-
|
|
98
|
-
@src_prefix = './src/'
|
|
99
|
-
@components_prefix = './src/components/'
|
|
100
|
-
@obj_prefix = './obj/'
|
|
101
|
-
|
|
102
|
-
@source_suffix = src_suffix
|
|
103
|
-
@header_suffix = hdr_suffix
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
def new
|
|
107
|
-
Dir.mkdir(@name)
|
|
108
|
-
Dir.mkdir(@src)
|
|
109
|
-
Dir.mkdir(@components)
|
|
110
|
-
Dir.mkdir("#{@workspace}/obj")
|
|
111
|
-
if @mode == :bin
|
|
112
|
-
DefaultFiles.create_main(@src, @source_suffix)
|
|
113
|
-
else
|
|
114
|
-
DefaultFiles.create_lib_header(@src, @name, @header_suffix)
|
|
115
|
-
end
|
|
116
|
-
File.new("#{@workspace}/.canoe", "w")
|
|
117
|
-
DefaultFiles.create_config @workspace, @source_suffix, @header_suffix
|
|
118
|
-
DefaultFiles.create_emacs_dir_local @workspace
|
|
119
|
-
|
|
120
|
-
Dir.mkdir(@third)
|
|
121
|
-
Dir.mkdir(@target)
|
|
122
|
-
puts "workspace #{@workspace} is created"
|
|
123
|
-
end
|
|
124
|
-
|
|
125
|
-
# args are commandline parameters passed to `canoe build`
|
|
126
|
-
def build(args)
|
|
127
|
-
deps = File.exist?(@deps) ?
|
|
128
|
-
DepAnalyzer.read_from(@deps) :
|
|
129
|
-
DepAnalyzer.new('./src').build_to_file(['./src', './src/components'], @deps)
|
|
130
|
-
target = "./target/#{@name}"
|
|
131
|
-
build_time = File.exist?(target) ? File.mtime(target) : Time.new(0)
|
|
132
|
-
files = DepAnalyzer.compiling_filter(deps, build_time, @source_suffix, @header_suffix)
|
|
133
|
-
|
|
134
|
-
if files.empty?
|
|
135
|
-
puts "nothing to do, all up to date"
|
|
136
|
-
return
|
|
137
|
-
end
|
|
138
|
-
|
|
139
|
-
self.send "build_#{@mode.to_s}", files, args
|
|
140
|
-
end
|
|
141
|
-
|
|
142
|
-
def generate
|
|
143
|
-
DepAnalyzer.new('./src', @source_suffix, @header_suffix)
|
|
144
|
-
.build_to_file ['./src', './src/components'], @deps
|
|
145
|
-
end
|
|
146
|
-
|
|
147
|
-
def update
|
|
148
|
-
generate
|
|
149
|
-
end
|
|
150
|
-
|
|
151
|
-
def clean
|
|
152
|
-
self.send "clean_#{@mode.to_s}"
|
|
153
|
-
end
|
|
154
|
-
|
|
155
|
-
def run(args)
|
|
156
|
-
return if @mode == :lib
|
|
157
|
-
build []
|
|
158
|
-
args = args.join " "
|
|
159
|
-
puts "./target/#{@name} #{args}"
|
|
160
|
-
exec "./target/#{@name} #{args}"
|
|
161
|
-
end
|
|
162
|
-
|
|
163
|
-
def add(args)
|
|
164
|
-
args.each do |i|
|
|
165
|
-
dir = @components
|
|
166
|
-
filenames = i.split("/")
|
|
167
|
-
prefix = []
|
|
168
|
-
filenames.each do |filename|
|
|
169
|
-
dir += "/#{filename}"
|
|
170
|
-
prefix << filename
|
|
171
|
-
unless Dir.exist? dir
|
|
172
|
-
FileUtils.mkdir dir
|
|
173
|
-
Dir.chdir(dir) do
|
|
174
|
-
puts "created " + Dir.pwd
|
|
175
|
-
create_working_files prefix.join('__'), filename
|
|
176
|
-
end
|
|
177
|
-
end
|
|
178
|
-
end
|
|
179
|
-
end
|
|
180
|
-
end
|
|
181
|
-
|
|
182
|
-
def dep
|
|
183
|
-
deps = DepAnalyzer.read_from(@deps) if File.exist?(@deps)
|
|
184
|
-
deps.each do |k, v|
|
|
185
|
-
unless v.empty?
|
|
186
|
-
puts "#{k} depends on: "
|
|
187
|
-
v.each {|f| puts " #{f}"}
|
|
188
|
-
puts ""
|
|
189
|
-
end
|
|
190
|
-
end
|
|
191
|
-
end
|
|
192
|
-
|
|
193
|
-
private
|
|
194
|
-
def create_working_files(prefix, filename)
|
|
195
|
-
DefaultFiles.create_cpp filename, @source_suffix, @header_suffix
|
|
196
|
-
DefaultFiles.create_hpp @name, prefix, filename, @header_suffix
|
|
197
|
-
end
|
|
198
|
-
|
|
199
|
-
def build_compiler_from_config(args)
|
|
200
|
-
Dir.chdir(@workspace) do
|
|
201
|
-
flags = ConfigReader.extract_flags "config.json"
|
|
202
|
-
compiler_name = flags['compiler'] ? flags['compiler'] : "clang++"
|
|
203
|
-
abort_on_err "compiler #{compiler_name} not found" unless File.exists?("/usr/bin/#{compiler_name}")
|
|
204
|
-
compiler_flags = ['-Isrc/components'] + args
|
|
205
|
-
|
|
206
|
-
if opts = flags['flags']
|
|
207
|
-
opts.each do |k, v|
|
|
208
|
-
case v
|
|
209
|
-
when String
|
|
210
|
-
compiler_flags << v
|
|
211
|
-
when Array
|
|
212
|
-
v.each do |o|
|
|
213
|
-
compiler_flags << o
|
|
214
|
-
end
|
|
215
|
-
else
|
|
216
|
-
abort_on_err "unknown options in config.json, #{v}"
|
|
217
|
-
end
|
|
218
|
-
end
|
|
219
|
-
end
|
|
220
|
-
|
|
221
|
-
@compiler = Compiler.new compiler_name, compiler_flags
|
|
222
|
-
end
|
|
223
|
-
end
|
|
224
|
-
|
|
225
|
-
def compile(f, o)
|
|
226
|
-
@compiler.compile f, o
|
|
227
|
-
end
|
|
228
|
-
|
|
229
|
-
def link_exectutable(odir, objs)
|
|
230
|
-
@compiler.link_executable "#{odir}/#{@name}", objs
|
|
231
|
-
end
|
|
232
|
-
|
|
233
|
-
def link_shared(odir, objs)
|
|
234
|
-
@compiler.link_shared "#{odir}/lib#{@name}", objs
|
|
235
|
-
end
|
|
236
|
-
|
|
237
|
-
def build_bin(files, args)
|
|
238
|
-
return if files.empty?
|
|
239
|
-
build_compiler_from_config args
|
|
240
|
-
build_common files, args
|
|
241
|
-
link_exectutable('./target', Dir.glob("obj/*.o"))
|
|
242
|
-
end
|
|
243
|
-
|
|
244
|
-
def build_lib(files, args)
|
|
245
|
-
return if files.empty?
|
|
246
|
-
build_compiler_from_config args
|
|
247
|
-
@compiler.append_flag '-fPIC'
|
|
248
|
-
build_common files, args
|
|
249
|
-
link_shared('./target', Dir.glob("obj/*.o"))
|
|
250
|
-
end
|
|
251
|
-
|
|
252
|
-
def build_common(files, args)
|
|
253
|
-
comps = files.select {|f| f.start_with? @components_prefix}
|
|
254
|
-
srcs = files - comps
|
|
255
|
-
|
|
256
|
-
srcs.each do |f|
|
|
257
|
-
puts "compiling #{f}"
|
|
258
|
-
fname = f.split("/")[-1]
|
|
259
|
-
o = @obj_prefix + fname.delete_suffix(File.extname(fname)) + '.o'
|
|
260
|
-
compile f, o
|
|
261
|
-
end
|
|
262
|
-
|
|
263
|
-
comps.each do |f|
|
|
264
|
-
puts "compiling #{f}"
|
|
265
|
-
o = @obj_prefix + f.delete_suffix(File.extname(f))[@components_prefix.length..]
|
|
266
|
-
.gsub('/', '_') + '.o'
|
|
267
|
-
compile f, o
|
|
268
|
-
end
|
|
269
|
-
end
|
|
270
|
-
|
|
271
|
-
def clean_obj
|
|
272
|
-
puts "rm -f ./obj/*.o"
|
|
273
|
-
system "rm -f ./obj/*.o"
|
|
274
|
-
end
|
|
275
|
-
|
|
276
|
-
def clean_target
|
|
277
|
-
puts "rm -f ./target/*"
|
|
278
|
-
system "rm -f ./target/*"
|
|
279
|
-
end
|
|
280
|
-
|
|
281
|
-
def clean_bin
|
|
282
|
-
clean_obj
|
|
283
|
-
clean_target
|
|
284
|
-
end
|
|
285
|
-
|
|
286
|
-
def clean_lib
|
|
287
|
-
clean_obj
|
|
288
|
-
clean_target
|
|
289
|
-
end
|
|
290
|
-
|
|
291
|
-
public
|
|
292
|
-
def inspect
|
|
293
|
-
puts "name is #{@name}"
|
|
294
|
-
puts "name is #{@workspace}"
|
|
295
|
-
end
|
|
296
|
-
end
|