ckick 0.1.0

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.
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ckick"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ckick/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ckick"
8
+ spec.version = CKick::VERSION
9
+ spec.authors = ["Jonathan Gingras"]
10
+ spec.email = ["jonathan.gingras.1@gmail.com"]
11
+ spec.license = "MPL-2.0"
12
+
13
+ spec.summary = %q{Kick start a C/C++ CMake project structure from a single JSON file}
14
+ spec.description = %q{CKick is a simple gem that helps to kick start a C/C++ project using CMake with an arbitrary structure. Using a CKickfile (a simple JSON), ckick is able to generate an whole project structure without having to write any CMakeLists.txt by your own.}
15
+ spec.homepage = "https://github.com/jonathangingras/ckick"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.13"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.0"
27
+ end
@@ -0,0 +1,54 @@
1
+ # This Source Code Form is subject to the terms of the Mozilla Public
2
+ # License, v. 2.0. If a copy of the MPL was not distributed with this
3
+ # file, You can obtain one at http://mozilla.org/MPL/2.0/.
4
+
5
+ require "ckick/version"
6
+ require "ckick/project"
7
+ require "ckick/find_plugin"
8
+ require "ckick/ckickfile"
9
+
10
+ module CKick
11
+ RESOURCE_DIR = File.join(File.dirname(File.dirname(__FILE__)), "resource")
12
+
13
+ class Error < ::Exception
14
+ end
15
+
16
+ class BadFlagError < Error
17
+ end
18
+
19
+ class NoSuchDirectoryError < Error
20
+ end
21
+
22
+ class IllegalInitializationError < Error
23
+ end
24
+
25
+ class NoNameError < Error
26
+ end
27
+
28
+ class NoSourceError < Error
29
+ end
30
+
31
+ class BadProjectNameError < Error
32
+ end
33
+
34
+ class BadSourceError < Error
35
+ end
36
+
37
+ class BadLibError < Error
38
+ end
39
+
40
+ class BadIncludePathError < Error
41
+ end
42
+
43
+ class BadLibraryPathError < Error
44
+ end
45
+
46
+ class BadSubDirectoryError < Error
47
+ end
48
+
49
+ class NoParentDirError < Error
50
+ end
51
+
52
+ class BadFileContentError < Error
53
+ end
54
+ end
@@ -0,0 +1,19 @@
1
+ # This Source Code Form is subject to the terms of the Mozilla Public
2
+ # License, v. 2.0. If a copy of the MPL was not distributed with this
3
+ # file, You can obtain one at http://mozilla.org/MPL/2.0/.
4
+
5
+ require "ckick/hash"
6
+
7
+ class Array
8
+ def array_aware_deep_transform_keys(&block)
9
+ result = []
10
+ each do |value|
11
+ if value.is_a?(Hash) || value.is_a?(Array)
12
+ result << value.array_aware_deep_transform_keys(&block)
13
+ else
14
+ result << value
15
+ end
16
+ end
17
+ result
18
+ end
19
+ end
@@ -0,0 +1,15 @@
1
+ # This Source Code Form is subject to the terms of the Mozilla Public
2
+ # License, v. 2.0. If a copy of the MPL was not distributed with this
3
+ # file, You can obtain one at http://mozilla.org/MPL/2.0/.
4
+
5
+ require "ckick/compiler_flag"
6
+
7
+ module CKick
8
+
9
+ class CFlag < CompilerFlag
10
+ def cmake
11
+ %Q(set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} #{@content}"))
12
+ end
13
+ end
14
+
15
+ end
@@ -0,0 +1,11 @@
1
+ # This Source Code Form is subject to the terms of the Mozilla Public
2
+ # License, v. 2.0. If a copy of the MPL was not distributed with this
3
+ # file, You can obtain one at http://mozilla.org/MPL/2.0/.
4
+
5
+ require "json"
6
+
7
+ module CKick
8
+ def self.load_ckickfile(dir=Dir.pwd, filename="CKickfile")
9
+ JSON.parse(File.read(File.join(dir, filename)), symbolize_names: true)
10
+ end
11
+ end
@@ -0,0 +1,39 @@
1
+ # This Source Code Form is subject to the terms of the Mozilla Public
2
+ # License, v. 2.0. If a copy of the MPL was not distributed with this
3
+ # file, You can obtain one at http://mozilla.org/MPL/2.0/.
4
+
5
+ module CKick
6
+
7
+ class CompilerFlag
8
+ attr_reader :content
9
+
10
+ def initialize args={}
11
+ raise IllegalInitializationError, "No flag provided to compiler flag" unless args.is_a?(Hash) && !args.empty?
12
+ flag = args[:flag] || nil
13
+ raise BadFlagError, "Bad flag content provided to compiler flag" unless flag.is_a?(String) && !flag.empty?
14
+
15
+ @content = args[:flag]
16
+ end
17
+
18
+ def to_s
19
+ @content
20
+ end
21
+
22
+ def to_hash_element
23
+ @content
24
+ end
25
+
26
+ def raw_flag
27
+ @content
28
+ end
29
+
30
+ def eql? other
31
+ @content.eql? other.content
32
+ end
33
+
34
+ def hash
35
+ @content.hash
36
+ end
37
+ end
38
+
39
+ end
@@ -0,0 +1,15 @@
1
+ # This Source Code Form is subject to the terms of the Mozilla Public
2
+ # License, v. 2.0. If a copy of the MPL was not distributed with this
3
+ # file, You can obtain one at http://mozilla.org/MPL/2.0/.
4
+
5
+ require "ckick/compiler_flag"
6
+
7
+ module CKick
8
+
9
+ class CXXFlag < CompilerFlag
10
+ def cmake
11
+ %Q(set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} #{@content}"))
12
+ end
13
+ end
14
+
15
+ end
@@ -0,0 +1,72 @@
1
+ # This Source Code Form is subject to the terms of the Mozilla Public
2
+ # License, v. 2.0. If a copy of the MPL was not distributed with this
3
+ # file, You can obtain one at http://mozilla.org/MPL/2.0/.
4
+
5
+ require "ckick/nil_class"
6
+ require "ckick/cflag"
7
+ require "ckick/cxxflag"
8
+ require "ckick/include_path"
9
+ require "ckick/library_path"
10
+ require "ckick/hashable"
11
+
12
+ module CKick
13
+
14
+ class Dependencies
15
+ include Hashable
16
+
17
+ def initialize args={}
18
+ raise IllegalInitializationError unless args.is_a?(Hash)
19
+
20
+ cflags = args[:cflags] || []
21
+ raise IllegalInitializationError, "cflags provided to dependencies is not an Array" unless cflags.is_a?(Array)
22
+ @cflags = cflags.collect do |flag|
23
+ CFlag.new(flag: flag)
24
+ end
25
+
26
+ cxxflags = args[:cxxflags] || []
27
+ raise IllegalInitializationError, "cxxflags provided to dependencied is not an Array" unless cxxflags.is_a?(Array)
28
+ @cxxflags = cxxflags.collect do |flag|
29
+ CXXFlag.new(flag: flag)
30
+ end
31
+
32
+ includes = args[:include] || []
33
+ raise IllegalInitializationError, "include provided to dependencies is not an Array" unless includes.is_a?(Array)
34
+ @include = includes.collect do |include|
35
+ IncludePath.new(path: include)
36
+ end
37
+
38
+ libs = args[:lib] || []
39
+ raise IllegalInitializationError, "lib provided to dependencies is not an Array" unless libs.is_a?(Array)
40
+ @lib = libs.collect do |lib|
41
+ LibraryPath.new(path: lib)
42
+ end
43
+ end
44
+
45
+ def to_hash
46
+ to_no_empty_value_hash
47
+ end
48
+
49
+ def cmake
50
+ [@cflags, @cxxflags, @include, @lib].flatten(1).collect do |unit|
51
+ unit.cmake
52
+ end.join("\n")
53
+ end
54
+
55
+ def flags
56
+ [@cflags, @cxxflags, @include, @lib].flatten(1).uniq.collect do |flag|
57
+ flag.raw_flag
58
+ end
59
+ end
60
+
61
+ def add_include(path)
62
+ raise BadIncludePathError, "path must be a CKick::IncludePath object" unless path.is_a?(IncludePath)
63
+ @include << path unless @include.include?(path)
64
+ end
65
+
66
+ def add_lib(path)
67
+ raise BadLibraryPathError, "path must be a CKick::LibraryPath object" unless path.is_a?(LibraryPath)
68
+ @lib << path unless @lib.include?(path)
69
+ end
70
+ end
71
+
72
+ end
@@ -0,0 +1,23 @@
1
+ # This Source Code Form is subject to the terms of the Mozilla Public
2
+ # License, v. 2.0. If a copy of the MPL was not distributed with this
3
+ # file, You can obtain one at http://mozilla.org/MPL/2.0/.
4
+
5
+ require "ckick/target"
6
+
7
+ module CKick
8
+
9
+ class Executable < Target
10
+ def cmake
11
+ res = []
12
+
13
+ res << "add_executable(#{@name} #{@source.join(' ')})"
14
+
15
+ unless @libs.empty?
16
+ res << "target_link_libraries(#{@name} #{@libs.join(' ')})"
17
+ end
18
+
19
+ res.join("\n")
20
+ end
21
+ end
22
+
23
+ end
@@ -0,0 +1,25 @@
1
+ # This Source Code Form is subject to the terms of the Mozilla Public
2
+ # License, v. 2.0. If a copy of the MPL was not distributed with this
3
+ # file, You can obtain one at http://mozilla.org/MPL/2.0/.
4
+
5
+ module CKick
6
+ $PLUGIN_PATH = [File.join(File.absolute_path(File.dirname(__FILE__)), "plugin")]
7
+
8
+ def self.find_builtin_plugins
9
+ res = []
10
+ $PLUGIN_PATH.each do |dir|
11
+ files = Dir.entries(dir).select { |entry| entry.length > 3 && entry[-3..-1] == '.rb'}
12
+ files.each do |file|
13
+ res << File.join(dir, file)
14
+ end
15
+ end
16
+ res.flatten(1)
17
+ end
18
+
19
+ def self.load_builtin_plugins
20
+ find_builtin_plugins.each do |file|
21
+ require file[0..-4]
22
+ end
23
+ end
24
+
25
+ end
@@ -0,0 +1,33 @@
1
+ # This Source Code Form is subject to the terms of the Mozilla Public
2
+ # License, v. 2.0. If a copy of the MPL was not distributed with this
3
+ # file, You can obtain one at http://mozilla.org/MPL/2.0/.
4
+
5
+ require "ckick/array"
6
+
7
+ class Hash
8
+ def array_aware_deep_transform_keys(&block)
9
+ result = {}
10
+ each do |key, value|
11
+ new_key = yield(key)
12
+
13
+ if value.is_a?(Hash) || value.is_a?(Array)
14
+ result[new_key] = value.array_aware_deep_transform_keys(&block)
15
+ else
16
+ result[new_key] = value
17
+ end
18
+ end
19
+ result
20
+ end
21
+
22
+ def array_aware_deep_symbolize_keys
23
+ array_aware_deep_transform_keys{ |key| key.to_sym rescue key }
24
+ end
25
+
26
+ def without(*keys)
27
+ dup.without!(*keys)
28
+ end
29
+
30
+ def without!(*keys)
31
+ reject! { |key| keys.include?(key) }
32
+ end
33
+ end
@@ -0,0 +1,51 @@
1
+ # This Source Code Form is subject to the terms of the Mozilla Public
2
+ # License, v. 2.0. If a copy of the MPL was not distributed with this
3
+ # file, You can obtain one at http://mozilla.org/MPL/2.0/.
4
+
5
+ class String
6
+ def to_hash_element
7
+ self
8
+ end
9
+ end
10
+
11
+ class Fixnum
12
+ def to_hash_element
13
+ self
14
+ end
15
+ end
16
+
17
+ class Float
18
+ def to_hash_element
19
+ self
20
+ end
21
+ end
22
+
23
+ class TrueClass
24
+ def to_hash_element
25
+ self
26
+ end
27
+ end
28
+
29
+ class FalseClass
30
+ def to_hash_element
31
+ self
32
+ end
33
+ end
34
+
35
+ class Array
36
+ def to_hash_element
37
+ collect do |element|
38
+ if element.respond_to?(:to_hash)
39
+ element.to_hash
40
+ else
41
+ element.to_hash_element
42
+ end
43
+ end
44
+ end
45
+ end
46
+
47
+ class NilClass
48
+ def to_hash_element
49
+ self
50
+ end
51
+ end
@@ -0,0 +1,44 @@
1
+ # This Source Code Form is subject to the terms of the Mozilla Public
2
+ # License, v. 2.0. If a copy of the MPL was not distributed with this
3
+ # file, You can obtain one at http://mozilla.org/MPL/2.0/.
4
+
5
+ require "ckick/hash"
6
+ require "ckick/hash_elements"
7
+
8
+ module CKick
9
+ module Hashable
10
+ def to_hash
11
+ a = {}
12
+ instance_variables_as_key_values.each do |name, obj|
13
+ a[name] = object_value(obj)
14
+ end
15
+ a
16
+ end
17
+
18
+ def to_no_empty_value_hash
19
+ a = {}
20
+ instance_variables_as_key_values.each do |name, obj|
21
+ if !obj.respond_to?(:empty?) || (obj.respond_to?(:empty?) && !obj.empty?)
22
+ a[name] = object_value(obj)
23
+ end
24
+ end
25
+ a
26
+ end
27
+
28
+ private
29
+
30
+ def instance_variables_as_key_values
31
+ instance_variables.collect do |att|
32
+ [att[1..-1].to_sym, instance_variable_get(att.to_sym)]
33
+ end
34
+ end
35
+
36
+ def object_value(obj)
37
+ if obj.respond_to?(:to_hash)
38
+ return obj.to_hash
39
+ else
40
+ return obj.to_hash_element
41
+ end
42
+ end
43
+ end
44
+ end