File: indigo-release-utils.py

package info (click to toggle)
indigo 1.4.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 48,936 kB
  • sloc: ansic: 332,816; cpp: 169,470; python: 20,033; java: 13,701; cs: 9,979; asm: 8,475; sql: 6,743; xml: 6,354; javascript: 1,245; sh: 555; php: 506; makefile: 54
file content (122 lines) | stat: -rw-r--r-- 5,014 bytes parent folder | download
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import os
import shutil
import subprocess
from optparse import OptionParser
import re

version = ""
cur_dir = os.path.split(__file__)[0]
for line in open(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "api", "indigo-version.cmake")):
    m = re.search(r'SET\(INDIGO_VERSION "(.*)"', line)
    if m:
        version = m.group(1)

presets = {
    "win32-2013": ("Visual Studio 12", ""),
    "win32-2015": ("Visual Studio 14", ""),
    "win32-2017": ("Visual Studio 15", ""),
    "win32-2019": ("Visual Studio 16 2019", "-A Win32"),
    "win64-2013": ("Visual Studio 12 Win64", ""),
    "win64-2015": ("Visual Studio 14 Win64", ""),
    "win64-2017": ("Visual Studio 15 Win64", ""),
    "win64-2019": ("Visual Studio 16 2019", ""),
    "win32-mingw": ("MinGW Makefiles", "-DSUBSYSTEM_NAME=x86"),
    "win64-mingw": ("MinGW Makefiles", "-DSUBSYSTEM_NAME=x64"),
    "linux32": ("Unix Makefiles", "-DSUBSYSTEM_NAME=x86"),
    "linux32-universal": ("Unix Makefiles", "-DSUBSYSTEM_NAME=x86"),
    "linux64": ("Unix Makefiles", "-DSUBSYSTEM_NAME=x64"),
    "linux64-universal": ("Unix Makefiles", "-DSUBSYSTEM_NAME=x64"),
    "mac10.7": ("Xcode", "-DSUBSYSTEM_NAME=10.7"),
    "mac10.8": ("Xcode", "-DSUBSYSTEM_NAME=10.8"),
    "mac10.9": ("Xcode", "-DSUBSYSTEM_NAME=10.9"),
    "mac10.10": ("Xcode", "-DSUBSYSTEM_NAME=10.10"),
    "mac10.11": ("Xcode", "-DSUBSYSTEM_NAME=10.11"),
    "mac10.12": ("Xcode", "-DSUBSYSTEM_NAME=10.12"),
    "mac10.13": ("Xcode", "-DSUBSYSTEM_NAME=10.13"),
    "mac10.14": ("Xcode", "-DSUBSYSTEM_NAME=10.14"),
    "mac10.15": ("Xcode", "-DSUBSYSTEM_NAME=10.15"),
    "mac-universal": ("Unix Makefiles", "-DSUBSYSTEM_NAME=10.7"),
}

parser = OptionParser(description='Indigo utilities build script')
parser.add_option('--generator', help='this option is passed as -G option for cmake')
parser.add_option('--params', default="", help='additional build parameters')
parser.add_option('--config', default="Release", help='project configuration')
parser.add_option('--nobuild', default=False, action="store_true", help='configure without building', dest="nobuild")
parser.add_option('--clean', default=False, action="store_true", help='delete all the build data', dest="clean")
parser.add_option('--preset', type="choice", dest="preset", choices=list(presets.keys()), help='build preset %s' % (str(presets.keys())))

(args, left_args) = parser.parse_args()
if len(left_args) > 0:
    print("Unexpected arguments: %s" % (str(left_args)))
    exit()

if args.preset:
    args.generator, args.params = presets[args.preset]
if not args.generator:
    print("Generator must be specified")
    exit()

cur_dir = os.path.abspath(os.path.dirname(__file__))
root = os.path.normpath(os.path.join(cur_dir, ".."))
project_dir = os.path.join(cur_dir, "indigo-utils")

if args.generator.find("Unix Makefiles") != -1:
    args.params += " -DCMAKE_BUILD_TYPE=" + args.config

if args.preset and args.preset.find('universal') != -1:
    args.params += ' -DUNIVERSAL_BUILD=TRUE'

args.params += ' -DWITH_STATIC=TRUE'

build_dir = (args.generator + " " + args.params)
build_dir = "indigo_utils_" + build_dir.replace(" ", "_").replace("=", "_").replace("-", "_")

full_build_dir = os.path.join(root, "build", build_dir)
if os.path.exists(full_build_dir) and args.clean:
    print("Removing previous project files")
    shutil.rmtree(full_build_dir)
if not os.path.exists(full_build_dir):
    os.makedirs(full_build_dir)

os.chdir(root)
if not os.path.exists("dist"):
    os.mkdir("dist")
dist_dir = os.path.join(root, "dist")

os.chdir(full_build_dir)
cmake_build_prefix = ''
if (args.preset.find('linux') != -1 or args.preset.find('universal') != -1):
    cmake_build_prefix = 'CC=gcc CXX=g++'
command = "%s cmake -G \"%s\" %s %s" % (cmake_build_prefix, args.generator, args.params, project_dir)
print(command)
subprocess.check_call(command, shell=True)

if args.nobuild:
    exit(0)

for f in os.listdir(full_build_dir):
    path, ext = os.path.splitext(f)
    if ext == ".zip":
        os.remove(os.path.join(full_build_dir, f))

command = "cmake --build . --config %s" % (args.config)
print(command)
subprocess.call(command, shell=True)
if args.generator.find("Unix Makefiles") != -1:
    subprocess.check_call("make package", shell=True)
elif args.generator.find("Xcode") != -1:
    subprocess.check_call("cmake --build . --target package --config %s" % (args.config), shell=True)
elif args.generator.find("Visual Studio") != -1:
    subprocess.check_call("cmake --build . --target PACKAGE --config %s" % (args.config), shell=True)
elif args.generator.find("MinGW Makefiles") != -1:
    subprocess.check_call("mingw32-make package", shell=True)
else:
    print("Do not know how to run package and install target")
subprocess.check_call("ctest -V --timeout 10 -C %s ." % (args.config), shell=True)


for f in os.listdir(full_build_dir):
    path, ext = os.path.splitext(f)
    if ext == ".zip":
        shutil.copy(os.path.join(full_build_dir, f), os.path.join(dist_dir, f.replace('-shared', '')))