[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
308/376: Build derivations in a more predictable order
From: |
Ludovic Courtès |
Subject: |
308/376: Build derivations in a more predictable order |
Date: |
Wed, 28 Jan 2015 22:05:49 +0000 |
civodul pushed a commit to tag 1.8
in repository guix.
commit b7b6e3ddecae5a0463861ec6b1f400f2e37fd2a7
Author: Eelco Dolstra <address@hidden>
Date: Mon Nov 24 16:48:04 2014 +0100
Build derivations in a more predictable order
Derivations are now built in order of derivation name, so a package
named "aardvark" is built before "baboon".
Fixes #399.
---
src/libstore/build.cc | 48 +++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 41 insertions(+), 7 deletions(-)
diff --git a/src/libstore/build.cc b/src/libstore/build.cc
index 72694cf..539d0b2 100644
--- a/src/libstore/build.cc
+++ b/src/libstore/build.cc
@@ -84,8 +84,12 @@ class Goal;
typedef std::shared_ptr<Goal> GoalPtr;
typedef std::weak_ptr<Goal> WeakGoalPtr;
+struct CompareGoalPtrs {
+ bool operator() (const GoalPtr & a, const GoalPtr & b);
+};
+
/* Set of goals. */
-typedef set<GoalPtr> Goals;
+typedef set<GoalPtr, CompareGoalPtrs> Goals;
typedef list<WeakGoalPtr> WeakGoals;
/* A map of paths to goals (and the other way around). */
@@ -172,11 +176,20 @@ public:
(important!), etc. */
virtual void cancel(bool timeout) = 0;
+ virtual string key() = 0;
+
protected:
void amDone(ExitCode result);
};
+bool CompareGoalPtrs::operator() (const GoalPtr & a, const GoalPtr & b) {
+ string s1 = a->key();
+ string s2 = b->key();
+ return s1 < s2;
+}
+
+
/* A mapping used to remember for each child process to what goal it
belongs, and file descriptors for receiving log data and output
path creation commands. */
@@ -303,6 +316,7 @@ public:
void addToWeakGoals(WeakGoals & goals, GoalPtr p)
{
// FIXME: necessary?
+ // FIXME: O(n)
foreach (WeakGoals::iterator, i, goals)
if (i->lock() == p) return;
goals.push_back(p);
@@ -767,6 +781,15 @@ public:
void cancel(bool timeout);
+ string key()
+ {
+ /* Ensure that derivations get built in order of their name,
+ i.e. a derivation named "aardvark" always comes before
+ "baboon". And substitution goals always happen before
+ derivation goals (due to "b$"). */
+ return "b$" + storePathToName(drvPath) + "$" + drvPath;
+ }
+
void work();
Path getDrvPath()
@@ -2575,6 +2598,13 @@ public:
void cancel(bool timeout);
+ string key()
+ {
+ /* "a$" ensures substitution goals happen before derivation
+ goals. */
+ return "a$" + storePathToName(storePath) + "$" + storePath;
+ }
+
void work();
/* The states. */
@@ -3085,15 +3115,19 @@ void Worker::run(const Goals & _topGoals)
checkInterrupt();
- /* Call every wake goal. */
+ /* Call every wake goal (in the ordering established by
+ CompareGoalPtrs). */
while (!awake.empty() && !topGoals.empty()) {
- WeakGoals awake2(awake);
+ Goals awake2;
+ for (auto & i : awake) {
+ GoalPtr goal = i.lock();
+ if (goal) awake2.insert(goal);
+ }
awake.clear();
- foreach (WeakGoals::iterator, i, awake2) {
+ for (auto & goal : awake2) {
checkInterrupt();
- GoalPtr goal = i->lock();
- if (goal) goal->work();
- if (topGoals.empty()) break;
+ goal->work();
+ if (topGoals.empty()) break; // stuff may have been cancelled
}
}
- 224/376: add manpage for nix-generate-patches, (continued)
- 224/376: add manpage for nix-generate-patches, Ludovic Courtès, 2015/01/28
- 246/376: Typo, Ludovic Courtès, 2015/01/28
- 245/376: Get rid of some unnecessary ExprConcatStrings nodes in dynamic attrs, Ludovic Courtès, 2015/01/28
- 243/376: Add primop ‘catAttrs’, Ludovic Courtès, 2015/01/28
- 249/376: nix-copy-closure: Use strict, Ludovic Courtès, 2015/01/28
- 241/376: Tweak, Ludovic Courtès, 2015/01/28
- 304/376: Combine introduction / quick start parts, Ludovic Courtès, 2015/01/28
- 250/376: Remove unused @sshOpts flag, Ludovic Courtès, 2015/01/28
- 305/376: Update quick start section, Ludovic Courtès, 2015/01/28
- 306/376: Update installation section, Ludovic Courtès, 2015/01/28
- 308/376: Build derivations in a more predictable order,
Ludovic Courtès <=
- 307/376: Don't create unnecessary substitution goals for derivations, Ludovic Courtès, 2015/01/28
- 309/376: More build-cache-failures -> build-cache-failure, Ludovic Courtès, 2015/01/28
- 310/376: forceString(): Accept pos argument, Ludovic Courtès, 2015/01/28
- 311/376: Add a primop for regular expression pattern matching, Ludovic Courtès, 2015/01/28
- 312/376: Rely on XML catalogs to find the DocBook schemas and stylesheets, Ludovic Courtès, 2015/01/28
- 313/376: Intro: Mention binary caches, Ludovic Courtès, 2015/01/28
- 303/376: Manual: Bump date, Ludovic Courtès, 2015/01/28
- 315/376: Make all ExternalValueBase functions const, Ludovic Courtès, 2015/01/28
- 318/376: Shut up a warning, Ludovic Courtès, 2015/01/28
- 317/376: Fix another operator precedence issue found by Perl 5.20, Ludovic Courtès, 2015/01/28