From 542d81d99eab7358415663df3364cd5381171c08 Mon Sep 17 00:00:00 2001 From: Tobias Ulmer Date: Mon, 25 Nov 2013 13:31:42 +0100 Subject: [PATCH] plugins: convert Makefile generation to eio While there, call the "makefile" "Makefile", like everyone else Signed-off-by: Tobias Ulmer --- plugins/cvs.lua | 22 +++++++++---------- plugins/files.lua | 56 ++++++++++++++++++++++------------------------- plugins/git.lua | 20 ++++++++--------- plugins/svn.lua | 17 +++++--------- 4 files changed, 52 insertions(+), 63 deletions(-) diff --git a/plugins/cvs.lua b/plugins/cvs.lua index a3e05b8..71d8918 100644 --- a/plugins/cvs.lua +++ b/plugins/cvs.lua @@ -387,7 +387,7 @@ function cvs.toresult(info, sourcename, sourceset, directory) -- /source/.tar.gz -- /makefile -- /licences - local rc, re + local rc, re, out local e = err.new("converting result") rc, re = scm.generic_source_check(info, sourcename, true) if not rc then @@ -395,7 +395,7 @@ function cvs.toresult(info, sourcename, sourceset, directory) end local src = info.sources[sourcename] -- write makefile - local makefile = "makefile" + local makefile = "Makefile" local source = "source" local sourcedir = string.format("%s/%s", directory, source) local archive = string.format("%s.tar.gz", sourcename) @@ -404,16 +404,16 @@ function cvs.toresult(info, sourcename, sourceset, directory) if not rc then return false, e:cat(re) end - local f, msg = io.open(fname, "w") - if not f then - return false, e:cat(msg) + + out = string.format( + ".PHONY:\tplace\n\n".. + "place:\n".. + "\ttar xzf \"%s/%s\" -C \"$(BUILD)\"\n", source, archive) + + rc, re = eio.file_write(fname, out) + if not rc then + return false, e:cat(re) end - f:write(string.format( - ".PHONY:\tplace\n\n".. - "place:\n".. - "\ttar xzf \"%s/%s\" -C \"$(BUILD)\"\n", - source, archive)) - f:close() -- export the source tree to a temporary directory local tmpdir, re = e2lib.mktempdir() if not tmpdir then diff --git a/plugins/files.lua b/plugins/files.lua index 3178c48..1c47c80 100644 --- a/plugins/files.lua +++ b/plugins/files.lua @@ -519,22 +519,17 @@ end -- @return Boolean, true on success. -- @return An error object on failure. function files.toresult(info, sourcename, sourceset, directory) - local rc, re + local rc, re, out local e = err.new("converting result failed") rc, re = files.validate_source(info, sourcename) if not rc then return false, e:cat(re) end local s = info.sources[sourcename] - local makefile = "makefile" -- name of the makefile local source = "source" -- directory to store source files in - local fname = string.format("%s/%s", directory, makefile) - local f, msg = io.open(fname, "w") - if not f then - return false, e:cat(msg) - end + local makefile = e2lib.join(directory, "Makefile") - f:write(string.format(".PHONY: place\n\nplace:\n")) + out = { ".PHONY: place\n\nplace:\n" } for _,file in ipairs(s.file) do e2lib.logf(4, "export file: %s", file.location) local destdir = string.format("%s/%s", directory, source) @@ -558,9 +553,8 @@ function files.toresult(info, sourcename, sourceset, directory) if not rc then return false, e:cat(re) end - f:write(string.format( - "\tcd source && sha1sum -c '%s'\n", - e2lib.basename(checksum_file))) + table.insert(out, string.format("\tcd source && sha1sum -c '%s'\n", + e2lib.basename(checksum_file))) end if file.unpack then local physpath = e2lib.join(destdir, e2lib.basename(file.location)) @@ -577,16 +571,15 @@ function files.toresult(info, sourcename, sourceset, directory) return false, e:cat(re) end - f:write(string.format("\t%s", toolname)) + table.insert(out, string.format("\t%s", toolname)) for _,v in ipairs(toolargv) do - f:write(string.format(" %s", e2lib.shquote(v))) + table.insert(out, string.format(" %s", e2lib.shquote(v))) end - f:write("\n") + table.insert(out, "\n") if file.unpack ~= sourcename then - f:write(string.format( - "\tln -s %s $(BUILD)/%s\n", file.unpack, - sourcename)) + table.insert(out, string.format("\tln -s %s $(BUILD)/%s\n", + file.unpack, sourcename)) end end if file.copy then @@ -600,12 +593,12 @@ function files.toresult(info, sourcename, sourceset, directory) -- is a directory? -- to = string.format('"$(BUILD)"%s', e2lib.shquote(destdir)) - f:write(string.format('\tif [ test -d %s ]; then \\\n', to)) + table.insert(out, string.format('\tif [ test -d %s ]; then \\\n', to)) to = string.format('"$(BUILD)"%s', e2lib.shquote(e2lib.join(destdir, destname))) - f:write(string.format('\t\tcp %s %s; \\\n', from, to)) - f:write(string.format('\telse \\\n')) + table.insert(out, string.format('\t\tcp %s %s; \\\n', from, to)) + table.insert(out, string.format('\telse \\\n')) -- -- not a directory -- @@ -613,19 +606,17 @@ function files.toresult(info, sourcename, sourceset, directory) file.location, "no") to = string.format('"$(BUILD)"%s', e2lib.shquote(destdir)) - f:write(string.format('\t\tmkdir -p %s; \\\n', to)) + table.insert(out, string.format('\t\tmkdir -p %s; \\\n', to)) to = string.format('"$(BUILD)"%s', e2lib.shquote(e2lib.join(destdir, destname))) - f:write(string.format('\t\tcp %s %s; \\\n', from, to)) - f:write('\tfi\n') + table.insert(out, string.format('\t\tcp %s %s; \\\n', from, to)) + table.insert(out, '\tfi\n') end if file.patch then - f:write(string.format( - "\tpatch -p%s -d \"$(BUILD)/%s\" ".. - "-i \"$(shell pwd)/%s/%s\"\n", - file.patch, sourcename, source, - e2lib.basename(file.location))) + table.insert(out, string.format( + "\tpatch -p%s -d \"$(BUILD)/%s\" -i \"$(shell pwd)/%s/%s\"\n", + file.patch, sourcename, source, e2lib.basename(file.location))) end -- write licences local destdir = string.format("%s/licences", directory) @@ -642,8 +633,13 @@ function files.toresult(info, sourcename, sourceset, directory) end e2lib.logf(4, "export file: %s done", file.location) end - f:close() - return true, nil + + rc, re = eio.file_write(makefile, table.concat(out)) + if not rc then + return false, e:cat(re) + end + + return true end --- Check for working copy availability. diff --git a/plugins/git.lua b/plugins/git.lua index 25c4e9e..c761394 100644 --- a/plugins/git.lua +++ b/plugins/git.lua @@ -555,7 +555,7 @@ function git.toresult(info, sourcename, sourceset, directory) return false, e:cat(re) end local src = info.sources[sourcename] - local makefile = "makefile" + local makefile = "Makefile" local source = "source" local sourcedir = string.format("%s/%s", directory, source) local archive = string.format("%s.tar.gz", src.name) @@ -620,16 +620,14 @@ function git.toresult(info, sourcename, sourceset, directory) sourceset) end local fname = string.format("%s/%s", directory, makefile) - local f, msg = io.open(fname, "w") - if not f then - return false, e:cat(msg) - end - f:write(string.format( - ".PHONY:\tplace\n\n".. - "place:\n".. - "\ttar xzf \"%s/%s\" -C \"$(BUILD)\"\n", - source, archive)) - f:close() + local out = string.format( + ".PHONY:\tplace\n\n".. + "place:\n".. + "\ttar xzf \"%s/%s\" -C \"$(BUILD)\"\n", source, archive) + rc, re = eio.file_write(fname, out) + if not rc then + return false, e:cat(re) + end -- write licences local destdir = string.format("%s/licences", directory) local fname = string.format("%s/%s.licences", destdir, archive) diff --git a/plugins/svn.lua b/plugins/svn.lua index 45aa9ba..d5f686f 100644 --- a/plugins/svn.lua +++ b/plugins/svn.lua @@ -373,7 +373,7 @@ function svn.toresult(info, sourcename, sourceset, directory) end local src = info.sources[sourcename] -- write makefile - local makefile = "makefile" + local makefile = "Makefile" local source = "source" local sourcedir = e2lib.join(directory, source) local archive = string.format("%s.tar.gz", sourcename) @@ -382,16 +382,11 @@ function svn.toresult(info, sourcename, sourceset, directory) if not rc then return false, e:cat(re) end - local f, msg = io.open(fname, "w") - if not f then - return false, e:cat(msg) - end - f:write(string.format( - ".PHONY:\tplace\n\n".. - "place:\n".. - "\ttar xzf \"%s/%s\" -C \"$(BUILD)\"\n", - source, archive)) - f:close() + local out = string.format( + ".PHONY:\tplace\n\n".. + "place:\n".. + "\ttar xzf \"%s/%s\" -C \"$(BUILD)\"\n", source, archive) + rc, re = eio.file_write(fname, out) -- export the source tree to a temporary directory local tmpdir, re = e2lib.mktempdir() if not tmpdir then -- 2.39.5