-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsconsUtils.py
124 lines (102 loc) · 4.7 KB
/
sconsUtils.py
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
# <license>
# Copyright (C) 2011 Andrea Interguglielmi, All rights reserved.
# This file is part of the coral repository downloaded from http://code.google.com/p/coral-repo.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# </license>
import os
import sys
import fnmatch
import string
import traceback
if os.environ.has_key("CORAL_BUILD_FLAVOUR") == False:
os.environ["CORAL_BUILD_FLAVOUR"] = ""
def findFiles(root, recurse = True, pattern = '*.*', return_folders = False):
result = []
try:
names = os.listdir(root)
except os.error:
return result
pattern = pattern or '*'
pat_list = string.splitfields( pattern , ';' )
for name in names:
fullname = os.path.normpath(os.path.join(root, name))
for pat in pat_list:
if fnmatch.fnmatch(name, pat):
if os.path.isfile(fullname) or (return_folders and os.path.isdir(fullname)):
result.append(fullname)
continue
if recurse:
if os.path.isdir(fullname) and not os.path.islink(fullname):
result = result + findFiles( fullname, recurse, pattern, return_folders )
return result
def autoFixDynamicLinks(lib, verbose = False):
f = os.popen('otool -L "%s"'%(lib,))
entries = f.read().split('\n')[1:]
for entry in entries:
oldLibName = entry.split(" ")[0].strip()
if not fnmatch.fnmatch(oldLibName, "/System/Library/Frameworks/*"): #exclude system frameworks
newLibName = entry.split(" ")[0].split("/")[-1].strip()
if verbose:
print "Changing lib path:", oldLibName, "from:", newLibName, "to:", lib
os.system('install_name_tool -change "' + oldLibName + '" "' + newLibName + '" "' + lib + '"')
if verbose:
print "- changeDynamicLink result-------"
print os.system("otool -L %s" %(lib))
print "---------------------------------"
def changeDynamicLink(lib, old_path_prefix, new_path_prefix, quiet = False):
f = os.popen('otool -L "%s"'%(lib,))
x = f.read().split('\n')[1:]
for l in x:
if l.count(old_path_prefix):
ol = l[1:].split(' ')[0]
nw = new_path_prefix + ol.split(old_path_prefix)[-1]
if not quiet:
print "Changing lib path:", lib, "from:", ol, "to:", nw
os.system('install_name_tool -change %s %s %s' %(ol,nw,lib))
if not quiet:
print "- changeDynamicLink result-------"
print os.system("otool -L %s" %(lib))
print "---------------------------------"
tryedImportingBuildEnv = False
def importBuildEnvs():
global tryedImportingBuildEnv
if "buildEnv" not in sys.modules.keys():
try:
sys.path.append(os.path.join(os.path.dirname(__file__), "buildEnvs"))
import buildEnv
print buildEnv.__file__
print "* Coral Build: imported buildEnv.py"
except:
if tryedImportingBuildEnv == False:
print "Coral Build: Tried importing buildEnv.py but failed."
tryedImportingBuildEnv = True
print traceback.format_exc()
def getEnvVar(varName):
var = ""
if varName in os.environ:
var = os.environ[varName]
else:
raise Exception("Could not find env var: " + str(varName))
return var