diff options
Diffstat (limited to 'src/libstore/build.cc')
-rw-r--r-- | src/libstore/build.cc | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/libstore/build.cc b/src/libstore/build.cc index 1fc5d4181d57..08b647cd6192 100644 --- a/src/libstore/build.cc +++ b/src/libstore/build.cc @@ -1969,6 +1969,42 @@ void DerivationGoal::startBuilder() } } + if (settings.preBuildHook != "") { + printMsg(lvlChatty, format("executing pre-build hook ‘%1%’") + % settings.preBuildHook); + auto args = useChroot ? Strings({drvPath, chrootRootDir}) : + Strings({ drvPath }); + enum BuildHookState { + stBegin, + stExtraChrootDirs + }; + auto state = stBegin; + auto lines = runProgram(settings.preBuildHook, false, args); + auto lastPos = std::string::size_type{0}; + for (auto nlPos = lines.find('\n'); nlPos != string::npos; + nlPos = lines.find('\n', lastPos)) { + auto line = std::string{lines, lastPos, nlPos}; + lastPos = nlPos + 1; + if (state == stBegin) { + if (line == "extra-chroot-dirs") { + state = stExtraChrootDirs; + } else { + throw Error(format("unknown pre-build hook command ‘%1%’") + % line); + } + } else if (state == stExtraChrootDirs) { + if (line == "") { + state = stBegin; + } else { + auto p = line.find('='); + if (p == string::npos) + dirsInChroot[line] = line; + else + dirsInChroot[string(line, 0, p)] = string(line, p + 1); + } + } + } + } /* Run the builder. */ printMsg(lvlChatty, format("executing builder ‘%1%’") % drv.builder); |