Ejemplo n.º 1
0
def get_build_path(fatal=True):
    global build_dir
    if build_dir:
        return build_dir

    def is_valid_build_directory(path):
        return os.path.exists(os.path.join(path, 'CMakeCache.txt')) or \
            os.path.exists(os.path.join(path, 'bin/WebKitTestRunner'))

    if len(sys.argv[1:]) > 1 and os.path.exists(sys.argv[-1]) and is_valid_build_directory(sys.argv[-1]):
        return sys.argv[-1]

    # Debian and Ubuntu build both flavours of the library (with gtk2
    # and with gtk3); they use directories build-2.0 and build-3.0 for
    # that, which is not handled by the above cases; we check that the
    # directory where we are called from is a valid build directory,
    # which should handle pretty much all other non-standard cases.
    build_dir = os.getcwd()
    if is_valid_build_directory(build_dir):
        return build_dir

    base_build_dir = top_level_path('WebKitBuild')

    scm = SCMDetector(FileSystem(), Executive()).default_scm()
    if isinstance(scm, Git):
        is_branch_build = scm.read_config('core.webKitBranchBuild', bool)
        if is_branch_build and is_branch_build.lower() == 'true':
            current_branch = scm._current_branch()
            if current_branch != 'master':
                base_build_dir = os.path.join(base_build_dir, scm._current_branch())

    global build_types
    for build_type in build_types:
        build_dir = os.path.join(base_build_dir, build_type)
        if is_valid_build_directory(build_dir):
            return build_dir

    # distcheck builds in a directory named _build in the top-level path.
    build_dir = top_level_path("_build")
    if is_valid_build_directory(build_dir):
        return build_dir

    build_dir = top_level_path()
    if is_valid_build_directory(build_dir):
        return build_dir

    build_dir = base_build_dir
    if is_valid_build_directory(build_dir):
        return build_dir

    print('Could not determine build directory.')
    if fatal:
        sys.exit(1)