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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6e9bebbc3472c5f6271c4c019f23bf18779492934ed86411f4d09384e51bfeab
4
- data.tar.gz: 9aa82b75a58e0992653ddc5419bf14e129846cc54cc9358f08baa1d2014d8d5a
3
+ metadata.gz: f86609a6f492e0a6633dab5d94a46443c24de7cad25640d9b4cfa0a8c97b2907
4
+ data.tar.gz: e80970d6113b6a155edbfed18e490ad297ad75d0da626394ecdc9d4f2a166d7b
5
5
  SHA512:
6
- metadata.gz: fd9be9cc303239eaa9853c177501e460023279a6385094afbe79e55b912257cebe72860633b53503dff96583a61aa88ea6034ce0e741e36f4fce8acce33c2496
7
- data.tar.gz: 6ee389790c8490d80ef9742e877fc0de8b13b6b74629361e68f363155c628a0dff1764d066f4608b0b7e7cef72f20b1775c2b214be487b4bdcf943ab1b985c3f
6
+ metadata.gz: 69ea4c7960c5240f870b9d9a851a55cf3ebfa41fed2417b2a0eae9d49dff93fe6d1bb1e0dedfcb6abf72d5c452ca38297b643848d25a1103000d0b280765f4a8
7
+ data.tar.gz: b9fc0c80a96a201af4f32eb6d8d787ebe7869996fbdd2c97b5f0c2f0871c52e5ae3bdeef94b2f79e5153a2fc5c43704fa6a3ee7b9286771de9aceed60339c798
data/bin/canoe CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # require_relative '../lib/canoe'
2
3
  require 'canoe'
3
4
 
4
5
  Canoe.new.parse ARGV
data/lib/canoe.rb CHANGED
@@ -1,23 +1,25 @@
1
- require_relative "workspace"
1
+ require_relative "workspace/workspace.rb"
2
2
  require_relative "cmd"
3
3
  require_relative "source_files"
4
4
 
5
5
  class Canoe
6
6
  def initialize
7
- options = ['new',
8
- 'add',
9
- 'build',
10
- 'generate',
11
- 'run',
12
- 'dep',
13
- 'clean',
14
- 'version',
15
- 'help',
16
- 'update']
7
+ options = ["new",
8
+ "add",
9
+ "build",
10
+ "generate",
11
+ "make",
12
+ "run",
13
+ "dep",
14
+ "clean",
15
+ "version",
16
+ "help",
17
+ "update",
18
+ "test"]
17
19
  @cmd = CmdParser.new options
18
20
  end
19
21
 
20
22
  def parse(args)
21
- @cmd.parse args
23
+ @cmd.parse args
22
24
  end
23
25
  end
data/lib/cmd.rb CHANGED
@@ -1,16 +1,20 @@
1
- require_relative "workspace"
1
+ require_relative "workspace/workspace"
2
2
  require_relative "err"
3
3
  require_relative "config_reader"
4
4
 
5
+ ##
6
+ # class CmdParser
7
+ # Parsing command arguments passed to canoe
5
8
  class CmdParser
6
9
  include Err
10
+
7
11
  def initialize(options)
8
- @options = options
12
+ @options = options
9
13
  end
10
14
 
11
15
  def parse(args)
12
- if args.size < 1
13
- abort_on_err "please give one command among #{@options.join(', ')}"
16
+ if args.size < 1
17
+ abort_on_err "please give one command among #{@options.join(", ")}"
14
18
  end
15
19
 
16
20
  unless @options.include?(args[0])
@@ -21,6 +25,7 @@ class CmdParser
21
25
  end
22
26
 
23
27
  private
28
+
24
29
  def get_current_workspace
25
30
  abort_on_err "not in a canoe workspace" unless File.exists? ".canoe"
26
31
  config = ConfigReader.extract_flags("config.json")
@@ -31,7 +36,7 @@ class CmdParser
31
36
  name = Dir.pwd.split("/")[-1]
32
37
  mode = File.exists?("src/main.#{src_sfx}") ? :bin : :lib
33
38
 
34
- Dir.chdir('..') do
39
+ Dir.chdir("..") do
35
40
  return WorkSpace.new(name, mode, src_sfx, hdr_sfx)
36
41
  end
37
42
  end
@@ -41,10 +46,10 @@ class CmdParser
41
46
 
42
47
  name, mode = nil, "bin"
43
48
  suffixes = ["cpp", "hpp"]
44
-
49
+
45
50
  args.each do |arg|
46
51
  case arg
47
- when '--bin', '--lib'
52
+ when "--bin", "--lib"
48
53
  mode = arg[2..]
49
54
  when /--suffix=(\w+)\:(\w+)/
50
55
  suffixes[0], suffixes[1] = $1, $2
@@ -52,7 +57,7 @@ class CmdParser
52
57
  name = arg unless name
53
58
  end
54
59
  end
55
-
60
+
56
61
  abort_on_err("please give a name to this project") unless name
57
62
  WorkSpace.new(name, mode.to_sym, suffixes[0], suffixes[1]).new
58
63
  end
@@ -64,7 +69,7 @@ class CmdParser
64
69
 
65
70
  get_current_workspace.add args
66
71
  end
67
-
72
+
68
73
  def parse_build(args)
69
74
  get_current_workspace.build args
70
75
  end
@@ -72,31 +77,27 @@ class CmdParser
72
77
  def parse_generate(args)
73
78
  get_current_workspace.generate
74
79
  end
75
-
80
+
76
81
  def parse_run(args)
77
82
  get_current_workspace.run args
78
83
  end
79
84
 
80
85
  def parse_dep(args)
81
- get_current_workspace.dep
86
+ get_current_workspace.dep
82
87
  end
83
-
88
+
84
89
  def parse_clean(args)
85
90
  get_current_workspace.clean
86
91
  end
87
92
 
93
+ def parse_test(args)
94
+ get_current_workspace.test args
95
+ end
96
+
88
97
  def parse_version(args)
89
- puts <<~VER
90
- canoe v0.2.1
91
- For features in this version, please visit https://github.com/Dicridon/canoe
92
- Currently, canoe can do below:
93
- - project creation
94
- - project auto build and run (works like Cargo for Rust)
95
- - project structure management
96
- by XIONG Ziwei
97
- VER
98
+ WorkSpace.version
98
99
  end
99
-
100
+
100
101
  def parse_help(args)
101
102
  WorkSpace.help
102
103
  end
@@ -104,4 +105,8 @@ class CmdParser
104
105
  def parse_update(args)
105
106
  get_current_workspace.update
106
107
  end
108
+
109
+ def parse_make(args)
110
+ get_current_workspace.make
111
+ end
107
112
  end
data/lib/coloring.rb ADDED
@@ -0,0 +1,23 @@
1
+ ##
2
+ # gem Colorize is a great tool, but I don't want add dependencies to Canoe
3
+ class String
4
+ def self.define_coloring_methods
5
+ colors = {
6
+ 30 => :black,
7
+ 31 => :red,
8
+ 32 => :green,
9
+ 33 => :yellow,
10
+ 34 => :blue,
11
+ 35 => :magenta,
12
+ 36 => :cyan,
13
+ 37 => :white,
14
+ }
15
+ colors.each do |k, v|
16
+ define_method v do
17
+ "\033[#{k}m#{self}\033[0m"
18
+ end
19
+ end
20
+ end
21
+
22
+ define_coloring_methods
23
+ end
data/lib/compiler.rb CHANGED
@@ -1,35 +1,48 @@
1
+ ##
2
+ # class Compiler
3
+ # Storing compiler name in String and flags as an array
1
4
  class Compiler
2
5
  attr_reader :name, :flags
3
- def initialize(name, flgs)
6
+ ##
7
+ # @name: String
8
+ # @flgs: Array of String
9
+ def initialize(name, compiling_flags, linking_flags)
4
10
  @name = name
5
- @flags = flgs
11
+ @linking_flags = linking_flags
12
+ @compiling_flags = compiling_flags
6
13
  end
7
14
 
8
- def flags_as_str
9
- flags.join " "
15
+ def compiling_flags_as_str
16
+ @compiling_flags.join " "
10
17
  end
11
18
 
12
- def append_flag(flag)
13
- @flags << flag
19
+ def linking_flags_as_str
20
+ @linking_flags.join " "
21
+ end
22
+
23
+ def append_compiling_flag(flag)
24
+ @compiling_flags << flag
25
+ end
26
+
27
+ def append_linking_flag(flag)
28
+ @linking_flags << flag
14
29
  end
15
30
 
16
31
  def compile(src, out)
17
- puts "#{name} -o #{out} #{flags_as_str} -c #{src}"
18
- system "#{name} -o #{out} #{flags_as_str} -c #{src}"
32
+ puts "#{name} -o #{out} #{compiling_flags_as_str} -c #{src}"
33
+ system "#{name} -o #{out} #{compiling_flags_as_str} -c #{src}"
19
34
  end
20
35
 
21
36
  def link_executable(out, objs)
22
- libs = flags.select {|f| f.start_with?('-l')}
23
- puts "#{name} -o #{out} #{objs.join(" ")} #{libs.join(" ")}"
24
- system "#{name} -o #{out} #{objs.join(" ")} #{libs.join(" ")}"
37
+ puts "#{name} -o #{out} #{objs.join(" ")} #{linking_flags_as_str}"
38
+ system "#{name} -o #{out} #{objs.join(" ")} #{linking_flags_as_str}"
25
39
  end
26
40
 
27
41
  def link_shared(out, objs)
28
- libs = flags.select {|f| f.start_with?('-l')}
29
- puts "#{name} -shared -o #{out}.so #{objs.join(" ")} #{libs.join(" ")}"
30
- system "#{name} -shared -o #{out}.so #{objs.join(" ")} #{libs.join(" ")}"
42
+ puts "#{name} -shared -o #{out}.so #{objs.join(" ")} #{linking_flags_as_str}"
43
+ system "#{name} -shared -o #{out}.so #{objs.join(" ")} #{linking_flags_as_str}"
31
44
  end
32
-
45
+
33
46
  def inspect
34
47
  puts "compiler name: #{name.inspect}"
35
48
  puts "compiler flags: #{flags.inspect}"
data/lib/config_reader.rb CHANGED
@@ -1,5 +1,8 @@
1
- require 'json'
1
+ require "json"
2
2
 
3
+ ##
4
+ # class ConfigReader
5
+ # Just read a json file
3
6
  class ConfigReader
4
7
  def self.extract_flags(file)
5
8
  abort_on_err("config file #{file} does not exsit") unless File.exists? file
data/lib/default_files.rb CHANGED
@@ -1,82 +1,98 @@
1
+ ##
2
+ # class DefaultFiles
3
+ # A singleton class to generate header and souce files.
4
+ # TODO: consider using class source_file.rb in Pareater
1
5
  class DefaultFiles
2
- def self.open_file_and_write(filename, content)
3
- File.open(filename, "w") {|f|
4
- f.write(content)
5
- }
6
- end
7
-
8
- def self.create_config(path, src_sfx='cpp', hdr_sfx='hpp')
9
- open_file_and_write(
10
- "#{path}/config.json",
11
- <<~CONFIG
12
- {
13
- "compiler": "clang++",
14
- "header-suffix": "#{hdr_sfx}",
15
- "source-suffix": "#{src_sfx}",
16
- "flags": {
17
- "opt": "-O2",
18
- "debug": "-g",
19
- "std": "-std=c++17"
20
- }
21
- }
22
- CONFIG
23
- )
24
- end
25
-
26
- def self.create_main(path, suffix='cpp')
27
- open_file_and_write(
28
- "#{path}/main.#{suffix}",
29
- <<~DOC
30
- #include <iostream>
31
- int main(int argc, char *argv[]) {
32
- std::cout << "hello world!" << std::endl;
33
- }
34
- DOC
35
- )
36
- end
6
+ class << self
7
+ def open_file_and_write(filename, content)
8
+ File.open(filename, "w") do |f|
9
+ f.write(content)
10
+ end
11
+ end
37
12
 
38
- def self.create_lib_header(path, lib_name, suffix='hpp')
39
- open_file_and_write(
40
- "#{path}/#{lib_name}.#{suffix}",
41
- <<~DOC
42
- #ifndef __#{lib_name.upcase}__
43
- #define __#{lib_name.upcase}__
13
+ def create_config(path, src_sfx = "cpp", hdr_sfx = "hpp")
14
+ open_file_and_write(
15
+ "#{path}/config.json",
16
+ <<~CONFIG
17
+ {
18
+ "compiler": "clang++",
19
+ "header-suffix": "#{hdr_sfx}",
20
+ "source-suffix": "#{src_sfx}",
21
+ "flags": {
22
+ "compile": {
23
+ "opt": "-O2",
24
+ "debug": "-g",
25
+ "std": "-std=c++17"
26
+ },
27
+ "link": {
28
+
29
+ }
30
+ }
31
+ }
32
+ CONFIG
33
+
34
+ )
35
+ end
44
36
 
45
- #endif
46
- DOC
47
- )
48
- end
37
+ def create_main(path, suffix = "cpp")
38
+ open_file_and_write(
39
+ "#{path}/main.#{suffix}",
40
+ <<~DOC
41
+ #include <iostream>
42
+ int main(int argc, char *argv[]) {
43
+ std::cout << "hello world!" << std::endl;
44
+ }
45
+ DOC
46
+
47
+ )
48
+ end
49
49
 
50
- def self.create_emacs_dir_local(path)
51
- open_file_and_write(
52
- "#{path}/.dir-locals.el",
53
- <<~DOC
54
- ((nil . ((company-clang-arguments . ("-I./src/components/"
55
- "-I./components/"))))
56
- (nil . ((company-c-headers-path-user . ("./src/components/"
57
- "./components/")))))
58
- DOC
59
- )
60
- end
50
+ def create_lib_header(path, lib_name, suffix = "hpp")
51
+ open_file_and_write(
52
+ "#{path}/#{lib_name}.#{suffix}",
53
+ <<~DOC
54
+ #ifndef __#{lib_name.upcase}__
55
+ #define __#{lib_name.upcase}__
56
+
57
+ #endif
58
+ DOC
59
+
60
+ )
61
+ end
61
62
 
62
- def self.create_cpp(filename, src_sfx='cpp', hdr_sfx='hpp')
63
- open_file_and_write(
64
- "#{filename}.#{src_sfx}",
65
- <<~DOC
66
- #include "#{filename}.#{hdr_sfx}"
67
- DOC
68
- )
69
- end
63
+ # def create_emacs_dir_local(path)
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
70
74
 
71
- def self.create_hpp(workspace, prefix, filename, hdr_sfx='hpp')
72
- open_file_and_write(
73
- "#{filename}.#{hdr_sfx}",
74
- <<~DOC
75
- #ifndef __#{workspace.upcase}__#{prefix.upcase}__#{filename.upcase}__
76
- #define __#{workspace.upcase}__#{prefix.upcase}__#{filename.upcase}__
75
+ def create_cpp(filename, src_sfx = "cpp", hdr_sfx = "hpp")
76
+ open_file_and_write(
77
+ "#{filename}.#{src_sfx}",
78
+ <<~DOC
79
+ #include "#{filename}.#{hdr_sfx}"
80
+ DOC
81
+
82
+ )
83
+ end
77
84
 
78
- #endif
79
- DOC
80
- )
85
+ def create_hpp(workspace, prefix, filename, hdr_sfx = "hpp")
86
+ open_file_and_write(
87
+ "#{filename}.#{hdr_sfx}",
88
+ <<~DOC
89
+ #ifndef __#{workspace.upcase}__#{prefix.upcase}__#{filename.upcase}__
90
+ #define __#{workspace.upcase}__#{prefix.upcase}__#{filename.upcase}__
91
+
92
+ #endif
93
+ DOC
94
+
95
+ )
96
+ end
81
97
  end
82
98
  end