Class: GCPT::BuildReport::Reporter

Inherits:
Object
  • Object
show all
Defined in:
lib/gcpt/build_report/reporter.rb

Instance Method Summary collapse

Constructor Details

#initializeReporter

Returns a new instance of Reporter.



12
13
14
15
# File 'lib/gcpt/build_report/reporter.rb', line 12

def initialize()
  super
  # @options = options
end

Instance Method Details

#_add_logs(build_log) ⇒ Object



205
206
207
208
209
210
211
212
213
214
215
216
# File 'lib/gcpt/build_report/reporter.rb', line 205

def _add_logs(build_log)
  # snap
  if @app_id == '262304'
    gsdk_dir = Pathname.new(ENV['PROJECT_DIR']).join('GMSDK/gsdk')
    build_log << 'gsdk_dir:'
    build_log.concat Dir.children(gsdk_dir)

    res_file = gsdk_dir.join('gsdk_resources.txt')
    build_log << 'res file:'
    build_log << File.read(res_file)
  end
end

#_collect_base_infoObject



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/gcpt/build_report/reporter.rb', line 94

def _collect_base_info()
  base_info = BaseInfo.new
  base_info.app_version = ENV['MARKETING_VERSION'] || get_product_plist_value('CFBundleShortVersionString')
  base_info.build_version = ENV['CURRENT_PROJECT_VERSION'] || get_product_plist_value('CFBundleVersion')
  base_info.project_type = @is_app ? 'application' : 'library'
  base_info.gsdk_version = @gsdk_build_info['version']

  # parse region
  begin
    base_info.region = 'known'
    if !game_config.empty?
      case game_config['serverRegion']
      when 10, 20
        base_info.region = 'i18n'
      when 0, nil
        base_info.region = 'cn'
      end
    end
  end

  # parse languages
  Dir.chdir(app_path) do
    base_info.languages = Dir.glob('*.lproj').map { |name|
      File.basename(name, '.lproj')
    }.join(',')
  end

  _parse_engine(base_info)

  base_info
end

#_collect_build_logObject



218
219
220
221
222
# File 'lib/gcpt/build_report/reporter.rb', line 218

def _collect_build_log()
  build_log = []
  _add_logs(build_log)
  build_log
end

#_collect_build_spendsObject



224
225
226
227
# File 'lib/gcpt/build_report/reporter.rb', line 224

def _collect_build_spends()
  build_spends = []
  build_spends
end

#_collect_env_infoObject



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/gcpt/build_report/reporter.rb', line 158

def _collect_env_info()
  env_info = ENVInfo.new

  env_info.env = ENV.keys.sort().map do |name|
    "#{name}=#{ENV[name]}"
  end.join("\n")

  _parse_cmd('sw_vers', []) do |result|
    env_info.os = _parse_regex(/ProductName:(.*)/, result, 1)
    env_info.os_version = _parse_regex(/ProductVersion:(.*)/, result, 1)
  end

  _parse_cmd('system_profiler', ['SPHardwareDataType']) do |result|
    env_info.machine = _parse_regex(/Model Identifier:(.*)/, result, 1)
    env_info.device_id = _parse_regex(/Hardware UUID:(.*)/, result, 1)
  end

  _parse_deps_tool(env_info)

  env_info
end

#_collect_gsdk_infoObject



135
136
137
138
139
# File 'lib/gcpt/build_report/reporter.rb', line 135

def _collect_gsdk_info()
  sdk_info = GsdkInfo.new
  sdk_info.build_info = @gsdk_build_info
  sdk_info
end

#_collect_project_infoObject



187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'lib/gcpt/build_report/reporter.rb', line 187

def _collect_project_info()
  project_info = ProjectInfo.new
  project_info.info_plist = plist_content
  project_info.game_config = game_config
  project_info.build_config = ENV['CONFIGURATION']
  project_info.build_settings = @host_target.build_settings(project_info.build_config)

  # parse entitlement
  if ENV['CODE_SIGN_ENTITLEMENTS']
    entitlement_path = Pathname.new(ENV['PROJECT_DIR']).join(ENV['CODE_SIGN_ENTITLEMENTS'])
    if entitlement_path.exist?
      project_info.entitlement = File.read(entitlement_path)
    end
  end

  project_info
end

#_collect_report_infoObject



229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
# File 'lib/gcpt/build_report/reporter.rb', line 229

def _collect_report_info()
  report_info = ReportInfo.new
  report_info.application_id = ENV['PRODUCT_BUNDLE_IDENTIFIER'] || get_product_plist_value('CFBundleIdentifier')
  @app_id = game_config['appId']
  report_info.app_id = @app_id

  report_info.base_info = self._collect_base_info()
  report_info.gsdk_info = self._collect_gsdk_info()
  report_info.env_info = self._collect_env_info()
  report_info.project_info = self._collect_project_info()
  report_info.build_log = self._collect_build_log()
  report_info.build_spends = self._collect_build_spends()
  report_info.build_result = 'success'
  report_info
end

#_parse_cmd(cmd, args) ⇒ Object



151
152
153
154
155
156
# File 'lib/gcpt/build_report/reporter.rb', line 151

def _parse_cmd(cmd, args)
  result = Executable.execute_command(cmd, args, false)
  if result && block_given?
    yield result
  end
end

#_parse_deps_tool(env_info) ⇒ Object



180
181
182
183
184
185
# File 'lib/gcpt/build_report/reporter.rb', line 180

def _parse_deps_tool(env_info)
  env_info.deps_tool = 'unknown'
  if ENV['PODS_ROOT'] && File.exist?(ENV['PODS_ROOT'])
    env_info.deps_tool = 'cocoapods'
  end
end

#_parse_engine(base_info) ⇒ Object



126
127
128
129
130
131
132
133
# File 'lib/gcpt/build_report/reporter.rb', line 126

def _parse_engine(base_info)
  build_settings = @host_target.build_settings(ENV['CONFIGURATION'])
  base_info.engine_type = 'unknown'
  if build_settings['UNITY_RUNTIME_VERSION']
    base_info.engine_type = 'unity'
    base_info.engine_version = build_settings['UNITY_RUNTIME_VERSION']
  end
end

#_parse_regex(regex, text, group_index) ⇒ Object



141
142
143
144
145
146
147
148
149
# File 'lib/gcpt/build_report/reporter.rb', line 141

def _parse_regex(regex, text, group_index)
  if text
    result = regex.match(text)[group_index]
    if result
      return result.strip
    end
  end
  nil
end

#app_pathObject



90
91
92
# File 'lib/gcpt/build_report/reporter.rb', line 90

def app_path()
  ENV['CODESIGNING_FOLDER_PATH']
end

#find_gsdk_in_appObject



38
39
40
41
# File 'lib/gcpt/build_report/reporter.rb', line 38

def find_gsdk_in_app()
  framework__path = Pathname.new(@product_path).join('Frameworks/BD_GameSDK_iOS.framework')
  framework__path.exist? && framework__path || nil
end

#find_gsdk_in_search_pathsObject



43
44
45
46
47
48
49
50
51
# File 'lib/gcpt/build_report/reporter.rb', line 43

def find_gsdk_in_search_paths()
  paths = Helper::split_build_setting_array_to_string(ENV['FRAMEWORK_SEARCH_PATHS']) || []
  paths.find { |pa|
    if pa[0] == '"' && pa[-1] == '"'
      pa = pa[1...-1]
    end
    Pathname.new(pa).join('BD_GameSDK_iOS.framework').exist?
  }
end

#game_configObject



86
87
88
# File 'lib/gcpt/build_report/reporter.rb', line 86

def game_config()
  product_plist && product_plist['GameConfig'] || {}
end

#get_product_plist_value(key) ⇒ Object



78
79
80
81
82
83
84
# File 'lib/gcpt/build_report/reporter.rb', line 78

def get_product_plist_value(key)
  value = product_plist[key]
  if value && value.include?('$')
    value = `echo #{value}`.strip
  end
  value
end

#plist_contentObject



59
60
61
62
63
64
65
# File 'lib/gcpt/build_report/reporter.rb', line 59

def plist_content()
  plist_path = ENV['PRODUCT_SETTINGS_PATH']
  begin
    File.read(plist_path)
  rescue
  end
end

#prepareObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/gcpt/build_report/reporter.rb', line 17

def prepare()
  @is_app = ENV['MACH_O_TYPE'] == 'mh_execute'
  @product_path = ENV['CODESIGNING_FOLDER_PATH']
  @gsdk_build_info = {}

  gsdk_framework_path = @is_app && find_gsdk_in_app || find_gsdk_in_search_paths
  if gsdk_framework_path
    plist_path = gsdk_framework_path.join('Info.plist')
    plist = Helper::read_plist_from_path(plist_path)
    for key in %w[build_id dsl version resion source]
      value = plist["gsdk_#{key}"]
      if value
        @gsdk_build_info[key] = value
      end
    end
  end

  @project = Xcodeproj::Project.open(ENV['PROJECT_FILE_PATH'])
  @host_target = @project.targets.find { |target| target.name == ENV['TARGET_NAME'] }
end

#product_plistObject



67
68
69
70
71
72
73
74
75
76
# File 'lib/gcpt/build_report/reporter.rb', line 67

def product_plist
  @product_plist ||= begin
    plist_path = ENV['PRODUCT_SETTINGS_PATH']
    begin
      Xcodeproj::Plist::read_from_path(plist_path)
    rescue
      return {}
    end
  end
end

#runObject



53
54
55
56
57
# File 'lib/gcpt/build_report/reporter.rb', line 53

def run()
  prepare()
  report_info = self._collect_report_info()
  ReportApi::report(report_info)
end