#!/usr/bin/python
##
## @author Edouard DUPIN
##
## @copyright 2012, Edouard DUPIN, all right reserved
##
## @license APACHE v2.0 (see license file)
##
import lutinDebug as debug
import lutinTarget
import lutinTools
import lutinImage
import os
import stat
import lutinExtProjectGeneratorXCode
import lutinMultiprocess
import lutinHost
import random
import re
class Target(lutinTarget.Target):
def __init__(self, config):
if config["compilator"] == "gcc":
debug.info("compile only with clang for IOs");
config["compilator"] = "clang"
#processor type selection (auto/arm/ppc/x86)
if config["arch"] == "auto":
config["arch"] = "arm"
#bus size selection (auto/32/64)
if config["bus-size"] == "auto":
config["bus-size"] = "64"
# http://biolpc22.york.ac.uk/pub/linux-mac-cross/
# http://devs.openttd.org/~truebrain/compile-farm/apple-darwin9.txt
if sumulator == True:
arch = "i386"
else:
arch="arm64" # for ipad air
#arch="armv7" # for Iphone 4
lutinTarget.Target.__init__(self, "IOs", config, arch)
if self.config["simulation"] == True:
self.set_cross_base("/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/")
else:
self.set_cross_base("/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/")
# remove unneeded ranlib ...
self.ranlib=""
self.folder_bin=""
self.folder_data="/share"
self.folder_doc="/doc"
self.suffix_lib_static='.a'
self.suffix_lib_dynamic='.dylib'
self.suffix_binary=''
self.suffix_package=''
if self.sumulator == True:
self.sysroot = "-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.1.sdk"
self.global_flags_ld.append("-mios-simulator-version-min=7.0")
self.global_flags_cc.append("-mios-simulator-version-min=7.0")
else:
self.sysroot = "-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.1.sdk"
self.global_flags_ld.append("-miphoneos-version-min=7.0")
self.global_flags_cc.append("-miphoneos-version-min=7.0")
self.global_flags_ld.append([
"-Xlinker",
"-objc_abi_version",
"-Xlinker 2",
"-Xlinker",
"-no_implicit_dylibs",
"-stdlib=libc++",
"-fobjc-arc",
"-fobjc-link-runtime"])
self.global_flags_m.append("-fobjc-arc")
#self.global_flags_m.append("-fmodules")
#add a project generator:
self.externProjectManager = lutinExtProjectGeneratorXCode.ExtProjectGeneratorXCode()
def get_staging_folder(self, binaryName):
return lutinTools.get_run_folder() + self.folder_out + self.folder_staging + "/" + binaryName + ".app/"
def get_staging_folder_data(self, binaryName):
return self.get_staging_folder(binaryName) + self.folder_data + "/"
def make_package(self, pkgName, pkgProperties, basePkgPath):
debug.debug("------------------------------------------------------------------------")
debug.info("Generate package '" + pkgName + "'")
debug.debug("------------------------------------------------------------------------")
if "ICON" in pkgProperties.keys() \
and pkgProperties["ICON"] != "":
# Resize all icon needed for Ios ...
# TODO : Do not regenerate if source resource is not availlable
# TODO : Add a colored background ...
debug.print_element("pkg", "iTunesArtwork.png", "<==", pkgProperties["ICON"])
lutinImage.resize(pkgProperties["ICON"], self.get_staging_folder(pkgName) + "/iTunesArtwork.png", 512, 512)
debug.print_element("pkg", "iTunesArtwork@2x.png", "<==", pkgProperties["ICON"])
lutinImage.resize(pkgProperties["ICON"], self.get_staging_folder(pkgName) + "/iTunesArtwork@2x.png", 1024, 1024)
debug.print_element("pkg", "Icon-60@2x.png", "<==", pkgProperties["ICON"])
lutinImage.resize(pkgProperties["ICON"], self.get_staging_folder(pkgName) + "/Icon-60@2x.png", 120, 120)
debug.print_element("pkg", "Icon-76.png", "<==", pkgProperties["ICON"])
lutinImage.resize(pkgProperties["ICON"], self.get_staging_folder(pkgName) + "/Icon-76.png", 76, 76)
debug.print_element("pkg", "Icon-76@2x.png", "<==", pkgProperties["ICON"])
lutinImage.resize(pkgProperties["ICON"], self.get_staging_folder(pkgName) + "/Icon-76@2x.png", 152, 152)
debug.print_element("pkg", "Icon-Small-40.png", "<==", pkgProperties["ICON"])
lutinImage.resize(pkgProperties["ICON"], self.get_staging_folder(pkgName) + "/Icon-Small-40.png", 40, 40)
debug.print_element("pkg", "Icon-Small-40@2x.png", "<==", pkgProperties["ICON"])
lutinImage.resize(pkgProperties["ICON"], self.get_staging_folder(pkgName) + "/Icon-Small-40@2x.png", 80, 80)
debug.print_element("pkg", "Icon-Small.png", "<==", pkgProperties["ICON"])
lutinImage.resize(pkgProperties["ICON"], self.get_staging_folder(pkgName) + "/Icon-Small.png", 29, 29)
debug.print_element("pkg", "Icon-Small@2x.png", "<==", pkgProperties["ICON"])
lutinImage.resize(pkgProperties["ICON"], self.get_staging_folder(pkgName) + "/Icon-Small@2x.png", 58, 58)
debug.print_element("pkg", "PkgInfo", "<==", "APPL????")
infoFile = self.get_staging_folder(pkgName) + "/PkgInfo"
# Create the info file
tmpFile = open(infoFile, 'w')
tmpFile.write("APPL????")
tmpFile.flush()
tmpFile.close()
debug.print_element("pkg", "Info.plist", "<==", "Package properties")
# http://www.sandroid.org/imcross/#Deployment
dataFile = "\n"
dataFile += "\n"
dataFile += "\n"
dataFile += " \n"
dataFile += " CFBundleDevelopmentRegion\n"
dataFile += " en\n"
dataFile += " CFBundleDisplayName\n"
dataFile += " " + pkgProperties["NAME"] + "\n"
dataFile += " CFBundleExecutable\n"
dataFile += " " + pkgName + "\n"
dataFile += " CFBundleIdentifier\n"
dataFile += " com." + pkgProperties["COMPAGNY_NAME2"] + "." + pkgName + "\n"
dataFile += " CFBundleIconFiles\n"
dataFile += " \n"
dataFile += " Icon-60@2x.png\n"
dataFile += " Icon-76.png\n"
dataFile += " Icon-76@2x.png\n"
dataFile += " Icon-Small-40.png\n"
dataFile += " Icon-Small-40@2x.png\n"
dataFile += " Icon-Small.png\n"
dataFile += " Icon-Small@2x.png\n"
dataFile += " iTunesArtwork.png\n"
dataFile += " iTunesArtwork@2x.png\n"
dataFile += " \n"
dataFile += " CFBundleInfoDictionaryVersion\n"
dataFile += " 6.0\n"
dataFile += " CFBundleName\n"
dataFile += " " + pkgName + "\n"
dataFile += " CFBundlePackageType\n"
dataFile += " APPL\n"
dataFile += " CFBundleSignature\n"
dataFile += " ????\n"
dataFile += " CFBundleSupportedPlatforms\n"
dataFile += " \n"
dataFile += " iPhoneSimulator\n"
dataFile += " \n"
dataFile += " \n"
dataFile += " CFBundleShortVersionString\n"
dataFile += " "+pkgProperties["VERSION"]+"\n"
dataFile += " CFBundleVersion\n"
dataFile += " "+pkgProperties["VERSION_CODE"]+"\n"
dataFile += " \n"
dataFile += " CFBundleResourceSpecification\n"
dataFile += " ResourceRules.plist\n"
if self.sumulator == False:
dataFile += " LSRequiresIPhoneOS\n"
dataFile += " \n"
else:
dataFile += " DTPlatformName\n"
dataFile += " iphonesimulator\n"
dataFile += " DTSDKName\n"
dataFile += " iphonesimulator7.0\n"
dataFile += " \n"
dataFile += " UIDeviceFamily\n"
dataFile += " \n"
dataFile += " 1\n"
dataFile += " 2\n"
dataFile += " \n"
dataFile += " UIRequiredDeviceCapabilities\n"
dataFile += " \n"
dataFile += " armv7\n"
dataFile += " \n"
dataFile += " UIStatusBarHidden\n"
dataFile += " \n"
dataFile += " UISupportedInterfaceOrientations\n"
dataFile += " \n"
dataFile += " UIInterfaceOrientationPortrait\n"
dataFile += " UIInterfaceOrientationPortraitUpsideDown\n"
dataFile += " UIInterfaceOrientationLandscapeLeft\n"
dataFile += " UIInterfaceOrientationLandscapeRight\n"
dataFile += " \n"
dataFile += " UISupportedInterfaceOrientations~ipad\n"
dataFile += " \n"
dataFile += " UIInterfaceOrientationPortrait\n"
dataFile += " UIInterfaceOrientationPortraitUpsideDown\n"
dataFile += " UIInterfaceOrientationLandscapeLeft\n"
dataFile += " UIInterfaceOrientationLandscapeRight\n"
dataFile += " \n"
dataFile += " \n"
dataFile += "\n"
dataFile += "\n\n"
infoFile = self.get_staging_folder(pkgName) + "/Info.plist"
# Create the info file
tmpFile = open(infoFile, 'w')
tmpFile.write(dataFile)
tmpFile.flush()
tmpFile.close()
"""
infoFile = self.get_staging_folder(pkgName) + "/" + pkgName + "-Info.plist"
# Create the info file
tmpFile = open(infoFile, 'w')
tmpFile.write(dataFile)
tmpFile.flush()
tmpFile.close()
cmdLine = "builtin-infoPlistUtility "
cmdLine += " " + self.get_staging_folder(pkgName) + "/" + pkgName + "-Info.plist "
cmdLine += " -genpkginfo " + self.get_staging_folder(pkgName) + "/PkgInfo"
cmdLine += " -expandbuildsettings "
cmdLine += " -format binary "
if self.sumulator == False:
cmdLine += " -platform iphonesimulator "
else:
cmdLine += " -platform iphoneos "
cmdLine += " -o " + self.get_staging_folder(pkgName) + "/" + "Info.plist"
lutinMultiprocess.run_command(cmdLine)
"""
"""
/Users/edouarddupin/dev/exampleProjectXcode/projectName/projectName/projectName-Info.plist
-genpkginfo
/Users/edouarddupin/Library/Developer/Xcode/DerivedData/projectName-gwycnyyzohokcmalgodeucqppxro/Build/Products/Debug-iphonesimulator/projectName.app/PkgInfo
-expandbuildsettings
-format binary
-platform iphonesimulator
-additionalcontentfile /Users/edouarddupin/Library/Developer/Xcode/DerivedData/projectName-gwycnyyzohokcmalgodeucqppxro/Build/Intermediates/projectName.build/Debug-iphonesimulator/projectName.build/assetcatalog_generated_info.plist
-o /Users/edouarddupin/Library/Developer/Xcode/DerivedData/projectName-gwycnyyzohokcmalgodeucqppxro/Build/Products/Debug-iphonesimulator/projectName.app/Info.plist
-additionalcontentfile /Users/edouarddupin/Library/Developer/Xcode/DerivedData/zdzdzd-bjuyukzpzhnyerdmxohjyuxfdllv/Build/Intermediates/zdzdzd.build/Debug-iphoneos/zdzdzd.build/assetcatalog_generated_info.plist -o /Users/edouarddupin/Library/Developer/Xcode/DerivedData/zdzdzd-bjuyukzpzhnyerdmxohjyuxfdllv/Build/Products/Debug-iphoneos/zdzdzd.app/Info.plist
"""
#/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/dsymutil /Users/edouarddupin/Library/Developer/Xcode/DerivedData/projectName-gwycnyyzohokcmalgodeucqppxro/Build/Products/Debug-iphonesimulator/projectName.app/projectName -o /Users/edouarddupin/Library/Developer/Xcode/DerivedData/projectName-gwycnyyzohokcmalgodeucqppxro/Build/Products/Debug-iphonesimulator/projectName.app.dSYM
debug.print_element("pkg", "ResourceRules.plist", "<==", "Resources autorisation")
dataFile = "\n"
dataFile += "\n"
dataFile += "\n"
dataFile += " \n"
dataFile += " rules\n"
dataFile += " \n"
dataFile += " .*\n"
dataFile += " \n"
dataFile += " Info.plist\n"
dataFile += " \n"
dataFile += " omit\n"
dataFile += " \n"
dataFile += " weight\n"
dataFile += " 10\n"
dataFile += " \n"
dataFile += " ResourceRules.plist\n"
dataFile += " \n"
dataFile += " omit\n"
dataFile += " \n"
dataFile += " weight\n"
dataFile += " 100\n"
dataFile += " \n"
dataFile += " \n"
dataFile += " \n"
dataFile += "\n"
dataFile += "\n\n"
infoFile = self.get_staging_folder(pkgName) + "/ResourceRules.plist"
# Create the info file
tmpFile = open(infoFile, 'w')
tmpFile.write(dataFile)
tmpFile.flush()
tmpFile.close()
debug.print_element("pkg", "Entitlements.plist", "<==", "application mode")
dataFile = "\n"
dataFile += "\n"
dataFile += "\n"
dataFile += " \n"
dataFile += " get-task-allow\n"
dataFile += " \n"
dataFile += " \n"
dataFile += "\n"
dataFile += "\n\n"
infoFile = self.get_staging_folder(pkgName) + "/Entitlements.plist"
# Create the info file
tmpFile = open(infoFile, 'w')
tmpFile.write(dataFile)
tmpFile.flush()
tmpFile.close()
# Simulateur folder :
#~/Library/Application\ Support/iPhone\ Simulator/7.0.3/Applications/
# must have a 'uuidgen' UID generate value with this elemennt ...
# get the bundle path : ==> maybe usefull in MocOS ...
# NSLog(@"%@",[[NSBundle mainBundle] bundlePath]);
# Must create the tarball of the application
#cd $(TARGET_OUT_FINAL)/; tar -cf $(PROJECT_NAME).tar $(PROJECT_NAME).app
#cd $(TARGET_OUT_FINAL)/; tar -czf $(PROJECT_NAME).tar.gz $(PROJECT_NAME).app
if self.sumulator == False:
# Create the info file
tmpFile = open(self.get_build_folder(pkgName) + "/worddown.xcent", 'w')
tmpFile.write("\n")
tmpFile.write("\n")
tmpFile.write("\n")
tmpFile.write(" \n")
tmpFile.write(" application-identifier\n")
tmpFile.write(" " + pkgProperties["APPLE_APPLICATION_IOS_ID"] + "." + pkgProperties["COMPAGNY_TYPE"] + "." + pkgProperties["COMPAGNY_NAME2"] + "." + pkgName + "\n")
tmpFile.write(" get-task-allow\n")
tmpFile.write(" \n")
tmpFile.write(" keychain-access-groups\n")
tmpFile.write(" \n")
tmpFile.write(" " + pkgProperties["APPLE_APPLICATION_IOS_ID"] + ".atriasoft.worddown\n")
tmpFile.write(" \n")
tmpFile.write(" \n")
tmpFile.write("\n")
tmpFile.flush()
tmpFile.close()
# application signing :
debug.print_element("pkg(signed)", "pkg", "<==", "Signing application")
iosDevelopperKeyFile = ".iosKey.txt"
if lutinTools.file_size(iosDevelopperKeyFile) < 10:
debug.error("To sign an application we need to have a signing key in the file '" + iosDevelopperKeyFile + "' \n it is represented like: 'iPhone Developer: Francis DUGENOUX (YRRQE5KGTH)'\n you can obtain it with : 'certtool y | grep \"Developer\"'")
signatureKey = lutinTools.file_read_data(iosDevelopperKeyFile)
signatureKey = re.sub('\n', '', signatureKey)
cmdLine = 'codesign --force --sign '
# to get this key ; certtool y | grep "Developer"
cmdLine += ' "' + signatureKey + '" '
cmdLine += ' --entitlements ' + self.get_build_folder(pkgName) + '/worddown.xcent'
cmdLine += ' ' + self.get_staging_folder(pkgName)
lutinMultiprocess.run_command(cmdLine)
# --force --sign "iPhone Developer: Edouard DUPIN (SDFGSDFGSDFG)"
# --resource-rules=/Users/edouarddupin/Library/Developer/Xcode/DerivedData/worddown-cmuvjchgtiteexdiacyqoexsyadg/Build/Products/Debug-iphoneos/worddown.app/ResourceRules.plist
# --entitlements /Users/edouarddupin/Library/Developer/Xcode/DerivedData/worddown-cmuvjchgtiteexdiacyqoexsyadg/Build/Intermediates/worddown.build/Debug-iphoneos/worddown.build/worddown.xcent
# /Users/edouarddupin/Library/Developer/Xcode/DerivedData/worddown-cmuvjchgtiteexdiacyqoexsyadg/Build/Products/Debug-iphoneos/worddown.app
def createRandomNumber(self, len):
out = ""
for iii in range(0,len):
out += random.choice(["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"])
return out
def install_package(self, pkgName):
debug.debug("------------------------------------------------------------------------")
debug.info("Install package '" + pkgName + "'")
debug.debug("------------------------------------------------------------------------")
if self.sumulator == False:
if lutinTools.file_size("ewol/ios-deploy/ios-deploy") == 0:
debug.print_element("tool", "ios-deploy", "<==", "external sources")
cmdLine = 'cd ewol/ios-deploy ; make ; cd ../.. '
lutinMultiprocess.run_command(cmdLine)
if lutinTools.file_size("ewol/ios-deploy/ios-deploy") == 0:
debug.error("Can not create ios-deploy external software ...")
debug.print_element("deploy", "iphone/ipad", "<==", "aplication")
cmdLine = './ewol/ios-deploy/ios-deploy --bundle ' + self.get_staging_folder(pkgName)
lutinMultiprocess.run_command(cmdLine)
else:
simulatorIdFile = ".iosSimutatorId_" + pkgName + ".txt"
if lutinTools.file_size(simulatorIdFile) < 10:
#create the file:
tmpFile = open(simulatorIdFile, 'w')
tmpFile.write(self.createRandomNumber(8))
tmpFile.write("-")
tmpFile.write(self.createRandomNumber(4))
tmpFile.write("-")
tmpFile.write(self.createRandomNumber(4))
tmpFile.write("-")
tmpFile.write(self.createRandomNumber(4))
tmpFile.write("-")
tmpFile.write(self.createRandomNumber(12))
tmpFile.flush()
tmpFile.close()
simulatorId = lutinTools.file_read_data(simulatorIdFile)
home = os.path.expanduser("~")
destinationFolderBase = home + "/Library/Application\\ Support/iPhone\\ Simulator/7.1/Applications/" + simulatorId
destinationFolder = home + "/Library/Application Support/iPhone Simulator/7.1/Applications/" + simulatorId + "/" + pkgName + ".app"
destinationFolder2 = home + "/Library/Application\\ Support/iPhone\\ Simulator/7.1/Applications/" + simulatorId + "/" + pkgName + ".app"
debug.info("install in simulator : " + destinationFolder)
lutinTools.create_directory_of_file(destinationFolder + "/plop.txt")
cmdLine = "cp -rf " + self.get_staging_folder(pkgName) + " " + destinationFolder2
lutinMultiprocess.run_command(cmdLine)
cmdLine = "touch " + destinationFolderBase
lutinMultiprocess.run_command(cmdLine)
#sudo dpkg -i $(TARGET_OUT_FINAL)/$(PROJECT_NAME) + self.suffix_package
def un_install_package(self, pkgName):
debug.debug("------------------------------------------------------------------------")
debug.info("Un-Install package '" + pkgName + "'")
debug.debug("------------------------------------------------------------------------")
if self.sumulator == False:
debug.warning("not implemented")
else:
simulatorIdFile = ".iosSimutatorId_" + pkgName + ".txt"
if lutinTools.file_size(simulatorIdFile) < 10:
debug.warning("Can not get simulation O_ID : " + simulatorIdFile)
#sudo dpkg -r $(TARGET_OUT_FINAL)/$(PROJECT_NAME) + self.suffix_package
def Log(self, pkgName):
debug.debug("------------------------------------------------------------------------")
debug.info("log of iOs board")
debug.debug("------------------------------------------------------------------------")
if self.sumulator == False:
if lutinTools.file_size("ewol/ios-deploy/ios-deploy") == 0:
debug.print_element("tool", "ios-deploy", "<==", "external sources")
cmdLine = 'cd ewol/ios-deploy ; make ; cd ../.. '
lutinMultiprocess.run_command(cmdLine)
if lutinTools.file_size("ewol/ios-deploy/ios-deploy") == 0:
debug.error("Can not create ios-deploy external software ...")
debug.print_element("deploy", "iphone/ipad", "<==", "aplication")
cmdLine = './ewol/ios-deploy/ios-deploy --debug --bundle ' + self.get_staging_folder(pkgName)
lutinMultiprocess.run_command(cmdLine)
else:
cmdLine = "tail -f ~/Library/Logs/iOS\ Simulator/7.1/system.log"
lutinMultiprocess.run_command(cmdLine)