ckick 0.1.0 → 0.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
  SHA1:
3
- metadata.gz: 756a6b9ffddc2fb04cc92a35d5983d8fe0445b81
4
- data.tar.gz: f9dbe348fbcbc56f201c79e66311b0af9e5b32f6
3
+ metadata.gz: 7f67bdb5b93f95f17d249d3ebb736234f169eeaf
4
+ data.tar.gz: 260c7c593b1ffba404fa08609d694841baf8261b
5
5
  SHA512:
6
- metadata.gz: 180ad0530a054bbc89fbca19bbee3e3c17101988edc5bacc2e389946403199977ea06b5af49efafb1434a076f8392ff7ec0e469ea7d3665d9e1317030e424c23
7
- data.tar.gz: fb30114d785eee8c572a5390c40e32ff02c6d5305dab38dbc06a48bd6a38ddfb1539d617beb9eeeda0e2df0f22a8108a189eac28679a1b0e879cfe774fec63c5
6
+ metadata.gz: b9d498bd063661c4904ce9c1c68a0feebcb42a167383c87f2e029ff58211a0fd5464307838336e5cf0f9b614a57f814abc9ee5c8bfc69c36b406fbbba09ed77f
7
+ data.tar.gz: c919cec6a8393f0c34c80590d695398322c739f95035b82048f74672b2b4bedbd42b7b5e48b04fec3af5a460d98ee5594f10814d748037287e1201283efd588c
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # CKick [![Build Status](https://travis-ci.org/jonathangingras/ckick.svg?branch=master)](https://travis-ci.org/jonathangingras/ckick)
1
+ # CKick [![Build Status](https://travis-ci.org/jonathangingras/ckick.svg?branch=master)](https://travis-ci.org/jonathangingras/ckick) [![Code Climate](https://codeclimate.com/github/jonathangingras/ckick/badges/gpa.svg)](https://codeclimate.com/github/jonathangingras/ckick)
2
2
 
3
3
  CKick is a simple gem that helps to kick start a C/C++ project using CMake with an arbitrary structure.
4
4
  Using a `CKickfile`, ckick is able to generate an whole project structure without having to write any `CMakeLists.txt` by your own.
data/Rakefile CHANGED
@@ -1,6 +1,7 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rspec/core/rake_task"
3
3
 
4
+ # rspec
4
5
  RSpec::Core::RakeTask.new(:spec)
5
6
 
6
7
  task :default => :spec
@@ -24,4 +24,5 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency "bundler", "~> 1.13"
25
25
  spec.add_development_dependency "rake", "~> 10.0"
26
26
  spec.add_development_dependency "rspec", "~> 3.0"
27
+ spec.add_development_dependency "rdoc", "~> 4.2.2"
27
28
  end
@@ -7,48 +7,66 @@ require "ckick/project"
7
7
  require "ckick/find_plugin"
8
8
  require "ckick/ckickfile"
9
9
 
10
+ # CKick module
11
+ # contains all CKick core code
10
12
  module CKick
13
+ # location of the resource directory.
14
+ # +RESOURCE_DIR+ contains default project files and non-code utilities
11
15
  RESOURCE_DIR = File.join(File.dirname(File.dirname(__FILE__)), "resource")
12
16
 
17
+ # :nodoc:
13
18
  class Error < ::Exception
14
19
  end
15
20
 
21
+ # :nodoc:
16
22
  class BadFlagError < Error
17
23
  end
18
24
 
25
+ # :nodoc:
19
26
  class NoSuchDirectoryError < Error
20
27
  end
21
28
 
29
+ # :nodoc:
22
30
  class IllegalInitializationError < Error
23
31
  end
24
32
 
33
+ # :nodoc:
25
34
  class NoNameError < Error
26
35
  end
27
36
 
37
+ # :nodoc:
28
38
  class NoSourceError < Error
29
39
  end
30
40
 
41
+ # :nodoc:
31
42
  class BadProjectNameError < Error
32
43
  end
33
44
 
45
+ # :nodoc:
34
46
  class BadSourceError < Error
35
47
  end
36
48
 
49
+ # :nodoc:
37
50
  class BadLibError < Error
38
51
  end
39
52
 
53
+ # :nodoc:
40
54
  class BadIncludePathError < Error
41
55
  end
42
56
 
57
+ # :nodoc:
43
58
  class BadLibraryPathError < Error
44
59
  end
45
60
 
61
+ # :nodoc:
46
62
  class BadSubDirectoryError < Error
47
63
  end
48
64
 
65
+ # :nodoc:
49
66
  class NoParentDirError < Error
50
67
  end
51
68
 
69
+ # :nodoc:
52
70
  class BadFileContentError < Error
53
71
  end
54
72
  end
@@ -4,7 +4,10 @@
4
4
 
5
5
  require "ckick/hash"
6
6
 
7
+ # :nodoc:
7
8
  class Array
9
+ # transforms any Hash key recursively
10
+ # * +block+ - transform operation
8
11
  def array_aware_deep_transform_keys(&block)
9
12
  result = []
10
13
  each do |value|
@@ -6,9 +6,12 @@ require "ckick/compiler_flag"
6
6
 
7
7
  module CKick
8
8
 
9
+ # C compiler flag representation
9
10
  class CFlag < CompilerFlag
11
+
12
+ # appends ${CMAKE_C_FLAGS} (CMake C compiler flags)
10
13
  def cmake
11
- %Q(set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} #{@content}"))
14
+ %Q|set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} #{@content}")|
12
15
  end
13
16
  end
14
17
 
@@ -5,6 +5,9 @@
5
5
  require "json"
6
6
 
7
7
  module CKick
8
+ # loads a CKickfile in +dir+
9
+ # * +dir+ - directory containing file, defaults to Dir.pwd
10
+ # * +filename+ - filename, defaults to "CKickfile"
8
11
  def self.load_ckickfile(dir=Dir.pwd, filename="CKickfile")
9
12
  JSON.parse(File.read(File.join(dir, filename)), symbolize_names: true)
10
13
  end
@@ -2,11 +2,17 @@
2
2
  # License, v. 2.0. If a copy of the MPL was not distributed with this
3
3
  # file, You can obtain one at http://mozilla.org/MPL/2.0/.
4
4
 
5
+ # :nodoc:
5
6
  module CKick
6
7
 
8
+ #represents a compiler flag to pass to the compiler
7
9
  class CompilerFlag
10
+ # raw flag
8
11
  attr_reader :content
9
12
 
13
+ # * +args+ - Hash containing flag data as String
14
+ # ==== Input hash keys
15
+ # * +:flag+ - raw flag content, must be String
10
16
  def initialize args={}
11
17
  raise IllegalInitializationError, "No flag provided to compiler flag" unless args.is_a?(Hash) && !args.empty?
12
18
  flag = args[:flag] || nil
@@ -15,22 +21,27 @@ module CKick
15
21
  @content = args[:flag]
16
22
  end
17
23
 
24
+ # converts to String, flag as is
18
25
  def to_s
19
26
  @content
20
27
  end
21
28
 
29
+ # converts to hash element: String
22
30
  def to_hash_element
23
31
  @content
24
32
  end
25
33
 
34
+ # raw flag
26
35
  def raw_flag
27
36
  @content
28
37
  end
29
38
 
39
+ # overrides Object#eql? for uniqueness
30
40
  def eql? other
31
41
  @content.eql? other.content
32
42
  end
33
43
 
44
+ # overrides Object#hash for uniqueness
34
45
  def hash
35
46
  @content.hash
36
47
  end
@@ -6,9 +6,12 @@ require "ckick/compiler_flag"
6
6
 
7
7
  module CKick
8
8
 
9
+ # C++ compiler flag representation
9
10
  class CXXFlag < CompilerFlag
11
+
12
+ # appends ${CMAKE_CXX_FLAGS} (CMake C++ compiler flags)
10
13
  def cmake
11
- %Q(set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} #{@content}"))
14
+ %Q|set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} #{@content}")|
12
15
  end
13
16
  end
14
17
 
@@ -11,9 +11,16 @@ require "ckick/hashable"
11
11
 
12
12
  module CKick
13
13
 
14
+ # Project dependency settings, such as include path, library path, and compiler flags
14
15
  class Dependencies
15
16
  include Hashable
16
17
 
18
+ # * +args+ - Dependencies hash (directly the CKickfile :dependencies element parsed with keys as Symbol), must be a Hash
19
+ # ====== Input hash keys
20
+ # * +:cflags+ - C language specific flags, for e.g. '-std=c89', '-Wall', etc., must be an Array of String
21
+ # * +:cxxflags+ - C++ language specific flags, for e.g. '-std=c++11', '-fno-exceptions', etc., must be an Array of String
22
+ # * +:include+ - Array of paths to append the include path (-I compiler option; include_directories() CMake command)
23
+ # * +:lib+ - Array of paths to append the link path (-L compiler option; link_directories() CMake command)
17
24
  def initialize args={}
18
25
  raise IllegalInitializationError unless args.is_a?(Hash)
19
26
 
@@ -21,7 +28,7 @@ module CKick
21
28
  raise IllegalInitializationError, "cflags provided to dependencies is not an Array" unless cflags.is_a?(Array)
22
29
  @cflags = cflags.collect do |flag|
23
30
  CFlag.new(flag: flag)
24
- end
31
+ end
25
32
 
26
33
  cxxflags = args[:cxxflags] || []
27
34
  raise IllegalInitializationError, "cxxflags provided to dependencied is not an Array" unless cxxflags.is_a?(Array)
@@ -42,27 +49,36 @@ module CKick
42
49
  end
43
50
  end
44
51
 
52
+ # converts to Hash (usable in CKickfile)
45
53
  def to_hash
46
54
  to_no_empty_value_hash
47
55
  end
48
56
 
57
+ # CMakeLists's section content
49
58
  def cmake
50
59
  [@cflags, @cxxflags, @include, @lib].flatten(1).collect do |unit|
51
60
  unit.cmake
52
61
  end.join("\n")
53
62
  end
54
63
 
64
+ # compiler flags in an Array
55
65
  def flags
56
66
  [@cflags, @cxxflags, @include, @lib].flatten(1).uniq.collect do |flag|
57
67
  flag.raw_flag
58
68
  end
59
69
  end
60
70
 
71
+ # appends include path (-I) with +path+
72
+ #
73
+ # +path+ - include path, must be a CKick::IncludePath
61
74
  def add_include(path)
62
75
  raise BadIncludePathError, "path must be a CKick::IncludePath object" unless path.is_a?(IncludePath)
63
76
  @include << path unless @include.include?(path)
64
77
  end
65
78
 
79
+ # appends link path (-L) with +path+
80
+ #
81
+ # +path+ - link path, must be a CKick::LibraryPath
66
82
  def add_lib(path)
67
83
  raise BadLibraryPathError, "path must be a CKick::LibraryPath object" unless path.is_a?(LibraryPath)
68
84
  @lib << path unless @lib.include?(path)
@@ -6,7 +6,10 @@ require "ckick/target"
6
6
 
7
7
  module CKick
8
8
 
9
+ # represents an executable target (in respect to CMake add_executable() command)
9
10
  class Executable < Target
11
+
12
+ # CMakeLists content of the target
10
13
  def cmake
11
14
  res = []
12
15
 
@@ -2,9 +2,12 @@
2
2
  # License, v. 2.0. If a copy of the MPL was not distributed with this
3
3
  # file, You can obtain one at http://mozilla.org/MPL/2.0/.
4
4
 
5
+ # :nodoc:
5
6
  module CKick
7
+ # CKick::Plugin load path
6
8
  $PLUGIN_PATH = [File.join(File.absolute_path(File.dirname(__FILE__)), "plugin")]
7
9
 
10
+ # finds ruby source files in $PLUGIN_PATH
8
11
  def self.find_builtin_plugins
9
12
  res = []
10
13
  $PLUGIN_PATH.each do |dir|
@@ -16,6 +19,7 @@ module CKick
16
19
  res.flatten(1)
17
20
  end
18
21
 
22
+ # requires all ruby source files in $PLUGIN_PATH
19
23
  def self.load_builtin_plugins
20
24
  find_builtin_plugins.each do |file|
21
25
  require file[0..-4]
@@ -4,7 +4,10 @@
4
4
 
5
5
  require "ckick/array"
6
6
 
7
+ # :nodoc:
7
8
  class Hash
9
+ # transforms keys recursively
10
+ # * +block+ - transform operation
8
11
  def array_aware_deep_transform_keys(&block)
9
12
  result = {}
10
13
  each do |key, value|
@@ -19,14 +22,17 @@ class Hash
19
22
  result
20
23
  end
21
24
 
25
+ # transforms each String-key to Symbol-key
22
26
  def array_aware_deep_symbolize_keys
23
- array_aware_deep_transform_keys{ |key| key.to_sym rescue key }
27
+ array_aware_deep_transform_keys { |key| key.to_sym rescue key }
24
28
  end
25
29
 
30
+ # copy of the hash without pairs of +keys+
26
31
  def without(*keys)
27
32
  dup.without!(*keys)
28
33
  end
29
34
 
35
+ # removes each pair of +keys+
30
36
  def without!(*keys)
31
37
  reject! { |key| keys.include?(key) }
32
38
  end
@@ -2,37 +2,49 @@
2
2
  # License, v. 2.0. If a copy of the MPL was not distributed with this
3
3
  # file, You can obtain one at http://mozilla.org/MPL/2.0/.
4
4
 
5
+ # :nodoc:
5
6
  class String
7
+ #converts to hash-serializable value
6
8
  def to_hash_element
7
9
  self
8
10
  end
9
11
  end
10
12
 
13
+ # :nodoc:
11
14
  class Fixnum
15
+ #converts to hash-serializable value
12
16
  def to_hash_element
13
17
  self
14
18
  end
15
19
  end
16
20
 
21
+ # :nodoc:
17
22
  class Float
23
+ #converts to hash-serializable value
18
24
  def to_hash_element
19
25
  self
20
26
  end
21
27
  end
22
28
 
29
+ # :nodoc:
23
30
  class TrueClass
31
+ #converts to hash-serializable value
24
32
  def to_hash_element
25
33
  self
26
34
  end
27
35
  end
28
36
 
37
+ # :nodoc:
29
38
  class FalseClass
39
+ #converts to hash-serializable value
30
40
  def to_hash_element
31
41
  self
32
42
  end
33
43
  end
34
44
 
45
+ # :nodoc:
35
46
  class Array
47
+ #converts to hash-serializable value
36
48
  def to_hash_element
37
49
  collect do |element|
38
50
  if element.respond_to?(:to_hash)
@@ -44,7 +56,9 @@ class Array
44
56
  end
45
57
  end
46
58
 
59
+ # :nodoc:
47
60
  class NilClass
61
+ #converts to hash-serializable value
48
62
  def to_hash_element
49
63
  self
50
64
  end
@@ -6,7 +6,11 @@ require "ckick/hash"
6
6
  require "ckick/hash_elements"
7
7
 
8
8
  module CKick
9
+
10
+ # mixin enabling hash serialization
9
11
  module Hashable
12
+
13
+ # transforms object to Hash such that { :instance_variable => value }
10
14
  def to_hash
11
15
  a = {}
12
16
  instance_variables_as_key_values.each do |name, obj|
@@ -15,6 +19,7 @@ module CKick
15
19
  a
16
20
  end
17
21
 
22
+ # transforms object to Hash such that { :instance_variable => value }, excluding any pair where value responds +true+ to :empty? method
18
23
  def to_no_empty_value_hash
19
24
  a = {}
20
25
  instance_variables_as_key_values.each do |name, obj|
@@ -6,11 +6,15 @@ require "ckick/path"
6
6
 
7
7
  module CKick
8
8
 
9
+ #Represents a compiler include path (-I option or CMake include_directories() fonction)
9
10
  class IncludePath < Path
11
+
12
+ #compiler flag as is
10
13
  def raw_flag
11
14
  "-I#{@path}"
12
15
  end
13
16
 
17
+ #cmake code content
14
18
  def cmake
15
19
  %Q{include_directories(#{@path})}
16
20
  end
@@ -6,13 +6,19 @@ require "ckick/target"
6
6
 
7
7
  module CKick
8
8
 
9
+ # represents an library target (in respect to CMake add_library() command)
9
10
  class Library < Target
11
+
12
+ # * +args+ - Target hash (directly a CKickfile library target element's hash parsed with keys as Symbol), must be a Hash
13
+ # ====== CKick::Library specific input hash keys (in addition of CKick::Target ones)
14
+ # * +:shared+ - whether or not this library should be a dynamic library (shared object) or a static library (archive)
10
15
  def initialize args={}
11
16
  super args
12
17
 
13
18
  @shared = args[:shared] || false
14
19
  end
15
20
 
21
+ # converts to Hash (for CKickfile)
16
22
  def to_hash
17
23
  if @shared
18
24
  return super
@@ -21,6 +27,7 @@ module CKick
21
27
  end
22
28
  end
23
29
 
30
+ # CMakeLists content of the target
24
31
  def cmake
25
32
  res = []
26
33
 
@@ -2,28 +2,40 @@
2
2
  # License, v. 2.0. If a copy of the MPL was not distributed with this
3
3
  # file, You can obtain one at http://mozilla.org/MPL/2.0/.
4
4
 
5
+ # :nodoc:
5
6
  module CKick
6
7
 
8
+ # Represents a library link
9
+ # (-l compiler option or library name to be passed to CMake target_link_libraries() function)
7
10
  class LibraryLink
8
11
 
12
+ # initializes object with an Hash
13
+ # hash keys:
14
+ # * +:name+ - library name (lib#{name}.a/.so) as is
9
15
  def initialize args={}
10
16
  name = args[:name] || ""
11
17
  raise CKick::IllegalInitializationError, "No name provided to library link" unless name.is_a?(String) && !name.empty?
12
18
  @name = name
13
19
  end
14
20
 
21
+ # converts to hashable element
22
+ # name as is
15
23
  def to_hash_element
16
24
  @name
17
25
  end
18
26
 
27
+ # converts to String
28
+ # name as is
19
29
  def to_s
20
30
  @name
21
31
  end
22
32
 
33
+ # corresponding compiler link flag (-l option)
23
34
  def raw_flag
24
35
  "-l#{@name}"
25
36
  end
26
37
 
38
+ # cmake code content (only library name, not command)
27
39
  def cmake
28
40
  @name
29
41
  end
@@ -6,11 +6,15 @@ require "ckick/path"
6
6
 
7
7
  module CKick
8
8
 
9
+ # Represents a library link path (in respect to compiler -L option and CMake link_directories() fonction)
9
10
  class LibraryPath < Path
11
+
12
+ #compiler flag as is
10
13
  def raw_flag
11
14
  "-L#{@path}"
12
15
  end
13
16
 
17
+ #cmake code content
14
18
  def cmake
15
19
  "link_directories(#{@path})"
16
20
  end
@@ -2,7 +2,9 @@
2
2
  # License, v. 2.0. If a copy of the MPL was not distributed with this
3
3
  # file, You can obtain one at http://mozilla.org/MPL/2.0/.
4
4
 
5
+ # :nodoc:
5
6
  class NilClass
7
+ # does nothing, but prevents no method errors
6
8
  def each &block
7
9
  end
8
10
  end
@@ -2,11 +2,14 @@
2
2
  # License, v. 2.0. If a copy of the MPL was not distributed with this
3
3
  # file, You can obtain one at http://mozilla.org/MPL/2.0/.
4
4
 
5
+ # :nodoc:
5
6
  module CKick
6
7
 
8
+ # Represents a file system path, it must exist
7
9
  class Path
8
10
  attr_reader :path
9
11
 
12
+ #initializes path, path must exist
10
13
  def initialize args={}
11
14
  raise IllegalInitializationError, "needs :path parameter" unless args.is_a?(Hash) && args[:path].is_a?(String)
12
15
  raise NoSuchDirectoryError, "invalid path #{args[:path]}" unless Dir.exist?(args[:path])
@@ -14,10 +17,12 @@ module CKick
14
17
  @path = args[:path]
15
18
  end
16
19
 
20
+ #returns path as is
17
21
  def to_s
18
22
  @path
19
23
  end
20
24
 
25
+ #converts to hash-serializable element
21
26
  def to_hash_element
22
27
  @path
23
28
  end
@@ -2,8 +2,10 @@
2
2
  # License, v. 2.0. If a copy of the MPL was not distributed with this
3
3
  # file, You can obtain one at http://mozilla.org/MPL/2.0/.
4
4
 
5
+ # :nodoc:
5
6
  module CKick
6
7
 
8
+ # Base class for a CKick plugin
7
9
  class Plugin
8
10
  def initialize args
9
11
  end
@@ -4,10 +4,12 @@
4
4
 
5
5
  require "ckick/plugin"
6
6
 
7
+ # Creates a .clang_complete file for clang auto completion
7
8
  class ClangComplete < CKick::Plugin
8
- # Creates a .clang_complete file for clang auto completion
9
9
 
10
+ # assembles project flags and writes a .clang_complete file at project root
10
11
  def call(project)
12
+ # :nodoc:
11
13
  def clang_complete project
12
14
  project.dependencies.flags.join("\n")
13
15
  end
@@ -2,10 +2,13 @@
2
2
  # License, v. 2.0. If a copy of the MPL was not distributed with this
3
3
  # file, You can obtain one at http://mozilla.org/MPL/2.0/.
4
4
 
5
+ # :nodoc:
5
6
  module CKick
6
7
 
8
+ # :nodoc:
7
9
  module PluginDelegate
8
10
 
11
+ # :nodoc:
9
12
  def self.find(plugin)
10
13
  Object.const_get(plugin[:name]).new(plugin[:args] || {})
11
14
  end
@@ -11,13 +11,36 @@ require "ckick/plugin_delegate"
11
11
 
12
12
  module CKick
13
13
 
14
+ # This class represents a CMake project (as a main CMakeLists)
14
15
  class Project
15
16
  include Hashable
16
- attr_reader :subdirs, :dependencies, :root, :build_dir
17
17
 
18
+ # each project CKick::SubDirectory
19
+ attr_reader :subdirs
20
+
21
+ # project CKick::Dependencies
22
+ attr_reader :dependencies
23
+
24
+ # project root directory
25
+ attr_reader :root
26
+
27
+ # project build directory
28
+ attr_reader :build_dir
29
+
30
+ # project name match pattern
18
31
  NAME_MATCH = /^[[A-Z][a-z]_[0-9]]+$/
32
+
33
+ # version match
19
34
  CMAKE_VERSION_MATCH = /^[0-9](\.[0-9]){0,2}$/
20
35
 
36
+ # * +args+ - project hash (directly the CKickfile parsed with keys as Symbol), must be a Hash
37
+ # ====== Input hash keys
38
+ # * +:name+ - project name, must respect NAME_MATCH
39
+ # * +:cmake_min_version+ - CMake minimum version (must be String), defaults to '3', must match CMAKE_VERSION_MATCH
40
+ # * +:root+ - Project root directory, usually '.'
41
+ # * +:build_dir+ - Project build directory, usually 'build'
42
+ # * +:subdirs+ - subdirectories (in respect to CMake subdirectory() command), must be a Array of Hash passed to SubDirectory::new
43
+ # * +:plugins+ - Array of Hash containing {:name => CKick::Plugin class name, :args => args for respective :initialize method }
21
44
  def initialize args
22
45
  name = args[:name] || ""
23
46
  raise IllegalInitializationError, "name must be a non-empty string only containing alphanumeric characters" unless name.is_a?(String) && name.match(NAME_MATCH)
@@ -54,23 +77,28 @@ module CKick
54
77
  init_subdirs
55
78
  end
56
79
 
80
+ # set the project name, must match NAME_MATCH
57
81
  def set_name(name)
58
82
  raise BadProjectNameError, "project name must be a non-empty alphanumeric string" unless name.is_a?(String) && name.match(NAME_MATCH)
59
83
  @name = name
60
84
  end
61
85
 
86
+ # convert to String -> the project name as is
62
87
  def to_s
63
88
  @name
64
89
  end
65
90
 
91
+ # convert to Hash (to CKickfile)
66
92
  def to_hash
67
93
  to_no_empty_value_hash.without(:subdirs_initiated)
68
94
  end
69
95
 
96
+ # project root directory path
70
97
  def path
71
98
  @root
72
99
  end
73
100
 
101
+ # creates the project CMake structure
74
102
  def create_structure
75
103
  raise "SubDirectories have not been initiated" unless @subdirs_initiated
76
104
 
@@ -86,6 +114,7 @@ module CKick
86
114
  call_plugins
87
115
  end
88
116
 
117
+ # register an additionnal CKick::Plugin or block
89
118
  def register_plugin(plugin=nil, &block)
90
119
  raise ArgumentError, "" unless plugin.is_a?(::CKick::Plugin) || block
91
120
 
@@ -96,6 +125,7 @@ module CKick
96
125
  end
97
126
  end
98
127
 
128
+ # main project's CMakeLists.txt content
99
129
  def cmake
100
130
  append_plugin_paths
101
131
 
@@ -119,6 +149,7 @@ module CKick
119
149
 
120
150
  private
121
151
 
152
+ # called at the end of Project::new
122
153
  def init_subdirs
123
154
  @subdirs.each do |subdir|
124
155
  subdir.__send__ :set_parent, path
@@ -127,6 +158,7 @@ module CKick
127
158
  @subdirs_initiated = true
128
159
  end
129
160
 
161
+ # appends include path and library path by each CKick::Plugin#include and CKick::Plugin#lib
130
162
  def append_plugin_paths
131
163
  @plugins.each do |plugin|
132
164
  plugin.include(self).each do |path|
@@ -138,22 +170,25 @@ module CKick
138
170
  end
139
171
  end
140
172
 
173
+ # ran before structure creation (calls each CKick::Plugin#run)
141
174
  def run_plugins
142
175
  @plugins.each do |plugin|
143
176
  plugin.run(self) if plugin.respond_to? :run
144
177
  end
145
178
  end
146
179
 
180
+ # ran after structure creation (calls each CKick::Plugin#call)
147
181
  def call_plugins
148
182
  @plugins.each do |plugin|
149
183
  plugin.call self
150
184
  end
151
185
  end
152
186
 
187
+ # plugins CMakeLists.txt content section in main CMakeLists.txt content
153
188
  def plugins_cmake
154
189
  res = "##ckick plugins section##\n"
155
190
 
156
- def plugin_name(plugin)
191
+ def plugin_name(plugin) #:nodoc:
157
192
  if plugin.respond_to?(:name)
158
193
  return plugin.name
159
194
  else
@@ -11,11 +11,26 @@ require "ckick/path_delegate"
11
11
 
12
12
  module CKick
13
13
 
14
+ # Represents a project sub directory (in respect to CMake sub_directory() command)
14
15
  class SubDirectory
15
16
  include Hashable
16
17
 
17
- attr_reader :name, :parent_dir, :has_cmake
18
+ # directory name
19
+ attr_reader :name
18
20
 
21
+ # parent directory
22
+ attr_reader :parent_dir
23
+
24
+ # whether or not this directory has targets and a CMakeLists.txt
25
+ attr_reader :has_cmake
26
+
27
+ # * +args+ - SubDirectory hash (directly a CKickfile :subdirs Array element parsed with keys as Symbol), must be a Hash
28
+ # ====== Input hash keys
29
+ # * +:name+ - subdirectory name
30
+ # * +:libraries+ - libraries built in this subdirectory (in respect to CMake add_library() command), Array of Hash each containing information for CKick::Library::new
31
+ # * +:executables+ - executables built in this subdirectory (in respect to CMake add_executable() command), Array of Hash each containing information for CKick::Executable::new
32
+ # * +:subdirs+ - recursive subdirectories (in respect to CMake subdirectory() command), must be a Array of Hash passed to CKick::SubDirectory::new
33
+ # * +:has_cmake+ - whether or not this subdirectory has a CMakeLists.txt (consequently builds targets or not)
19
34
  def initialize args={}
20
35
  name = args[:name]
21
36
  raise IllegalInitializationError, "no name provided to sub directory" unless name.is_a?(String) && !name.empty?
@@ -52,10 +67,12 @@ module CKick
52
67
  @parent_dir = nil
53
68
  end
54
69
 
70
+ # converts to String, subdirectory name as is
55
71
  def to_s
56
72
  @name
57
73
  end
58
74
 
75
+ # converts to Hash (to CKickfile :subdirs element)
59
76
  def to_hash
60
77
  if !@has_cmake
61
78
  return to_no_empty_value_hash.without(:parent_dir)
@@ -63,11 +80,15 @@ module CKick
63
80
  to_no_empty_value_hash.without(:parent_dir, :has_cmake)
64
81
  end
65
82
 
83
+ # subdirectory path
66
84
  def path
67
85
  raise NoParentDirError, "sub directory #{@name} has no parent set" unless @parent_dir
68
86
  File.join(@parent_dir, @name)
69
87
  end
70
88
 
89
+ # creates subdirectory structure
90
+ #
91
+ # this method is called recursively on subdirectories
71
92
  def create_structure
72
93
  PathDelegate.create_directory(path)
73
94
 
@@ -84,6 +105,7 @@ module CKick
84
105
  end
85
106
  end
86
107
 
108
+ # subdirectory CMakeLists.txt file content
87
109
  def cmake
88
110
  res = ''
89
111
 
@@ -101,10 +123,14 @@ module CKick
101
123
 
102
124
  private
103
125
 
126
+ # Array of all targets ( CKick::Target ) contained in this subdirectory
104
127
  def targets
105
128
  @executables + @libraries
106
129
  end
107
130
 
131
+ # sets parent directory path
132
+ #
133
+ # this method is called recursively on subdirectories
108
134
  def set_parent(parent_dir)
109
135
  @parent_dir = parent_dir
110
136
 
@@ -9,9 +9,15 @@ require "ckick/hashable"
9
9
 
10
10
  module CKick
11
11
 
12
+ # common representation of targets to build, such as executables and libraries
12
13
  class Target
13
14
  include Hashable
14
15
 
16
+ # * +args+ - Target hash (directly a CKickfile target element's hash parsed with keys as Symbol), must be a Hash
17
+ # ====== Input hash keys
18
+ # * +:name+ - name of the target
19
+ # * +:source+ - either a String (single-source file) or Array of String (multiple source files)
20
+ # * +:libs+ - names of the libraries to link to the target, must be Array of String
15
21
  def initialize args={}
16
22
  raise IllegalInitializationError unless args.is_a?(Hash) && !args.empty?
17
23
 
@@ -46,14 +52,17 @@ module CKick
46
52
  @parent_dir = nil
47
53
  end
48
54
 
55
+ # converts to Hash (for CKickfile)
49
56
  def to_hash
50
57
  to_no_empty_value_hash.without(:parent_dir)
51
58
  end
52
59
 
60
+ # converts to String, the target's name as is
53
61
  def to_s
54
62
  @name
55
63
  end
56
64
 
65
+ # Array of source file paths
57
66
  def paths
58
67
  raise NoParentDirError, "No parent directory has been set for target #{@name}" unless @parent_dir
59
68
  res = []
@@ -63,6 +72,7 @@ module CKick
63
72
  res
64
73
  end
65
74
 
75
+ # creates target's structure (each missing source file)
66
76
  def create_structure
67
77
  paths.each do |path|
68
78
  unless File.exist? path
@@ -73,6 +83,7 @@ module CKick
73
83
 
74
84
  private
75
85
 
86
+ # set's parent directory
76
87
  def set_parent(parent_dir)
77
88
  @parent_dir = parent_dir
78
89
  end
@@ -2,6 +2,8 @@
2
2
  # License, v. 2.0. If a copy of the MPL was not distributed with this
3
3
  # file, You can obtain one at http://mozilla.org/MPL/2.0/.
4
4
 
5
+ # :nodoc:
5
6
  module CKick
6
- VERSION = "0.1.0"
7
+ # gem version
8
+ VERSION = "0.1.1"
7
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ckick
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Gingras
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-10-30 00:00:00.000000000 Z
11
+ date: 2016-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ~>
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rdoc
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 4.2.2
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 4.2.2
55
69
  description: CKick is a simple gem that helps to kick start a C/C++ project using
56
70
  CMake with an arbitrary structure. Using a CKickfile (a simple JSON), ckick is able
57
71
  to generate an whole project structure without having to write any CMakeLists.txt