Skip to content

Commit

Permalink
Serialize schemes the same way Xcode does
Browse files Browse the repository at this point in the history
  • Loading branch information
segiddins committed Jan 15, 2021
1 parent 3adafad commit bfe0a6d
Show file tree
Hide file tree
Showing 30 changed files with 153 additions and 199 deletions.
73 changes: 43 additions & 30 deletions .rubocop_todo.yml
@@ -1,45 +1,52 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2016-03-10 12:10:23 -0600 using RuboCop version 0.38.0.
# on 2021-01-15 10:50:09 -0800 using RuboCop version 0.47.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 13
# Offense count: 2
Lint/IneffectiveAccessModifier:
Exclude:
- 'lib/xcodeproj/differ.rb'
- 'lib/xcodeproj/plist/ffi/core_foundation.rb'
- 'lib/xcodeproj/plist/ffi/dev_tools_core.rb'
- 'lib/xcodeproj/xcodebuild_helper.rb'

# Offense count: 1
Lint/NestedMethodDefinition:
Exclude:
- 'spec/project/project_helper_integration_spec.rb'

# Offense count: 2
# Cop supports --auto-correct.
Lint/UnneededDisable:
Exclude:
- 'spec/plist_helper_spec.rb'
- 'spec/xcodebuild_helper_spec.rb'

# Offense count: 33
# Offense count: 29
# Configuration parameters: ContextCreatingMethods, MethodCreatingMethods.
Lint/UselessAccessModifier:
Enabled: false
Exclude:
- 'lib/xcodeproj/config.rb'
- 'lib/xcodeproj/differ.rb'
- 'lib/xcodeproj/project.rb'
- 'lib/xcodeproj/project/object.rb'
- 'lib/xcodeproj/project/object/build_configuration.rb'
- 'lib/xcodeproj/project/object/build_file.rb'
- 'lib/xcodeproj/project/object/build_phase.rb'
- 'lib/xcodeproj/project/object/configuration_list.rb'
- 'lib/xcodeproj/project/object/file_reference.rb'
- 'lib/xcodeproj/project/object/group.rb'
- 'lib/xcodeproj/project/object/native_target.rb'
- 'lib/xcodeproj/project/object/reference_proxy.rb'
- 'lib/xcodeproj/project/object/target_dependency.rb'
- 'lib/xcodeproj/project/object_list.rb'
- 'lib/xcodeproj/scheme.rb'

# Offense count: 881
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
# Offense count: 1365
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Metrics/LineLength:
Max: 186

# Offense count: 2
# Offense count: 3
# Configuration parameters: CountKeywordArgs.
Metrics/ParameterLists:
Max: 7
Max: 8

# Offense count: 1
# Cop supports --auto-correct.
Expand All @@ -54,7 +61,7 @@ Performance/RedundantMerge:
Exclude:
- 'spec/config_spec.rb'

# Offense count: 10
# Offense count: 12
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: prefer_alias, prefer_alias_method
Expand All @@ -69,50 +76,55 @@ Style/Alias:
- 'lib/xcodeproj/workspace/file_reference.rb'
- 'lib/xcodeproj/workspace/group_reference.rb'

# Offense count: 3
# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: SingleLineConditionsOnly.
# Configuration parameters: EnforcedStyle, SupportedStyles, SingleLineConditionsOnly, IncludeTernaryExpressions.
# SupportedStyles: assign_to_condition, assign_inside_condition
Style/ConditionalAssignment:
Exclude:
- 'lib/xcodeproj/config.rb'
- 'lib/xcodeproj/plist/ffi.rb'
- 'lib/xcodeproj/project/object_attributes.rb'

# Offense count: 98
# Offense count: 100
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: leading, trailing
Style/DotPosition:
Enabled: false
Exclude:
- 'lib/xcodeproj/project.rb'
- 'spec/scheme/environment_variables_spec.rb'
- 'spec/scheme_spec.rb'

# Offense count: 2
Style/IdenticalConditionalBranches:
Exclude:
- 'lib/xcodeproj/project.rb'

# Offense count: 83
# Offense count: 95
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth.
# SupportedStyles: aligned, indented
# SupportedStyles: aligned, indented, indented_relative_to_receiver
Style/MultilineMethodCallIndentation:
Enabled: false
Exclude:
- 'spec/scheme/environment_variables_spec.rb'
- 'spec/scheme_spec.rb'

# Offense count: 14
# Offense count: 12
# Cop supports --auto-correct.
Style/MutableConstant:
Exclude:
- 'lib/xcodeproj/constants.rb'
- 'lib/xcodeproj/plist.rb'
- 'lib/xcodeproj/plist/ffi/core_foundation.rb'
- 'lib/xcodeproj/scheme/environment_variables.rb'
- 'spec/xcodebuild_helper_spec.rb'

# Offense count: 4
# Cop supports --auto-correct.
Style/NestedParenthesizedCalls:
Exclude:
- 'spec/scheme_spec.rb'

# Offense count: 4
# Offense count: 5
# Cop supports --auto-correct.
Style/RedundantSelf:
Exclude:
Expand All @@ -121,7 +133,7 @@ Style/RedundantSelf:
- 'lib/xcodeproj/project/object.rb'
- 'lib/xcodeproj/project/object/group.rb'

# Offense count: 3
# Offense count: 4
# Cop supports --auto-correct.
# Configuration parameters: AllowForAlignment.
Style/SpaceAroundOperators:
Expand All @@ -136,6 +148,7 @@ Style/UnneededInterpolation:
- 'lib/xcodeproj/workspace/group_reference.rb'

# Offense count: 2
# Cop supports --auto-correct.
Style/ZeroLengthPredicate:
Exclude:
- 'lib/xcodeproj/scheme.rb'
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -18,6 +18,10 @@
* Update Swift packages annotations to match Xcode
[Tommaso Madonia](https://github.com/Frugghi)

* Update format of generated schemes to match the ordering Xcode uses,
minimizing the amount of time it takes to open projects in Xcode.
[Samuel Giddins](https://github.com/segiddins)


## 1.19.0 (2020-10-09)

Expand Down
10 changes: 6 additions & 4 deletions lib/xcodeproj/project.rb
Expand Up @@ -711,9 +711,10 @@ def new_group(name, path = nil, source_tree = :group)
#
# @return [PBXNativeTarget] the target.
#
def new_target(type, name, platform, deployment_target = nil, product_group = nil, language = nil)
def new_target(type, name, platform, deployment_target = nil, product_group = nil, language = nil, product_basename = nil)
product_group ||= products_group
ProjectHelper.new_target(self, type, name, platform, deployment_target, product_group, language)
product_basename ||= name
ProjectHelper.new_target(self, type, name, platform, deployment_target, product_group, language, product_basename)
end

# Creates a new resource bundles target and adds it to the project.
Expand All @@ -731,9 +732,10 @@ def new_target(type, name, platform, deployment_target = nil, product_group = ni
#
# @return [PBXNativeTarget] the target.
#
def new_resources_bundle(name, platform, product_group = nil)
def new_resources_bundle(name, platform, product_group = nil, product_basename = nil)
product_group ||= products_group
ProjectHelper.new_resources_bundle(self, name, platform, product_group)
product_basename ||= name
ProjectHelper.new_resources_bundle(self, name, platform, product_group, product_basename)
end

# Creates a new target and adds it to the project.
Expand Down
12 changes: 6 additions & 6 deletions lib/xcodeproj/project/object/group.rb
Expand Up @@ -226,24 +226,24 @@ def new_reference(path, source_tree = :group)
# Creates a file reference to a static library and adds it to the
# group.
#
# @param [#to_s] product_name
# @param [#to_s] product_basename
# The name of the static library.
#
# @return [PBXFileReference] The new file reference.
#
def new_product_ref_for_target(target_name, product_type)
FileReferencesFactory.new_product_ref_for_target(self, target_name, product_type)
def new_product_ref_for_target(product_basename, product_type)
FileReferencesFactory.new_product_ref_for_target(self, product_basename, product_type)
end

# Creates a file reference to a new bundle.
#
# @param [#to_s] product_name
# @param [#to_s] product_basename
# The name of the bundle.
#
# @return [PBXFileReference] The new file reference.
#
def new_bundle(product_name)
FileReferencesFactory.new_bundle(self, product_name)
def new_bundle(product_basename)
FileReferencesFactory.new_bundle(self, product_basename)
end

# Creates a file reference to a new bundle and adds it to the group.
Expand Down
12 changes: 6 additions & 6 deletions lib/xcodeproj/project/object/helpers/file_references_factory.rb
Expand Up @@ -42,17 +42,17 @@ def new_reference(group, path, source_tree)
# @param [PBXGroup] group
# The group to which to add the reference.
#
# @param [#to_s] product_name
# @param [#to_s] product_basename
# The name of the static library.
#
# @return [PBXFileReference] The new file reference.
#
def new_product_ref_for_target(group, target_name, product_type)
def new_product_ref_for_target(group, product_basename, product_type)
if product_type == :static_library
prefix = 'lib'
end
extension = Constants::PRODUCT_UTI_EXTENSIONS[product_type]
path = "#{prefix}#{target_name}"
path = "#{prefix}#{product_basename}"
path += ".#{extension}" if extension
ref = new_reference(group, path, :built_products)
ref.include_in_index = '0'
Expand All @@ -66,13 +66,13 @@ def new_product_ref_for_target(group, target_name, product_type)
# @param [PBXGroup] group
# The group to which to add the reference.
#
# @param [#to_s] product_name
# @param [#to_s] product_basename
# The name of the bundle.
#
# @return [PBXFileReference] The new file reference.
#
def new_bundle(group, product_name)
ref = new_reference(group, "#{product_name}.bundle", :built_products)
def new_bundle(group, product_basename)
ref = new_reference(group, "#{product_basename}.bundle", :built_products)
ref.include_in_index = '0'
ref.set_explicit_file_type('wrapper.cfbundle')
ref
Expand Down
12 changes: 6 additions & 6 deletions lib/xcodeproj/project/project_helper.rb
Expand Up @@ -41,17 +41,17 @@ module ProjectHelper
#
# @return [PBXNativeTarget] the target.
#
def self.new_target(project, type, name, platform, deployment_target, product_group, language)
def self.new_target(project, type, name, platform, deployment_target, product_group, language, product_basename)
# Target
target = project.new(PBXNativeTarget)
project.targets << target
target.name = name
target.product_name = name
target.product_name = product_basename
target.product_type = Constants::PRODUCT_TYPE_UTI[type]
target.build_configuration_list = configuration_list(project, platform, deployment_target, type, language)

# Product
product = product_group.new_product_ref_for_target(name, type)
product = product_group.new_product_ref_for_target(target.product_name, type)
target.product_reference = product

# Build phases
Expand Down Expand Up @@ -88,12 +88,12 @@ def self.new_target(project, type, name, platform, deployment_target, product_gr
#
# @return [PBXNativeTarget] the target.
#
def self.new_resources_bundle(project, name, platform, product_group)
def self.new_resources_bundle(project, name, platform, product_group, product_basename)
# Target
target = project.new(PBXNativeTarget)
project.targets << target
target.name = name
target.product_name = name
target.product_name = product_basename
target.product_type = Constants::PRODUCT_TYPE_UTI[:bundle]

# Configuration List
Expand All @@ -111,7 +111,7 @@ def self.new_resources_bundle(project, name, platform, product_group)
target.build_configuration_list = cl

# Product
product = product_group.new_bundle(name)
product = product_group.new_bundle(target.product_name)
target.product_reference = product

# Build phases
Expand Down
2 changes: 1 addition & 1 deletion lib/xcodeproj/scheme.rb
Expand Up @@ -224,7 +224,7 @@ def set_launch_target(build_target)
launch_runnable = BuildableProductRunnable.new(build_target, 0)
launch_action.buildable_product_runnable = launch_runnable

profile_runnable = BuildableProductRunnable.new(build_target)
profile_runnable = BuildableProductRunnable.new(build_target, 0)
profile_action.buildable_product_runnable = profile_runnable

macro_exp = MacroExpansion.new(build_target)
Expand Down
2 changes: 1 addition & 1 deletion lib/xcodeproj/scheme/build_action.rb
Expand Up @@ -189,11 +189,11 @@ def initialize(target_or_node = nil)
is_app_target = app_types.include?(target_or_node.product_type)
end

self.build_for_analyzing = true
self.build_for_testing = is_test_target
self.build_for_running = is_app_target
self.build_for_profiling = is_app_target
self.build_for_archiving = is_app_target
self.build_for_analyzing = true

add_buildable_reference BuildableReference.new(target_or_node) if target_or_node
end
Expand Down
4 changes: 2 additions & 2 deletions lib/xcodeproj/scheme/launch_action.rb
Expand Up @@ -11,6 +11,8 @@ class LaunchAction < AbstractSchemeAction
#
def initialize(node = nil)
create_xml_element_with_fallback(node, 'LaunchAction') do
self.build_configuration = 'Debug'

# Add some attributes (that are not handled by this wrapper class yet but expected in the XML)
@xml_element.attributes['selectedDebuggerIdentifier'] = 'Xcode.DebuggerFoundation.Debugger.LLDB'
@xml_element.attributes['selectedLauncherIdentifier'] = 'Xcode.DebuggerFoundation.Launcher.LLDB'
Expand All @@ -19,10 +21,8 @@ def initialize(node = nil)
@xml_element.attributes['ignoresPersistentStateOnLaunch'] = bool_to_string(false)
@xml_element.attributes['debugDocumentVersioning'] = bool_to_string(true)
@xml_element.attributes['debugServiceExtension'] = 'internal'
@xml_element.add_element('AdditionalOptions')

# Setup default values for other (handled) attributes
self.build_configuration = 'Debug'
self.allow_location_simulation = true
end
end
Expand Down
10 changes: 5 additions & 5 deletions lib/xcodeproj/scheme/profile_action.rb
Expand Up @@ -11,14 +11,14 @@ class ProfileAction < AbstractSchemeAction
#
def initialize(node = nil)
create_xml_element_with_fallback(node, 'ProfileAction') do
# Setup default values for other (handled) attributes
self.build_configuration = 'Release'
self.should_use_launch_scheme_args_env = true

# Add some attributes (that are not handled by this wrapper class yet but expected in the XML)
@xml_element.attributes['savedToolIdentifier'] = ''
@xml_element.attributes['useCustomWorkingDirectory'] = bool_to_string(false)
@xml_element.attributes['debugDocumentVersioning'] = bool_to_string(true)

# Setup default values for other (handled) attributes
self.build_configuration = 'Release'
self.should_use_launch_scheme_args_env = true
end
end

Expand All @@ -42,7 +42,7 @@ def should_use_launch_scheme_args_env=(flag)
# The BuildableProductRunnable to launch when launching the Profile action
#
def buildable_product_runnable
BuildableProductRunnable.new @xml_element.elements['BuildableProductRunnable']
BuildableProductRunnable.new @xml_element.elements['BuildableProductRunnable'], 0
end

# @param [BuildableProductRunnable] runnable
Expand Down

0 comments on commit bfe0a6d

Please sign in to comment.