Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
vhosune committed Dec 4, 2019
0 parents commit f22237c
Show file tree
Hide file tree
Showing 11 changed files with 226 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
*.gem
Gemfile.lock

## Documentation cache and generated files:
/.yardoc/
/_yardoc/
/doc/
/rdoc/
fastlane/README.md
fastlane/report.xml
coverage
test-results
6 changes: 6 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
source('https://rubygems.org')

gemspec

plugins_path = File.join(File.dirname(__FILE__), 'fastlane', 'Pluginfile')
eval_gemfile(plugins_path) if File.exist?(plugins_path)
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 Vincent HO-SUNE

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# xcode_tools_select plugin

[![fastlane Plugin Badge](https://rawcdn.githack.com/fastlane/fastlane/master/fastlane/assets/plugin-badge.svg)](https://rubygems.org/gems/fastlane-plugin-xcode_tools_select)

## Getting Started

This project is a [_fastlane_](https://github.com/fastlane/fastlane) plugin. To get started with `fastlane-plugin-xcode_tools_select`, add it to your project by running:

```bash
fastlane add_plugin xcode_tools_select
```

## About xcode_tools_select

When you have multiple Xcode installed, you can use this plugin to select which version of Xcode to build with.

add this line in your fastlane/Fastfile before the building section

```
xcode_tools_select(version: "[VERSION]")
```


## Example

Check out the [example `Fastfile`](fastlane/Fastfile) to see how to use this plugin. Try it by cloning the repo, running `fastlane install_plugins` and `bundle exec fastlane test`.

To select Xcode 10.+ to compile:
```
xcode_tools_select(version: "10.*")
```

## Issues and Feedback

For any other issues and feedback about this plugin, please submit it to this repository.

## Troubleshooting

If you have trouble using plugins, check out the [Plugins Troubleshooting](https://docs.fastlane.tools/plugins/plugins-troubleshooting/) guide.

## Using _fastlane_ Plugins

For more information about how the `fastlane` plugin system works, check out the [Plugins documentation](https://docs.fastlane.tools/plugins/create-plugin/).

## About _fastlane_

_fastlane_ is the easiest way to automate beta deployments and releases for your iOS and Android apps. To learn more, check out [fastlane.tools](https://fastlane.tools).
25 changes: 25 additions & 0 deletions fastlane-plugin-xcode_tools_select.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# coding: utf-8

lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'fastlane/plugin/xcode_tools_select/version'

Gem::Specification.new do |spec|
spec.name = 'fastlane-plugin-xcode_tools_select'
spec.version = Fastlane::XcodeToolsSelect::VERSION
spec.author = 'Vincent HO-SUNE'
spec.email = 'vhosune@gmail.com'

spec.summary = 'Set the [version] of the default Xcode Command Line Tools path to use.'
spec.homepage = "https://github.com/vhosune/fastlane-plugin-xcode_tools_select"
spec.license = "MIT"
spec.description = "Sets the DEVELOPER_DIR environment, used by fastlane to run Xcode command line tools, to a specific Xcode version found on the current system."

spec.files = Dir["lib/**/*"] + %w(README.md LICENSE)
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ['lib']

# Don't add a dependency to fastlane or fastlane_re
# since this would cause a circular dependency

end
4 changes: 4 additions & 0 deletions fastlane/Fastfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

lane :test do
xcode_tools_select(version: "10.*")
end
1 change: 1 addition & 0 deletions fastlane/Pluginfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Autogenerated by fastlane
16 changes: 16 additions & 0 deletions lib/fastlane/plugin/xcode_tools_select.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
require 'fastlane/plugin/xcode_tools_select/version'

module Fastlane
module XcodeToolsSelect
# Return all .rb files inside the "actions" and "helper" directory
def self.all_classes
Dir[File.expand_path('**/{actions,helper}/*.rb', File.dirname(__FILE__))]
end
end
end

# By default we want to import all available actions and helpers
# A plugin can contain any number of actions and plugins
Fastlane::XcodeToolsSelect.all_classes.each do |current|
require current
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
require 'fastlane/action'
require_relative '../helper/xcode_tools_select_helper'

module Fastlane
module Actions
class XcodeToolsSelectAction < Action
def self.run(params)
required_version = params[:version]

UI.message("Search for Xcode Command Line Tools with version: #{required_version}")

# Search for Xcode paths
output = Actions.sh_no_action("mdfind -0 'kMDItemCFBundleIdentifier = 'com.apple.dt.Xcode' && kMDItemVersion = '#{required_version}''", log: false)

UI.user_error!("Xcode matching version `#{required_version}` not found !") unless !output.empty?

paths = output.split("\0")
paths.each do |line|
UI.message("found: #{line} ")
end

# Select the first matching one
xcode_path = paths.first
xcode_tools_path = File.join(xcode_path, "/Contents/Developer")

# Verify that the path exists
UI.user_error!("Path '#{xcode_tools_path}' doesn't exist") unless Dir.exist?(xcode_tools_path)

# Get the exact Version found
itemVersion = Actions.sh_no_action("mdls -name 'kMDItemVersion' -raw #{xcode_path}", log: false)

UI.message("Setting Xcode version #{itemVersion} to #{xcode_tools_path} for all build steps")

ENV["DEVELOPER_DIR"] = xcode_tools_path

end

def self.description
"Set the [version] of the default Xcode Command Line Tools path to use."
end

def self.authors
["Vincent HO-SUNE"]
end

def self.available_options
[
FastlaneCore::ConfigItem.new(key: :version,
env_name: "XCODE_TOOLS_SELECT_VERSION",
description: "Version of Xcode to select",
optional: false,
type: String)
]
end

def self.is_supported?(platform)
[:ios, :mac].include?(platform)
true
end

def self.example_code
[
'xcode_tools_select(version: "10.*")'
]
end

def self.category
:building
end

end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
require 'fastlane_core/ui/ui'

module Fastlane
UI = FastlaneCore::UI unless Fastlane.const_defined?("UI")

module Helper
class XcodeToolsSelectHelper
# class methods that you define here become available in your action
# as `Helper::XcodeToolsSelectHelper.your_method`
#
def self.show_message
UI.message("Hello from the xcode_tools_select plugin helper!")
end
end
end
end
5 changes: 5 additions & 0 deletions lib/fastlane/plugin/xcode_tools_select/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Fastlane
module XcodeToolsSelect
VERSION = "0.1.0"
end
end

0 comments on commit f22237c

Please sign in to comment.