Class: Zewo::App::Repo

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, data = nil) ⇒ Repo

Returns a new instance of Repo.



28
29
30
31
# File 'lib/zewo.rb', line 28

def initialize(name, data = nil)
  @name = name
  @data = data
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



23
24
25
# File 'lib/zewo.rb', line 23

def data
  @data
end

#nameObject (readonly)

Returns the value of attribute name.



21
22
23
# File 'lib/zewo.rb', line 21

def name
  @name
end

Instance Method Details

#add_files(direc, current_group, main_target) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/zewo.rb', line 80

def add_files(direc, current_group, main_target)
  Dir.glob(direc) do |item|
    next if item == '.' || item == '.DS_Store'

    if File.directory?(item)
      new_folder = File.basename(item)
      created_group = current_group.new_group(new_folder)
      add_files("#{item}/*", created_group, main_target)
    else
      item = item.split('/')[1..-1].unshift('..') * '/'
      i = current_group.new_file(item)
      main_target.add_file_references([i]) if item.include? '.swift'
    end
  end
end

#build_dependenciesObject



96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/zewo.rb', line 96

def build_dependencies
  puts "Configuring dependencies for #{name}".green
  dependency_repos = File.read(dir('Package.swift')).scan(/(?<=Zewo\/|SwiftX\/|VeniceX\/|paulofaria\/)(.*?)(?=\.git)/).map(&:first)
  group = xcode_project.new_group('Subprojects')
  dependency_repos.each do |repo_name|
    next if repo_name.end_with?('-OSX')

    repo = Repo.new(repo_name)
    project_reference = group.new_file(repo.xcode_project_path.to_s)
    project_reference.path = "../../#{project_reference.path}"
    framework_target.add_dependency(repo.framework_target) if framework_target
  end
  xcode_project.save
end

#configure_xcode_projectObject



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/zewo.rb', line 111

def configure_xcode_project
  @xcodeproj = nil
  silent_cmd("rm -rf #{dir(xcode_dirname)}")

  puts "Creating Xcode project #{name}".green

  framework_target.build_configurations.each do |configuration|
    framework_target.build_settings(configuration.name)['HEADER_SEARCH_PATHS'] = '/usr/local/include'
    framework_target.build_settings(configuration.name)['LIBRARY_SEARCH_PATHS'] = '/usr/local/lib'
    framework_target.build_settings(configuration.name)['ENABLE_TESTABILITY'] = 'YES'

    if File.exist?(dir('module.modulemap'))
      framework_target.build_settings(configuration.name)['MODULEMAP_FILE'] = '../module.modulemap'
    end
  end

  framework_target.frameworks_build_phase.clear

  xcode_project.new_file('../module.modulemap') if File.exist?(dir('module.modulemap'))

  if sources_dirname
    group = xcode_project.new_group(sources_dirname)
    add_files(dir("#{sources_dirname}/*"), group, framework_target)
  end

  test_target.resources_build_phase
  test_target.add_dependency(framework_target)

  test_target.build_configurations.each do |configuration|
    test_target.build_settings(configuration.name)['WRAPPER_EXTENSION'] = 'xctest'
    test_target.build_settings(configuration.name)['LD_RUNPATH_SEARCH_PATHS'] = '$(inherited) @executable_path/../../Frameworks @loader_path/../Frameworks'
    test_target.build_settings(configuration.name)['HEADER_SEARCH_PATHS'] = '/usr/local/include'
    test_target.build_settings(configuration.name)['LIBRARY_SEARCH_PATHS'] = '/usr/local/lib'
  end

  group = xcode_project.new_group(tests_dirname)
  add_files(dir("#{tests_dirname}/*"), group, test_target)

  xcode_project.save

  scheme = Xcodeproj::XCScheme.new
  scheme.configure_with_targets(framework_target, test_target)
  scheme.test_action.code_coverage_enabled = true
  scheme.save_as(xcode_project.path, framework_target.name, true)
end

#dir(ext = nil) ⇒ Object



47
48
49
50
51
# File 'lib/zewo.rb', line 47

def dir(ext = nil)
  r = name
  r = "#{r}/#{ext}" if ext
  r
end

#framework_targetObject



33
34
35
36
37
38
39
40
# File 'lib/zewo.rb', line 33

def framework_target
  target_name = name.gsub('-OSX', '').gsub('-', '_')

  if target_name == 'OS'
    target_name = 'OperatingSystem'
  end
  xcode_project.native_targets.find { |t| t.name == target_name } || xcode_project.new_target(:framework, target_name, :osx)
end

#sources_dirnameObject



65
66
67
68
# File 'lib/zewo.rb', line 65

def sources_dirname
  return 'Sources' if File.directory?(dir('Sources'))
  return 'Source'  if File.directory?(dir('Source'))
end

#test_targetObject



42
43
44
45
# File 'lib/zewo.rb', line 42

def test_target
  target_name = "#{framework_target.name}-Test"
  xcode_project.native_targets.find { |t| t.name == target_name } || xcode_project.new_target(:bundle, target_name, :osx)
end

#tests_dirnameObject



53
54
55
# File 'lib/zewo.rb', line 53

def tests_dirname
  'Tests'
end

#xcode_dirnameObject



57
58
59
# File 'lib/zewo.rb', line 57

def xcode_dirname
  'XcodeDevelopment'
end

#xcode_projectObject



70
71
72
73
74
75
76
77
78
# File 'lib/zewo.rb', line 70

def xcode_project
  return @xcodeproj if @xcodeproj
  if File.exist?(xcode_project_path)
    @xcodeproj = Xcodeproj::Project.open(xcode_project_path)
  else
    @xcodeproj = Xcodeproj::Project.new(xcode_project_path)
  end
  @xcodeproj
end

#xcode_project_pathObject



61
62
63
# File 'lib/zewo.rb', line 61

def xcode_project_path
  dir("#{xcode_dirname}/#{name}.xcodeproj")
end