toolchain: handle addition of frameworks/libraries within the Xcode project depending of the compiled recipes.
Done automatically during the creation time, or use the update command
This commit is contained in:
parent
3bf4339d12
commit
e51be2eec8
9 changed files with 1620 additions and 2 deletions
|
@ -11,6 +11,10 @@ class FFPyplayerRecipe(Recipe):
|
||||||
url = "https://github.com/tito/ffpyplayer/archive/{version}.zip"
|
url = "https://github.com/tito/ffpyplayer/archive/{version}.zip"
|
||||||
library = "libffpyplayer.a"
|
library = "libffpyplayer.a"
|
||||||
depends = ["python", "ffmpeg"]
|
depends = ["python", "ffmpeg"]
|
||||||
|
pbx_frameworks = [
|
||||||
|
"CoreVideo", "CoreMedia", "CoreImage", "AVFoundation", "UIKit",
|
||||||
|
"CoreMotion"]
|
||||||
|
pbx_libraries = ["libiconv"]
|
||||||
|
|
||||||
def cythonize(self, filename):
|
def cythonize(self, filename):
|
||||||
if filename.startswith(self.build_dir):
|
if filename.startswith(self.build_dir):
|
||||||
|
|
|
@ -11,6 +11,7 @@ class IosRecipe(Recipe):
|
||||||
url = "src"
|
url = "src"
|
||||||
library = "libios.a"
|
library = "libios.a"
|
||||||
depends = ["python"]
|
depends = ["python"]
|
||||||
|
pbx_frameworks = ["MessageUI", "CoreMotion", "UIKit"]
|
||||||
|
|
||||||
def cythonize(self, filename):
|
def cythonize(self, filename):
|
||||||
if filename.startswith(self.build_dir):
|
if filename.startswith(self.build_dir):
|
||||||
|
|
|
@ -11,6 +11,7 @@ class KivyRecipe(Recipe):
|
||||||
url = "https://github.com/kivy/kivy/archive/{version}.zip"
|
url = "https://github.com/kivy/kivy/archive/{version}.zip"
|
||||||
library = "libkivy.a"
|
library = "libkivy.a"
|
||||||
depends = ["python", "sdl2", "sdl2_image", "sdl2_mixer", "sdl2_ttf", "ios"]
|
depends = ["python", "sdl2", "sdl2_image", "sdl2_mixer", "sdl2_ttf", "ios"]
|
||||||
|
pbx_frameworks = ["OpenGLES", "Accelerate"]
|
||||||
|
|
||||||
def cythonize(self, filename):
|
def cythonize(self, filename):
|
||||||
if filename.startswith(self.build_dir):
|
if filename.startswith(self.build_dir):
|
||||||
|
|
|
@ -9,6 +9,7 @@ class PythonRecipe(Recipe):
|
||||||
url = "https://www.python.org/ftp/python/{version}/Python-{version}.tar.bz2"
|
url = "https://www.python.org/ftp/python/{version}/Python-{version}.tar.bz2"
|
||||||
depends = ["hostpython", "libffi", ]
|
depends = ["hostpython", "libffi", ]
|
||||||
library = "libpython2.7.a"
|
library = "libpython2.7.a"
|
||||||
|
pbx_libraries = ["libz", "libbz2", "libsqlite3"]
|
||||||
|
|
||||||
def prebuild_arch(self, arch):
|
def prebuild_arch(self, arch):
|
||||||
# common to all archs
|
# common to all archs
|
||||||
|
|
|
@ -9,6 +9,8 @@ class LibSDL2Recipe(Recipe):
|
||||||
url = "https://bitbucket.org/slime73/sdl-experiments/get/{version}.tar.gz"
|
url = "https://bitbucket.org/slime73/sdl-experiments/get/{version}.tar.gz"
|
||||||
library = "Xcode-iOS/SDL/build/Release-{arch.sdk}/libSDL2.a"
|
library = "Xcode-iOS/SDL/build/Release-{arch.sdk}/libSDL2.a"
|
||||||
include_dir = "include"
|
include_dir = "include"
|
||||||
|
pbx_frameworks = ["OpenGLES", "AudioToolbox", "QuartzCore", "CoreGraphics",
|
||||||
|
"CoreMotion"]
|
||||||
|
|
||||||
def build_arch(self, arch):
|
def build_arch(self, arch):
|
||||||
shprint(sh.xcodebuild,
|
shprint(sh.xcodebuild,
|
||||||
|
|
|
@ -9,6 +9,7 @@ class LibSDL2ImageRecipe(Recipe):
|
||||||
library = "Xcode-iOS/build/Release-{arch.sdk}/libSDL2_image.a"
|
library = "Xcode-iOS/build/Release-{arch.sdk}/libSDL2_image.a"
|
||||||
include_dir = "SDL_image.h"
|
include_dir = "SDL_image.h"
|
||||||
depends = ["sdl2"]
|
depends = ["sdl2"]
|
||||||
|
pbx_frameworks = ["CoreGraphics", "MobileCoreServices"]
|
||||||
|
|
||||||
def build_arch(self, arch):
|
def build_arch(self, arch):
|
||||||
shprint(sh.xcodebuild,
|
shprint(sh.xcodebuild,
|
||||||
|
|
|
@ -8,6 +8,8 @@ class LibSDL2MixerRecipe(Recipe):
|
||||||
library = "Xcode-iOS/build/Release-{arch.sdk}/libSDL2_mixer.a"
|
library = "Xcode-iOS/build/Release-{arch.sdk}/libSDL2_mixer.a"
|
||||||
include_dir = "SDL_mixer.h"
|
include_dir = "SDL_mixer.h"
|
||||||
depends = ["sdl2"]
|
depends = ["sdl2"]
|
||||||
|
pbx_frameworks = ["ImageIO"]
|
||||||
|
pbx_libraries = ["libc++"]
|
||||||
|
|
||||||
def build_arch(self, arch):
|
def build_arch(self, arch):
|
||||||
shprint(sh.xcodebuild,
|
shprint(sh.xcodebuild,
|
||||||
|
|
112
toolchain.py
112
toolchain.py
|
@ -9,7 +9,7 @@ This tool intend to replace all the previous tools/ in shell script.
|
||||||
import sys
|
import sys
|
||||||
from sys import stdout
|
from sys import stdout
|
||||||
from os.path import join, dirname, realpath, exists, isdir, basename
|
from os.path import join, dirname, realpath, exists, isdir, basename
|
||||||
from os import listdir, unlink, makedirs, environ, chdir
|
from os import listdir, unlink, makedirs, environ, chdir, getcwd
|
||||||
import zipfile
|
import zipfile
|
||||||
import tarfile
|
import tarfile
|
||||||
import importlib
|
import importlib
|
||||||
|
@ -353,8 +353,11 @@ class Recipe(object):
|
||||||
archs = []
|
archs = []
|
||||||
depends = []
|
depends = []
|
||||||
library = None
|
library = None
|
||||||
|
libraries = []
|
||||||
include_dir = None
|
include_dir = None
|
||||||
include_per_arch = False
|
include_per_arch = False
|
||||||
|
pbx_frameworks = []
|
||||||
|
pbx_libraries = []
|
||||||
|
|
||||||
# API available for recipes
|
# API available for recipes
|
||||||
def download_file(self, url, filename, cwd=None):
|
def download_file(self, url, filename, cwd=None):
|
||||||
|
@ -485,6 +488,20 @@ class Recipe(object):
|
||||||
if not self.archs or (arch.arch in self.archs):
|
if not self.archs or (arch.arch in self.archs):
|
||||||
yield arch
|
yield arch
|
||||||
|
|
||||||
|
@property
|
||||||
|
def dist_libraries(self):
|
||||||
|
libraries = []
|
||||||
|
name = self.name
|
||||||
|
if not name.startswith("lib"):
|
||||||
|
name = "lib{}".format(name)
|
||||||
|
if self.library:
|
||||||
|
static_fn = join(self.ctx.dist_dir, "lib", "{}.a".format(name))
|
||||||
|
libraries.append(static_fn)
|
||||||
|
for library in self.libraries:
|
||||||
|
static_fn = join(self.ctx.dist_dir, "lib", basename(library))
|
||||||
|
libraries.append(static_fn)
|
||||||
|
return libraries
|
||||||
|
|
||||||
def get_build_dir(self, arch):
|
def get_build_dir(self, arch):
|
||||||
return join(self.ctx.build_dir, self.name, arch, self.archive_root)
|
return join(self.ctx.build_dir, self.name, arch, self.archive_root)
|
||||||
|
|
||||||
|
@ -499,7 +516,7 @@ class Recipe(object):
|
||||||
else:
|
else:
|
||||||
include_dir = join("common", self.name)
|
include_dir = join("common", self.name)
|
||||||
if include_dir:
|
if include_dir:
|
||||||
print("Include dir added: {}".format(include_dir))
|
#print("Include dir added: {}".format(include_dir))
|
||||||
self.ctx.include_dirs.append(include_dir)
|
self.ctx.include_dirs.append(include_dir)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -752,6 +769,58 @@ def ensure_dir(filename):
|
||||||
makedirs(filename)
|
makedirs(filename)
|
||||||
|
|
||||||
|
|
||||||
|
def update_pbxproj(filename):
|
||||||
|
# list all the compiled recipes
|
||||||
|
ctx = Context()
|
||||||
|
pbx_libraries = []
|
||||||
|
pbx_frameworks = []
|
||||||
|
libraries = []
|
||||||
|
for recipe in Recipe.list_recipes():
|
||||||
|
key = "{}.build_all".format(recipe)
|
||||||
|
if key not in ctx.state:
|
||||||
|
continue
|
||||||
|
recipe = Recipe.get_recipe(recipe, ctx)
|
||||||
|
recipe.init_with_ctx(ctx)
|
||||||
|
pbx_frameworks.extend(recipe.pbx_frameworks)
|
||||||
|
pbx_libraries.extend(recipe.pbx_libraries)
|
||||||
|
libraries.extend(recipe.dist_libraries)
|
||||||
|
|
||||||
|
pbx_frameworks = list(set(pbx_frameworks))
|
||||||
|
pbx_libraries = list(set(pbx_libraries))
|
||||||
|
libraries = list(set(libraries))
|
||||||
|
|
||||||
|
print("-" * 70)
|
||||||
|
print("The project need to have:")
|
||||||
|
print("iOS Frameworks: {}".format(pbx_frameworks))
|
||||||
|
print("iOS Libraries: {}".format(pbx_libraries))
|
||||||
|
print("Libraries: {}".format(libraries))
|
||||||
|
|
||||||
|
print("-" * 70)
|
||||||
|
print("Analysis of {}".format(filename))
|
||||||
|
|
||||||
|
from mod_pbxproj import XcodeProject
|
||||||
|
project = XcodeProject.Load(filename)
|
||||||
|
sysroot = sh.xcrun("--sdk", "iphonesimulator", "--show-sdk-path").strip()
|
||||||
|
|
||||||
|
group = project.get_or_create_group("Frameworks")
|
||||||
|
for framework in pbx_frameworks:
|
||||||
|
print("Ensure {} is in the project".format(framework))
|
||||||
|
f_path = join(sysroot, "System", "Library", "Frameworks",
|
||||||
|
"{}.framework".format(framework))
|
||||||
|
project.add_file_if_doesnt_exist(f_path, parent=group, tree="DEVELOPER_DIR")
|
||||||
|
for library in pbx_libraries:
|
||||||
|
print("Ensure {} is in the project".format(library))
|
||||||
|
f_path = join(sysroot, "usr", "lib",
|
||||||
|
"{}.dylib".format(library))
|
||||||
|
project.add_file_if_doesnt_exist(f_path, parent=group, tree="DEVELOPER_DIR")
|
||||||
|
for library in libraries:
|
||||||
|
print("Ensure {} is in the project".format(library))
|
||||||
|
project.add_file_if_doesnt_exist(library, parent=group)
|
||||||
|
if project.modified:
|
||||||
|
project.backup()
|
||||||
|
project.save()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
|
@ -770,6 +839,7 @@ Available commands:
|
||||||
|
|
||||||
Xcode:
|
Xcode:
|
||||||
create Create a new xcode project
|
create Create a new xcode project
|
||||||
|
update Update an existing xcode project (frameworks, libraries..)
|
||||||
""")
|
""")
|
||||||
parser.add_argument("command", help="Command to run")
|
parser.add_argument("command", help="Command to run")
|
||||||
args = parser.parse_args(sys.argv[1:2])
|
args = parser.parse_args(sys.argv[1:2])
|
||||||
|
@ -875,5 +945,43 @@ Xcode:
|
||||||
"dist_dir": ctx.dist_dir,
|
"dist_dir": ctx.dist_dir,
|
||||||
}
|
}
|
||||||
cookiecutter(template_dir, no_input=True, extra_context=context)
|
cookiecutter(template_dir, no_input=True, extra_context=context)
|
||||||
|
filename = join(
|
||||||
|
getcwd(),
|
||||||
|
"{}-ios".format(args.name.lower()),
|
||||||
|
"{}.xcodeproj".format(args.name.lower()),
|
||||||
|
"project.pbxproj")
|
||||||
|
update_pbxproj(filename)
|
||||||
|
print("--")
|
||||||
|
print("Project directory : {}-ios".format(
|
||||||
|
args.name.lower()))
|
||||||
|
print("XCode project : {0}-ios/{0}.xcodeproj".format(
|
||||||
|
args.name.lower()))
|
||||||
|
|
||||||
|
def update(self):
|
||||||
|
parser = argparse.ArgumentParser(
|
||||||
|
description="Update an existing xcode project")
|
||||||
|
parser.add_argument("filename", help="Path to your project or xcodeproj")
|
||||||
|
args = parser.parse_args(sys.argv[2:])
|
||||||
|
|
||||||
|
|
||||||
|
filename = args.filename
|
||||||
|
if not filename.endswith(".xcodeproj"):
|
||||||
|
# try to find the xcodeproj
|
||||||
|
from glob import glob
|
||||||
|
xcodeproj = glob(join(filename, "*.xcodeproj"))
|
||||||
|
if not xcodeproj:
|
||||||
|
print("ERROR: Unable to find a xcodeproj in {}".format(filename))
|
||||||
|
sys.exit(1)
|
||||||
|
filename = xcodeproj[0]
|
||||||
|
|
||||||
|
filename = join(filename, "project.pbxproj")
|
||||||
|
if not exists(filename):
|
||||||
|
print("ERROR: {} not found".format(filename))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
update_pbxproj(filename)
|
||||||
|
print("--")
|
||||||
|
print("Project {} updated".format(filename))
|
||||||
|
|
||||||
|
|
||||||
ToolchainCL()
|
ToolchainCL()
|
||||||
|
|
1498
tools/external/mod_pbxproj.py
vendored
Executable file
1498
tools/external/mod_pbxproj.py
vendored
Executable file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue