Class: Xcodeproj::Project::Object::AbstractBuildPhase Abstract

Inherits:
AbstractObject
  • Object
show all
Defined in:
lib/xcodeproj/project/object/build_phase.rb

Overview

This class is abstract.

This class is abstract and it doesn’t appear in the project document.

Attributes collapse

Attributes inherited from AbstractObject

#isa, #project, #uuid

Attributes collapse

Helpers collapse

Methods inherited from AbstractObject

#<=>, #==, #inspect, isa, #nested_object_for_hash, #pretty_print, #remove_from_project, #sort_recursively, #to_ascii_plist, #to_hash

Instance Attribute Details

#always_out_of_dateString

Note:

This setting is exposed in Xcode in the UI of PBXShellScriptBuildPhase as ‘Based on dependency analysis` (selected by default).

Returns whether or not this run script will be forced to run even on incremental builds. Can be either ‘1’, or missing. By default this option is disabled in Xcode.

Returns:

  • (String)

    whether or not this run script will be forced to run even on incremental builds. Can be either ‘1’, or missing. By default this option is disabled in Xcode.



41
# File 'lib/xcodeproj/project/object/build_phase.rb', line 41

attribute :always_out_of_date, String

#build_action_maskString

Returns some kind of magic number which usually is ‘2147483647’ (can be also ‘8` and `12` in PBXCopyFilesBuildPhase, one of the masks is run_only_for_deployment_postprocessing).

Returns:

  • (String)

    some kind of magic number which usually is ‘2147483647’ (can be also ‘8` and `12` in PBXCopyFilesBuildPhase, one of the masks is run_only_for_deployment_postprocessing).



21
# File 'lib/xcodeproj/project/object/build_phase.rb', line 21

attribute :build_action_mask, String, '2147483647'

#commentsString

Note:

This is apparently no longer used by Xcode.

Returns Comments associated with this build phase.

Returns:

  • (String)

    Comments associated with this build phase.



47
# File 'lib/xcodeproj/project/object/build_phase.rb', line 47

attribute :comments, String

#run_only_for_deployment_postprocessingString

Note:

This option is exposed in Xcode in the UI of PBXCopyFilesBuildPhase as ‘Copy only when installing` or in PBXShellScriptBuildPhase as `Run script only when installing`.

Returns whether or not this should only be processed before deployment. Can be either ‘0’, or ‘1’.

Returns:

  • (String)

    whether or not this should only be processed before deployment. Can be either ‘0’, or ‘1’.



31
# File 'lib/xcodeproj/project/object/build_phase.rb', line 31

attribute :run_only_for_deployment_postprocessing, String, '0'

Instance Method Details

#add_file_reference(file_ref, avoid_duplicates = false) ⇒ PBXBuildFile

Adds a new build file, initialized with the given file reference, to the phase.

Parameters:

  • file_ref (PBXFileReference)

    The file reference that should be added to the build phase.

Returns:



93
94
95
96
97
98
99
100
101
102
# File 'lib/xcodeproj/project/object/build_phase.rb', line 93

def add_file_reference(file_ref, avoid_duplicates = false)
  if avoid_duplicates && existing = build_file(file_ref)
    existing
  else
    build_file = project.new(PBXBuildFile)
    build_file.file_ref = file_ref
    files << build_file
    build_file
  end
end

#ascii_plist_annotationObject



145
146
147
# File 'lib/xcodeproj/project/object/build_phase.rb', line 145

def ascii_plist_annotation
  " #{display_name} "
end

#build_file(file_ref) ⇒ PBXBuildFile

Returns the first build file associated with the given file reference if one exists.

Returns:

  • (PBXBuildFile)

    the first build file associated with the given file reference if one exists.



71
72
73
# File 'lib/xcodeproj/project/object/build_phase.rb', line 71

def build_file(file_ref)
  (file_ref.referrers & files).first
end

#clearvoid Also known as: clear_build_files

This method returns an undefined value.

Removes all the build files from the phase and clears their relationship to the file reference.



134
135
136
137
138
# File 'lib/xcodeproj/project/object/build_phase.rb', line 134

def clear
  files.objects.each do |bf|
    remove_build_file(bf)
  end
end

#display_nameObject



141
142
143
# File 'lib/xcodeproj/project/object/build_phase.rb', line 141

def display_name
  super.gsub(/BuildPhase$/, '')
end

#file_display_namesArray<String>

Returns The display name of the build files.

Returns:

  • (Array<String>)

    The display name of the build files.



64
65
66
# File 'lib/xcodeproj/project/object/build_phase.rb', line 64

def file_display_names
  files.map(&:display_name)
end

#filesObjectList<PBXBuildFile>

Returns the files processed by this build configuration.

Returns:



14
# File 'lib/xcodeproj/project/object/build_phase.rb', line 14

has_many :files, PBXBuildFile

#files_referencesArray<PBXFileReference>

Returns the list of all the files referenced by this build phase.

Returns:

  • (Array<PBXFileReference>)

    the list of all the files referenced by this build phase.



58
59
60
# File 'lib/xcodeproj/project/object/build_phase.rb', line 58

def files_references
  files.map(&:file_ref)
end

#include?(file_ref) ⇒ Bool

Returns whether a build file for the given file reference exists.

Parameters:

Returns:

  • (Bool)

    whether the reference is already present.



81
82
83
# File 'lib/xcodeproj/project/object/build_phase.rb', line 81

def include?(file_ref)
  !build_file(file_ref).nil?
end

#remove_build_file(build_file) ⇒ void

This method returns an undefined value.

Removes a build file from the phase and clears its relationship to the file reference.

Parameters:



124
125
126
127
# File 'lib/xcodeproj/project/object/build_phase.rb', line 124

def remove_build_file(build_file)
  build_file.file_ref = nil
  build_file.remove_from_project
end

#remove_file_reference(file_ref) ⇒ void

This method returns an undefined value.

Removes the build file associated with the given file reference from the phase.

Parameters:



112
113
114
115
# File 'lib/xcodeproj/project/object/build_phase.rb', line 112

def remove_file_reference(file_ref)
  build_file = files.find { |bf| bf.file_ref == file_ref }
  remove_build_file(build_file) if build_file
end

#sort(_options = nil) ⇒ void

This method returns an undefined value.

Sorts the build files of the phase according to the display name or the path.

Parameters:

  • _options (Hash) (defaults to: nil)

    Not used.



157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/xcodeproj/project/object/build_phase.rb', line 157

def sort(_options = nil)
  files.sort! do |x, y|
    result = File.basename(x.display_name.downcase, '.*') <=> File.basename(y.display_name.downcase, '.*')
    if result.zero?
      result = File.extname(x.display_name.downcase) <=> File.extname(y.display_name.downcase)
      if result.zero? && x.file_ref.respond_to?(:full_path) && y.file_ref.respond_to?(:full_path)
        result = x.file_ref.full_path.to_s.downcase <=> y.file_ref.full_path.to_s.downcase
      end
    end
    result
  end
end