From 892e678d05303e3c4e4f04e127706994d48a8852 Mon Sep 17 00:00:00 2001 From: Tobias Ulmer Date: Tue, 25 Mar 2014 17:47:06 +0100 Subject: [PATCH] Unbreak --wc-mode and make it work with intermediary deps Adds a partially random buildid to scratch results, triggering a rebuild of any result that has a scratch result in its dependency chain. Signed-off-by: Tobias Ulmer --- Changelog | 3 +++ local/e2build.lua | 10 +++++----- local/policy.lua | 46 +++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 53 insertions(+), 6 deletions(-) diff --git a/Changelog b/Changelog index ee6892a..318cf53 100644 --- a/Changelog +++ b/Changelog @@ -1,4 +1,7 @@ NEXT: + * Unbreak --wc-mode and allow specifying multiple results, including + intermediary dependencies. Beware this changes wc-mode buildid from "scratch" + to "scratch-". * Include revision ID in SVN sourceid calculation, fixing various issue with moving tags and branch mode. Also fix licenceid calculation for svn sources. * Fix error message for unknown chroot tarball extension. diff --git a/local/e2build.lua b/local/e2build.lua index 9e81c5a..2bd525c 100644 --- a/local/e2build.lua +++ b/local/e2build.lua @@ -50,7 +50,7 @@ local function linklast(info, r, return_flags) local server, location = res.build_mode.storage(info.project_location, info.release_id) local location1 = string.format("%s/%s/%s", location, r, - res.build_mode.buildid(res.buildid)) + e2tool.buildid(info, r)) local cache_flags = { check_only = true } @@ -91,7 +91,7 @@ local function result_available(info, r, return_flags) e2lib.log(4, string.format("result_available(%s)", tostring(r))) local res = info.results[r] local mode = res.build_mode - local buildid = res.build_mode.buildid(e2tool.buildid(info, r)) + local buildid = e2tool.buildid(info, r) local sbid = e2tool.bid_display(buildid) local rc, re local e = err.new("error while checking if result is available: %s", r) @@ -476,8 +476,8 @@ function e2build.unpack_result(info, r, dep, destdir) local d = info.results[dep] local buildid = e2tool.buildid(info, dep) - local dep_set = res.build_mode.dep_set(buildid) - local server, location = res.build_mode.storage(info.project_location, + local dep_set = d.build_mode.dep_set(buildid) + local server, location = d.build_mode.storage(info.project_location, info.release_id) e2lib.log(3, string.format("searching for dependency %s in %s:%s", dep, server, location)) @@ -917,7 +917,7 @@ local function store_result(info, r, return_flags) end local server, location = res.build_mode.storage(info.project_location, info.release_id) - local buildid = res.build_mode.buildid(e2tool.buildid(info, r)) + local buildid = e2tool.buildid(info, r) local sourcefile = string.format("%s/result.tar", tmpdir) local location1 = string.format("%s/%s/%s/result.tar", location, r, buildid) local cache_flags = { diff --git a/local/policy.lua b/local/policy.lua index e9dc427..eef4f41 100644 --- a/local/policy.lua +++ b/local/policy.lua @@ -33,6 +33,7 @@ local e2lib = require("e2lib") local err = require("err") local e2option = require("e2option") local strict = require("strict") +local hash = require("hash") --- source_set_* get the source set identifier -- @class function @@ -113,8 +114,51 @@ local function buildid_buildid(buildid) return buildid end +local buildid_scratch_cache = {} + local function buildid_scratch(buildid) - return "scratch" + --- XXX: Always returning a fixed buildid string does not work when + -- the scratch results gets used by results not in scratch mode. + -- eg. if we have a result graph like this: root->tag->wc-mode->tag + -- the final tag would only be built once and then cached globally. + -- + -- Ideally we would use the hash of the wc-mode result.tar (and making sure + -- that its checksum is stable), but getting it requires some bigger + -- changes that are currently not possible. + -- + -- Next best thing is to generate a random buildid. However, since + -- buildid_scratch() is called multiple times, we need to cache the result + -- to make the new buildid stable. + + -- calculate buildid only once to make stable. + if buildid_scratch_cache[buildid] then + return buildid_scratch_cache[buildid] + end + + local rfile, msg, rstr + local hc, newbuildid + + rfile, msg = io.open("/dev/urandom") + if not rfile then + e2lib.abort(msg) + end + + rstr = rfile:read(16) + if not rstr or string.len(rstr) ~= 16 then + e2lib.abort("could not get 16 bytes of entrophy") + end + + rfile:close() + + hc = hash.hash_start() + hash.hash_append(hc, buildid) + hash.hash_append(hc, rstr) + + newbuildid = hash.hash_finish(hc) + newbuildid = "scratch-" .. newbuildid + buildid_scratch_cache[buildid] = newbuildid + + return buildid_scratch_cache[buildid] end function policy.init(info) -- 2.39.5