From 08c53923dba9c7fe6c2676be862744dc1f90f660 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Sun, 14 Aug 2005 12:38:47 +0000 Subject: * A primitive operation `dependencyClosure' to do automatic dependency determination (e.g., finding the header files dependencies of a C file) in Nix low-level builds automatically. For instance, in the function `compileC' in make/lib/default.nix, we find the header file dependencies of C file `main' as follows: localIncludes = dependencyClosure { scanner = file: import (findIncludes { inherit file; }); startSet = [main]; }; The function works by "growing" the set of dependencies, starting with the set `startSet', and calling the function `scanner' for each file to get its dependencies (which should yield a list of strings representing relative paths). For instance, when `scanner' is called on a file `foo.c' that includes the line #include "../bar/fnord.h" then `scanner' should yield ["../bar/fnord.h"]. This list of dependencies is absolutised relative to the including file and added to the set of dependencies. The process continues until no more dependencies are found (hence its a closure). `dependencyClosure' yields a list that contains in alternation a dependency, and its relative path to the directory of the start file, e.g., [ /bla/bla/foo.c "foo.c" /bla/bar/fnord.h "../bar/fnord.h" ] These relative paths are necessary for the builder that compiles foo.c to reconstruct the relative directory structure expected by foo.c. The advantage of `dependencyClosure' over the old approach (using the impure `__currentTime') is that it's completely pure, and more efficient because it only rescans for dependencies (i.e., by building the derivations yielded by `scanner') if sources have actually changed. The old approach rescanned every time. --- make/lib/default.nix | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'make/lib/default.nix') diff --git a/make/lib/default.nix b/make/lib/default.nix index a9b17d2ced77..b2f26a936785 100644 --- a/make/lib/default.nix +++ b/make/lib/default.nix @@ -14,11 +14,13 @@ rec { builder = ./compile-c.sh; localIncludes = if localIncludes == "auto" then - import (findIncludes { - main = toString main; - hack = __currentTime; - inherit cFlags; - }) + dependencyClosure { + scanner = main: + import (findIncludes { + inherit main; + }); + startSet = [main]; + } else localIncludes; inherit main; @@ -36,10 +38,11 @@ rec { }; */ - findIncludes = {main, hack, cFlags ? ""}: stdenv.mkDerivation { + findIncludes = {main}: stdenv.mkDerivation { name = "find-includes"; - builder = ./find-includes.sh; - inherit main hack cFlags; + realBuilder = pkgs.perl ~ "bin/perl"; + args = [ ./find-includes.pl ]; + inherit main; }; link = {objects, programName ? "program", libraries ? []}: stdenv.mkDerivation { -- cgit 1.4.1