magica 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.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/README.md +36 -0
- data/Rakefile +6 -0
- data/bin/magica +3 -0
- data/lib/Magicafile +3 -0
- data/lib/magica.rb +5 -0
- data/lib/magica/all.rb +14 -0
- data/lib/magica/application.rb +48 -0
- data/lib/magica/build.rb +6 -0
- data/lib/magica/builder.rb +67 -0
- data/lib/magica/command.rb +21 -0
- data/lib/magica/commands/compiler.rb +19 -0
- data/lib/magica/commands/linker.rb +17 -0
- data/lib/magica/dsl.rb +23 -0
- data/lib/magica/extension.rb +9 -0
- data/lib/magica/framework.rb +2 -0
- data/lib/magica/i18n.rb +13 -0
- data/lib/magica/initialize.rb +1 -0
- data/lib/magica/magica.rb +27 -0
- data/lib/magica/tasks/build.rake +0 -0
- data/lib/magica/tasks/framework.rake +11 -0
- data/lib/magica/tasks/initialize.rake +9 -0
- data/lib/magica/templates/Magicafile +15 -0
- data/lib/magica/toolchain.rb +29 -0
- data/lib/magica/toolchains/gcc.rake +4 -0
- data/lib/magica/version.rb +3 -0
- data/magica.gemspec +34 -0
- metadata +130 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1259e052adafafdb1d4552c0352b3bf67553d66f
|
4
|
+
data.tar.gz: 916a17a280d294aeb52b2f0d1837d661b371bcad
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 90796306ad23fc5f3afb39479056bc869a282a6fac40f10fd505ee681aec4e4b7855628a1898e4555ce9a6cbb6e27cd0ac1195dcb874e9ec2fa4ea3f7ce66428
|
7
|
+
data.tar.gz: 554feb338c2ed4bb1c6211c594dddb46f3529c776a670841935739e3567b726a7e403b2fc570a367461268f312c6ad0958906fd21183f5ec32f28a5198e8ce43
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# Magica
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/magica`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'magica'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install magica
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/magica.
|
36
|
+
|
data/Rakefile
ADDED
data/bin/magica
ADDED
data/lib/Magicafile
ADDED
data/lib/magica.rb
ADDED
data/lib/magica/all.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require "rake"
|
2
|
+
|
3
|
+
require "magica/extension"
|
4
|
+
require "magica/i18n"
|
5
|
+
require "magica/dsl"
|
6
|
+
require "magica/toolchain"
|
7
|
+
require "magica/builder"
|
8
|
+
require "magica/application"
|
9
|
+
|
10
|
+
require "magica/command"
|
11
|
+
require "magica/commands/compiler"
|
12
|
+
require "magica/commands/linker"
|
13
|
+
|
14
|
+
require "magica/magica"
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Magica
|
2
|
+
class Application < Rake::Application
|
3
|
+
|
4
|
+
DEFAULT_MAGICAFILES = [
|
5
|
+
"magicafile",
|
6
|
+
"Magicafile",
|
7
|
+
"magicafile.rb",
|
8
|
+
"Magicafile.rb"
|
9
|
+
].freeze
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
super
|
13
|
+
@rakefiles = DEFAULT_MAGICAFILES.dup << magicafile
|
14
|
+
end
|
15
|
+
|
16
|
+
def name
|
17
|
+
"magica"
|
18
|
+
end
|
19
|
+
|
20
|
+
def run
|
21
|
+
Rake.application = self
|
22
|
+
super
|
23
|
+
end
|
24
|
+
|
25
|
+
def top_level_tasks
|
26
|
+
unless File.exists?("Magicafile")
|
27
|
+
@top_level_tasks.unshift(warning_not_init.to_s) unless default_tasks.include?(@top_level_tasks.first)
|
28
|
+
end
|
29
|
+
@top_level_tasks
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
def magicafile
|
34
|
+
File.expand_path("../../Magicafile", __FILE__)
|
35
|
+
end
|
36
|
+
|
37
|
+
def warning_not_init
|
38
|
+
Rake::Task.define_task(:warning_not_init) do
|
39
|
+
puts I18n.t("not_init_project", scope: :magica)
|
40
|
+
exit 1
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def default_tasks
|
45
|
+
%{init}
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/lib/magica/build.rb
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
module Magica
|
2
|
+
class Builder
|
3
|
+
include Rake::DSL
|
4
|
+
|
5
|
+
COMPILERS = %w(cxx)
|
6
|
+
COMMANDS = COMPILERS + %w(linker)
|
7
|
+
|
8
|
+
attr_block COMMANDS
|
9
|
+
|
10
|
+
def initialize(name = 'host', dest = 'build', &block)
|
11
|
+
@name = name.to_s
|
12
|
+
@dest = dest.to_s
|
13
|
+
@sources = FileList["src/**/*.cpp"]
|
14
|
+
@cxx = Command::Compiler.new(self, %w(.cpp))
|
15
|
+
@linker = Command::Linker.new(self)
|
16
|
+
|
17
|
+
Magica.targets[@name] = self
|
18
|
+
Magica.targets[@name].instance_eval(&block) unless block.nil?
|
19
|
+
|
20
|
+
Magica.default_toolchain.setup(self, Magica.toolchain_params) if Magica.default_toolchain
|
21
|
+
end
|
22
|
+
|
23
|
+
def source(path)
|
24
|
+
@sources = FileList[path]
|
25
|
+
end
|
26
|
+
|
27
|
+
def filename
|
28
|
+
end
|
29
|
+
|
30
|
+
def exefile(name)
|
31
|
+
if name.is_a?(Array)
|
32
|
+
name.flatten.map { |n| exefile(n) }
|
33
|
+
else
|
34
|
+
"#{name}"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def libfile
|
39
|
+
end
|
40
|
+
|
41
|
+
def objfile(name)
|
42
|
+
if name.is_a?(Array)
|
43
|
+
name.flatten.map { |n| objfile(n) }
|
44
|
+
else
|
45
|
+
"#{@dest}/#{name}.o"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def toolchain(name, params = {})
|
50
|
+
toolchain = Toolchain.toolchains[name]
|
51
|
+
fail I18n.t("magica.unknow_toolchain", toolchain: name) unless toolchain
|
52
|
+
toolchain.setup(self, params)
|
53
|
+
end
|
54
|
+
|
55
|
+
def compile(source)
|
56
|
+
file objfile(source) => source do |t|
|
57
|
+
@cxx.run t.name, t.prerequisites.first
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def link(exec, objects)
|
62
|
+
task "build:#{@name}" => objects do
|
63
|
+
@linker.run "#{exec}", objects
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
|
3
|
+
module Magica
|
4
|
+
class Command
|
5
|
+
include Rake::DSL
|
6
|
+
extend Forwardable
|
7
|
+
|
8
|
+
def_delegators :@build, :filename, :objfile, :libfile, :exefile
|
9
|
+
attr_accessor :build, :command
|
10
|
+
|
11
|
+
def initialize(build)
|
12
|
+
@build = build
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
def _run(options, params = {})
|
17
|
+
sh command + ' ' + (options % params)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Magica
|
2
|
+
class Command::Compiler < Command
|
3
|
+
attr_accessor :flags
|
4
|
+
|
5
|
+
def initialize(build, source_exts = [])
|
6
|
+
super(build)
|
7
|
+
|
8
|
+
@command = ENV['CC'] || 'cc'
|
9
|
+
@flags = [ENV['CFLAGS'] || []]
|
10
|
+
@source_exts = source_exts
|
11
|
+
@compile_options = "%{flags} -o %{outfile} -c %{infile}"
|
12
|
+
end
|
13
|
+
|
14
|
+
def run(outfile, infile)
|
15
|
+
FileUtils.mkdir_p File.dirname(outfile)
|
16
|
+
_run @compile_options, { outfile: outfile, infile: infile, flags: "" }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Magica
|
2
|
+
class Command::Linker < Command
|
3
|
+
attr_accessor :flags
|
4
|
+
|
5
|
+
def initialize(build)
|
6
|
+
super
|
7
|
+
|
8
|
+
@command = ENV['LD'] || 'ld'
|
9
|
+
@flags = (ENV['LDFLAGS'] || [])
|
10
|
+
@link_options = "%{flags} -o %{outfile} %{objects}"
|
11
|
+
end
|
12
|
+
|
13
|
+
def run(outfile, objects)
|
14
|
+
_run @link_options, { outfile: outfile, objects: objects.join(" "), flags: "" }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/magica/dsl.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
module Magica
|
2
|
+
module DSL
|
3
|
+
def toolchain(name, params = {})
|
4
|
+
toolchain = Toolchain.toolchains[name.to_s]
|
5
|
+
fail I18n.t("magica.unknow_toolchain", toolchain: name) if toolchain.nil?
|
6
|
+
Magica.default_toolchain = toolchain
|
7
|
+
Magica.toolchain_params = params
|
8
|
+
end
|
9
|
+
|
10
|
+
def define_builder(name = 'host', dest = 'build', &block)
|
11
|
+
Builder.new(name, dest, &block)
|
12
|
+
end
|
13
|
+
|
14
|
+
def build(name, options = {}, &block)
|
15
|
+
builder = Magica.targets[name.to_s]
|
16
|
+
fail I18n.t("magica.unknow_build", build: name) unless builder
|
17
|
+
block = Magica.default_compile_task if block.nil?
|
18
|
+
builder.instance_exec(options, &block)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
extend Magica::DSL
|
data/lib/magica/i18n.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'i18n'
|
2
|
+
|
3
|
+
en = {
|
4
|
+
not_init_project: 'The project is not initialize, please run "magica init" before start use it',
|
5
|
+
unknow_toolchain: 'Unknow %{toolchain} toolchain',
|
6
|
+
unknow_build: 'Unknow %{build} build'
|
7
|
+
}
|
8
|
+
|
9
|
+
I18n.backend.store_translations(:en, magica: en)
|
10
|
+
|
11
|
+
if I18n.respond_to?(:enforce_available_locales=)
|
12
|
+
I18n.enforce_available_locales = true
|
13
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
load File.expand_path("../tasks/initialize.rake", __FILE__)
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Magica
|
2
|
+
class << self
|
3
|
+
attr_accessor :default_toolchain, :toolchain_params
|
4
|
+
|
5
|
+
def targets
|
6
|
+
@targets ||= {}
|
7
|
+
end
|
8
|
+
|
9
|
+
def each_target(&block)
|
10
|
+
return to_enum(:each_target) if block.nil?
|
11
|
+
@targets.each do |key, target|
|
12
|
+
target.instance_eval(&block)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def default_compile_task
|
17
|
+
proc { |options|
|
18
|
+
FileUtils.rm_r(@dest, force: true) if options[:clean]
|
19
|
+
|
20
|
+
objects = objfile(@sources)
|
21
|
+
@sources.each { |source| compile source }
|
22
|
+
|
23
|
+
link exefile("#{@dest}/#{@name}"), objects
|
24
|
+
}
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
File without changes
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Magica
|
2
|
+
class Toolchain
|
3
|
+
include Rake::DSL
|
4
|
+
|
5
|
+
class << self
|
6
|
+
attr_accessor :toolchains
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(name, &block)
|
10
|
+
@name, @initializer = name.to_s, block
|
11
|
+
Toolchain.toolchains ||= {}
|
12
|
+
Toolchain.toolchains[@name] = self
|
13
|
+
end
|
14
|
+
|
15
|
+
def setup(builder, options = {})
|
16
|
+
builder.instance_exec(builder, options, &@initializer)
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.load
|
20
|
+
builtin_path = File.join(File.dirname(__FILE__), "toolchains")
|
21
|
+
Dir.glob("#{builtin_path}/*.rake").each do |file|
|
22
|
+
Kernel.load file
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
Toolchain.load
|
28
|
+
end
|
29
|
+
|
data/magica.gemspec
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'magica/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "magica"
|
8
|
+
spec.version = Magica::VERSION
|
9
|
+
spec.authors = ["蒼時弦也"]
|
10
|
+
spec.email = ["elct9620@frost.tw"]
|
11
|
+
|
12
|
+
spec.summary = %q{A tool to build C++ project}
|
13
|
+
spec.description = %q{A tool to build C++ project}
|
14
|
+
spec.homepage = "https://github.com/elct9620/magica"
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
17
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
18
|
+
# if spec.respond_to?(:metadata)
|
19
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
20
|
+
# else
|
21
|
+
# raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
22
|
+
# end
|
23
|
+
|
24
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
spec.bindir = "bin"
|
26
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ["lib"]
|
28
|
+
|
29
|
+
spec.add_dependency "rake", "~> 10.0"
|
30
|
+
spec.add_dependency "i18n"
|
31
|
+
|
32
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
33
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: magica
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- 蒼時弦也
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-09-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '10.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '10.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: i18n
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.12'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.12'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
description: A tool to build C++ project
|
70
|
+
email:
|
71
|
+
- elct9620@frost.tw
|
72
|
+
executables:
|
73
|
+
- magica
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- ".rspec"
|
79
|
+
- ".travis.yml"
|
80
|
+
- Gemfile
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- bin/magica
|
84
|
+
- lib/Magicafile
|
85
|
+
- lib/magica.rb
|
86
|
+
- lib/magica/all.rb
|
87
|
+
- lib/magica/application.rb
|
88
|
+
- lib/magica/build.rb
|
89
|
+
- lib/magica/builder.rb
|
90
|
+
- lib/magica/command.rb
|
91
|
+
- lib/magica/commands/compiler.rb
|
92
|
+
- lib/magica/commands/linker.rb
|
93
|
+
- lib/magica/dsl.rb
|
94
|
+
- lib/magica/extension.rb
|
95
|
+
- lib/magica/framework.rb
|
96
|
+
- lib/magica/i18n.rb
|
97
|
+
- lib/magica/initialize.rb
|
98
|
+
- lib/magica/magica.rb
|
99
|
+
- lib/magica/tasks/build.rake
|
100
|
+
- lib/magica/tasks/framework.rake
|
101
|
+
- lib/magica/tasks/initialize.rake
|
102
|
+
- lib/magica/templates/Magicafile
|
103
|
+
- lib/magica/toolchain.rb
|
104
|
+
- lib/magica/toolchains/gcc.rake
|
105
|
+
- lib/magica/version.rb
|
106
|
+
- magica.gemspec
|
107
|
+
homepage: https://github.com/elct9620/magica
|
108
|
+
licenses: []
|
109
|
+
metadata: {}
|
110
|
+
post_install_message:
|
111
|
+
rdoc_options: []
|
112
|
+
require_paths:
|
113
|
+
- lib
|
114
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
requirements: []
|
125
|
+
rubyforge_project:
|
126
|
+
rubygems_version: 2.5.1
|
127
|
+
signing_key:
|
128
|
+
specification_version: 4
|
129
|
+
summary: A tool to build C++ project
|
130
|
+
test_files: []
|