| 1 |
|
| 2 |
|
| 3 |
import optparse |
| 4 |
import os |
| 5 |
import platform |
| 6 |
import socket |
| 7 |
import subprocess |
| 8 |
import sys |
| 9 |
|
| 10 |
PROG = "r" + "$Rev: 17 $".strip("$ ").replace("Rev: ", "") |
| 11 |
PYTHON = os.path.basename(sys.executable) |
| 12 |
build_type = "" |
| 13 |
vs_target = "" |
| 14 |
s60_target = "" |
| 15 |
no_test = False |
| 16 |
no_pjsua_test = False |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
def gcc_version(gcc): |
| 22 |
proc = subprocess.Popen(gcc + " -v", stdout=subprocess.PIPE, |
| 23 |
stderr=subprocess.STDOUT, shell=True) |
| 24 |
ver = "" |
| 25 |
while True: |
| 26 |
s = proc.stdout.readline() |
| 27 |
if not s: |
| 28 |
break |
| 29 |
if s.find("gcc version") >= 0: |
| 30 |
ver = s.split(None, 3)[2] |
| 31 |
break |
| 32 |
proc.wait() |
| 33 |
return "gcc" + ver |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
class VSVersion: |
| 39 |
def __init__(self): |
| 40 |
self.version = "8" |
| 41 |
self.release = "2005" |
| 42 |
|
| 43 |
proc = subprocess.Popen("cl", stdout=subprocess.PIPE, |
| 44 |
stderr=subprocess.STDOUT) |
| 45 |
while True: |
| 46 |
s = proc.stdout.readline() |
| 47 |
if s=="": |
| 48 |
break |
| 49 |
pos = s.find("Version") |
| 50 |
if pos > 0: |
| 51 |
proc.wait() |
| 52 |
s = s[pos+8:] |
| 53 |
ver = s.split(None, 1)[0] |
| 54 |
major = ver[0:2] |
| 55 |
if major=="12": |
| 56 |
self.version = "6" |
| 57 |
self.release = "98" |
| 58 |
break |
| 59 |
elif major=="13": |
| 60 |
self.version = "7" |
| 61 |
self.release = "2003" |
| 62 |
break |
| 63 |
elif major=="14": |
| 64 |
self.version = "8" |
| 65 |
self.release = "2005" |
| 66 |
break |
| 67 |
elif major=="15": |
| 68 |
self.version = "9" |
| 69 |
self.release = "2008" |
| 70 |
break |
| 71 |
elif major=="16": |
| 72 |
self.version = "10" |
| 73 |
self.release = "2010" |
| 74 |
break |
| 75 |
else: |
| 76 |
self.version = "11" |
| 77 |
self.release = "2012" |
| 78 |
break |
| 79 |
proc.wait() |
| 80 |
self.vs_version = "vs" + self.version |
| 81 |
self.vs_release = "vs" + self.release |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
class S60SDK: |
| 88 |
def __init__(self): |
| 89 |
self.epocroot = "" |
| 90 |
self.sdk = "" |
| 91 |
self.device = "" |
| 92 |
|
| 93 |
|
| 94 |
if not "EPOCROOT" in os.environ: |
| 95 |
sys.stderr.write("Error: EPOCROOT environment variable is not set\n") |
| 96 |
sys.exit(1) |
| 97 |
epocroot = os.environ["EPOCROOT"] |
| 98 |
|
| 99 |
if epocroot[-1] != "\\": |
| 100 |
epocroot = epocroot + "\\" |
| 101 |
os.environ["EPOCROOT"] = epocroot |
| 102 |
self.epocroot = epocroot |
| 103 |
self.sdk = sdk1 = epocroot.split("\\")[-2] |
| 104 |
self.device = "@" + self.sdk + ":com.nokia.s60" |
| 105 |
|
| 106 |
|
| 107 |
proc = subprocess.Popen("devices", stdout=subprocess.PIPE, |
| 108 |
stderr=subprocess.STDOUT, shell=True) |
| 109 |
sdk2 = "" |
| 110 |
while True: |
| 111 |
line = proc.stdout.readline() |
| 112 |
if line.find("- default") > 0: |
| 113 |
sdk2 = line.split(":",1)[0] |
| 114 |
break |
| 115 |
proc.wait() |
| 116 |
|
| 117 |
if sdk1 != sdk2: |
| 118 |
sys.stderr.write("Error: default SDK in device doesn't match EPOCROOT\n") |
| 119 |
sys.stderr.write("Default device SDK = '" + sdk2 + "'\n") |
| 120 |
sys.stderr.write("EPOCROOT SDK = '" + sdk1 + "'\n") |
| 121 |
sys.exit(1) |
| 122 |
|
| 123 |
self.name = sdk2.replace("_", "-") |
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
def replace_vars(text): |
| 128 |
global vs_target, s60_target, build_type, no_test, no_pjsua_test |
| 129 |
suffix = "" |
| 130 |
|
| 131 |
os_info = platform.system() + platform.release() + "-" + platform.machine() |
| 132 |
|
| 133 |
|
| 134 |
s60sdk_var = None |
| 135 |
if build_type == "s60": |
| 136 |
s60sdk_var = S60SDK() |
| 137 |
os_info = s60sdk_var.name |
| 138 |
elif platform.system().lower() == "windows" or platform.system().lower() == "microsoft": |
| 139 |
if platform.system().lower() == "microsoft": |
| 140 |
os_info = platform.release() + "-" + platform.version() + "-" + platform.win32_ver()[2] |
| 141 |
elif platform.system().lower() == "linux": |
| 142 |
os_info = "-" + "-".join(platform.linux_distribution()[0:2]) |
| 143 |
|
| 144 |
|
| 145 |
if not vs_target and text.find("$(VSTARGET)") >= 0: |
| 146 |
if build_type != "vs": |
| 147 |
sys.stderr.write("Warning: $(VSTARGET) only valid for Visual Studio\n") |
| 148 |
print "Enter Visual Studio vs_target name (e.g. Release, Debug) [Release]: ", |
| 149 |
vs_target = sys.stdin.readline().replace("\n", "").replace("\r", "") |
| 150 |
if not vs_target: |
| 151 |
vs_target = "Release" |
| 152 |
|
| 153 |
|
| 154 |
if not s60_target and text.find("$(S60TARGET)") >= 0: |
| 155 |
if build_type != "s60": |
| 156 |
sys.stderr.write("Warning: $(S60TARGET) only valid for S60\n") |
| 157 |
print "Enter S60 target name (e.g. \"gcce urel\") [gcce urel]: ", |
| 158 |
s60_target = sys.stdin.readline().replace("\n", "").replace("\r", "") |
| 159 |
if not s60_target: |
| 160 |
s60_target = "gcce urel" |
| 161 |
|
| 162 |
|
| 163 |
if build_type == "vs": |
| 164 |
suffix = "i386-Win32-vc8-" + vs_target |
| 165 |
elif build_type == "s60": |
| 166 |
suffix = s60sdk_var.name + "-" + s60_target.replace(" ", "-") |
| 167 |
elif build_type == "gnu": |
| 168 |
proc = subprocess.Popen("sh config.guess", cwd="../..", |
| 169 |
shell=True, stdout=subprocess.PIPE) |
| 170 |
suffix = proc.stdout.readline().rstrip(" \r\n") |
| 171 |
else: |
| 172 |
sys.stderr.write("Error: unsupported build type '" + build_type + "'\n") |
| 173 |
sys.exit(1) |
| 174 |
|
| 175 |
while True: |
| 176 |
if text.find("$(PJSUA-TESTS)") >= 0: |
| 177 |
if no_test==False and no_pjsua_test==False: |
| 178 |
|
| 179 |
exe = "../../pjsip-apps/bin/pjsua-" + suffix |
| 180 |
proc = subprocess.Popen(PYTHON + " runall.py --list-xml -e " + exe, |
| 181 |
cwd="../pjsua", |
| 182 |
shell=True, stdout=subprocess.PIPE) |
| 183 |
content = proc.stdout.read() |
| 184 |
else: |
| 185 |
content = "" |
| 186 |
text = text.replace("$(PJSUA-TESTS)", content) |
| 187 |
elif text.find("$(GCC)") >= 0: |
| 188 |
text = text.replace("$(GCC)", gcc_version("gcc")) |
| 189 |
elif text.find("$(VS)") >= 0: |
| 190 |
vsver = VSVersion() |
| 191 |
text = text.replace("$(VS)", VSVersion().vs_release) |
| 192 |
elif text.find("$(VSTARGET)") >= 0: |
| 193 |
text = text.replace("$(VSTARGET)", vs_target) |
| 194 |
elif text.find("$(S60TARGET)") >= 0: |
| 195 |
text = text.replace("$(S60TARGET)", s60_target) |
| 196 |
elif text.find("$(S60TARGETNAME)") >= 0: |
| 197 |
text = text.replace("$(S60TARGETNAME)", s60_target.replace(" ", "-")) |
| 198 |
elif text.find("$(S60DEVICE)") >= 0: |
| 199 |
text = text.replace("$(S60DEVICE)", s60sdk_var.device) |
| 200 |
elif text.find("$(EPOCROOT)") >= 0: |
| 201 |
text = text.replace("$(EPOCROOT)", s60sdk_var.epocroot) |
| 202 |
elif text.find("$(DISABLED)") >= 0: |
| 203 |
text = text.replace("$(DISABLED)", "0") |
| 204 |
elif text.find("$(IPPROOT)") >= 0: |
| 205 |
if not os.environ.has_key("IPPROOT"): |
| 206 |
sys.stderr.write("Error: environment variable IPPROOT is needed but not set\n") |
| 207 |
sys.exit(1) |
| 208 |
text = text.replace("$(IPPROOT)", os.environ["IPPROOT"]) |
| 209 |
elif text.find("$(IPPSAMPLES)") >= 0: |
| 210 |
if not os.environ.has_key("IPPSAMPLES"): |
| 211 |
sys.stderr.write("Error: environment variable IPPSAMPLES is needed but not set\n") |
| 212 |
sys.exit(1) |
| 213 |
text = text.replace("$(IPPSAMPLES)", os.environ["IPPSAMPLES"]) |
| 214 |
elif text.find("$(IPPARCH)") >= 0: |
| 215 |
if not os.environ.has_key("IPPARCH"): |
| 216 |
text = text.replace("$(IPPARCH)", "") |
| 217 |
else: |
| 218 |
text = text.replace("$(IPPARCH)", os.environ["IPPARCH"]) |
| 219 |
elif text.find("$(OS)") >= 0: |
| 220 |
text = text.replace("$(OS)", os_info) |
| 221 |
elif text.find("$(SUFFIX)") >= 0: |
| 222 |
text = text.replace("$(SUFFIX)", suffix) |
| 223 |
elif text.find("$(HOSTNAME)") >= 0: |
| 224 |
text = text.replace("$(HOSTNAME)", socket.gethostname()) |
| 225 |
elif text.find("$(PJDIR)") >= 0: |
| 226 |
wdir = os.path.join(os.getcwd(), "../..") |
| 227 |
wdir = os.path.normpath(wdir) |
| 228 |
text = text.replace("$(PJDIR)", wdir) |
| 229 |
elif text.find("$(NOP)") >= 0: |
| 230 |
if platform.system().lower() == "windows" or platform.system().lower() == "microsoft": |
| 231 |
cmd = "CMD /C echo Success" |
| 232 |
else: |
| 233 |
cmd = "echo Success" |
| 234 |
text = text.replace("$(NOP)", cmd) |
| 235 |
elif text.find("$(NOTEST)") >= 0: |
| 236 |
if no_test: |
| 237 |
str = '"1"' |
| 238 |
else: |
| 239 |
str = '"0"' |
| 240 |
text = text.replace("$(NOTEST)", str) |
| 241 |
else: |
| 242 |
break |
| 243 |
return text |
| 244 |
|
| 245 |
|
| 246 |
def main(args): |
| 247 |
global vs_target, s60_target, build_type, no_test, no_pjsua_test |
| 248 |
output = sys.stdout |
| 249 |
usage = """Usage: configure.py [OPTIONS] scenario_template_file |
| 250 |
|
| 251 |
Where OPTIONS: |
| 252 |
-o FILE Output to file, otherwise to stdout. |
| 253 |
-t TYPE Specify build type. If not specified, it will be |
| 254 |
asked if necessary. Values are: |
| 255 |
vs: Visual Studio |
| 256 |
gnu: Makefile based |
| 257 |
s60: Symbian S60 |
| 258 |
-vstarget TARGETNAME Specify Visual Studio target name if build type is set |
| 259 |
to vs. If not specified then it will be asked. |
| 260 |
Sample target names: |
| 261 |
- Debug |
| 262 |
- Release |
| 263 |
- or any other target in the project file |
| 264 |
-s60target TARGETNAME Specify S60 target name if build type is set to s60. |
| 265 |
If not specified then it will be asked. Sample target |
| 266 |
names: |
| 267 |
- "gcce udeb" |
| 268 |
- "gcce urel" |
| 269 |
-notest Disable all tests in the scenario. |
| 270 |
-nopjsuatest Disable pjsua tests in the scenario. |
| 271 |
""" |
| 272 |
|
| 273 |
args.pop(0) |
| 274 |
while len(args): |
| 275 |
if args[0]=='-o': |
| 276 |
args.pop(0) |
| 277 |
if len(args): |
| 278 |
output = open(args[0], "wt") |
| 279 |
args.pop(0) |
| 280 |
else: |
| 281 |
sys.stderr.write("Error: needs value for -o\n") |
| 282 |
sys.exit(1) |
| 283 |
elif args[0]=='-vstarget': |
| 284 |
args.pop(0) |
| 285 |
if len(args): |
| 286 |
vs_target = args[0] |
| 287 |
args.pop(0) |
| 288 |
else: |
| 289 |
sys.stderr.write("Error: needs value for -vstarget\n") |
| 290 |
sys.exit(1) |
| 291 |
elif args[0]=='-s60target': |
| 292 |
args.pop(0) |
| 293 |
if len(args): |
| 294 |
s60_target = args[0] |
| 295 |
args.pop(0) |
| 296 |
else: |
| 297 |
sys.stderr.write("Error: needs value for -s60target\n") |
| 298 |
sys.exit(1) |
| 299 |
elif args[0]=='-t': |
| 300 |
args.pop(0) |
| 301 |
if len(args): |
| 302 |
build_type = args[0].lower() |
| 303 |
args.pop(0) |
| 304 |
else: |
| 305 |
sys.stderr.write("Error: needs value for -t\n") |
| 306 |
sys.exit(1) |
| 307 |
if not ["vs", "gnu", "s60"].count(build_type): |
| 308 |
sys.stderr.write("Error: invalid -t argument value\n") |
| 309 |
sys.exit(1) |
| 310 |
elif args[0]=='-notest' or args[0]=='-notests': |
| 311 |
args.pop(0) |
| 312 |
no_test = True |
| 313 |
elif args[0]=='-nopjsuatest' or args[0]=='-nopjsuatests': |
| 314 |
args.pop(0) |
| 315 |
no_pjsua_test = True |
| 316 |
else: |
| 317 |
break |
| 318 |
|
| 319 |
if len(args) != 1: |
| 320 |
sys.stderr.write(usage + "\n") |
| 321 |
return 1 |
| 322 |
|
| 323 |
if not build_type: |
| 324 |
defval = "vs" |
| 325 |
if "SHELL" in os.environ: |
| 326 |
shell = os.environ["SHELL"] |
| 327 |
if shell.find("sh") > -1: |
| 328 |
defval = "gnu" |
| 329 |
print "Enter the build type (values: vs, gnu, s60) [%s]: " % (defval), |
| 330 |
build_type = sys.stdin.readline().replace("\n", "").replace("\r", "") |
| 331 |
if not build_type: |
| 332 |
build_type = defval |
| 333 |
|
| 334 |
|
| 335 |
tpl_file = args[len(args)-1] |
| 336 |
if not os.path.isfile(tpl_file): |
| 337 |
print "Error: unable to find template file '%s'" % (tpl_file) |
| 338 |
return 1 |
| 339 |
|
| 340 |
f = open(tpl_file, "r") |
| 341 |
tpl = f.read() |
| 342 |
f.close() |
| 343 |
|
| 344 |
tpl = replace_vars(tpl) |
| 345 |
output.write(tpl) |
| 346 |
if output != sys.stdout: |
| 347 |
output.close() |
| 348 |
return 0 |
| 349 |
|
| 350 |
|
| 351 |
if __name__ == "__main__": |
| 352 |
rc = main(sys.argv) |
| 353 |
sys.exit(rc) |
| 354 |
|