Class: HMap::Workspace

Inherits:
Object
  • Object
show all
Defined in:
lib/hmap/xc/workspace/workspace.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(save_setting, projects) ⇒ Workspace

Returns a new instance of Workspace.



29
30
31
32
# File 'lib/hmap/xc/workspace/workspace.rb', line 29

def initialize(save_setting, projects)
  @save_setting = save_setting
  @projects = projects.map { |project| Project.new(project, self) }
end

Instance Attribute Details

#projectsObject (readonly)

Returns the value of attribute projects.



9
10
11
# File 'lib/hmap/xc/workspace/workspace.rb', line 9

def projects
  @projects
end

#save_settingObject (readonly)

Returns the value of attribute save_setting.



9
10
11
# File 'lib/hmap/xc/workspace/workspace.rb', line 9

def save_setting
  @save_setting
end

Class Method Details

.new_from_xcprojects(paths) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/hmap/xc/workspace/workspace.rb', line 21

def self.new_from_xcprojects(paths)
  paths.map do |path|
    ss = ProjectProductPath.new(path)
    projects = PBXHelper.projects(path)
    new(ss, projects)
  end
end

.new_from_xcworkspaces(paths) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/hmap/xc/workspace/workspace.rb', line 11

def self.new_from_xcworkspaces(paths)
  paths.flat_map do |path|
    xc = Xcodeproj::Workspace.new_from_xcworkspace(path)
    schemes = xc.schemes.values.uniq || []
    ss = WorkspaceProductPath.new(path)
    projects = PBXHelper.projects(*schemes)
    new(ss, projects)
  end
end

Instance Method Details

#all_target_headersObject



80
81
82
83
84
# File 'lib/hmap/xc/workspace/workspace.rb', line 80

def all_target_headers
  @projects.flat_map(&:targets).inject({}) do |sum, entry|
    sum.merge!(entry.all_target_headers) { |_, v1, _| v1 }
  end
end

#build_rootObject



34
35
36
# File 'lib/hmap/xc/workspace/workspace.rb', line 34

def build_root
  save_setting.build_root
end

#hmap_rootObject



50
51
52
53
54
# File 'lib/hmap/xc/workspace/workspace.rb', line 50

def hmap_root
  # dir = build_root.dirname.dirname
  dir = workspace_dir
  File.join(dir, Constants::HMAP_DIR)
end

#nameObject



42
43
44
# File 'lib/hmap/xc/workspace/workspace.rb', line 42

def name
  save_setting.name
end

#obj_rootObject



38
39
40
# File 'lib/hmap/xc/workspace/workspace.rb', line 38

def obj_root
  save_setting.obj_root
end

#remove_hmap_settings!Object



74
75
76
77
78
# File 'lib/hmap/xc/workspace/workspace.rb', line 74

def remove_hmap_settings!
  UserInterface.puts('[hmapfile] Cleanning hmap settings')
  FileUtils.rm_rf(hmap_root) if Dir.exist?(hmap_root)
  projects.each(&:remove_hmap_settings!)
end

#save_hmap_settings!Object



68
69
70
71
72
# File 'lib/hmap/xc/workspace/workspace.rb', line 68

def save_hmap_settings!
  UserInterface.puts('[hmapfile] Saving hmap settings')

  projects.each(&:save_hmap_settings!)
end

#workspace_dirObject



46
47
48
# File 'lib/hmap/xc/workspace/workspace.rb', line 46

def workspace_dir
  File.dirname(save_setting.path)
end

#write_hmapfile!Object



63
64
65
66
# File 'lib/hmap/xc/workspace/workspace.rb', line 63

def write_hmapfile!
  UserInterface.puts('[hmapfile] Starting generate hmap file')
  projects.each(&:write_hmapfile!)
end

#write_save!Object



56
57
58
59
60
61
# File 'lib/hmap/xc/workspace/workspace.rb', line 56

def write_save!
  UserInterface.puts('[hmapfile] Got workspace/project build directory')
  UserInterface.puts("[hmapfile] #{name} hmapfile gen directory: #{hmap_root} ")
  write_hmapfile!
  save_hmap_settings!
end

#xcconfig_pathsObject



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/hmap/xc/workspace/workspace.rb', line 86

def xcconfig_paths
  return @xcconfig_paths if defined?(@xcconfig_paths)

  @xcconfig_paths = projects.flat_map do |project|
    project.targets.flat_map do |target|
      target.target.build_configurations.map do |configuration|
        next unless configuration.is_a?(Constants::XCBuildConfiguration)

        bcr = configuration.base_configuration_reference
        next if bcr.nil?

        s_path = PBXHelper.group_paths(bcr)
        x = bcr.instance_variable_get('@simple_attributes_hash')['path'] || ''
        path = File.expand_path(File.join(project.project_dir, s_path, x))
        target.xcconfig_paths << path
        path
      end.compact
    end
  end.uniq
end