rubygems-xcodeproj_generator 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bd3609d33811ffcb5a33d2d07760c8aa9326c3cb
4
+ data.tar.gz: 584c86d0d89645c67f09a7bed9b733b70bdb7d78
5
+ SHA512:
6
+ metadata.gz: dfe55460bf96d1212f3add1456be6e478253b1da2b74c16320b999d9ffe3cb4d83f513f8d703fee69b297d2538c4b1beccad726d32c563b4a33e09e6aa9b2798
7
+ data.tar.gz: 39fc8422f176f284d93c663c15cd1fd97e73455dcf1e9902456214ad882ec6bcf36533e21b4a78aa9c15d3bc71065eadf17aef181f32d0a328a4e26d7917f827
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,20 @@
1
+ Metrics/LineLength:
2
+ Max: 100
3
+
4
+ Style/AlignHash:
5
+ EnforcedHashRocketStyle: table
6
+ EnforcedColonStyle: separator
7
+
8
+ Style/Documentation:
9
+ Enabled: false
10
+
11
+ Style/EmptyElse:
12
+ Enabled: false
13
+
14
+ Style/GuardClause:
15
+ Enabled: false
16
+
17
+ Style/RegexpLiteral:
18
+ Exclude:
19
+ - '*.gemspec'
20
+ - 'Guardfile'
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 2.1
5
+ - 2.2
6
+ script: bundle exec rake ci
7
+ sudo: false
8
+ cache: bundler
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :development, :test do
6
+ gem 'rake', '~> 10.0'
7
+ gem 'rspec', '~> 3.2'
8
+ gem 'rubocop', '~> 0.29'
9
+ gem 'simplecov', '~> 0.9'
10
+ end
11
+
12
+ group :test do
13
+ gem 'coveralls', '~> 0.7'
14
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Yuji Nakayama
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,55 @@
1
+ [![Gem Version](http://img.shields.io/gem/v/rubygems-xcodeproj_generator.svg?style=flat)](http://badge.fury.io/rb/rubygems-xcodeproj_generator)
2
+ [![Dependency Status](http://img.shields.io/gemnasium/yujinakayama/rubygems-xcodeproj_generator.svg?style=flat)](https://gemnasium.com/yujinakayama/rubygems-xcodeproj_generator)
3
+ [![Build Status](https://travis-ci.org/yujinakayama/rubygems-xcodeproj_generator.svg?branch=master&style=flat)](https://travis-ci.org/yujinakayama/rubygems-xcodeproj_generator)
4
+ [![Coverage Status](http://img.shields.io/coveralls/yujinakayama/rubygems-xcodeproj_generator/master.svg?style=flat)](https://coveralls.io/r/yujinakayama/rubygems-xcodeproj_generator)
5
+ [![Code Climate](https://img.shields.io/codeclimate/github/yujinakayama/rubygems-xcodeproj_generator.svg?style=flat)](https://codeclimate.com/github/yujinakayama/rubygems-xcodeproj_generator)
6
+
7
+ # Rubygems::XcodeprojGenerator
8
+
9
+ Provides a Rake task for generating an Xcode project for C extension development.
10
+
11
+ Within the generated Xcode project:
12
+
13
+ * Code completion is enabled, including Ruby internal functions and macros.
14
+ * You can build the extension by running **⌘B**, though this is just for checking while development and not for production release.
15
+
16
+ ## Basic Usage
17
+
18
+ Add the following development dependencies to your extension's Gemfile or gemspec:
19
+
20
+ ```ruby
21
+ gem 'rake-compiler'
22
+ gem 'rubygems-xcodeproj_generator'
23
+ ```
24
+
25
+ And execute:
26
+
27
+ ```bash
28
+ $ bundle install
29
+ ```
30
+
31
+ Then add the following code to your Rakefile:
32
+
33
+ ```ruby
34
+ require 'rake/extensiontask'
35
+ require 'rubygems/xcodeproj_generator/rake_task'
36
+
37
+ Rake::ExtensionTask.new('your-comple-task-name')
38
+
39
+ Rubygems::XcodeprojGenerator::RakeTask.new do |project|
40
+ project.name = 'your-xcode-project-name'
41
+ project.build_command = 'bundle exec rake your-comple-task-name'
42
+ end
43
+ ```
44
+
45
+ And run:
46
+
47
+ ```bash
48
+ $ bundle exec rake generate_xcode_project
49
+ ```
50
+
51
+ ## License
52
+
53
+ Copyright (c) 2015 Yuji Nakayama
54
+
55
+ See the [LICENSE.txt](LICENSE.txt) for details.
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ require 'bundler/setup'
2
+ require 'bundler/gem_tasks'
3
+ require 'rspec/core/rake_task'
4
+ require 'rubocop/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec) do |task|
7
+ task.verbose = false
8
+ end
9
+
10
+ RuboCop::RakeTask.new(:style)
11
+
12
+ task ci: [:spec, :style]
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'rubygems/xcodeproj_generator'
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
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,7 @@
1
+ require 'rubygems/xcodeproj_generator/version'
2
+
3
+ module Rubygems
4
+ module XcodeprojGenerator
5
+ # Your code goes here...
6
+ end
7
+ end
@@ -0,0 +1,35 @@
1
+ module Rubygems
2
+ module XcodeprojGenerator
3
+ class AbstractRubyHeaderProvider
4
+ attr_reader :root_path
5
+
6
+ def initialize(root_path)
7
+ @root_path = File.expand_path(root_path)
8
+ end
9
+
10
+ def available?
11
+ Dir.exist?(root_path)
12
+ end
13
+
14
+ def ruby_header_paths
15
+ [base_ruby_header_path, platform_ruby_header_path].compact
16
+ end
17
+
18
+ private
19
+
20
+ def base_ruby_header_path
21
+ fail NotImplementedError
22
+ end
23
+
24
+ def platform_ruby_header_path
25
+ return nil unless base_ruby_header_path
26
+ find_path(base_ruby_header_path, '*darwin*')
27
+ end
28
+
29
+ def find_path(*parts)
30
+ pattern = File.join(*parts)
31
+ Dir[pattern].first
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,98 @@
1
+ require 'xcodeproj'
2
+ require 'rubygems/xcodeproj_generator/rbenv'
3
+ require 'rubygems/xcodeproj_generator/xcode'
4
+
5
+ module Rubygems
6
+ module XcodeprojGenerator
7
+ class Project
8
+ attr_accessor :name, :build_command
9
+
10
+ def initialize(name = nil)
11
+ @name = name
12
+ end
13
+
14
+ def path
15
+ project.path
16
+ end
17
+
18
+ def save
19
+ configure_header_search_paths
20
+ configure_groups
21
+ configure_build_phase
22
+ project.save
23
+ end
24
+
25
+ private
26
+
27
+ def project
28
+ @project ||= Xcodeproj::Project.new("#{name}.xcodeproj")
29
+ end
30
+
31
+ def target
32
+ # We don't use the PBXLegacyTarget class (a.k.a External Build System) since it cannot have
33
+ # build settings and the Xcode's code completion cannot be enabled.
34
+ @target ||= project.new_target(:static_library, name, :osx).tap do |target|
35
+ target.product_reference = nil
36
+ target.build_phases.clear
37
+ project.targets << target
38
+ end
39
+ end
40
+
41
+ def configure_header_search_paths
42
+ target.build_configurations.each do |config|
43
+ config.build_settings['HEADER_SEARCH_PATHS'] = ruby_header_paths.join(' ')
44
+ end
45
+ end
46
+
47
+ def configure_build_phase
48
+ return unless build_command
49
+
50
+ build_phase = target.new_shell_script_build_phase
51
+
52
+ build_phase.shell_path = '/usr/bin/ruby'
53
+
54
+ # Xcode automatically sets a number of environment variables from the Xcode project's build
55
+ # settings and clang refers them. However we configure the build settings only for code
56
+ # completion in Xcode and they may be wrong for the real build. So we reset the Xcode's
57
+ # environments variables and restore the current variables before invoking the external
58
+ # build command.
59
+ build_phase.shell_script = <<-END.gsub(/^\s+\|/, '')
60
+ |ENV.clear
61
+ |ENV.update(#{ENV.to_hash.inspect})
62
+ |system(#{build_command.inspect})
63
+ END
64
+ end
65
+
66
+ def configure_groups
67
+ project.main_group.clear
68
+
69
+ group = project.new_group('Sources')
70
+
71
+ file_references = Dir['ext/**/*.{h,c}'].map do |path|
72
+ group.new_reference(path, :project)
73
+ end
74
+
75
+ # Xcode's code completion is enabled only in files that are compiled in the active target.
76
+ target.add_file_references(file_references)
77
+
78
+ group.sort
79
+ end
80
+
81
+ def ruby_header_paths
82
+ if rbenv.available?
83
+ rbenv.ruby_header_paths
84
+ else
85
+ xcode.ruby_header_paths
86
+ end
87
+ end
88
+
89
+ def rbenv
90
+ @rbenv ||= Rbenv.new
91
+ end
92
+
93
+ def xcode
94
+ @xcode ||= Xcode.new
95
+ end
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,28 @@
1
+ require 'rake'
2
+ require 'rake/tasklib'
3
+ require 'rubygems/xcodeproj_generator/project'
4
+
5
+ module Rubygems
6
+ module XcodeprojGenerator
7
+ class RakeTask < ::Rake::TaskLib
8
+ include ::Rake::DSL if defined?(::Rake::DSL)
9
+
10
+ def initialize(name = :generate_xcode_project)
11
+ unless ::Rake.application.last_comment
12
+ desc 'Generate an Xcode project for C extension development'
13
+ end
14
+
15
+ task(name) do
16
+ project = Project.new
17
+
18
+ yield project
19
+
20
+ project.name ||= File.basename(Dir.pwd)
21
+ project.save
22
+
23
+ puts "Xcode project has been generated to #{project.path}."
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,40 @@
1
+ require 'rubygems/xcodeproj_generator/abstract_ruby_header_provider'
2
+
3
+ module Rubygems
4
+ module XcodeprojGenerator
5
+ class Rbenv < AbstractRubyHeaderProvider
6
+ DEFAULT_ROOT_PATH = '~/.rbenv'
7
+ VERSIONS_PATH = 'versions'
8
+
9
+ def initialize(root_path = nil)
10
+ root_path ||= ENV['RBENV_ROOT'] || DEFAULT_ROOT_PATH
11
+ super(root_path)
12
+ end
13
+
14
+ private
15
+
16
+ def base_ruby_header_path
17
+ return nil unless latest_cruby_version
18
+ find_path(root_path, VERSIONS_PATH, latest_cruby_version, 'include/ruby-*')
19
+ end
20
+
21
+ def latest_cruby_version
22
+ cruby_versions.sort_by { |version| Gem::Version.new(version) }.last
23
+ end
24
+
25
+ def cruby_versions
26
+ versions.select { |version| version.match(/\A\d+\.\d+\.\d+/) }
27
+ end
28
+
29
+ def versions
30
+ return [] unless available?
31
+
32
+ versions_dir = File.join(root_path, VERSIONS_PATH)
33
+
34
+ Dir.chdir(versions_dir) do
35
+ Dir['*']
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,13 @@
1
+ module Rubygems
2
+ module XcodeprojGenerator
3
+ module Version
4
+ MAJOR = 0
5
+ MINOR = 1
6
+ PATCH = 0
7
+
8
+ def self.to_s
9
+ [MAJOR, MINOR, PATCH].join('.')
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,42 @@
1
+ require 'rubygems/xcodeproj_generator/abstract_ruby_header_provider'
2
+
3
+ module Rubygems
4
+ module XcodeprojGenerator
5
+ class Xcode < AbstractRubyHeaderProvider
6
+ DEFAULT_ROOT_PATH = '/Applications/Xcode.app'
7
+ OSX_SDKS_PATH = 'Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs'
8
+ RUBY_INCLUDE_PATH_PATTERN =
9
+ 'System/Library/Frameworks/Ruby.framework/Versions/*/usr/include/*'
10
+
11
+ def initialize(root_path = nil)
12
+ root_path ||= DEFAULT_ROOT_PATH
13
+ super(root_path)
14
+ end
15
+
16
+ private
17
+
18
+ def base_ruby_header_path
19
+ return nil unless latest_osx_sdk
20
+ find_path(root_path, OSX_SDKS_PATH, latest_osx_sdk, RUBY_INCLUDE_PATH_PATTERN)
21
+ end
22
+
23
+ def latest_osx_sdk
24
+ osx_sdks.sort_by do |sdk|
25
+ version = sdk.match(/\d+\.\d+/).to_s
26
+ Gem::Version.new(version)
27
+ end.last
28
+ end
29
+
30
+ def osx_sdks
31
+ return [] unless available?
32
+
33
+ sdks_dir = File.join(root_path, OSX_SDKS_PATH)
34
+ return [] unless Dir.exist?(sdks_dir)
35
+
36
+ Dir.chdir(sdks_dir) do
37
+ Dir['*']
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -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 'rubygems/xcodeproj_generator/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'rubygems-xcodeproj_generator'
8
+ spec.version = Rubygems::XcodeprojGenerator::Version.to_s
9
+ spec.authors = ['Yuji Nakayama']
10
+ spec.email = ['nkymyj@gmail.com']
11
+
12
+ spec.summary = 'Provides a Rake task for generating an Xcode project ' \
13
+ 'for C extension development.'
14
+ spec.description = spec.summary
15
+ spec.homepage = 'https://github.com/yujinakayama/rubygems-xcodeproj_generator'
16
+ spec.license = 'MIT'
17
+
18
+ spec.files =
19
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
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_runtime_dependency 'xcodeproj', '~> 0.23'
25
+
26
+ spec.add_development_dependency 'bundler', '~> 1.7'
27
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubygems-xcodeproj_generator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Yuji Nakayama
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-03-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: xcodeproj
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.23'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.23'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ description: Provides a Rake task for generating an Xcode project for C extension
42
+ development.
43
+ email:
44
+ - nkymyj@gmail.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - ".rspec"
51
+ - ".rubocop.yml"
52
+ - ".travis.yml"
53
+ - Gemfile
54
+ - LICENSE.txt
55
+ - README.md
56
+ - Rakefile
57
+ - bin/console
58
+ - bin/setup
59
+ - lib/rubygems/xcodeproj_generator.rb
60
+ - lib/rubygems/xcodeproj_generator/abstract_ruby_header_provider.rb
61
+ - lib/rubygems/xcodeproj_generator/project.rb
62
+ - lib/rubygems/xcodeproj_generator/rake_task.rb
63
+ - lib/rubygems/xcodeproj_generator/rbenv.rb
64
+ - lib/rubygems/xcodeproj_generator/version.rb
65
+ - lib/rubygems/xcodeproj_generator/xcode.rb
66
+ - rubygems-xcodeproj_generator.gemspec
67
+ homepage: https://github.com/yujinakayama/rubygems-xcodeproj_generator
68
+ licenses:
69
+ - MIT
70
+ metadata: {}
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubyforge_project:
87
+ rubygems_version: 2.4.6
88
+ signing_key:
89
+ specification_version: 4
90
+ summary: Provides a Rake task for generating an Xcode project for C extension development.
91
+ test_files: []