From c5fef482ecacf944e5dd6fcd5edf3f1db7ac8b8c Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Thu, 8 Feb 2018 15:18:21 -0500 Subject: [PATCH] Use the patched carnix output for faster builds --- ircbot/Cargo.toml | 2 +- nix/ircbot-carnix.nix | 41 ++++++++++++++++++++++++++++++++++------- nix/ofborg-carnix.nix | 41 ++++++++++++++++++++++++++++++++++------- ofborg/Cargo.toml | 3 +++ 4 files changed, 72 insertions(+), 15 deletions(-) diff --git a/ircbot/Cargo.toml b/ircbot/Cargo.toml index 5060a42..5266311 100644 --- a/ircbot/Cargo.toml +++ b/ircbot/Cargo.toml @@ -2,7 +2,7 @@ name = "ircbot" version = "0.1.0" authors = ["Graham Christensen "] - +include = [ "Cargo.lock", "Cargot.toml", "lib.rs", "src"] [dependencies] log = "0.3.8" env_logger = "0.4.3" diff --git a/nix/ircbot-carnix.nix b/nix/ircbot-carnix.nix index 799901c..0d8b3ed 100644 --- a/nix/ircbot-carnix.nix +++ b/nix/ircbot-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: @@ -337,7 +364,7 @@ rec { crateName = "ircbot"; version = "0.1.0"; authors = [ "Graham Christensen " ]; - src = ./../ircbot; + src = include [ "Cargo.lock" "Cargot.toml" "lib.rs" "src" ] ./../ircbot; inherit dependencies buildDependencies features; }; itoa_0_3_4_ = { dependencies?[], buildDependencies?[], features?[] }: buildRustCrate { diff --git a/nix/ofborg-carnix.nix b/nix/ofborg-carnix.nix index e974c8f..891c991 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: @@ -383,7 +410,7 @@ rec { crateName = "ofborg"; version = "0.1.1"; authors = [ "Graham Christensen " ]; - src = ./../ofborg; + src = include [ "Cargo.toml" "Cargo.lock" "src" "test-srcs" ] ./../ofborg; inherit dependencies buildDependencies features; }; openssl_0_9_23_ = { dependencies?[], buildDependencies?[], features?[] }: buildRustCrate { diff --git a/ofborg/Cargo.toml b/ofborg/Cargo.toml index 92332d9..5e4aade 100644 --- a/ofborg/Cargo.toml +++ b/ofborg/Cargo.toml @@ -2,6 +2,9 @@ name = "ofborg" version = "0.1.1" authors = ["Graham Christensen "] +include = ["Cargo.toml", "Cargo.lock", "src", "test-srcs"] + + [dependencies] log = "= 0.3.8"