-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbilder.py
More file actions
666 lines (590 loc) · 18.8 KB
/
bilder.py
File metadata and controls
666 lines (590 loc) · 18.8 KB
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
import os
import subprocess
import errno
import re
import sys
import shutil
import urllib2
import glob
from distutils import dir_util
from distutils import file_util
import zipfile
import fnmatch
import inspect
import time
import string
# evil globals
_ = None
bild_completed = set() # which *targets* have been built.
BILD = os.path.expanduser("~/.bild")
JARCACHE = os.path.join(BILD, "jars")
ERRORS=0 # increment this when error found so we can set exit value
# CLASSPATH = JARCACHE + "/*" + os.pathsep + os.environ['CLASSPATH']
def findjdks_win():
return {}
def findjdks_linux():
"""
CentOS: /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.55.x86_64/jre/bin/java
/usr/java/jdk1.7.0_51
ubuntu: /usr/lib/jvm/java-6-openjdk/ for OpenJDK
/usr/lib/jvm/* for Oracle JDK
"""
versions = {}
for jdk in glob.glob("/usr/lib/jvm/*") + glob.glob("/usr/java/*"):
name = os.path.basename(jdk)
if name.startswith("java-1.6") or name.startswith("jdk1.6"):
versions["1.6"] = jdk
if name.startswith("java-1.7") or name.startswith("jdk1.7"):
versions["1.7"] = jdk
if name.startswith("java-1.8") or name.startswith("jdk1.8"):
versions["1.8"] = jdk
return versions
def findjdks_mac():
"""find Java installations on a mac"""
versions = {}
dirs = []
for jdk in glob.glob("/Library/Java/JavaVirtualMachines/*"):
dirs.append(jdk)
for jdk in glob.glob("/System/Library/Java/JavaVirtualMachines/*"):
dirs.append(jdk)
for jdk in dirs:
name = os.path.basename(jdk)
if name.startswith("1.6."):
versions["1.6"] = jdk + "/Contents/Home"
elif name.startswith("jdk1.7."):
versions["1.7"] = jdk + "/Contents/Home"
elif name.startswith("jdk1.8."):
versions["1.8"] = jdk + "/Contents/Home"
return versions
def findjdks():
if sys.platform == 'win32':
return findjdks_win()
if sys.platform == 'darwin':
return findjdks_mac()
if sys.platform == 'linux2':
return findjdks_linux()
jdk = findjdks()
#print sys.platform + " java =", jdk
todo = """
def chkjava(version):
#Version in {1.6,1.7,1.8}
javahome = 'JAVA' + version
if os.environ.get(javahome):
jdk[version] = os.environ[javahome]
print "Setting java to "+jdk[version]+""
else:
jdk = findjdks()
if version in jdk:
print javahome+" not set, using "+jdk[version]
else:
p = subprocess.Popen(["java", "-version"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out,err = p.communicate()
# java version "1.7.0_65"
vline = err.split("\n")[0]
vquote = vline.split(" ")[2]
v = vquote.replace('"',"")
print javahome+" not set, using system default: "+v
"""
def modtime(fname):
try:
return os.path.getmtime(fname)
except:
return 0 # mod date of epoch means ancient sys.float_info.max # meaning mod date in future if file not there
def uniformpath(dir):
dir = os.path.expanduser(dir) # ~parrt -> /Users/parrt on unix
dir = os.path.abspath(dir) # expand relative dirs
return dir
def mkdir(path):
"""
From: http://stackoverflow.com/questions/600268/mkdir-p-functionality-in-python
"""
try:
os.makedirs(path)
except OSError as exc: # Python >2.5
if exc.errno == errno.EEXIST and os.path.isdir(path):
pass
else:
raise
def rmdir(dir):
shutil.rmtree(dir, ignore_errors=True)
def files(pathspec):
"""
Get all files matching pathspec (nonrecursive)
"""
return [f for f in glob.glob(pathspec)]
def allfiles(dir, pattern="*"):
"""
Return list<string> all files in subtree dir, optionally matching
a pattern spec like "*.java"
"""
dir = uniformpath(dir)
if not os.path.isdir(dir): # must be file
return [dir]
matching_files = []
for root, subFolders, files in os.walk(dir):
matching = fnmatch.filter(files, pattern)
matching_files.extend(os.path.join(root, f) for f in matching)
return matching_files
def copytree(src, trg, ignore=None):
if os.path.exists(trg) and not os.path.isdir(trg):
os.remove(trg) # can't copy onto a file
mkdir(trg)
dir_util.copy_tree(src, trg, preserve_mode=True)
def copyfile(src, trg):
if not os.path.exists(trg):
trg_dirname = os.path.dirname(trg)
if len(trg_dirname.strip()) > 0:
mkdir(trg_dirname)
file_util.copy_file(src, trg, preserve_mode=True)
def replsuffix(files, suffix):
"""
Return list<string> all files with their .suffix replaced
"""
outfiles = []
if suffix is None: return
if type(files) is type(""):
files = [files]
for f in files:
fname, ext = os.path.splitext(f)
newfname = fname + suffix
outfiles.append(newfname)
return outfiles
def javac_targets(srcdir, trgdir):
"""
Return a map<string,string> of files javac would create given a subdir of java
files and a target dir. E.g.,
javac_targets("/Users/parrt/mantra/code/compiler/src/java", "out")
generates
{".../src/java/mantra/Tool.java":"out/mantra/Tool.class", ...}
"""
srcdir = uniformpath(srcdir)
trgdir = uniformpath(trgdir)
mapping = {}
javafiles = allfiles(srcdir, "*.java")
classfiles = replsuffix(javafiles, ".class")
if not os.path.isdir(srcdir): # must be a Java file
srcdir = os.path.dirname(srcdir)
classfiles = [f.replace(srcdir, trgdir) for f in classfiles] # shift to trg dir
for i in range(len(javafiles)):
mapping[javafiles[i]] = classfiles[i]
return mapping
def grep(file, regex):
matches = []
with open(file) as f:
contents = f.read()
m = re.search(regex, contents)
if m:
matches.append(m.group())
return matches
def antlr3_targets(srcdir, trgdir, package=None):
"""
Return a map<string,string> of files antlr3 would create given a subdir of grammars
files and a target dir. E.g.,
antlr3_targets("tool/src/org/antlr/v4/codegen", "gen")
gives:
{'/Volumes/SSD2/Users/parrt/antlr/code/antlr4/tool/src/org/antlr/v4/codegen/SourceGenTriggers.g':
'/Volumes/SSD2/Users/parrt/antlr/code/antlr4/gen/SourceGenTriggers.java'}
"""
srcdir = uniformpath(srcdir)
if package is not None:
package = re.sub('[.]', '/', package)
trgdir = uniformpath(os.path.join(trgdir, package))
else:
trgdir = uniformpath(trgdir)
mapping = {}
gfiles = allfiles(srcdir, "*.g")
for f in gfiles:
fdir, fsuffix = os.path.splitext(f)
gname = os.path.basename(fdir)
fullgname = os.path.join(trgdir, gname)
lexer = grep(f, r"lexer\s+grammar")
parser = grep(f, r"parser\s+grammar")
tree = grep(f, r"tree\s+grammar")
if len(lexer) > 0 or len(parser) > 0 or len(tree) > 0:
# print "a lexer or parser or tree parser"
mapping[f] = fullgname + ".java"
else:
# must be combined grammar
# print "a combined"
mapping[f] = [fullgname + "Parser.java", fullgname + "Lexer.java"]
return mapping
def antlr4_targets(srcdir, trgdir, package=None):
"""
Return a map<string,string> of files antlr4 would create given a subdir of grammars
files and a target dir. E.g.,
antlr4_targets("tests", "gen")
gives:
{'/Volumes/SSD2/Users/parrt/github/bild/tests/sample1/src/grammars/org/foo/T.g4':
['/Volumes/SSD2/Users/parrt/github/bild/gen/TParser.java',
'/Volumes/SSD2/Users/parrt/github/bild/gen/TLexer.java']
}
"""
srcdir = uniformpath(srcdir)
if package is not None:
package = re.sub('[.]', '/', package)
trgdir = uniformpath(os.path.join(trgdir, package))
else:
trgdir = uniformpath(trgdir)
mapping = {}
gfiles = allfiles(srcdir, "*.g4")
for f in gfiles:
fdir, fsuffix = os.path.splitext(f)
gname = os.path.basename(fdir)
fullgname = os.path.join(trgdir, gname)
lexer = grep(f, r"lexer\s+grammar")
parser = grep(f, r"parser\s+grammar")
if len(lexer) > 0 or len(parser) > 0:
# print "a lexer or parser"
mapping[f] = fullgname + ".java"
else:
# must be combined grammar
# print "a combined"
mapping[f] = [fullgname + "Parser.java", fullgname + "Lexer.java"]
return mapping
def newer(a, b):
"""
Return true if a newer than b
"""
return modtime(a) < modtime(b) # smaller is earlier
def older(a, b):
"""
Return true if a older or same as b
"""
return not newer(a, b)
def stale(map): # accept map<string,string> or map<string,list<string>>
"""
Return map<string,string-or-list> with files to build as they are out of date
"""
out = {}
for src in map:
trg = map[src]
fstale = False
if type(trg) == type([]):
for t in trg:
# print src,"->",t
# print modtime(src), modtime(t)
if isstale(src, t):
fstale = True
break
else:
# print src,"->",trg
# print modtime(src), modtime(trg)
if isstale(src, trg):
# print "target newer so no build"
fstale = True
if fstale:
out[src] = trg
return out
def isstale(src, trg):
return modtime(trg) < modtime(src) # smaller is earlier
def require(target):
global ERRORS
print "require", target.__name__
if id(target) in bild_completed:
return
bild_completed.add(id(target))
target()
caller = inspect.currentframe().f_back.f_code.co_name
if ERRORS==0:
print "build", caller
else:
print "skipping", caller
raise Exception
def antlr3(srcdir, trgdir=".", package=None, version="3.5.1", args=[]):
srcdir = uniformpath(srcdir)
trgdir = uniformpath(trgdir)
map = antlr3_targets(srcdir, trgdir, package)
tobuild = stale(map).keys()
if len(tobuild) == 0:
return
jarname = "antlr-" + version + "-complete.jar"
# if jarname not in filelist(JARCACHE):
download("http://www.antlr3.org/download/" + jarname, JARCACHE)
if package is not None:
packageAsDir = re.sub('[.]', '/', package)
cmd = ["java", "-cp", os.path.join(JARCACHE, jarname),
"org.antlr.Tool",
"-o", os.path.join(trgdir, packageAsDir)] + args + tobuild
else:
cmd = ["java", "org.antlr.Tool", "-o", trgdir] + args + tobuild
# print cmd
subprocess.call(cmd)
def antlr4(srcdir, trgdir=".", package=None, version="4.3", args=[]):
srcdir = uniformpath(srcdir)
trgdir = uniformpath(trgdir)
map = antlr4_targets(srcdir, trgdir, package)
tobuild = stale(map).keys()
if len(tobuild) == 0:
return
jarname = "antlr-" + version + "-complete.jar"
# if jarname not in filelist(JARCACHE):
download("http://www.antlr.org/download/" + jarname, JARCACHE)
if package is not None:
packageAsDir = re.sub('[.]', '/', package)
cmd = ["java", "-cp", os.path.join(JARCACHE, jarname),
"org.antlr.v4.Tool",
"-o", os.path.join(trgdir, packageAsDir),
"-package", package] + args + tobuild
else:
cmd = ["java", "org.antlr.v4.Tool", "-o", trgdir] + args + tobuild
# print string.join(cmd, " ")
subprocess.call(cmd)
def java(classname, cp=None, version=None, vmargs=[], progargs=[], background=False):
global ERRORS
if cp is None:
cp = JARCACHE + "/*"
j = "java"
if version is not None:
j = os.path.join(jdk[version], "bin/java")
cmd = [j, "-cp", cp] + vmargs + progargs + [classname]
print ' '.join(cmd)
if background:
# background cannot set bild errors
p = subprocess.Popen(cmd)
return p.pid
else:
exitcode = subprocess.call(cmd)
if exitcode!=0: ERRORS += 1
def javac(srcdir, trgdir=".", cp=None, version=None, args=[]):
global ERRORS
srcdir = uniformpath(srcdir)
trgdir = uniformpath(trgdir)
mkdir(trgdir)
map = javac_targets(srcdir, trgdir)
tobuild = stale(map).keys()
# print "build",stale(map)
if len(tobuild) == 0:
return
if cp is None:
cp = trgdir + os.pathsep + JARCACHE + "/*"
# cmd = ["javac", "-sourcepath", srcdir, "-d", trgdir, "-cp", cp] + args + tobuild
javac = "javac"
if version is not None:
javac = os.path.join(jdk[version], "bin/javac")
cmd = [javac, "-d", trgdir, "-cp", cp] + args + tobuild
# print string.join(cmd, " ")
exitcode = subprocess.call(cmd)
if exitcode!=0: ERRORS += 1
def jar(jarfile, inputfiles=".", srcdir=".", manifest=None):
trgdir = os.path.dirname(jarfile)
mkdir(trgdir)
if type(inputfiles) == type(""):
inputfiles = [inputfiles]
contents_with_C = []
for f in inputfiles:
contents_with_C.append("-C")
contents_with_C.append(srcdir)
contents_with_C.append(f)
# write manifest
metadir = os.path.join(srcdir, "META-INF")
mkdir(metadir)
with open(os.path.join(metadir, "MANIFEST.MF"), "w") as mf:
mf.write(manifest)
mfile = os.path.join(srcdir, "META-INF/MANIFEST.MF")
cmd = ["jar", "cmf", mfile, jarfile] + contents_with_C
subprocess.call(cmd)
def unjar(jarfile, trgdir="."):
jar = zipfile.ZipFile(jarfile)
jar.extractall(path=trgdir)
jar.close()
def javadoc(srcdir, trgdir, packages, classpath=None, title=None, recursive=True):
if type(packages) == type(""):
packages = [packages]
if type(srcdir) == type(""):
srcdir = [srcdir]
if not classpath:
classpath = srcdir
if type(classpath) == type(""):
classpath = [classpath]
cmd = ["javadoc", "-quiet", "-d", trgdir, "-sourcepath", os.pathsep.join(srcdir),
"-classpath", os.pathsep.join(classpath)]
if title:
cmd += ["-doctitle", title, "-windowtitle", title]
if recursive:
cmd += ["-subpackages"]
cmd += packages
print ' '.join(cmd)
subprocess.call(cmd)
def load_junitjars():
junit_version = '4.11'
junit_jar = 'junit-' + junit_version + '.jar'
hamcrest_version = '1.3'
hamcrest_jar = 'hamcrest-core-' + hamcrest_version + '.jar'
download("http://search.maven.org/remotecontent?filepath=junit/junit/" + junit_version + "/" + junit_jar,
JARCACHE)
download(
"http://search.maven.org/remotecontent?filepath=org/hamcrest/hamcrest-core/" + hamcrest_version + "/" + hamcrest_jar,
JARCACHE)
return JARCACHE + "/" + junit_jar, JARCACHE + "/" + hamcrest_jar
def junit(srcdir, cp=None, verbose=False, args=[]):
global ERRORS
hamcrest_jar, junit_jar = load_junitjars()
download("https://github.com/parrt/bild/raw/master/lib/bild-junit.jar", JARCACHE)
srcdir = uniformpath(srcdir)
testfiles = allfiles(srcdir, "*.java")
testfiles = [f[len(srcdir) + 1:] for f in testfiles]
testclasses = replsuffix(testfiles, '')
testclasses = [c for c in testclasses if os.path.basename(c).startswith("Test") and '$' not in os.path.basename(c)]
testclasses = [c.replace('/', '.') for c in testclasses]
cp_ = srcdir + os.pathsep + junit_jar + os.pathsep + hamcrest_jar + os.pathsep + JARCACHE + "/bild-junit.jar"
if cp is not None:
cp_ = cp + os.pathsep + cp_
processes = []
# launch all tests in srcdir in parallel
for c in testclasses:
cmd = ['java'] + args + ['-cp', cp_, 'org.bild.JUnitLauncher', c]
if verbose:
cmd = ['java'] + args + ['-cp', cp_, 'org.bild.JUnitLauncher', '-verbose', c]
# print ' '.join(cmd)
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
processes.append(p)
# busy wait with sleep for any results
while len(processes) > 0:
for p in processes:
r = p.poll()
if r is not None: # p is done
processes.remove(p)
stdout, stderr = p.communicate() # hush output
print stdout,
summary = stdout.split('\n')[0]
if "0 failures" not in summary:
ERRORS += 1
time.sleep(0.200)
print "Tests complete"
def junit_runner(testclasses, cp=None, verbose=False, args=[]):
global ERRORS
if type(testclasses) == type(""):
testclasses = [testclasses]
hamcrest_jar, junit_jar = load_junitjars()
download("https://github.com/parrt/bild/raw/master/lib/bild-junit.jar", JARCACHE)
testclasses = [c.replace('/', '.') for c in testclasses]
cp_ = os.pathsep + junit_jar + os.pathsep + hamcrest_jar + os.pathsep + JARCACHE +\
"/bild-junit.jar"
if cp is not None:
cp_ = cp + os.pathsep + cp_
processes = []
# launch all tests in srcdir in parallel
for c in testclasses:
cmd = ['java'] + args + ['-cp', cp_, 'org.bild.JUnitLauncher', c]
if verbose:
cmd = ['java'] + args + ['-cp', cp_, 'org.bild.JUnitLauncher', '-verbose', c]
# print ' '.join(cmd)
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
processes.append(p)
# busy wait with sleep for any results
while len(processes) > 0:
for p in processes:
r = p.poll()
if r is not None: # p is done
processes.remove(p)
stdout, stderr = p.communicate() # hush output
print stdout,
summary = stdout.split('\n')[0]
if "0 failures" not in summary:
ERRORS += 1
time.sleep(0.200)
print "Tests complete"
def dot(src, trgdir=".", format="pdf"):
if not src.endswith(".dot"):
return
nosuffix = src[0:-4]
base = os.path.basename(nosuffix)
cmd = ["dot", "-T" + format, "-o" + os.path.join(trgdir, base + "." + format), src]
subprocess.call(cmd)
def download(url, trgdir=".", force=False):
file_name = url.split('/')[-1]
mkdir(trgdir)
target_name = os.path.join(trgdir, file_name)
if os.path.exists(target_name) and not force:
return
try:
response = urllib2.urlopen(url)
except urllib2.HTTPError, e:
sys.stderr.write("can't download %s: %s\n" % (url, str(e)))
else:
output = open(target_name, 'wb')
output.write(response.read())
output.close()
def wget(url, level=None, trgdir=None, proxy=None, verbose=False):
"""
$ http_proxy=http://localhost:8080
$ wget -P foo --proxy=on -r --level 1 http://www.cs.usfca.edu/index.html
wget("http://www.cs.usfca.edu/index.html", trgdir="foo")
wget("http://www.cs.usfca.edu/index.html", trgdir="foo", proxy="http://localhost:8080")
"""
global ERRORS
cmd = ["wget", "-r", "--wait=0", "--keep-session-cookies"]
if not verbose:
cmd += ["-q"]
if trgdir is not None:
mkdir(trgdir)
cmd += ["-P", trgdir]
env = os.environ.copy()
if proxy is None:
cmd += ["--proxy=off"]
else:
env["http_proxy"] = proxy
cmd += ["--proxy=on"]
if level is not None:
cmd += ["--level", str(level)]
cmd += [url]
# print ', '.join(cmd)
p = subprocess.Popen(cmd, env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out,err = p.communicate()
#print out
if err is not None and len(err)>0:
print "wget errors:"
print err
if p.returncode!=0: ERRORS += 1
return p.returncode
def diff(file1, file2, recursive=False):
global ERRORS
cmd = ["diff"]
if recursive:
cmd += ["-r"]
cmd += [file1, file2]
#print ', '.join(cmd)
output = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
return output
def scp(src, user, machine, trg):
subprocess.check_call(
["scp", src, "%s@%s:%s" % (user, machine, trg)]
)
def zip(zipfilename, srcdir): # , recursive=True):
"""
Last element of srcdir is considered root of zip'd content. E.g.,
srcdir="doc/Java" gives zip file with Java as the root element.
srcdir might expand to /Volumes/SSD2/Users/parrt/antlr/code/antlr4/doc/Java
"""
srcdir = uniformpath(srcdir)
rootdir = os.path.dirname(srcdir) # "...doc/Java" gives doc
rootnameindex = len(rootdir) + 1 # "...doc/Java" gives start of "Java"
with zipfile.ZipFile(zipfilename, mode="w", compression=zipfile.ZIP_DEFLATED) as z:
for f in allfiles(srcdir):
z.write(f, f[rootnameindex:])
def python(filename, workingdir=".", args=[]):
savedcwd = os.getcwd()
os.chdir(workingdir)
try:
if type(args) is not type([]):
args = [args]
cmd = [sys.executable, filename] + args
subprocess.call(cmd)
finally:
os.chdir(savedcwd)
def processargs(globals):
global ERRORS
if len(sys.argv) == 1:
target = globals["all"]
else:
target = globals[sys.argv[1]]
if target is not None:
print "target", target.__name__
try:
target()
except Exception as e:
print e
if ERRORS>0 : print "bild failed"; sys.exit(1)
else: print "bild succeeded"; sys.exit(0)
else:
sys.stderr.write("unknown target: %s\n" % sys.argv[1])