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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f216d0dc37bc62674772eb685e40bae7859af341e75f3b67e4f9327030ad3483
4
- data.tar.gz: 28c69b2037f47926b86a5f927ff0398f6122a30adb725ce0e5830dea81acf549
3
+ metadata.gz: 50752029532b56ce10a610ae7d9705212a1c424533ed2fde71a3133505c11d0e
4
+ data.tar.gz: 501d882198eb59157961a741d786dbbe5c420e9d2704d37e7b1ca9a0f651854a
5
5
  SHA512:
6
- metadata.gz: 110c69c11e3be4d7d38e23cb2d83680fd4677f5537f5448fba4a5d68999e5e1727794d9c857ccb290a628e6c4586c22a68c8ee73799f7ecf1e58ffa9dd1ea351
7
- data.tar.gz: 05a9808ee35431a874a932c36af3b6ab3d5f0734a04fd2ed70aa9d18ac2a4d3c211340142f722acee9dea997030b80c5e34e77491c6a387ab1bad74936529e7e
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
- get_current_workspace.add args
56
+ current_workspace.add args
57
57
  end
58
58
 
59
59
  def parse_build(args)
60
- get_current_workspace.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]
61
63
  end
62
64
 
63
65
  def parse_generate(args)
64
- get_current_workspace.generate
66
+ current_workspace.generate
65
67
  end
66
68
 
67
69
  def parse_run(args)
68
- get_current_workspace.run args
70
+ current_workspace.run args
69
71
  end
70
72
 
71
73
  def parse_dep(args)
72
- get_current_workspace.dep
74
+ current_workspace.dep
73
75
  end
74
76
 
75
77
  def parse_clean(args)
76
- get_current_workspace.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]
77
84
  end
78
85
 
79
86
  def parse_test(args)
80
- get_current_workspace.test args
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
- get_current_workspace.update
99
+ current_workspace.update
93
100
  end
94
101
 
95
102
  def parse_make(args)
96
- get_current_workspace.make
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": "clang++",
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 <iostream>
40
+ #include <#{header}>
41
41
  int main(int argc, char *argv[]) {
42
- std::cout << "hello world!" << std::endl;
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 get_current_workspace
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
- get_current_workspace.src_to_obj(src)
40
+ current_workspace.src_to_obj(src)
38
41
  end
39
42
 
40
43
  def comp_to_obj(comp)
41
- get_current_workspace.comp_to_obj(comp)
44
+ current_workspace.comp_to_obj(comp)
42
45
  end
43
46
 
44
47
  def file_to_obj(file)
45
- get_current_workspace.file_to_obj(file)
48
+ current_workspace.file_to_obj(file)
46
49
  end
47
50
 
48
51
  def extract_one_file(file, deps)
49
- get_current_workspace.extract_one_file(file, deps)
52
+ current_workspace.extract_one_file(file, deps)
50
53
  end
51
54
 
52
55
  def extract_one_file_obj(file, deps)
53
- get_current_workspace.extract_one_file_obj(file, deps)
56
+ current_workspace.extract_one_file_obj(file, deps)
54
57
  end
55
58
  end
56
59
 
@@ -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(args)
23
- options = {[] => 'target', ['all'] => 'all', ['test'] => 'test'}
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 deps, build_time, @source_suffix, @header_suffix
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
@@ -1,16 +1,8 @@
1
1
  module Canoe
2
2
  class WorkSpace
3
3
  # valid options: none, 'all', 'target', 'tests'
4
- def clean(args)
5
- options = {
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
@@ -1,6 +1,8 @@
1
1
  # If the project has circular dependency, this command would fail
2
2
  module Canoe
3
- class Makefile
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("OUT: $(OUT_OBJS)\n\t$(#{cmplr}) $(#{cmplr}FLAGS) -o $(TARGET) $(OUT_OBJS) $(LDFLAGS) $(LDLIBS)")
222
+ makefile.puts("out: $(OUT_OBJS)\n\t$(#{cmplr}) $(#{cmplr}FLAGS) -o $(TARGET) $(OUT_OBJS) $(LDFLAGS) $(LDLIBS)")
225
223
  else
226
- makefile.puts("OUT: $(OUT_OBJS)\n\t$(#{cmplr}) $(#{cmplr}FLAGS) -shared -o $(TARGET) $(OUT_OBJS) -fPIC $(LDFLAGS) $(LDLIBS)")
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 = Makefile.new self
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
- DefaultFiles.create_config @workspace, @source_suffix, @header_suffix
19
- # DefaultFiles.create_emacs_dir_local @workspace
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
@@ -3,7 +3,7 @@ module Canoe
3
3
  def run(args)
4
4
  return if @mode == :lib
5
5
 
6
- return unless build []
6
+ return unless build
7
7
 
8
8
  args = args.join ' '
9
9
  issue_command "#{@target_short}/#{@name} #{args}"
@@ -2,7 +2,7 @@ module Canoe
2
2
  class WorkSpace
3
3
  def self.version
4
4
  puts <<~VER
5
- canoe v0.3.2.1
5
+ canoe v0.3.2.2
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
@@ -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.1
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-13 00:00:00.000000000 Z
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.