summaryrefslogtreecommitdiff
path: root/dist/create_installer.py
blob: 584df06772f78f4ed2bc63b65a213f7a22abfa5e (plain)
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/usr/bin/python
# -*- coding: utf-8 -*-

# Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
# Contact: http://engin.io
#
# You may use this file under the terms of the 3-clause BSD license.
# See the file LICENSE from this package for details.
#

from __future__ import print_function
import os
import shutil
import subprocess
import sys
import glob

# Qt
qmake = "qmake"
qmake_spec = subprocess.check_output([qmake, "-query", "QMAKE_SPEC"]).strip()

make = "make"
if sys.platform == "win32":
    make = "jom"


# from the installer framework
binarycreator = "binarycreator"

# visual studio
#setEnv = "c:\\Program Files\\Microsoft SDKs\\Windows\\v7.1\\Bin\\SetEnv.Cmd"

# should be extracted from .qmake.conf
VERSION = "unknown_version"

# Build Enginio

subprocess.check_call(["git", "clean", "-xdf"])

os.mkdir("build")
os.chdir("build")

# this is evil - keep the process alive so that we can set the right sdk env here
# and it may not work, at least currently I have conflicts with VS 7.1 and 8
#process = subprocess.Popen('cmd.exe /k\n', shell=True, stdin=subprocess.PIPE)
#process.stdin.write('call "' + setEnv + '"\n')
#process.stdin.write(qmake + " ../..\r\n")
#process.stdin.write(jom + "\n")

# docs build currently errors out!
# process.stdin.write("nmake docs\n")
#process.stdin.write("exit\n")
#process.communicate()

subprocess.check_call([qmake, "../.."])
print("Compiling Enginio...")

try:
    from subprocess import DEVNULL # py3k
except ImportError:
    DEVNULL = open(os.devnull, 'wb')

subprocess.check_call([make,], stdout=DEVNULL)

if sys.platform == "win32": # bug with jom subtargets
    subprocess.check_call(["nmake", "docs"])
else:
    subprocess.check_call([make, "docs"])


# on Windows dlls are built in the lib dir but need to be in bin
if sys.platform == "win32":
    os.mkdir("bin")
    alldlls = glob.glob("lib/*.dll")
    for dll in alldlls:
        os.rename(dll, "bin" + dll[3:])

# Copy files around
os.chdir("../..")

packages = {
    "com.digia.enginio": ["include", "lib", "qml", "doc/qtenginio.qch", ],
    "com.digia.enginioExamples": ["examples",],
    "com.digia.enginioDocumentation": ["doc/qtenginio",],
    "com.digia.enginioSources": ["src",],
}
if sys.platform == "win32":
    packages["com.digia.enginio"].append("bin")


print("Creating installer...")

for package in packages:
    for path in packages[package]:
        sourcePath = path
        if not os.path.exists(sourcePath):
            sourcePath = "dist/build/" + path
        if not os.path.exists(sourcePath):
            print("ERROR: Could not find path '" + path + "' in source or build directory.")
            exit(1)
        print("Creating ", path, " dir.")
        dest = "dist/packages/" + package + "/data/" + path
        if os.path.exists(dest):
            print("ERROR: ", dest, " exists already.")
            exit(1)
        if os.path.isfile(sourcePath):
            os.mkdir(os.path.dirname(dest))
            shutil.copyfile(sourcePath, dest)
        else:
            shutil.copytree(sourcePath, dest)

# copy the real headers
# src/enginio_client
# src/enginio_plugin
headerPath = "dist/packages/com.digia.enginio/data/include/Enginio/"

import fileinput
for line in fileinput.input(".qmake.conf"):
    if line.startswith("MODULE_VERSION"):
        import re
        VERSION = re.search(r'[0-9.]+', line).group(0)


privateHeaderPath = headerPath + VERSION + "/Enginio/private"
allHeaders = glob.glob("src/*/*.h")
for header in allHeaders:
    fileName = header[header.rindex(os.sep):]
    if header.endswith("_p.h"):
        print("Copy ", header, " to ", privateHeaderPath + fileName)
        shutil.copyfile(header, privateHeaderPath + fileName)
    else:
        print("Copy ", header, " to ", headerPath + fileName)
        shutil.copyfile(header, headerPath + fileName)


os.chdir("dist")


# the Module .pri file is special - take the one from mkspecs/modules_inst
modulesPath = "packages/com.digia.enginio/data/mkspecs/modules"
os.mkdir("packages/com.digia.enginio/data/mkspecs")
os.mkdir(modulesPath)
shutil.copyfile("build/mkspecs/modules-inst/qt_lib_enginio.pri", modulesPath + "/qt_lib_enginio.pri")

pkgname = "QtEnginioInstaller_" + VERSION + '-' + qmake_spec
subprocess.check_call([binarycreator, "--offline-only", "-c", "config" + os.sep + "config.xml", "-p", "packages", pkgname])

if sys.platform == "darwin":
    subprocess.check_call(["hdiutil", "create", pkgname + ".dmg", "-srcfolder", pkgname + ".app"])

print("Installer created.")