Class: XcodeprojUtils::Project

Inherits:
Object
  • Object
show all
Defined in:
lib/xcodeproj_utils.rb

Instance Method Summary collapse

Constructor Details

#initialize(proj_name, target_name) ⇒ Project

Returns a new instance of Project.

Raises:

  • (ArgumentError)


6
7
8
9
10
11
12
13
14
15
# File 'lib/xcodeproj_utils.rb', line 6

def initialize(proj_name, target_name)
  @proj = Xcodeproj::Project::open(proj_name)
  @target = @proj.targets.select {|target| target.name == target_name}
  for t in @proj.targets
    next if t.name != target_name
    @target = t
    break
  end
  raise ArgumentError, "#{target_name} is not found in #{proj_name}" if @target.empty?
end

Instance Method Details

#show(kind, fullpath = false) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/xcodeproj_utils.rb', line 49

def show(kind, fullpath=false)
  if kind == 'resource'
    files = @target.resources_build_phase.files_references
  elsif kind == 'source'
    files = @target.source_build_phase.files_references
  end

  if files
    for file in files
      if fullpath
        puts file.real_path
      else
        puts file.path
      end
    end
  end
  return nil
end

#wc(header_only = false, source_only = false) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/xcodeproj_utils.rb', line 17

def wc(header_only=false, source_only=false)
  all = !(header_only || source_only) # default is all
  count_source = lambda do
    sources = []
    for file in @target.source_build_phase.files_references
      if file.last_known_file_type and file.last_known_file_type.include? "sourcecode"
        sources.push("'#{file.real_path}'")
      end
    end
    file_params = sources.join(' ')
    source_total = %x{wc -l #{file_params}}
    return source_total.lines[-1].split.first.to_i
  end

  count_header = lambda do
    headers = []
    for file in @proj.files
      if file.path.end_with? ".h"
        headers.push("'#{file.real_path}'")
      end
    end
    file_params = headers.join(' ')
    header_total = %x{wc -l #{file_params}}
    return header_total.lines[-1].split.first.to_i
  end

  source_total = header_total = 0
  source_total = count_source.call if all or source_only
  header_total = count_header.call if all or header_only
  source_total + header_total
end