]> git.e2factory.org Git - e2factory.git/commitdiff
plugins: convert Makefile generation to eio
authorTobias Ulmer <tu@emlix.com>
Mon, 25 Nov 2013 12:31:42 +0000 (13:31 +0100)
committerTobias Ulmer <tu@emlix.com>
Wed, 16 Nov 2016 14:41:17 +0000 (15:41 +0100)
While there, call the "makefile" "Makefile", like everyone else

Signed-off-by: Tobias Ulmer <tu@emlix.com>
plugins/cvs.lua
plugins/files.lua
plugins/git.lua
plugins/svn.lua

index a3e05b8f2c643811242a80179bfa68dd2d0d7005..71d8918ed8b222cbbf75ff30b87a873564cf9b8e 100644 (file)
@@ -387,7 +387,7 @@ function cvs.toresult(info, sourcename, sourceset, directory)
     -- <directory>/source/<sourcename>.tar.gz
     -- <directory>/makefile
     -- <directory>/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
index 3178c48897e5843f9ba101264824107c0042a5a6..1c47c802c4e7be7b00f2e52666373de63936f2a9 100644 (file)
@@ -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.
index 25c4e9e96d8556d598d9ef23f55263d56b49fb28..c7613942c7efd29b798522f40a01d35cf8ff37ea 100644 (file)
@@ -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)
index 45aa9ba2e3024dec76a3ee0176384970671fff13..d5f686f67839758b6f10b7cc2566e057946368b4 100644 (file)
@@ -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