about summary refs log tree commit diff
path: root/make/examples
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2005-08-14T12·38+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2005-08-14T12·38+0000
commit08c53923dba9c7fe6c2676be862744dc1f90f660 (patch)
tree8830cb88956a1e797587a06ae1adaee7c3be2679 /make/examples
parent714b7256cd5a6783813c3d3a7468f36ba637f567 (diff)
* 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.

Diffstat (limited to 'make/examples')
-rw-r--r--make/examples/not-so-simple-header-auto/default.nix6
1 files changed, 4 insertions, 2 deletions
diff --git a/make/examples/not-so-simple-header-auto/default.nix b/make/examples/not-so-simple-header-auto/default.nix
index 9e84b0c28ae5..521af7e89fc4 100644
--- a/make/examples/not-so-simple-header-auto/default.nix
+++ b/make/examples/not-so-simple-header-auto/default.nix
@@ -1,11 +1,13 @@
-let {
+with import ../../lib;
 
-  inherit (import ../../lib) compileC findIncludes link;
+let {
 
   hello = link {programName = "hello"; objects = compileC {
     main = ./foo/hello.c;
     localIncludes = "auto";
   };};
 
+#  body = findIncludes {main = ./foo/hello.c;};
+
   body = [hello];
 }