File: cv_build_utils.py

package info (click to toggle)
opencv 4.6.0%2Bdfsg-12
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 276,172 kB
  • sloc: cpp: 1,079,020; xml: 682,526; python: 43,885; lisp: 30,943; java: 25,642; ansic: 7,968; javascript: 5,956; objc: 2,039; sh: 1,017; cs: 601; perl: 494; makefile: 179
file content (65 lines) | stat: -rw-r--r-- 2,108 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python
"""
Common utilities. These should be compatible with Python 2 and 3.
"""

from __future__ import print_function
import sys, re
from subprocess import check_call, check_output, CalledProcessError

def execute(cmd, cwd = None):
    print("Executing: %s in %s" % (cmd, cwd), file=sys.stderr)
    print('Executing: ' + ' '.join(cmd))
    retcode = check_call(cmd, cwd = cwd)
    if retcode != 0:
        raise Exception("Child returned:", retcode)

def print_header(text):
    print("="*60)
    print(text)
    print("="*60)

def print_error(text):
    print("="*60, file=sys.stderr)
    print("ERROR: %s" % text, file=sys.stderr)
    print("="*60, file=sys.stderr)

def get_xcode_major():
    ret = check_output(["xcodebuild", "-version"]).decode('utf-8')
    m = re.match(r'Xcode\s+(\d+)\..*', ret, flags=re.IGNORECASE)
    if m:
        return int(m.group(1))
    else:
        raise Exception("Failed to parse Xcode version")

def get_xcode_version():
    """
    Returns the major and minor version of the current Xcode
    command line tools as a tuple of (major, minor)
    """
    ret = check_output(["xcodebuild", "-version"]).decode('utf-8')
    m = re.match(r'Xcode\s+(\d+)\.(\d+)', ret, flags=re.IGNORECASE)
    if m:
        return (int(m.group(1)), int(m.group(2)))
    else:
        raise Exception("Failed to parse Xcode version")

def get_xcode_setting(var, projectdir):
    ret = check_output(["xcodebuild", "-showBuildSettings"], cwd = projectdir).decode('utf-8')
    m = re.search("\s" + var + " = (.*)", ret)
    if m:
        return m.group(1)
    else:
        raise Exception("Failed to parse Xcode settings")

def get_cmake_version():
    """
    Returns the major and minor version of the current CMake
    command line tools as a tuple of (major, minor, revision)
    """
    ret = check_output(["cmake", "--version"]).decode('utf-8')
    m = re.match(r'cmake\sversion\s+(\d+)\.(\d+).(\d+)', ret, flags=re.IGNORECASE)
    if m:
        return (int(m.group(1)), int(m.group(2)), int(m.group(3)))
    else:
        raise Exception("Failed to parse CMake version")