qianyou.py 5.81 KB
import shutil
import os
import plistlib

import config
import json
import packageProj
import commands

from mod_pbxproj import XcodeProject


gameProjName = config.gameProjName
channelName = "qianyou"
#copy dir xcodeproj
copyNewDirName = gameProjName + '_' + channelName + '.xcodeproj'
currentPath = os.path.abspath('.')
currentPath += '/' + copyNewDirName

if os.path.exists(currentPath):
    shutil.rmtree(currentPath)

shutil.copytree(gameProjName + '.xcodeproj',currentPath)

project = XcodeProject.Load(copyNewDirName + '/project.pbxproj')

project.add_other_ldflags('-ObjC')

channelRootPath = config.channelRootPath#'poolsdk_file'

frameworksPath = '$(PROJECT_DIR)/' + channelRootPath + '/poolsdk_' + channelName + '/SDK'
print(frameworksPath);
#add header search path
project.add_header_search_paths(frameworksPath, recursive=False)
project.add_header_search_paths(frameworksPath + '/iaphelper', recursive=False)

#add framework search path
project.add_framework_search_paths(frameworksPath, recursive=False)
#add library search path
project.add_library_search_paths(frameworksPath, recursive=False)

#add poolsdk_xy dir all file into project
project.remove_group_by_name('poolsdk')
frameworkRelativePath = project.add_folder(channelRootPath + '/poolsdk_' + channelName + '/SDK')

#ignore_unknown_type
project.add_file_if_doesnt_exist('pool_setting',parent=frameworkRelativePath, weak=True,ignore_unknown_type=True)

systemFrameworks = project.get_or_create_group('Frameworks')
#add system framework
project.add_file_if_doesnt_exist('System/Library/Frameworks/AdSupport.framework',parent=systemFrameworks, weak=True, tree='SDKROOT')
project.add_file_if_doesnt_exist('System/Library/Frameworks/CFNetwork.framework',parent=systemFrameworks, weak=True, tree='SDKROOT')
project.add_file_if_doesnt_exist('System/Library/Frameworks/Security.framework',parent=systemFrameworks, weak=True, tree='SDKROOT')
project.add_file_if_doesnt_exist('System/Library/Frameworks/CoreTelephony.framework',parent=systemFrameworks, weak=True, tree='SDKROOT')
project.add_file_if_doesnt_exist('System/Library/Frameworks/SystemConfiguration.framework',parent=systemFrameworks, weak=True, tree='SDKROOT')


#add system dylib
systemLibs = project.get_or_create_group('Libraries')
project.add_file_if_doesnt_exist('/usr/lib/libsqlite3.dylib',parent=systemLibs, weak=True, tree='<absolute>')#absolute path
project.add_file_if_doesnt_exist('/usr/lib/libz.dylib',parent=systemLibs, weak=True, tree='<absolute>')
project.add_file_if_doesnt_exist('/usr/lib/libc++.dylib',parent=systemLibs, weak=True, tree='<absolute>')


#modify info.plist reference path
project.add_single_valued_flag('INFOPLIST_FILE',channelRootPath + '/poolsdk_' + channelName + '/Info.plist')

project.add_single_valued_flag('ENABLE_BITCODE', 'NO')

readInfoPlistFilePath = channelRootPath + '/poolsdk/Info.plist'
writeInfoFilePath = channelRootPath + '/poolsdk_' + channelName + '/Info.plist'
infoContent = plistlib.readPlist(readInfoPlistFilePath)

channelInfoPath = channelRootPath + '/poolsdk_' + channelName + '/Info_' + channelName + '.plist'

#read pool_setting file
settingFile = open(channelRootPath + '/poolsdk_' + channelName + '/SDK/pool_setting','rw')
try:
    settingFileContent = settingFile.read( )
finally:
    settingFile.close( )
#json op
jsonStr = json.loads(settingFileContent)

#modify bundle id
project.add_single_valued_flag('PRODUCT_BUNDLE_IDENTIFIER',jsonStr["appScheme"])

appSecret = jsonStr["appSecret"];
appKey = jsonStr["appKey"];
appId = jsonStr["appId"];
pvc = jsonStr["pvc"];
qqAppId = jsonStr["qqAppId"];
qqAppKey = jsonStr["qqAppKey"];
channel = jsonStr["channel"];
sdkProtocolGame = jsonStr["sdkProtocolGame"];
sdkProtocolToken = jsonStr["sdkProtocolToken"];
headLink = "'" + jsonStr["head_link"] + "'";
keychain_access_groups = jsonStr["keychain-access-groups"];
#set info.plist channel parame

channelParamesFilePath = channelRootPath + '/poolsdk_' + channelName + '/SDK/p2y9y_private.plist'
absolutionInfoPath = os.path.abspath('.') + '/' + channelParamesFilePath
commands.getstatusoutput("/usr/libexec/PlistBuddy -c 'Set :com_2y9y_appSecret '" + appSecret + ' ' + absolutionInfoPath)
commands.getstatusoutput("/usr/libexec/PlistBuddy -c 'Set :com_2y9y_appKey '" + appKey + ' ' + absolutionInfoPath)
commands.getstatusoutput("/usr/libexec/PlistBuddy -c 'Set :com_2y9y_appId '" + appId + ' ' + absolutionInfoPath)
commands.getstatusoutput("/usr/libexec/PlistBuddy -c 'Set :com_2y9y_pvc '" + pvc + ' ' + absolutionInfoPath)
commands.getstatusoutput("/usr/libexec/PlistBuddy -c 'Set :com_2y9_qqAppId '" + qqAppId + ' ' + absolutionInfoPath)
commands.getstatusoutput("/usr/libexec/PlistBuddy -c 'Set :com_2y9y_qqAppKey '" + qqAppKey + ' ' + absolutionInfoPath)
commands.getstatusoutput("/usr/libexec/PlistBuddy -c 'Set :com_2y9y_channel '" + channel + ' ' + absolutionInfoPath)
commands.getstatusoutput("/usr/libexec/PlistBuddy -c 'Set :com_2y9y_sdkProtocolGame '" + sdkProtocolGame + ' ' + absolutionInfoPath)
commands.getstatusoutput("/usr/libexec/PlistBuddy -c 'Set :com_2y9y_sdkProtocolToken '" + sdkProtocolToken + ' ' + absolutionInfoPath)
commands.getstatusoutput("/usr/libexec/PlistBuddy -c 'Set :head_link '" + headLink + ' ' + absolutionInfoPath)

channelKeychainFilePath = channelRootPath + '/poolsdk_' + channelName + '/SDK/KeychainAccessGroups.plist'
channelKeychainFilePath =  os.path.abspath('.') + '/' + channelKeychainFilePath
commands.getstatusoutput("/usr/libexec/PlistBuddy -c 'Set keychain-access-groups:0 '" + keychain_access_groups + ' ' + channelKeychainFilePath)

#read channel info plist content
channelInfoContent = plistlib.readPlist(channelInfoPath)
#update and add info.plist content
infoContent.update(channelInfoContent)
#write
plistlib.writePlist(infoContent,writeInfoFilePath)

#copy keychain file
newFilePath = os.path.abspath('.') + '/KeychainAccessGroups.plist'
shutil.copyfile(channelKeychainFilePath,newFilePath)

project.save()