magica 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/magica/all.rb +2 -0
- data/lib/magica/application.rb +11 -2
- data/lib/magica/build.rb +62 -14
- data/lib/magica/command.rb +1 -1
- data/lib/magica/commands/compiler.rb +1 -0
- data/lib/magica/commands/git.rb +45 -0
- data/lib/magica/commands/linker.rb +1 -0
- data/lib/magica/dependency.rb +128 -0
- data/lib/magica/toolchains/gcc.rake +14 -2
- data/lib/magica/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 75b6c620691aaf5e3ae2ed6322042efdbac359d8
|
4
|
+
data.tar.gz: 3f3b4950ec4ace3c13794d018337f7a1d26df8c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 41ccaa64898ac96fd5fb769afe53187db32afa579aaedd572fd243d13dd379f49f6ca82d5115af15313a485433ddf463a37752a6a20f21c3f273167fab5512a1
|
7
|
+
data.tar.gz: 9b3a47b548bb0ba211fa7851837954fba5cf95856d5aee8f82cd7b4a30bed136a48171022447f17c2fb14648b60d6f47f82969f1edaa3302b6a9b0714ee96195
|
data/lib/magica/all.rb
CHANGED
@@ -6,10 +6,12 @@ require "magica/extension"
|
|
6
6
|
require "magica/i18n"
|
7
7
|
require "magica/dsl"
|
8
8
|
require "magica/toolchain"
|
9
|
+
require "magica/dependency"
|
9
10
|
require "magica/application"
|
10
11
|
|
11
12
|
require "magica/command"
|
12
13
|
require "magica/commands/compiler"
|
13
14
|
require "magica/commands/linker"
|
15
|
+
require "magica/commands/git"
|
14
16
|
|
15
17
|
require "magica/magica"
|
data/lib/magica/application.rb
CHANGED
@@ -44,7 +44,7 @@ module Magica
|
|
44
44
|
switch =~ /--#{Regexp.union(not_applicable_to_capistrano)}/
|
45
45
|
end
|
46
46
|
|
47
|
-
super.push(version, clean)
|
47
|
+
super.push(version, clean, clean_all)
|
48
48
|
end
|
49
49
|
|
50
50
|
def top_level_tasks
|
@@ -80,11 +80,20 @@ module Magica
|
|
80
80
|
end
|
81
81
|
|
82
82
|
def clean
|
83
|
-
["--clean",
|
83
|
+
["--clean", "-c",
|
84
84
|
"Clean all files before build",
|
85
85
|
lambda do |_value|
|
86
86
|
options.clean = true
|
87
87
|
end]
|
88
88
|
end
|
89
|
+
|
90
|
+
def clean_all
|
91
|
+
["--clean-all", '-C',
|
92
|
+
"Clean all files before build include dependency",
|
93
|
+
lambda do |_value|
|
94
|
+
options.clean = true
|
95
|
+
options.clean_all = true
|
96
|
+
end]
|
97
|
+
end
|
89
98
|
end
|
90
99
|
end
|
data/lib/magica/build.rb
CHANGED
@@ -12,11 +12,14 @@ module Magica
|
|
12
12
|
|
13
13
|
include Rake::DSL
|
14
14
|
|
15
|
-
COMPILERS = %w(cxx)
|
16
|
-
COMMANDS = COMPILERS + %w(linker)
|
15
|
+
COMPILERS = %w(cc cxx)
|
16
|
+
COMMANDS = COMPILERS + %w(linker git)
|
17
17
|
|
18
|
+
attr_reader :options
|
18
19
|
attr_block COMMANDS
|
19
20
|
|
21
|
+
Exts = Struct.new(:object, :executable, :library)
|
22
|
+
|
20
23
|
def initialize(name = 'host', options = {dest: 'build'}, &block)
|
21
24
|
@name = name.to_s
|
22
25
|
@dest = (options[:dest] || 'build').to_s
|
@@ -26,15 +29,25 @@ module Magica
|
|
26
29
|
@exe_name = @name
|
27
30
|
@exe_path = "bin"
|
28
31
|
|
32
|
+
@exts = Exts.new('.o', '', '.a')
|
33
|
+
|
34
|
+
@cc = Command::Compiler.new(self, %w(.c))
|
29
35
|
@cxx = Command::Compiler.new(self, %w(.cpp))
|
30
36
|
@linker = Command::Linker.new(self)
|
31
37
|
|
38
|
+
@compiler = @cc
|
39
|
+
|
40
|
+
@git = Command::Git.new(self)
|
41
|
+
|
32
42
|
@defines = %w()
|
33
43
|
@include_paths = %w()
|
34
44
|
@libaries = %w()
|
35
45
|
@libary_paths = %w()
|
36
46
|
@flags = %w()
|
37
47
|
|
48
|
+
@dependencies = []
|
49
|
+
@static_libraries = []
|
50
|
+
|
38
51
|
Magica.targets[@name] = self
|
39
52
|
Magica.targets[@name].instance_eval(&block) unless block.nil?
|
40
53
|
Magica.targets[@name].instance_exec(@options, &Magica.default_compile_task)
|
@@ -43,15 +56,30 @@ module Magica
|
|
43
56
|
end
|
44
57
|
|
45
58
|
def define(name)
|
46
|
-
|
59
|
+
if name.is_a?(Array)
|
60
|
+
name.flatten.map { |n| define(n) }
|
61
|
+
else
|
62
|
+
@defines<< name.to_s.upcase
|
63
|
+
end
|
64
|
+
@defines
|
47
65
|
end
|
48
66
|
|
49
67
|
def include_path(path)
|
50
|
-
|
68
|
+
if path.is_a?(Array)
|
69
|
+
path.flatten.map { |p| include_path(p) }
|
70
|
+
else
|
71
|
+
@include_paths << path.to_s
|
72
|
+
end
|
73
|
+
@include_paths
|
51
74
|
end
|
52
75
|
|
53
76
|
def flag(flag)
|
54
|
-
|
77
|
+
if flag.is_a?(Array)
|
78
|
+
flag.flatten.map { |f| flag(f) }
|
79
|
+
else
|
80
|
+
@flags << flag.to_s
|
81
|
+
end
|
82
|
+
@flags
|
55
83
|
end
|
56
84
|
|
57
85
|
def library(name, path)
|
@@ -63,9 +91,10 @@ module Magica
|
|
63
91
|
config = PackageConfig[name]
|
64
92
|
@libaries.push(*config.libaries)
|
65
93
|
@libary_paths.push(*config.libary_paths)
|
66
|
-
|
67
|
-
|
68
|
-
|
94
|
+
|
95
|
+
include_path(config.include_paths)
|
96
|
+
define(config.defines)
|
97
|
+
flag(config.flags)
|
69
98
|
end
|
70
99
|
|
71
100
|
def source(path)
|
@@ -76,6 +105,21 @@ module Magica
|
|
76
105
|
@dest = path.to_s
|
77
106
|
end
|
78
107
|
|
108
|
+
def dependency(name, options = {}, &block)
|
109
|
+
Dependency.new(name, options, &block)
|
110
|
+
desc "The targets #{@name}'s dependency project : #{name}"
|
111
|
+
task "#{@name}:dependency:#{name}" do |t|
|
112
|
+
Dependency[name].build(self)
|
113
|
+
end
|
114
|
+
@dependencies << "#{@name}:dependency:#{name}"
|
115
|
+
@static_libraries.push(*Dependency[name].static_libraries)
|
116
|
+
end
|
117
|
+
|
118
|
+
def use(compiler)
|
119
|
+
return @compiler = self.send(compiler.to_s) if COMPILERS.include?(compiler.to_s)
|
120
|
+
@compiler = @cc
|
121
|
+
end
|
122
|
+
|
79
123
|
def filename(name)
|
80
124
|
'"%s"' % name
|
81
125
|
end
|
@@ -89,11 +133,11 @@ module Magica
|
|
89
133
|
end
|
90
134
|
|
91
135
|
def exefile(name = nil)
|
92
|
-
return exefile(@exe_name) if name.nil?
|
136
|
+
return exefile("#{@exe_name}#{@exts.executable}") if name.nil?
|
93
137
|
if name.is_a?(Array)
|
94
138
|
name.flatten.map { |n| exefile(n) }
|
95
139
|
else
|
96
|
-
File.join(*[Magica.root, @exe_path, "#{name}"].flatten.reject(&:empty?))
|
140
|
+
File.join(*[Magica.root, @exe_path, "#{name}#{@exts.executable}"].flatten.reject(&:empty?))
|
97
141
|
end
|
98
142
|
end
|
99
143
|
|
@@ -104,7 +148,7 @@ module Magica
|
|
104
148
|
if name.is_a?(Array)
|
105
149
|
name.flatten.map { |n| objfile(n) }
|
106
150
|
else
|
107
|
-
File.join(*[Magica.root, @dest, "#{name}.
|
151
|
+
File.join(*[Magica.root, @dest, "#{name}#{@exts.object}"].flatten.reject(&:empty?))
|
108
152
|
end
|
109
153
|
end
|
110
154
|
|
@@ -123,6 +167,10 @@ module Magica
|
|
123
167
|
clear_exe
|
124
168
|
end
|
125
169
|
|
170
|
+
def add(source)
|
171
|
+
FileUtils.cp(source, File.join(*[Magica.root, @dest].flatten.reject(&:empty?)))
|
172
|
+
end
|
173
|
+
|
126
174
|
def toolchain(name, params = {})
|
127
175
|
toolchain = Toolchain.toolchains[name]
|
128
176
|
fail I18n.t("magica.unknow_toolchain", toolchain: name) unless toolchain
|
@@ -132,15 +180,15 @@ module Magica
|
|
132
180
|
def compile(source)
|
133
181
|
file objfile(source) => source do |t|
|
134
182
|
Build.current = Magica.targets[@name]
|
135
|
-
@
|
183
|
+
@compiler.run t.name, t.prerequisites.first, @defines, @include_paths, @flags
|
136
184
|
end
|
137
185
|
end
|
138
186
|
|
139
187
|
def link(exec, objects)
|
140
188
|
desc "Build target #{@name}'s executable file"
|
141
|
-
task "build:#{@name}" => objects
|
189
|
+
task "build:#{@name}" => @dependencies + objects do
|
142
190
|
Build.current = Magica.targets[@name]
|
143
|
-
@linker.run "#{exec}", objects, @libaries, @libary_paths, @flags
|
191
|
+
@linker.run "#{exec}", objects + @static_libraries, @libaries, @libary_paths, @flags
|
144
192
|
end
|
145
193
|
end
|
146
194
|
|
data/lib/magica/command.rb
CHANGED
@@ -24,6 +24,7 @@ module Magica
|
|
24
24
|
|
25
25
|
def run(outfile, infile, _defines = [], _include_paths = [], _flags = [])
|
26
26
|
FileUtils.mkdir_p File.dirname(outfile)
|
27
|
+
puts "COMPILE\t#{outfile}"
|
27
28
|
_run @compile_options, { outfile: outfile, infile: infile, flags: combine_flags(_defines, _include_paths, _flags) }
|
28
29
|
end
|
29
30
|
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Magica
|
2
|
+
class Command::Git < Command
|
3
|
+
attr_accessor :flags
|
4
|
+
attr_accessor :clone_options, :pull_options, :checkout_options
|
5
|
+
|
6
|
+
def initialize(build)
|
7
|
+
super
|
8
|
+
|
9
|
+
@command = "git"
|
10
|
+
@flags = %w[]
|
11
|
+
@clone_options = "clone %{flags} %{url} %{dir}"
|
12
|
+
@pull_options = "pull %{flags} %{remote} %{branch}"
|
13
|
+
@checkout_options = "checkout %{flags} %{checksum_hash}"
|
14
|
+
end
|
15
|
+
|
16
|
+
def clone(dir, url, _flags = [])
|
17
|
+
_run @clone_options % {
|
18
|
+
flags: [@flags, _flags].flatten.join(" "),
|
19
|
+
dir: filename(dir),
|
20
|
+
url: url
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
def pull(dir, remote = 'origin', branch = 'master')
|
25
|
+
workin dir do
|
26
|
+
_run @pull_options % {remote: remote, branch: branch, flags: @flags.join(" ")}
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def checkout(dir, checksum_hash)
|
31
|
+
workin dir do
|
32
|
+
_run @checkout_options % {checksum_hash: checksum_hash, flags: @flags.join(" ")}
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
def workin(dir)
|
38
|
+
root = Dir.pwd
|
39
|
+
Dir.chdir dir
|
40
|
+
yield if block_given?
|
41
|
+
Dir.chdir root
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,128 @@
|
|
1
|
+
module Magica
|
2
|
+
class Dependency
|
3
|
+
class << self
|
4
|
+
def [](name)
|
5
|
+
@dependencies ||= {}
|
6
|
+
@dependencies[name.to_s]
|
7
|
+
end
|
8
|
+
|
9
|
+
def []=(name, value)
|
10
|
+
@dependencies ||= {}
|
11
|
+
@dependencies[name.to_s] = value
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
include Rake::DSL
|
16
|
+
|
17
|
+
def initialize(name, options = {}, &block)
|
18
|
+
|
19
|
+
@name = name.to_s
|
20
|
+
@vcs = nil
|
21
|
+
@command = :git
|
22
|
+
@source = ""
|
23
|
+
@version = nil
|
24
|
+
@dir = "lib/#{@name}"
|
25
|
+
@install_dir = "#{@dir}/build"
|
26
|
+
@build_command = "make"
|
27
|
+
@environments = {}
|
28
|
+
|
29
|
+
@static_libraries = []
|
30
|
+
|
31
|
+
Dependency[name] = self
|
32
|
+
Dependency[name].instance_eval(&block)
|
33
|
+
end
|
34
|
+
|
35
|
+
def use(name)
|
36
|
+
@vcs = name.to_sym
|
37
|
+
end
|
38
|
+
|
39
|
+
def env(name, value)
|
40
|
+
@environments[name.to_s] = value
|
41
|
+
end
|
42
|
+
|
43
|
+
def source(_source)
|
44
|
+
@source = _source.to_s
|
45
|
+
end
|
46
|
+
|
47
|
+
def dir(_dir)
|
48
|
+
@dir = _dir.to_s
|
49
|
+
end
|
50
|
+
|
51
|
+
def install_dir(_dir)
|
52
|
+
@install_dir = _dir.to_s
|
53
|
+
end
|
54
|
+
|
55
|
+
def version(_version)
|
56
|
+
@version = _version.to_s
|
57
|
+
end
|
58
|
+
|
59
|
+
def command(_command)
|
60
|
+
@build_command = _command.to_s
|
61
|
+
end
|
62
|
+
|
63
|
+
def static_library(*name)
|
64
|
+
@static_libraries.push(*name.flatten)
|
65
|
+
end
|
66
|
+
|
67
|
+
def build(builder)
|
68
|
+
root = Dir.pwd
|
69
|
+
|
70
|
+
options = builder.send(:options)
|
71
|
+
clean if options[:clean_all]
|
72
|
+
|
73
|
+
return if !options[:clean_all] & File.exists?(@install_dir)
|
74
|
+
|
75
|
+
setup_environment
|
76
|
+
|
77
|
+
@vcs = builder.send(@command)
|
78
|
+
@vcs.flags = %w(--quiet)
|
79
|
+
clone
|
80
|
+
|
81
|
+
Dir.chdir source_dir
|
82
|
+
sh @build_command, verbose: false
|
83
|
+
Dir.chdir root
|
84
|
+
end
|
85
|
+
|
86
|
+
def static_libraries
|
87
|
+
@static_libraries.map do |library|
|
88
|
+
File.join(*[Magica.root, @install_dir, library].flatten.reject(&:empty?))
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
private
|
93
|
+
def clone
|
94
|
+
if Dir.exists?(source_dir)
|
95
|
+
puts "UPDATE DEPENDENCY\t#{@name}-#{@version}"
|
96
|
+
checkout if @version
|
97
|
+
pull
|
98
|
+
else
|
99
|
+
puts "DOWNLOAD DEPENDENCY\t#{@name}-#{@version}"
|
100
|
+
@vcs.clone(source_dir, @source)
|
101
|
+
checkout if @version
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def checkout
|
106
|
+
@vcs.checkout(source_dir, @version)
|
107
|
+
end
|
108
|
+
|
109
|
+
def pull
|
110
|
+
@vcs.pull(source_dir, 'origin', @version)
|
111
|
+
end
|
112
|
+
|
113
|
+
def source_dir
|
114
|
+
File.join(Magica.root, @dir)
|
115
|
+
end
|
116
|
+
|
117
|
+
def setup_environment
|
118
|
+
@environments.each do |name, value|
|
119
|
+
ENV[name] = value
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def clean
|
124
|
+
FileUtils.rm_r(@install_dir, force: true)
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
128
|
+
end
|
@@ -1,4 +1,16 @@
|
|
1
1
|
Magica::Toolchain.new :gcc do |config, params|
|
2
|
-
config.
|
3
|
-
|
2
|
+
config.cc do |cc|
|
3
|
+
cc.command = ENV['CC'] || "gcc"
|
4
|
+
cc.flags = [ENV['CFLAGS'] || %w(-g -std=gnu99 -O3 -Wall -Werror-implicit-function-declaration -Wdeclaration-after-statement -Wwrite-strings)]
|
5
|
+
end
|
6
|
+
|
7
|
+
config.cxx do |cxx|
|
8
|
+
cxx.command = [ENV['CXX'] || "g++"]
|
9
|
+
cxx.flags = [ENV['CXXFLAGS'] || %w(-g -O3 -Wall -Werror-implicit-function-declaration)]
|
10
|
+
end
|
11
|
+
|
12
|
+
config.linker do |linker|
|
13
|
+
linker.command = ENV['LD'] || "gcc"
|
14
|
+
linker.flags = [ENV['LDFLAGS'] || %w()]
|
15
|
+
end
|
4
16
|
end
|
data/lib/magica/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: magica
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- 蒼時弦也
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-09-
|
11
|
+
date: 2016-09-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -88,7 +88,9 @@ files:
|
|
88
88
|
- lib/magica/build.rb
|
89
89
|
- lib/magica/command.rb
|
90
90
|
- lib/magica/commands/compiler.rb
|
91
|
+
- lib/magica/commands/git.rb
|
91
92
|
- lib/magica/commands/linker.rb
|
93
|
+
- lib/magica/dependency.rb
|
92
94
|
- lib/magica/dsl.rb
|
93
95
|
- lib/magica/extension.rb
|
94
96
|
- lib/magica/framework.rb
|