From 7e6caf03ad2f4a9ededd2ea5430b403e75a3cc5e Mon Sep 17 00:00:00 2001 From: Pedro Pombeiro Date: Mon, 25 Nov 2019 10:17:28 +0100 Subject: [PATCH] nix: Use mkFilter in local status-go source Signed-off-by: Pedro Pombeiro --- fastlane/Gemfile | 8 ++------ nix/derivation.nix | 2 +- nix/status-go/default.nix | 17 +++++++++++++++-- nix/tools/mkFilter.nix | 28 ++++++++++++++++------------ 4 files changed, 34 insertions(+), 21 deletions(-) diff --git a/fastlane/Gemfile b/fastlane/Gemfile index 3d67e067aa..73c57f2c46 100644 --- a/fastlane/Gemfile +++ b/fastlane/Gemfile @@ -2,10 +2,6 @@ source 'https://rubygems.org' gem 'fastlane', '>= 2.131.0' -plugins_path = ENV['FASTLANE_PLUGINFILE_PATH'] - -if plugins_path == nil - plugins_path = File.join(__dir__, 'Pluginfile') -end - +plugins_path = ENV['FASTLANE_PLUGINFILE_PATH'] || + File.join(__dir__, 'Pluginfile') eval_gemfile(plugins_path) if plugins_path diff --git a/nix/derivation.nix b/nix/derivation.nix index 442874e44f..7f52b7a48c 100644 --- a/nix/derivation.nix +++ b/nix/derivation.nix @@ -22,7 +22,7 @@ let buildGoPackage = pkgs.buildGoPackage.override { inherit go; }; desktop = pkgs.callPackage ./desktop { inherit target-os stdenv status-go pkgs go nodejs; inherit (pkgs) darwin; }; mobile = pkgs.callPackage ./mobile { inherit target-os config stdenv pkgs mkShell nodejs yarn status-go maven localMavenRepoBuilder mkFilter; inherit (pkgs.xcodeenv) composeXcodeWrapper; }; - status-go = pkgs.callPackage ./status-go { inherit target-os config go buildGoPackage; inherit (mobile.ios) xcodeWrapper; androidPkgs = mobile.android.androidComposition; }; + status-go = pkgs.callPackage ./status-go { inherit target-os config go buildGoPackage mkFilter; inherit (mobile.ios) xcodeWrapper; androidPkgs = mobile.android.androidComposition; }; # mkFilter is a function that allows filtering a directory structure (used for filtering source files being captured in a closure) mkFilter = import ./tools/mkFilter.nix { inherit (stdenv) lib; }; localMavenRepoBuilder = diff --git a/nix/status-go/default.nix b/nix/status-go/default.nix index edeb57ef61..fbe9e964bf 100644 --- a/nix/status-go/default.nix +++ b/nix/status-go/default.nix @@ -1,5 +1,5 @@ { target-os, config, stdenv, callPackage, - buildGoPackage, go, fetchFromGitHub, openjdk, + buildGoPackage, go, fetchFromGitHub, mkFilter, openjdk, androidPkgs, xcodeWrapper }: let @@ -23,7 +23,20 @@ let rev = "unknown"; shortRev = "unknown"; versionName = "develop"; - src = stdenv.lib.cleanSource "${traceValFn (path: "Using local ${repo} sources from ${path}\n") config.status_go.src_override}"; + src = + let path = traceValFn (path: "Using local ${repo} sources from ${path}\n") config.status_go.src_override; + in builtins.path { # We use builtins.path so that we can name the resulting derivation, otherwise the name would be taken from the checkout directory, which is outside of our control + inherit path; + name = "${repo}-source-${shortRev}"; + filter = + # Keep this filter as restrictive as possible in order to avoid unnecessary rebuilds and limit closure size + mkFilter { + dirRootsToInclude = []; + dirsToExclude = [ ".git" ".svn" "CVS" ".hg" ".vscode" ".dependabot" ".github" ".ethereumtest" "build" "eth-node" "protocol" ]; + filesToInclude = [ "Makefile" "go.mod" "go.sum" "VERSION" ]; + root = path; + }; + }; } else # Otherwise grab it from the location defined by status-go-version.json let diff --git a/nix/tools/mkFilter.nix b/nix/tools/mkFilter.nix index b0e6225da5..de71ffff1e 100644 --- a/nix/tools/mkFilter.nix +++ b/nix/tools/mkFilter.nix @@ -16,23 +16,27 @@ let allowedPathElementsSubset = take count allowedPathElements; in (compareLists compare allowedPathElementsSubset pathElementsSubset) == 0; - mkFilter = { dirRootsToInclude, # Relative paths of directories to include + mkFilter = { + dirRootsToInclude, # Relative paths of directories to include dirsToExclude ? [ ], # Base names of directories to exclude filesToInclude ? [ ], # Relative path of files to include filesToExclude ? [ ], # Relative path of files to exclude root }: - path: type: let - baseName = baseNameOf (toString path); - subpath = elemAt (splitString "${toString root}/" path) 1; - spdir = elemAt (splitString "/" subpath) 0; + allPathRootsAllowed = (length dirRootsToInclude) == 0; + in + path: type: + let + baseName = baseNameOf (toString path); + subpath = elemAt (splitString "${toString root}/" path) 1; + spdir = elemAt (splitString "/" subpath) 0; - in lib.cleanSourceFilter path type && ( - (type != "directory" && (elem spdir filesToInclude) && !(elem spdir filesToExclude)) || - # check if any part of the directory path is described in dirRootsToInclude - ((any (dirRootToInclude: isPathAllowed dirRootToInclude subpath) dirRootsToInclude) && ! ( - # Filter out version control software files/directories - (type == "directory" && (elem baseName dirsToExclude)) - ))); + in lib.cleanSourceFilter path type && ( + (type != "directory" && (elem spdir filesToInclude) && !(elem spdir filesToExclude)) || + # check if any part of the directory path is described in dirRootsToInclude + ((allPathRootsAllowed || (any (dirRootToInclude: isPathAllowed dirRootToInclude subpath) dirRootsToInclude)) && ! ( + # Filter out version control software files/directories + (type == "directory" && (elem baseName dirsToExclude)) + ))); in mkFilter