This commit is contained in:
Thomas Nagy 2012-05-19 09:45:57 +02:00
parent 2038d79a60
commit ed56a01764
2 changed files with 54 additions and 36 deletions

View File

@ -30,13 +30,17 @@ def modif(dir, name, fun):
filename = os.path.join(dir, name)
f = open(filename, 'r')
try:
txt = f.read()
finally:
f.close()
txt = fun(txt)
f = open(filename, 'w')
try:
f.write(txt)
finally:
f.close()
def subst(*k):

34
wscript
View File

@ -36,7 +36,9 @@ Configure.autoconfig = 1
def sub_file(fname, lst):
f = open(fname, 'rU')
try:
txt = f.read()
finally:
f.close()
for (key, val) in lst:
@ -44,7 +46,9 @@ def sub_file(fname, lst):
txt = re_pat.sub(val, txt)
f = open(fname, 'w')
try:
f.write(txt)
finally:
f.close()
print("------> Executing code from the top-level wscript <-----")
@ -198,17 +202,25 @@ def process_decorators(body):
def sfilter(path):
if sys.version_info[0] >= 3 and Options.options.strip_comments:
f = open(path, "rb")
try:
tk = tokenize.tokenize(f.readline)
next(tk) # the first one is always tokenize.ENCODING for Python 3, ignore it
cnt = process_tokens(tk)
finally:
f.close()
elif Options.options.strip_comments and path.endswith('.py'):
f = open(path, "r")
try:
cnt = process_tokens(tokenize.generate_tokens(f.readline))
finally:
f.close()
else:
f = open(path, "r")
try:
cnt = f.read()
finally:
f.close()
if path.endswith('.py') :
# WARNING: since we now require python 2.4, we do not process the decorators anymore
# if you need such a thing, uncomment the code below:
@ -266,7 +278,9 @@ def create_waf(*k, **kw):
tar.close()
f = open('waf-light', 'rU')
try:
code1 = f.read()
finally:
f.close()
# now store the revision unique number in waf
@ -286,7 +300,9 @@ def create_waf(*k, **kw):
code1 = code1.replace('bunzip2', 'gzip -d')
f = open('%s.tar.%s' % (mw, zipType), 'rb')
try:
cnt = f.read()
finally:
f.close()
# the REVISION value is the md5 sum of the binary blob (facilitate audits)
@ -310,19 +326,22 @@ def create_waf(*k, **kw):
# The reverse order prevent collisions
(cnt, C2) = find_unused(cnt, '\r')
(cnt, C1) = find_unused(cnt, '\n')
f = open('waf', 'wb')
ccc = code1.replace("C1='x'", "C1='%s'" % C1).replace("C2='x'", "C2='%s'" % C2)
f = open('waf', 'wb')
try:
f.write(ccc.encode())
f.write(b'#==>\n#')
f.write(cnt)
f.write(b'\n#<==\n')
finally:
f.close()
if sys.platform == 'win32' or Options.options.make_batch:
f = open('waf.bat', 'w')
try:
f.write('@python -x "%~dp0waf" %* & exit /b\n')
finally:
f.close()
if sys.platform != 'win32':
@ -332,21 +351,16 @@ def create_waf(*k, **kw):
def make_copy(inf, outf):
(a, b, cnt) = sfilter(inf)
f = open(outf, "wb")
try:
f.write(cnt)
finally:
f.close()
def configure(conf):
conf.load('python')
conf.check_python_version((2,4))
def build(bld):
waf = bld.path.make_node('waf') # create the node right here
bld(name='create_waf', rule=create_waf, target=waf, always=True, color='PINK', update_outputs=True)
#def dist():
# import Scripting
# Scripting.g_dist_exts += ['Weak.py'] # shows how to exclude a file from dist
# Scripting.Dist(APPNAME, VERSION)