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