end
--- Parse e2version file.
+-- @return Table containing tag and branch. False on error.
+-- @return Error object on failure.
function e2lib.parse_e2versionfile(filename)
local f = luafile.open(filename, "r")
if not f then
- e2lib.abort("can't open e2version file: " .. filename)
+ return false, err.new("can't open e2version file: %s", filename)
end
+
local l = f:readline()
f:close()
if not l then
- e2lib.abort("can't parse e2version file: " .. filename)
+ return false, err.new("can't parse e2version file: %s", filename)
end
+
local match = l:gmatch("[^%s]+")
- local v = {}
- v.branch = match() or e2lib.abort("invalid branch name `", l, "' in e2 version file ",
- filename)
- v.tag = match() or e2lib.abort("invalid tag name `", l, "' in e2 version file ",
- filename)
- e2lib.logf(3, "using e2 branch %s tag %s", v.branch, v.tag)
- return v
+
+ local version_table = {}
+ version_table.branch = match()
+ if not version_table.branch then
+ return false, err.new("invalid branch name `%s' in e2 version file %s",
+ l, filename)
+ end
+
+ version_table.tag = match()
+ if not version_table.tag then
+ return false, err.new("invalid tag name `%s' in e2 version file %s",
+ l, filename)
+ end
+
+ e2lib.logf(3, "using e2 branch %s tag %s",
+ version_table.branch, version_table.tag)
+
+ return strict.lock(version_table)
end
--- Create a temporary file.
return false, re
end
- if opts.release and not e2tool.e2_has_fixed_tag(info) then
- return false, err.new("Failure: e2 is on pseudo tag while building in release mode.")
+ if opts.release then
+ local version_table, re = e2lib.parse_e2versionfile(
+ e2lib.join(info.root, ".e2/e2version"))
+ if not version_table then
+ return false, re
+ end
+
+ if version_table.tag == "^" then
+ return false,
+ err.new("e2 is on a pseudo tag while building in release mode.")
+ end
end
-- calculate buildids for selected results
if e2option.opts["check"] then
local f = ".e2/e2version"
- local v = e2lib.parse_e2versionfile(f)
+ local v, re = e2lib.parse_e2versionfile(f)
+ if not v then
+ return false, re
+ end
+
if v.tag == "^" then
return false, err.new("local tool version is not configured to " ..
"a fixed tag\nfix you configuration in %s before running " ..
return info.projid
end
---- Check if e2 is in a fixed tag.
---
--- e2tool.e2_has_fixed_tag(info)
---
--- return true if e2 is at fixed tag, and false if not.
-function e2tool.e2_has_fixed_tag(info)
- local v = e2lib.parse_e2versionfile(info.root .. "/.e2/e2version")
- e2lib.log(2, "Checking for fixed e2 tag.")
- if v.tag == "^" then
- e2lib.log(1, "Fatal: e2 is not at a fixed tag.")
- return false
- end
- return true
-end
-
--- hashcache write.
local function hashcache_write(info)
local e = err.new("writing hash cache file")