build:wafsamba: Close file handles in the build scripts too
authorThomas Nagy <tnagy@waf.io>
Fri, 26 Jun 2015 18:48:43 +0000 (20:48 +0200)
committerAndrew Bartlett <abartlet@samba.org>
Tue, 1 Sep 2015 22:47:18 +0000 (00:47 +0200)
Signed-off-by: Thomas Nagy <tnagy@waf.io>
Reviewed-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
buildtools/wafsamba/configure_file.py
buildtools/wafsamba/pkgconfig.py
buildtools/wafsamba/samba_abi.py
buildtools/wafsamba/samba_conftests.py
buildtools/wafsamba/samba_patterns.py
buildtools/wafsamba/samba_version.py
buildtools/wafsamba/wafsamba.py
docs-xml/wscript_build

index 8e2ba3bc23f1495efbfa1b18ddc9170729db9898..21264cfca5cd074f6ad0af0a0ccdca32f37c13e9 100644 (file)
@@ -7,12 +7,8 @@ def subst_at_vars(task):
     '''substiture @VAR@ style variables in a file'''
 
     env = task.env
     '''substiture @VAR@ style variables in a file'''
 
     env = task.env
-    src = task.inputs[0].srcpath(env)
-    tgt = task.outputs[0].bldpath(env)
+    s = task.inputs[0].read()
 
 
-    f = open(src, 'r')
-    s = f.read()
-    f.close()
     # split on the vars
     a = re.split('(@\w+@)', s)
     out = []
     # split on the vars
     a = re.split('(@\w+@)', s)
     out = []
@@ -27,9 +23,7 @@ def subst_at_vars(task):
             v = SUBST_VARS_RECURSIVE(task.env[vname], task.env)
         out.append(v)
     contents = ''.join(out)
             v = SUBST_VARS_RECURSIVE(task.env[vname], task.env)
         out.append(v)
     contents = ''.join(out)
-    f = open(tgt, 'w')
-    s = f.write(contents)
-    f.close()
+    task.outputs[0].write(contents)
     return 0
 
 def CONFIGURE_FILE(bld, in_file, **kwargs):
     return 0
 
 def CONFIGURE_FILE(bld, in_file, **kwargs):
index 8a3f807dc5530c1709b6a8653e07b707eacb69b2..c837804ee8ece76055308dd7cc601489394f56f8 100644 (file)
@@ -5,12 +5,8 @@ from samba_utils import *
 
 def subst_at_vars(task):
     '''substiture @VAR@ style variables in a file'''
 
 def subst_at_vars(task):
     '''substiture @VAR@ style variables in a file'''
-    src = task.inputs[0].srcpath(task.env)
-    tgt = task.outputs[0].bldpath(task.env)
 
 
-    f = open(src, 'r')
-    s = f.read()
-    f.close()
+    s = task.inputs[0].read()
     # split on the vars
     a = re.split('(@\w+@)', s)
     out = []
     # split on the vars
     a = re.split('(@\w+@)', s)
     out = []
@@ -37,9 +33,7 @@ def subst_at_vars(task):
                     break
         out.append(v)
     contents = ''.join(out)
                     break
         out.append(v)
     contents = ''.join(out)
-    f = open(tgt, 'w')
-    s = f.write(contents)
-    f.close()
+    task.outputs[0].write(contents)
     return 0
 
 
     return 0
 
 
index 76acd006777e7ecabffefa3e76412cbec93b0721..3ff6d77811c413d72bd6993b8305a43ec9c91a3f 100644 (file)
@@ -147,12 +147,10 @@ def abi_check(self):
 
 def abi_process_file(fname, version, symmap):
     '''process one ABI file, adding new symbols to the symmap'''
 
 def abi_process_file(fname, version, symmap):
     '''process one ABI file, adding new symbols to the symmap'''
-    f = open(fname, mode='r')
-    for line in f:
+    for line in Utils.readf(fname).splitlines():
         symname = line.split(":")[0]
         if not symname in symmap:
             symmap[symname] = version
         symname = line.split(":")[0]
         if not symname in symmap:
             symmap[symname] = version
-    f.close()
 
 
 def abi_write_vscript(f, libname, current_version, versions, symmap, abi_match):
 
 
 def abi_write_vscript(f, libname, current_version, versions, symmap, abi_match):
index 96fead5812833fe80e42d852c57ccf66cec04712..fe8c30bef01165deda3adeb6431ae9a0694805ea 100644 (file)
@@ -216,9 +216,7 @@ def CHECK_NEED_LC(conf, msg):
 
     os.makedirs(subdir)
 
 
     os.makedirs(subdir)
 
-    dest = open(os.path.join(subdir, 'liblc1.c'), 'w')
-    dest.write('#include <stdio.h>\nint lib_func(void) { FILE *f = fopen("foo", "r");}\n')
-    dest.close()
+    Utils.writef(os.path.join(subdir, 'liblc1.c'), '#include <stdio.h>\nint lib_func(void) { FILE *f = fopen("foo", "r");}\n')
 
     bld = Build.BuildContext()
     bld.log = conf.log
 
     bld = Build.BuildContext()
     bld.log = conf.log
@@ -291,13 +289,8 @@ def CHECK_LIBRARY_SUPPORT(conf, rpath=False, version_script=False, msg=None):
 
     os.makedirs(subdir)
 
 
     os.makedirs(subdir)
 
-    dest = open(os.path.join(subdir, 'lib1.c'), 'w')
-    dest.write('int lib_func(void) { return 42; }\n')
-    dest.close()
-
-    dest = open(os.path.join(dir, 'main.c'), 'w')
-    dest.write('int main(void) {return !(lib_func() == 42);}\n')
-    dest.close()
+    Utils.writef(os.path.join(subdir, 'lib1.c'), 'int lib_func(void) { return 42; }\n')
+    Utils.writef(os.path.join(dir, 'main.c'), 'int main(void) {return !(lib_func() == 42);}\n')
 
     bld = Build.BuildContext()
     bld.log = conf.log
 
     bld = Build.BuildContext()
     bld.log = conf.log
@@ -311,9 +304,7 @@ def CHECK_LIBRARY_SUPPORT(conf, rpath=False, version_script=False, msg=None):
     ldflags = []
     if version_script:
         ldflags.append("-Wl,--version-script=%s/vscript" % bld.path.abspath())
     ldflags = []
     if version_script:
         ldflags.append("-Wl,--version-script=%s/vscript" % bld.path.abspath())
-        dest = open(os.path.join(dir,'vscript'), 'w')
-        dest.write('TEST_1.0A2 { global: *; };\n')
-        dest.close()
+        Utils.writef(os.path.join(dir,'vscript'), 'TEST_1.0A2 { global: *; };\n')
 
     bld(features='cc cshlib',
         source='libdir/lib1.c',
 
     bld(features='cc cshlib',
         source='libdir/lib1.c',
@@ -383,15 +374,13 @@ def CHECK_PERL_MANPAGE(conf, msg=None, section=None):
     if not os.path.exists(bdir):
         os.makedirs(bdir)
 
     if not os.path.exists(bdir):
         os.makedirs(bdir)
 
-    dest = open(os.path.join(bdir, 'Makefile.PL'), 'w')
-    dest.write("""
+    Utils.writef(os.path.join(bdir, 'Makefile.PL'), """
 use ExtUtils::MakeMaker;
 WriteMakefile(
     'NAME'    => 'WafTest',
     'EXE_FILES' => [ 'WafTest' ]
 );
 """)
 use ExtUtils::MakeMaker;
 WriteMakefile(
     'NAME'    => 'WafTest',
     'EXE_FILES' => [ 'WafTest' ]
 );
 """)
-    dest.close()
     back = os.path.abspath('.')
     os.chdir(bdir)
     proc = Utils.pproc.Popen(['perl', 'Makefile.PL'],
     back = os.path.abspath('.')
     os.chdir(bdir)
     proc = Utils.pproc.Popen(['perl', 'Makefile.PL'],
@@ -406,9 +395,7 @@ WriteMakefile(
         return
 
     if section:
         return
 
     if section:
-        f = open(os.path.join(bdir,'Makefile'), 'r')
-        man = f.read()
-        f.close()
+        man = Utils.readf(os.path.join(bdir,'Makefile'))
         m = re.search('MAN%sEXT\s+=\s+(\w+)' % section, man)
         if not m:
             conf.check_message_2('not found', color='YELLOW')
         m = re.search('MAN%sEXT\s+=\s+(\w+)' % section, man)
         if not m:
             conf.check_message_2('not found', color='YELLOW')
index 04699927624f8ee2745783b1026e4f19a42c40a2..5183e8657454e1f3981b939d6d48c802bac3365f 100644 (file)
@@ -8,14 +8,11 @@ from wafsamba import samba_version_file
 def write_version_header(task):
     '''print version.h contents'''
     src = task.inputs[0].srcpath(task.env)
 def write_version_header(task):
     '''print version.h contents'''
     src = task.inputs[0].srcpath(task.env)
-    tgt = task.outputs[0].bldpath(task.env)
 
     version = samba_version_file(src, task.env.srcdir, env=task.env, is_install=task.env.is_install)
     string = str(version)
 
 
     version = samba_version_file(src, task.env.srcdir, env=task.env, is_install=task.env.is_install)
     string = str(version)
 
-    f = open(tgt, 'w')
-    s = f.write(string)
-    f.close()
+    task.outputs[0].write(string)
     return 0
 
 
     return 0
 
 
index bb0be96f86942e6900b43a90c62e562881b87791..950a855c1efceee416a0a79fc911bbd824ded697 100644 (file)
@@ -42,12 +42,10 @@ def git_version_summary(path, env=None):
 
 def distversion_version_summary(path):
     #get version from .distversion file
 
 def distversion_version_summary(path):
     #get version from .distversion file
-    f = open(path + '/.distversion', 'r')
     suffix = None
     fields = {}
 
     suffix = None
     fields = {}
 
-    for line in f:
-        line = line.strip()
+    for line in Utils.readf(path + '/.distversion').splitlines():
         if line == '':
             continue
         if line.startswith("#"):
         if line == '':
             continue
         if line.startswith("#"):
@@ -64,7 +62,6 @@ def distversion_version_summary(path):
         except:
             print("Failed to parse line %s from .distversion file." % (line))
             raise
         except:
             print("Failed to parse line %s from .distversion file." % (line))
             raise
-    f.close()
 
     if "COMMIT_TIME" in fields:
         fields["COMMIT_TIME"] = int(fields["COMMIT_TIME"])
 
     if "COMMIT_TIME" in fields:
         fields["COMMIT_TIME"] = int(fields["COMMIT_TIME"])
index c27241eff8d9c6b41770b87f7ae122f09be1317b..078e411db25e68fb70429e78232ef46b46df2b66 100644 (file)
@@ -95,9 +95,7 @@ Build.BuildContext.ADD_INIT_FUNCTION = ADD_INIT_FUNCTION
 
 
 def generate_empty_file(task):
 
 
 def generate_empty_file(task):
-    target_fname = installed_location=task.outputs[0].bldpath(task.env)
-    target_file = open(installed_location, 'w')
-    target_file.close()
+    task.outputs[0].write('')
     return 0
 
 #################################################################
     return 0
 
 #################################################################
index 515746075acaede2798a838bbcb88917dbadf423..568eba1d66d16bb10b126c9c6dcab4c7c0610e96 100644 (file)
@@ -111,9 +111,7 @@ def smbdotconf_generate_parameter_list(task):
     t += "]>\n"
     t += "<section>\n"
     for article in articles:
     t += "]>\n"
     t += "<section>\n"
     for article in articles:
-        f = open(article.abspath(task.env), 'r')
-        t += f.read()
-        f.close()
+        t += article.read()
 
     t += "</section>\n"
     save_file(parameter_all, t , create_dir=True)
 
     t += "</section>\n"
     save_file(parameter_all, t , create_dir=True)