Sha256: 887121c1af2c8a52b3a9d8a333b78710bd11d81d9928f7fbc0dd32ee7d455f05

Contents?: true

Size: 1.32 KB

Versions: 2

Compression:

Stored size: 1.32 KB

Contents

require 'pathname'

module Xcake
  # This generator processes the files to add to the project from the
  # `include_files` and `exclude_files`
  #
  class TargetFileReferenceGenerator < Generator
    def initialize(context)
      @context = context
    end

    def self.dependencies
      [TargetGenerator]
    end

    def visit_target(target)

      paths_to_include = Dir.glob(target.include_files).map { |f|
        Pathname.new(f).cleanpath.to_s
      }
      paths_to_exclude = Dir.glob(target.exclude_files).map { |f|
        Pathname.new(f).cleanpath.to_s
      }

      paths = paths_to_include - paths_to_exclude
      paths.each do |p|
        include_file_for_path_and_target(p, target) if PathClassifier.should_include_path?(p)
      end
    end

    private

    def include_file_for_path_and_target(path, target)
      file_reference = @context.file_reference_for_path(path)
      native_target = @context.native_object_for(target)

      build_phase_symbol = PathClassifier.classification_for_path(path)

      if PathClassifier.should_create_build_phase_for_classification?(build_phase_symbol)
        build_phase_class = Xcodeproj::Project::Object.const_get(build_phase_symbol)
        build_phase = native_target.build_phase_by_class(build_phase_class)
        build_phase.add_file_reference(file_reference)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
xcake-0.7.1 lib/xcake/generator/target_file_reference_generator.rb
xcake-0.7.0 lib/xcake/generator/target_file_reference_generator.rb