dyci-compiler 0.0.1.pre

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,23 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ tmp/
19
+ bin/autospec
20
+ bin/htmldiff
21
+ bin/ldiff
22
+ bin/rake
23
+ bin/rspec
data/.rvmrc ADDED
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # This is an RVM Project .rvmrc file, used to automatically load the ruby
4
+ # development environment upon cd'ing into the directory
5
+
6
+ # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
7
+ # Only full ruby name is supported here, for short names use:
8
+ # echo "rvm use ree" > .rvmrc
9
+ environment_id="ree-1.8.7-2012.02@dyci_compiler"
10
+
11
+ # Uncomment the following lines if you want to verify rvm version per project
12
+ # rvmrc_rvm_version="1.13.6 (stable)" # 1.10.1 seams as a safe start
13
+ # eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
14
+ # echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
15
+ # return 1
16
+ # }
17
+
18
+ # First we attempt to load the desired environment directly from the environment
19
+ # file. This is very fast and efficient compared to running through the entire
20
+ # CLI and selector. If you want feedback on which environment was used then
21
+ # insert the word 'use' after --create as this triggers verbose mode.
22
+ if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
23
+ && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
24
+ then
25
+ \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
26
+ [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]] &&
27
+ \. "${rvm_path:-$HOME/.rvm}/hooks/after_use" || true
28
+ else
29
+ # If the environment file has not yet been created, use the RVM CLI to select.
30
+ rvm --create "$environment_id" || {
31
+ echo "Failed to create RVM environment '${environment_id}'."
32
+ return 1
33
+ }
34
+ fi
35
+
36
+ # If you use bundler, this might be useful to you:
37
+ # if [[ -s Gemfile ]] && {
38
+ # ! builtin command -v bundle >/dev/null ||
39
+ # builtin command -v bundle | GREP_OPTIONS= \grep $rvm_path/bin/bundle >/dev/null
40
+ # }
41
+ # then
42
+ # printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
43
+ # gem install bundler
44
+ # fi
45
+ # if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
46
+ # then
47
+ # bundle install | GREP_OPTIONS= \grep -vE '^Using|Your bundle is complete'
48
+ # fi
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in dyci-compiler.gemspec
4
+ gemspec
5
+
6
+ gem 'rspec'
7
+ gem 'rake'
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Alex Denisov
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # DyCI::Compiler
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'dyci-compiler'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install dyci-compiler
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require 'rspec/core/rake_task'
4
+ RSpec::Core::RakeTask.new('spec')
5
+
6
+ task :default => 'spec'
7
+
data/bin/dyci-compiler ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'dyci-compiler'
5
+
6
+ if ARGV[0] == 'recompile'
7
+ DyCI::Compiler.recompile ARGV
8
+ else
9
+ DyCI::Compiler.compile ARGV
10
+ end
11
+
12
+
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/dyci-compiler/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Alex Denisov"]
6
+ gem.email = ["1101.debian@gmail.com"]
7
+ gem.description = %q{: Write a gem description}
8
+ gem.summary = %q{: Write a gem summary}
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(spec)/})
14
+ gem.name = "dyci-compiler"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = DyCI::Compiler::VERSION
17
+
18
+
19
+ gem.add_development_dependency "rspec"
20
+ end
@@ -0,0 +1,50 @@
1
+ module DyCI
2
+ class ClangParser
3
+ class << self
4
+
5
+ def params(args = nil)
6
+ parse_arguments args
7
+ end
8
+
9
+ protected
10
+ def parse_arguments(args = nil)
11
+ parsed_params = {}
12
+ args.each_with_index do |arg, index|
13
+ case arg
14
+ when /.*\w+\.m\z/
15
+ parsed_params[:class_name] = arg
16
+ when /.*\w+\.o\z/
17
+ parsed_params[:object_compilation] = arg
18
+ when /\A-L.*/
19
+ parsed_params[:l_params] ||= []
20
+ parsed_params[:l_params] << arg
21
+ when /\A-F.*/
22
+ parsed_params[:f_params] ||= []
23
+ parsed_params[:f_params] << arg
24
+ when /-arch/
25
+ parsed_params[:arch] = args[index + 1]
26
+ when /-isysroot/
27
+ parsed_params[:i_sys_root] = args[index + 1]
28
+ when /\A-mi.*-min=.*/
29
+ parsed_params[:min_os_param] = arg
30
+ end
31
+ end if args
32
+ defaults.merge parsed_params
33
+ end
34
+
35
+ def defaults
36
+ {
37
+ :class_name => '',
38
+ :object_compilation => '',
39
+ :arch => '',
40
+ :i_sys_root => '',
41
+ :l_params => [],
42
+ :f_params => [],
43
+ :min_os_param => ''
44
+ }
45
+ end
46
+
47
+ end
48
+ end
49
+ end
50
+
@@ -0,0 +1,84 @@
1
+ module DyCI
2
+ class ClangRunner
3
+
4
+ def compile args
5
+ args = args.map do |arg|
6
+ if arg =~ /\A-mmacosx-version-min/
7
+ ""
8
+ else
9
+ arg.gsub /(.+)/, '"\0"'
10
+ end
11
+ end
12
+ cmd = "clang #{args.join(" ")}"
13
+
14
+ Kernel.exec(cmd)
15
+ end
16
+
17
+ def recompile class_name
18
+ class_name = class_name.gsub /\.h\z/, '.m'
19
+ # TODO: refactor this shit too
20
+ storage = ClangStorage.new
21
+ arguments = storage.load_arguments class_name
22
+ # we store working directory at first argument
23
+ Dir.chdir arguments.shift.chomp
24
+
25
+ fork {
26
+ self.compile arguments
27
+ }
28
+ params = ClangParser.params arguments
29
+ self.cleanup
30
+ lib_name = "dyci_#{Time.now.to_i}.dylib"
31
+
32
+ recompile_params = []
33
+ recompile_params << "-arch"
34
+ recompile_params << "#{params[:arch]}"
35
+ recompile_params << "-dynamiclib"
36
+ recompile_params << "-isysroot"
37
+ recompile_params << "#{params[:i_sys_root]}"
38
+ recompile_params + params[:l_params]
39
+ recompile_params + params[:f_params]
40
+ recompile_params << params[:object_compilation]
41
+ recompile_params << "-install_name"
42
+ recompile_params << "/usr/local/lib/#{lib_name}"
43
+ recompile_params << "-Xlinker"
44
+ recompile_params << "-objc_abi_version"
45
+ recompile_params << "-Xlinker"
46
+ recompile_params << "2"
47
+ recompile_params << "-ObjC"
48
+ recompile_params << "-undefined"
49
+ recompile_params << "dynamic_lookup"
50
+ recompile_params << "-fobjc-arc"
51
+ recompile_params << "-fobjc-link-runtime"
52
+ recompile_params << "-Xlinker"
53
+ recompile_params << "-no_implicit_dylibs"
54
+ recompile_params << params[:min_os_param]
55
+ recompile_params << "-single_module"
56
+ recompile_params << "-compatibility_version"
57
+ recompile_params << "5"
58
+ recompile_params << "-current_version"
59
+ recompile_params << "5"
60
+ recompile_params << "-v"
61
+ # TODO: fix that shit
62
+ recompile_params << "-o"
63
+ recompile_params << "#{File.expand_path('~/.dyci')}/#{lib_name}"
64
+
65
+ self.compile recompile_params
66
+ end
67
+
68
+ def cleanup
69
+ files = []
70
+ # TODO: move to utils module
71
+ begin
72
+ index_dir = Dir.new File.expand_path('~/.dyci')
73
+ rescue
74
+ return false
75
+ end
76
+ index_dir.each do |file_entry|
77
+ files << "#{index_dir.path}/#{file_entry}" if file_entry =~ /.*\.dylib|.*resource/
78
+ end
79
+
80
+ FileUtils.rm files, :force => true
81
+ end
82
+ end
83
+ end
84
+
@@ -0,0 +1,40 @@
1
+ require 'digest'
2
+ require 'dyci-compiler/clang_parser'
3
+ require 'fileutils'
4
+
5
+ module DyCI
6
+ class ClangStorage
7
+
8
+ def save_arguments(args)
9
+ arguments = args.dup
10
+ class_name = ClangParser.params(arguments)[:class_name]
11
+ index_file_path = self.index_path class_name
12
+ arguments.unshift Dir.pwd
13
+ File.open(index_file_path, 'w') do |f|
14
+ f.write arguments.join("\n")
15
+ end
16
+ end
17
+
18
+ def load_arguments(class_name)
19
+ args = []
20
+ index_file_path = self.index_path class_name
21
+ File.open(index_file_path, 'r').each_line do |line|
22
+ args << line.chomp.strip
23
+ end
24
+ args
25
+ end
26
+
27
+
28
+ protected
29
+ def index_path class_name
30
+ index_name = Digest::MD5.hexdigest(class_name || "")
31
+ # TODO: move to utils
32
+ index_dir = File.join(File.expand_path('~'), '.dyci', 'index')
33
+ # TODO: move directory creating to installer
34
+ FileUtils.mkdir_p index_dir
35
+ File.join(index_dir, index_name)
36
+ end
37
+
38
+ end
39
+ end
40
+
@@ -0,0 +1,5 @@
1
+ module DyCI
2
+ module Compiler
3
+ VERSION = "0.0.1.pre"
4
+ end
5
+ end
@@ -0,0 +1,19 @@
1
+ require 'dyci-compiler/version'
2
+ require 'dyci-compiler/clang_storage'
3
+ require 'dyci-compiler/clang_runner'
4
+
5
+ module DyCI
6
+ module Compiler
7
+ def self.compile args
8
+ storage = ClangStorage.new
9
+ storage.save_arguments args
10
+ runner = ClangRunner.new
11
+ runner.compile args
12
+ end
13
+
14
+ def self.recompile args
15
+ runner = ClangRunner.new
16
+ runner.recompile args[1]
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+ require 'dyci-compiler/clang_parser'
3
+
4
+ include DyCI
5
+
6
+ describe ClangParser do
7
+ let(:default_params) {
8
+ {
9
+ :class_name => '',
10
+ :object_compilation => '',
11
+ :arch => '',
12
+ :i_sys_root => '',
13
+ :l_params => [],
14
+ :f_params => [],
15
+ :min_os_param => ''
16
+ }
17
+
18
+ }
19
+ context 'parse' do
20
+ describe 'without arguments' do
21
+ it 'should return default parameters' do
22
+ params = ClangParser.params
23
+ params.should == default_params
24
+ end
25
+ end
26
+
27
+ describe 'within arguments' do
28
+ context 'should return valid parameters' do
29
+ let(:args) { Factory.create :args }
30
+ let(:parsed_params) { ClangParser.params args }
31
+ it { parsed_params[:i_sys_root].should == "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.0.sdk" }
32
+ it { parsed_params[:arch].should == "i386"}
33
+ it { parsed_params[:l_params].should == ["-L/test/DerivedData/test/Build/Products/Debug-iphonesimulator"] }
34
+ it { parsed_params[:f_params].should == ["-F/test/DerivedData/test/Build/Products/Debug-iphonesimulator"] }
35
+ it { parsed_params[:min_os_param].should == "-mios-simulator-version-min=6.0"}
36
+ end
37
+ end
38
+ end
39
+ end
data/spec/factory.rb ADDED
@@ -0,0 +1,19 @@
1
+ module DyCI
2
+ class Factory
3
+ class << self
4
+
5
+ def create(factory_name)
6
+ self.send factory_name
7
+ end
8
+
9
+ # concrete factories
10
+ def args
11
+ fixture_path = File.join('spec', 'fixtures', 'params.txt')
12
+ string = File.open(fixture_path, 'r'){ |file| file.read }
13
+ string.split ' '
14
+ end
15
+
16
+ end
17
+ end
18
+ end
19
+
@@ -0,0 +1,2 @@
1
+ -arch i386 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.0.sdk -L/test/DerivedData/test/Build/Products/Debug-iphonesimulator -F/test/DerivedData/test/Build/Products/Debug-iphonesimulator -filelist /test/DerivedData/test/Build/Intermediates/test.build/Debug-iphonesimulator/test.build/Objects-normal/i386/test.LinkFileList -Xlinker -objc_abi_version -Xlinker 2 -fobjc-link-runtime -mios-simulator-version-min=6.0 -framework UIKit -framework Foundation -framework CoreGraphics -o /test/DerivedData/test/Build/Products/Debug-iphonesimulator/test.app/test
2
+
@@ -0,0 +1,8 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'factory'
4
+
5
+ RSpec.configure do |config|
6
+ config.formatter = 'documentation'
7
+ end
8
+
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dyci-compiler
3
+ version: !ruby/object:Gem::Version
4
+ hash: -1887926852
5
+ prerelease: 6
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ - pre
11
+ version: 0.0.1.pre
12
+ platform: ruby
13
+ authors:
14
+ - Alex Denisov
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2012-11-11 00:00:00 Z
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rspec
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :development
34
+ version_requirements: *id001
35
+ description: ": Write a gem description"
36
+ email:
37
+ - 1101.debian@gmail.com
38
+ executables:
39
+ - dyci-compiler
40
+ extensions: []
41
+
42
+ extra_rdoc_files: []
43
+
44
+ files:
45
+ - .gitignore
46
+ - .rvmrc
47
+ - Gemfile
48
+ - LICENSE
49
+ - README.md
50
+ - Rakefile
51
+ - bin/dyci-compiler
52
+ - dyci-compiler.gemspec
53
+ - lib/dyci-compiler.rb
54
+ - lib/dyci-compiler/clang_parser.rb
55
+ - lib/dyci-compiler/clang_runner.rb
56
+ - lib/dyci-compiler/clang_storage.rb
57
+ - lib/dyci-compiler/version.rb
58
+ - spec/clang_parser_spec.rb
59
+ - spec/factory.rb
60
+ - spec/fixtures/params.txt
61
+ - spec/spec_helper.rb
62
+ homepage: ""
63
+ licenses: []
64
+
65
+ post_install_message:
66
+ rdoc_options: []
67
+
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ hash: 3
76
+ segments:
77
+ - 0
78
+ version: "0"
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ">"
83
+ - !ruby/object:Gem::Version
84
+ hash: 25
85
+ segments:
86
+ - 1
87
+ - 3
88
+ - 1
89
+ version: 1.3.1
90
+ requirements: []
91
+
92
+ rubyforge_project:
93
+ rubygems_version: 1.8.24
94
+ signing_key:
95
+ specification_version: 3
96
+ summary: ": Write a gem summary"
97
+ test_files:
98
+ - spec/clang_parser_spec.rb
99
+ - spec/factory.rb
100
+ - spec/fixtures/params.txt
101
+ - spec/spec_helper.rb