2
0
mirror of https://gitlab.com/ita1024/waf.git synced 2024-11-22 01:46:15 +01:00
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,14 +30,18 @@ def modif(dir, name, fun):
filename = os.path.join(dir, name) filename = os.path.join(dir, name)
f = open(filename, 'r') f = open(filename, 'r')
txt = f.read() try:
f.close() txt = f.read()
finally:
f.close()
txt = fun(txt) txt = fun(txt)
f = open(filename, 'w') f = open(filename, 'w')
f.write(txt) try:
f.close() f.write(txt)
finally:
f.close()
def subst(*k): def subst(*k):
"""register a substitution function""" """register a substitution function"""

78
wscript
View File

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