From f0912a3bbbb6345cea0296f215d510285b55d8dd Mon Sep 17 00:00:00 2001 From: Gautier Pelloux-Prayer Date: Thu, 2 Jul 2015 17:33:08 +0200 Subject: [PATCH] prepare.py: add check_tools function --- prepare.py | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 70 insertions(+), 2 deletions(-) diff --git a/prepare.py b/prepare.py index c4469b0f1..23a448966 100755 --- a/prepare.py +++ b/prepare.py @@ -27,10 +27,11 @@ import os import re import shutil import sys -from subprocess import Popen +from subprocess import Popen, PIPE sys.dont_write_bytecode = True sys.path.insert(0, 'submodules/cmake-builder') import prepare +from distutils.spawn import find_executable class IOSTarget(prepare.Target): @@ -148,6 +149,69 @@ def extract_libs_list(): return list(set(l)) +def check_installed(binary, prog=None, warn=True): + if not find_executable(binary): + if warn: + print("Could not find {}. Please install {}".format(binary, prog)) + return 1 + return 0 + + +def check_tools(): + ret = 0 + + if " " in os.path.dirname(os.path.realpath(__file__)): + print("Invalid location: your location should not contain spaces") + ret = 1 + + for prog in ["autoconf", "automake", "pkg-config", "doxygen", "java", "nasm", "gettext", "wget", "yasm", "optipng"]: + ret |= check_installed(prog, "it") + ret |= check_installed("ginstall", "coreutils") + ret |= check_installed("intltoolize", "intltool") + ret |= check_installed("convert", "imagemagick") + + if not check_installed("libtoolize", warn=False): + if check_installed("glibtoolize", "libtool"): + glibtoolize_path = find_executable(glibtoolize) + ret = 1 + error = "Please do a symbolic link from glibtoolize to libtoolize: 'ln -s {} ${}'" + print(error.format(glibtoolize_path, glibtoolize_path.replace("glibtoolize", "libtoolize"))) + + # just ensure that JDK is installed - if not, it will automatiaclyl display a popup to user + if not Popen("java -version".split(" "), stderr=PIPE, stdout=PIPE): + print("Please install Java JDK (not just JRE)") + ret = 1 + + # needed by x264 + check_installed("gas-preprocessor.pl", "it following the README.md") + + devnull = open(os.devnull, 'wb') + nasm_output = Popen("nasm -f elf32".split(" "), stderr=PIPE, stdout=PIPE).stderr.read() + if "fatal: unrecognised output format" in nasm_output: + print( + "Invalid version of nasm: your version does not support elf32 output format. If you have installed nasm, please check that your PATH env variable is set correctly.") + ret = 1 + + if not os.path.isdir("submodules/linphone/mediastreamer2") or not os.path.isdir("submodules/linphone/oRTP"): + print("Missing some git submodules. Did you run 'git submodule update --init --recursive'?") + ret = 1 + if not Popen("xcrun --sdk iphoneos --show-sdk-path".split(" "), stdout=devnull, stderr=devnull): + print("iOS SDK not found, please install Xcode from AppStore or equivalent") + ret = 1 + else: + sdk_platform_path = Popen("xcrun --sdk iphonesimulator --show-sdk-platform-path".split(" "), stdout=PIPE, stderr=devnull).stdout.read()[:-1] + sdk_strings_path = "{}/{}".format(sdk_platform_path, "Developer/usr/bin/strings") + if not os.path.isfile(sdk_strings_path): + strings_path = find_executable("strings") + print("strings binary missing, please run 'sudo ln -s {} {}'".format(strings_path, sdk_strings_path)) + ret = 1 + + if ret == 1: + print("Failed to detect required tools, aborting.") + + return ret + + def install_git_hook(): git_hook_path = ".git{sep}hooks{sep}pre-commit".format(sep=os.sep) if os.path.isdir(".git{sep}hooks".format(sep=os.sep)) and not os.path.isfile(git_hook_path): @@ -398,6 +462,9 @@ def main(argv=None): if args.debug_verbose: additional_args += ["-DENABLE_DEBUG_LOGS=YES"] + if check_tools() != 0: + return 1 + install_git_hook() selected_platforms = [] @@ -426,7 +493,8 @@ def main(argv=None): retcode = prepare.run(target, args.debug, False, args.list_cmake_variables, args.force, additional_args) if retcode != 0: if retcode == 51: - retcode = Popen(["make", "help-prepare-options"]) + Popen("make help-prepare-options".split(" ")) + retcode = 0 return retcode if args.clean: