-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from DeployGate/feature/ios_build
[WIP] Support ios build
- Loading branch information
Showing
18 changed files
with
845 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module DeployGate | ||
class Build | ||
class << self | ||
|
||
# @param [String] path | ||
# @return [Boolean] | ||
def ios?(path) | ||
DeployGate::Builds::Ios.workspace?(path) || DeployGate::Builds::Ios.project?(path) || DeployGate::Builds::Ios.ios_root?(path) | ||
end | ||
|
||
# @param [String] path | ||
# @return [Boolean] | ||
def android?(path) | ||
false # TODO: support android build | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
module DeployGate | ||
module Builds | ||
module Ios | ||
WORK_DIR_EXTNAME = '.xcworkspace' | ||
PROJECT_DIR_EXTNAME = '.xcodeproj' | ||
|
||
class NotSupportExportMethodError < StandardError | ||
end | ||
|
||
class << self | ||
# @param [Analyze] ios_analyze | ||
# @param [String] target_scheme | ||
# @param [String] codesigning_identity | ||
# @param [String] export_method | ||
# @return [String] | ||
def build(ios_analyze, target_scheme, codesigning_identity, export_method = Export::AD_HOC) | ||
raise NotSupportExportMethodError, 'Not support export' unless Export::SUPPORT_EXPORT_METHOD.include?(export_method) | ||
|
||
values = { | ||
:export_method => export_method, | ||
:workspace => ios_analyze.build_workspace, | ||
:configuration => Analyze::BUILD_CONFIGRATION, | ||
:scheme => target_scheme, | ||
:codesigning_identity => codesigning_identity | ||
} | ||
v = FastlaneCore::Configuration.create(Gym::Options.available_options, values) | ||
absolute_ipa_path = File.expand_path(Gym::Manager.new.work(v)) | ||
absolute_dsym_path = absolute_ipa_path.gsub(".ipa", ".app.dSYM.zip") # TODO: upload to deploygate | ||
|
||
absolute_ipa_path | ||
end | ||
|
||
# @param [String] path | ||
# @return [Boolean] | ||
def workspace?(path) | ||
WORK_DIR_EXTNAME == File.extname(path) | ||
end | ||
|
||
# @param [String] path | ||
# @return [Boolean] | ||
def project?(path) | ||
PROJECT_DIR_EXTNAME == File.extname(path) | ||
end | ||
|
||
def ios_root?(base_path) | ||
Find.find(base_path) do |path| | ||
next if path == base_path | ||
return true if workspace?(path) || project?(path) | ||
Find.prune if FileTest.directory?(path) | ||
end | ||
false | ||
end | ||
|
||
# @param [String] base_path | ||
# @param [Boolean] current_only | ||
# @return [Array] | ||
def find_workspaces(base_path) | ||
projects = [] | ||
Find.find(base_path) do |path| | ||
next if path == base_path | ||
if File.extname(path) == WORK_DIR_EXTNAME | ||
projects.push(path) | ||
end | ||
end | ||
|
||
projects | ||
end | ||
|
||
# @param [String] path | ||
# @return [String] | ||
def project_root_path(path) | ||
result = path | ||
if workspace?(path) || project?(path) | ||
result = project_root_path(File.dirname(path)) | ||
end | ||
result | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
module DeployGate | ||
module Builds | ||
module Ios | ||
class Analyze | ||
attr_reader :workspaces, :scheme_workspace, :build_workspace, :scheme | ||
|
||
class NotLocalProvisioningProfileError < StandardError | ||
end | ||
|
||
BASE_WORK_DIR_NAME = 'project.xcworkspace' | ||
BUILD_CONFIGRATION = 'Release' | ||
|
||
# @param [Array] workspaces | ||
# @return [DeployGate::Builds::Ios::Analyze] | ||
def initialize(workspaces) | ||
@workspaces = workspaces | ||
@scheme_workspace = find_scheme_workspace(workspaces) | ||
@build_workspace = find_build_workspace(workspaces) | ||
@xcodeproj = File.dirname(@scheme_workspace) | ||
|
||
config = FastlaneCore::Configuration.create(Gym::Options.available_options, {:workspace => @scheme_workspace}) | ||
project = FastlaneCore::Project.new(config) | ||
if project.schemes.empty? | ||
config = FastlaneCore::Configuration.create(Gym::Options.available_options, {:workspace => @build_workspace}) | ||
project = FastlaneCore::Project.new(config) | ||
end | ||
project.select_scheme | ||
@scheme = project.options[:scheme] | ||
end | ||
|
||
# @return [String] | ||
def target_bundle_identifier | ||
scheme_file = find_xcschemes | ||
xs = Xcodeproj::XCScheme.new(scheme_file) | ||
target_name = xs.profile_action.buildable_product_runnable.buildable_reference.target_name | ||
|
||
project = Xcodeproj::Project.open(@xcodeproj) | ||
target = project.native_targets.reject{|target| target.name != target_name}.first | ||
product_name = target.product_name | ||
conf = target.build_configuration_list.build_configurations.reject{|conf| conf.name != BUILD_CONFIGRATION}.first | ||
identifier = conf.build_settings['PRODUCT_BUNDLE_IDENTIFIER'] | ||
identifier.gsub!(/\$\(PRODUCT_NAME:.+\)/, product_name) | ||
|
||
identifier | ||
end | ||
|
||
private | ||
|
||
def find_xcschemes | ||
shared_schemes = Dir[File.join(@xcodeproj, 'xcshareddata', 'xcschemes', '*.xcscheme')].reject do |scheme| | ||
@scheme != File.basename(scheme, '.xcscheme') | ||
end | ||
user_schemes = Dir[File.join(@xcodeproj, 'xcuserdata', '*.xcuserdatad', 'xcschemes', '*.xcscheme')].reject do |scheme| | ||
@scheme != File.basename(scheme, '.xcscheme') | ||
end | ||
|
||
shared_schemes.concat(user_schemes).first | ||
end | ||
|
||
# @param [Array] workspaces | ||
# @return [String] | ||
def find_scheme_workspace(workspaces) | ||
return nil if workspaces.empty? | ||
return workspaces.first if workspaces.count == 1 | ||
|
||
select = nil | ||
workspaces.each do |workspace| | ||
if BASE_WORK_DIR_NAME == File.basename(workspace) | ||
select = workspace | ||
end | ||
end | ||
|
||
select | ||
end | ||
|
||
# @param [Array] workspaces | ||
# @return [String] | ||
def find_build_workspace(workspaces) | ||
return nil if workspaces.empty? | ||
return workspaces.first if workspaces.count == 1 | ||
|
||
select = nil | ||
workspaces.each do |workspace| | ||
if BASE_WORK_DIR_NAME != File.basename(workspace) | ||
select = workspace | ||
end | ||
end | ||
|
||
select | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.