Use a patched carnix emission with a smarter include

This commit is contained in:
Graham Christensen 2018-02-08 15:17:43 -05:00
parent 5f9bc10a2d
commit d466b9d3b7
No known key found for this signature in database
GPG key ID: ACA1C1D120C83D5C
2 changed files with 60 additions and 2 deletions

50
nix/carnix.patch Normal file
View file

@ -0,0 +1,50 @@
diff --git a/nix/ofborg-carnix.nix b/nix/ofborg-carnix.nix
index e974c8f..0094e27 100644
--- a/nix/ofborg-carnix.nix
+++ b/nix/ofborg-carnix.nix
@@ -2,12 +2,39 @@
{ lib, buildPlatform, buildRustCrate, fetchgit }:
let kernel = buildPlatform.parsed.kernel.name;
abi = buildPlatform.parsed.abi.name;
- include = includedFiles: src: builtins.filterSource (path: type:
- lib.lists.any (f:
- let p = toString (src + ("/" + f)); in
- (path == p) || (type == "directory" && lib.strings.hasPrefix path p)
- ) includedFiles
- ) src;
+ include = includedFiles: src:
+ # The comments assume the `include` field of the Cargo.toml like:
+ # include = [ "foo", "bar" ]
+ # and the package is being built from /mypackage
+ #
+ # includeFiles == [ "foo" "bar" ]
+ let
+ # and includedFileAbsolutePaths == [ "/mypackage/foo" "/mypackage/bar" ]
+ includedFileAbsolutePaths = builtins.map (relativePath: toString (src + ("/" + relativePath))) includedFiles;
+
+ # Return true only when a possible path exactly matches an
+ # absolute path, ie:
+ #
+ # checkExactMatch "/mypackage/foo" == true
+ # checkExactMatch "/mypackage/foo/bar" == false
+ # checkExactMatch "/mypackage/baz" == false
+ checkExactMatch = possiblePath: builtins.elem possiblePath includedFileAbsolutePaths;
+
+ # Return true only when a possible path is a suffix to a
+ # directory described by the include.
+ #
+ # checkPrefixMatch "/mypackage/buzfoo" == false
+ # checkPrefixMatch "/mypackage/foo" == false
+ # checkPrefixMatch "/mypackage/foo/bar" == true
+ # checkPrefixMatch "/mypackage/baz/foo" == false
+ checkPrefixMatch = possiblePath: lib.lists.any
+ (acceptablePrefix: lib.strings.hasPrefix "${acceptablePrefix}/" possiblePath)
+ includedFileAbsolutePaths;
+
+ in builtins.filterSource (possiblePath: _type:
+ builtins.trace "${possiblePath}" ((checkExactMatch possiblePath) || (checkPrefixMatch possiblePath))
+ )
+ src;
updateFeatures = f: up: functions: builtins.deepSeq f (lib.lists.foldl' (features: fun: fun features) (lib.attrsets.recursiveUpdate f up) functions);
mapFeatures = features: map (fun: fun { features = features; });
mkFeatures = feat: lib.lists.foldl (features: featureName:

View file

@ -2,5 +2,13 @@
cd nix cd nix
carnix ./../ofborg/Cargo.lock --output ./ofborg-carnix.nix patched_carnix() {
carnix ./../ircbot/Cargo.lock --output ./ircbot-carnix.nix src=$1
result=$2
carnix "$src" --output "$result"
patch -p1 "$result" ./carnix.patch
}
patched_carnix ./../ofborg/Cargo.lock ./ofborg-carnix.nix
patched_carnix ./../ircbot/Cargo.lock ./ircbot-carnix.nix