summary refs log tree commit diff
path: root/pkgs/build-support/gcc-wrapper
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2004-03-08 18:29:08 +0000
committerEelco Dolstra <eelco.dolstra@logicblox.com>2004-03-08 18:29:08 +0000
commit946a2d4a4824d415e3c2c306dd7b4c1360946662 (patch)
treed6d51221bcfb90e9341c93fa04efd02bf387bd5a /pkgs/build-support/gcc-wrapper
parentce50734cf067496ae50d1a6fd139fc03de283cbc (diff)
downloadnixpkgs-946a2d4a4824d415e3c2c306dd7b4c1360946662.tar
nixpkgs-946a2d4a4824d415e3c2c306dd7b4c1360946662.tar.gz
nixpkgs-946a2d4a4824d415e3c2c306dd7b4c1360946662.tar.bz2
nixpkgs-946a2d4a4824d415e3c2c306dd7b4c1360946662.tar.lz
nixpkgs-946a2d4a4824d415e3c2c306dd7b4c1360946662.tar.xz
nixpkgs-946a2d4a4824d415e3c2c306dd7b4c1360946662.tar.zst
nixpkgs-946a2d4a4824d415e3c2c306dd7b4c1360946662.zip
* gcc-wrapper now filters out -L and -I flags referring to paths
  outside the store (in pure builds).

svn path=/nixpkgs/trunk/; revision=817
Diffstat (limited to 'pkgs/build-support/gcc-wrapper')
-rwxr-xr-xpkgs/build-support/gcc-wrapper/builder.sh1
-rw-r--r--pkgs/build-support/gcc-wrapper/default.nix1
-rw-r--r--pkgs/build-support/gcc-wrapper/gcc-wrapper.sh39
-rw-r--r--pkgs/build-support/gcc-wrapper/setup-hook.sh2
4 files changed, 41 insertions, 2 deletions
diff --git a/pkgs/build-support/gcc-wrapper/builder.sh b/pkgs/build-support/gcc-wrapper/builder.sh
index d3b1f433559..92d187ab84d 100755
--- a/pkgs/build-support/gcc-wrapper/builder.sh
+++ b/pkgs/build-support/gcc-wrapper/builder.sh
@@ -57,6 +57,7 @@ test -z "$isNative" && echo $glibc > $out/nix-support/orig-glibc
 
 sed \
     -e "s^@isNative@^$isNative^g" \
+    -e "s^@enforcePurity@^$enforcePurity^g" \
     -e "s^@gcc@^$gcc^g" \
     -e "s^@glibc@^$glibc^g" \
     < $setupHook > $out/nix-support/setup-hook
diff --git a/pkgs/build-support/gcc-wrapper/default.nix b/pkgs/build-support/gcc-wrapper/default.nix
index da189661164..11282e131da 100644
--- a/pkgs/build-support/gcc-wrapper/default.nix
+++ b/pkgs/build-support/gcc-wrapper/default.nix
@@ -17,6 +17,7 @@ derivation {
   gccWrapper = ./gcc-wrapper.sh;
   ldWrapper = ./ld-wrapper.sh;
   inherit name stdenv isNative gcc glibc binutils;
+  enforcePurity = if isNative then false else gcc.noSysDirs;
   langC = if isNative then true else gcc.langC;
   langCC = if isNative then true else gcc.langCC;
   langF77 = if isNative then false else gcc.langF77;
diff --git a/pkgs/build-support/gcc-wrapper/gcc-wrapper.sh b/pkgs/build-support/gcc-wrapper/gcc-wrapper.sh
index 59f38086f32..6cb3493f6bf 100644
--- a/pkgs/build-support/gcc-wrapper/gcc-wrapper.sh
+++ b/pkgs/build-support/gcc-wrapper/gcc-wrapper.sh
@@ -10,6 +10,7 @@ if test -z "$NIX_GLIBC_FLAGS_SET"; then
     NIX_LDFLAGS="@ldflags@ $NIX_LDFLAGS"
 fi
 
+
 # Figure out if linker flags should be passed.  GCC prints annoying
 # warnings when they are not needed.
 dontLink=0
@@ -33,6 +34,40 @@ else
     done
 fi
 
+
+# Optionally filter out paths not refering to the store.
+skip () {
+    if test "$NIX_DEBUG" = "1"; then
+        echo "skipping impure path $1" >&2
+    fi
+}
+
+params=("$@")
+if test "$NIX_ENFORCE_PURITY" = "1" -a -n "$NIX_STORE"; then
+    rest=()
+    n=0
+    while test $n -lt ${#params[*]}; do
+        p=${params[n]}
+        p2=${params[$((n+1))]}
+        if test "${p:0:3}" = "-L/" -a "${p:2:${#NIX_STORE}}" != "$NIX_STORE"; then
+            skip $p
+        elif test "$p" = "-L" -a "${p2:0:${#NIX_STORE}}" != "$NIX_STORE"; then
+            n=$((n + 1)); skip $p2
+        elif test "${p:0:3}" = "-I/" -a "${p:2:${#NIX_STORE}}" != "$NIX_STORE"; then
+            skip $p
+        elif test "$p" = "-I" -a "${p2:0:${#NIX_STORE}}" != "$NIX_STORE"; then
+            n=$((n + 1)); skip $p2
+        elif test "$p" = "-isystem" -a "${p2:0:${#NIX_STORE}}" != "$NIX_STORE"; then
+            n=$((n + 1)); skip $p2
+        else
+            rest=("${rest[@]}" "$p")
+        fi
+        n=$((n + 1))
+    done
+    params=("${rest[@]}")
+fi
+
+
 # Add the flags for the C compiler proper.
 extra=($NIX_CFLAGS_COMPILE)
 
@@ -58,7 +93,7 @@ fi
 # Optionally print debug info.
 if test "$NIX_DEBUG" = "1"; then
   echo "original flags to @gcc@:" >&2
-  for i in "$@"; do
+  for i in "${params[@]}"; do
       echo "  $i" >&2
   done
   echo "extra flags to @gcc@:" >&2
@@ -71,4 +106,4 @@ if test -n "$NIX_GCC_WRAPPER_EXEC_HOOK"; then
     . "$NIX_GCC_WRAPPER_EXEC_HOOK"
 fi
 
-exec @gcc@ "$@" ${extra[@]}
+exec @gcc@ "${params[@]}" ${extra[@]}
diff --git a/pkgs/build-support/gcc-wrapper/setup-hook.sh b/pkgs/build-support/gcc-wrapper/setup-hook.sh
index a4c52ba803d..07c3b54b473 100644
--- a/pkgs/build-support/gcc-wrapper/setup-hook.sh
+++ b/pkgs/build-support/gcc-wrapper/setup-hook.sh
@@ -13,3 +13,5 @@ envHooks=(${envHooks[@]} addCVars)
 if test -z "@isNative@"; then
     PATH=$PATH:@gcc@/bin:@glibc@/bin
 fi
+
+export NIX_ENFORCE_PURITY=@enforcePurity@