summaryrefslogtreecommitdiff
path: root/buildtools
diff options
context:
space:
mode:
authorThomas Nagy <tnagy@waf.io>2015-06-26 20:48:43 +0200
committerAndrew Bartlett <abartlet@samba.org>2015-09-02 00:47:18 +0200
commitffea9a17d775005539692b1516eb4178d6c5234a (patch)
tree3411ac085dc9d449f0fcc71c8d28f4f3ea62719f /buildtools
parentda9eee80e4bf6a00694074d1a16438420b7c09f2 (diff)
downloadsamba-ffea9a17d775005539692b1516eb4178d6c5234a.tar.gz
build:wafsamba: Close file handles in the build scripts too
Signed-off-by: Thomas Nagy <tnagy@waf.io> Reviewed-by: Michael Adam <obnox@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Diffstat (limited to 'buildtools')
-rw-r--r--buildtools/wafsamba/configure_file.py10
-rw-r--r--buildtools/wafsamba/pkgconfig.py10
-rw-r--r--buildtools/wafsamba/samba_abi.py4
-rw-r--r--buildtools/wafsamba/samba_conftests.py25
-rw-r--r--buildtools/wafsamba/samba_patterns.py5
-rw-r--r--buildtools/wafsamba/samba_version.py5
-rw-r--r--buildtools/wafsamba/wafsamba.py4
7 files changed, 14 insertions, 49 deletions
diff --git a/buildtools/wafsamba/configure_file.py b/buildtools/wafsamba/configure_file.py
index 8e2ba3bc23f..21264cfca5c 100644
--- a/buildtools/wafsamba/configure_file.py
+++ b/buildtools/wafsamba/configure_file.py
@@ -7,12 +7,8 @@ def subst_at_vars(task):
'''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 = []
@@ -27,9 +23,7 @@ def subst_at_vars(task):
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):
diff --git a/buildtools/wafsamba/pkgconfig.py b/buildtools/wafsamba/pkgconfig.py
index 8a3f807dc55..c837804ee8e 100644
--- a/buildtools/wafsamba/pkgconfig.py
+++ b/buildtools/wafsamba/pkgconfig.py
@@ -5,12 +5,8 @@ from samba_utils import *
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 = []
@@ -37,9 +33,7 @@ def subst_at_vars(task):
break
out.append(v)
contents = ''.join(out)
- f = open(tgt, 'w')
- s = f.write(contents)
- f.close()
+ task.outputs[0].write(contents)
return 0
diff --git a/buildtools/wafsamba/samba_abi.py b/buildtools/wafsamba/samba_abi.py
index 76acd006777..3ff6d77811c 100644
--- a/buildtools/wafsamba/samba_abi.py
+++ b/buildtools/wafsamba/samba_abi.py
@@ -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'''
- 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
- f.close()
def abi_write_vscript(f, libname, current_version, versions, symmap, abi_match):
diff --git a/buildtools/wafsamba/samba_conftests.py b/buildtools/wafsamba/samba_conftests.py
index 96fead58128..fe8c30bef01 100644
--- a/buildtools/wafsamba/samba_conftests.py
+++ b/buildtools/wafsamba/samba_conftests.py
@@ -216,9 +216,7 @@ def CHECK_NEED_LC(conf, msg):
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
@@ -291,13 +289,8 @@ def CHECK_LIBRARY_SUPPORT(conf, rpath=False, version_script=False, msg=None):
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
@@ -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())
- 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',
@@ -383,15 +374,13 @@ def CHECK_PERL_MANPAGE(conf, msg=None, section=None):
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' ]
);
""")
- dest.close()
back = os.path.abspath('.')
os.chdir(bdir)
proc = Utils.pproc.Popen(['perl', 'Makefile.PL'],
@@ -406,9 +395,7 @@ WriteMakefile(
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')
diff --git a/buildtools/wafsamba/samba_patterns.py b/buildtools/wafsamba/samba_patterns.py
index 04699927624..5183e865745 100644
--- a/buildtools/wafsamba/samba_patterns.py
+++ b/buildtools/wafsamba/samba_patterns.py
@@ -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)
- 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)
- f = open(tgt, 'w')
- s = f.write(string)
- f.close()
+ task.outputs[0].write(string)
return 0
diff --git a/buildtools/wafsamba/samba_version.py b/buildtools/wafsamba/samba_version.py
index bb0be96f869..950a855c1ef 100644
--- a/buildtools/wafsamba/samba_version.py
+++ b/buildtools/wafsamba/samba_version.py
@@ -42,12 +42,10 @@ def git_version_summary(path, env=None):
def distversion_version_summary(path):
#get version from .distversion file
- f = open(path + '/.distversion', 'r')
suffix = None
fields = {}
- for line in f:
- line = line.strip()
+ for line in Utils.readf(path + '/.distversion').splitlines():
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
- f.close()
if "COMMIT_TIME" in fields:
fields["COMMIT_TIME"] = int(fields["COMMIT_TIME"])
diff --git a/buildtools/wafsamba/wafsamba.py b/buildtools/wafsamba/wafsamba.py
index c27241eff8d..078e411db25 100644
--- a/buildtools/wafsamba/wafsamba.py
+++ b/buildtools/wafsamba/wafsamba.py
@@ -95,9 +95,7 @@ Build.BuildContext.ADD_INIT_FUNCTION = ADD_INIT_FUNCTION
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
#################################################################