Hello, avin. Thanks for your work.
I do some changes to redist.py to create installer for x64. I never
use python before and I not sure that my changes enough for full x64
support but it work. Maybe it can be useful for your work.
So, I'm use python 3.1.3.amd64, OpenNI-Win64-1.1.0.39-Dev-Unstable,
VS2008 and VS2010.
---
# This code is mod of initial redist.py created by
avin...@gmail.com
# Python version: 3.1.3.amd64
# Platform: Windows 7 x64
# OpenNI: OpenNI-Win64-1.1.0.39-Dev-Unstable
# VS: VS2008 and VS2010
# Code was modificate to automate creating redist for x64 version of
Win platform because initial version isn't work correctly. You can
change env "vc_build_bits", "VC_version" and VS_INST_DIR_09
(VS_INST_DIR_10) to build installer for your platform.
#
derig...@gmail.com
# 2011-04-17
#
import os
import sys
import shutil
import win32con, pywintypes
import re
import subprocess
from xml.dom.minidom import parse, parseString
###
vc_build_bits = 64 # or 32
VC_version = 10 # or 9
VS_INST_DIR_09 = "c:\\Program Files (x86)\\Microsoft Visual Studio 9.0\
\Common7\\IDE\\"
VS_INST_DIR_10 = "c:\\Program Files (x86)\\Microsoft Visual Studio
10.0\\Common7\\IDE\\"
###
ROOT_DIR = os.path.abspath(os.path.dirname(sys.argv[0]))
REDIST_DIR = os.path.join(ROOT_DIR, "..", "Redist")
OUTPUT_DIR = os.path.join(ROOT_DIR, "Output")
SCRIPT_DIR = os.getcwd()
print("work dir of redist.py:")
print (SCRIPT_DIR)
def finish_script(exit_code):
os.chdir(SCRIPT_DIR)
#logging.shutdown()
exit(exit_code)
def regx_replace(findStr,repStr,filePath):
"replaces all findStr by repStr in file filePath using regualr
expression"
findStrRegx = re.compile(findStr)
tempName=filePath+'~~~'
input = open(filePath)
output = open(tempName,'w')
for s in input:
output.write(findStrRegx.sub(repStr,s))
output.close()
input.close()
os.remove(filePath)
os.rename(tempName,filePath)
# remove output dir
if os.path.exists(REDIST_DIR):
os.system("rmdir /S /Q \"" + REDIST_DIR + "\"")
if os.path.exists(OUTPUT_DIR):
os.system("rmdir /S /Q \"" + OUTPUT_DIR + "\"")
os.mkdir(REDIST_DIR)
os.mkdir(OUTPUT_DIR)
# build
print("Building...")
os.chdir(os.path.join(ROOT_DIR, "..", "Build"))
#
VS_NEED_UPGRADE = 0
VS_INST_DIR = VS_INST_DIR_09
if VC_version == 10:
VS_NEED_UPGRADE = 1
VS_INST_DIR = VS_INST_DIR_10
if VS_NEED_UPGRADE == 1:
res = subprocess.call("\"" + VS_INST_DIR + "devenv\" " +
"Engine.sln" + " /upgrade /out " + SCRIPT_DIR + "\\Output\
\build.log",close_fds=True)
if res != 0:
raise Exception("build failed!")
# check version
if vc_build_bits == 32:
ACTIVE_CONFIG = "win32"
elif vc_build_bits==64:
ACTIVE_CONFIG = "x64"
res = subprocess.call("\"" + VS_INST_DIR + "devenv\" Engine.sln /build
\"Release|"+ACTIVE_CONFIG+"\" /out " + SCRIPT_DIR + "\\Output\
\build.log",close_fds=True)
if res != 0:
raise Exception("build failed!")
os.chdir(SCRIPT_DIR)
print("Copying into redist folder...")
# check version
if vc_build_bits == 32:
VERSION_DIR = "Bin"
elif vc_build_bits==64:
VERSION_DIR = "Bin64"
# create folder structure
os.mkdir(os.path.join(REDIST_DIR, VERSION_DIR))
os.mkdir(os.path.join(REDIST_DIR, "Data"))
os.mkdir(os.path.join(REDIST_DIR, "Driver"))
os.mkdir(os.path.join(REDIST_DIR, "Driver", "amd64"))
os.mkdir(os.path.join(REDIST_DIR, "Driver", "x86"))
# copy EPL
shutil.copy(os.path.join(ROOT_DIR, "..", "..", "..", "GPL.txt"),
REDIST_DIR)
shutil.copy(os.path.join(ROOT_DIR, "..", "..", "..", "GPL.txt"),
OUTPUT_DIR)
shutil.copy(os.path.join(ROOT_DIR, "..", "..", "..", "LGPL.txt"),
REDIST_DIR)
shutil.copy(os.path.join(ROOT_DIR, "..", "..", "..", "LGPL.txt"),
OUTPUT_DIR)
# copy binaries
RELEASE_DIR = os.path.join(ROOT_DIR, "..", VERSION_DIR, "Release")
for file in os.listdir(RELEASE_DIR):
if os.path.splitext(file)[1] in [".dll", ".exe"]:
shutil.copy(os.path.join(RELEASE_DIR, file),
os.path.join(REDIST_DIR, VERSION_DIR))
# copy data
DATA_DIR = os.path.join(ROOT_DIR, "..", "..", "..", "Data")
for file in os.listdir(DATA_DIR):
shutil.copy(os.path.join(DATA_DIR, file), os.path.join(REDIST_DIR,
"Data"))
# copy driver
DRIVER_DIR = os.path.join(ROOT_DIR, "..", "Driver")
for file in os.listdir(DRIVER_DIR):
try:
shutil.copy(os.path.join(DRIVER_DIR, file), os.path.join(REDIST_DIR,
"Driver"))
except IOError:
pass
DRIVER_DIRX86 = os.path.join(ROOT_DIR, "..", "Driver", "x86")
for file in os.listdir(DRIVER_DIRX86):
shutil.copy(os.path.join(DRIVER_DIRX86, file),
os.path.join(REDIST_DIR, "Driver", "x86"))
DRIVER_DIRAMD64 = os.path.join(ROOT_DIR, "..", "Driver", "amd64")
for file in os.listdir(DRIVER_DIRAMD64):
shutil.copy(os.path.join(DRIVER_DIRAMD64, file),
os.path.join(REDIST_DIR, "Driver", "amd64"))
# create installer
print("Creating installer...")
os.chdir(SCRIPT_DIR + "\\EE_NI")
#print "* move XnLeanDeviceSensorV2.dll"
#os.system("move /Y " + WORK_DIR + "\\Platform\\Win32\\Bin\
\XnLeanDeviceSensorV2.dll \\Platform\\Win32\\Bin\
\XnDeviceSensorV2.dll")
print ("* Set BinaryOnlyRedist=True")
os.system("attrib -r Includes\\EENIVariables.wxi")
regx_replace("BinaryOnlyRedist=(.*)", "BinaryOnlyRedist=True?>",
"Includes\\EENIVariables.wxi")
logFilename = "BuildEngine"
print ("* Build EE_NI.wixproj")
if VS_NEED_UPGRADE == 1:
res = subprocess.call("\""+VS_INST_DIR + "devenv\" EE_NI.sln /
upgrade /out " + SCRIPT_DIR + "\\Output\\" + logFilename +
".txt",close_fds=True)
if res != 0:
raise Exception("Failed upgrade installer!")
# check version
if vc_build_bits == 32:
ACTIVE_CONFIG = "x86"
elif vc_build_bits==64:
ACTIVE_CONFIG = "x64"
res = subprocess.call("\""+VS_INST_DIR + "devenv\" EE_NI.wixproj /
build \"release|"+ACTIVE_CONFIG+""\
+"\" /out "+SCRIPT_DIR+"\\Output\\" + logFilename +
".txt",close_fds=True)
if res != 0:
raise Exception("Failed creating installer!")
currDir = os.getcwd()
print (currDir)
moveCmd = "move bin\\Release\\en-US\\EE_NI.msi " + SCRIPT_DIR + "\
\Output\\Sensor-Win-OpenSource" + "-" + str(vc_build_bits) + "bit.msi"
print (moveCmd + "...")
os.system(moveCmd)
print("Done.")
finish_script(0)