Repository: spack/spack

Issue:
perl "remembers" spack's compiler, which does the wrong thing
Additional Perl packages (e.g. from CPAN) should (need to) be built with the same compiler that built `perl` itself.

Perl handles this detail by remembering the compiler with which it was built.  It "remembers" it by stashing a copy of it in the `Config` hash defined in `Config.pm`:

```perl
tie %Config, 'Config', {
    archlibexp => '/home/hartzelg/tmp/spack-perl-cc/opt/spack/linux-centos7-x86_64/gcc-4.8.5/perl-5.24.1-35ejv4426dmzreum4ekdibu3ddmhquvi/lib/5.24.1/x86_64-linux',
    archname => 'x86_64-linux',
    cc => 'cc',
    # [...]
```

On my system this drags `/usr/bin/cc` into the fray, resulting in sadness.

As an example, using the `cpanm` that Spack built

```
cpanm -l /path/to/library/dir XML::Simple
```

will eventually fail while trying to build `Net::HTTP` because it tries to use `cc` as its compiler.

As a quick hack/test, telling configure to use `gcc` as the C compiler results `$Config{cc}` containing `gcc` and happily the first gcc on my path is the one I used to build Perl.

```diff
diff --git a/var/spack/repos/builtin/packages/perl/package.py b/var/spack/repos/builtin/packages/perl/package.py
index 10895f60..ed30bac5 100644
--- a/var/spack/repos/builtin/packages/perl/package.py
+++ b/var/spack/repos/builtin/packages/perl/package.py
@@ -86,7 +86,8 @@ class Perl(Package):  # Perl doesn't use Autotools, it should subclass Package
             '-des',
             '-Dprefix={0}'.format(prefix),
             '-Dlocincpth=' + self.spec['gdbm'].prefix.include,
-            '-Dloclibpth=' + self.spec['gdbm'].prefix.lib
+            '-Dloclibpth=' + self.spec['gdbm'].prefix.lib,
+            '-Dcc=gcc'
         ]

         # Discussion of -fPIC for Intel at:
```

This changes lets `Net::HTTP` build and install.

Spack's compiler wrappers and *etc* seem magical to me.  What's a good way to fix this?









Discussion:
This snippet:
```perl
tie %Config, 'Config', {
    archlibexp => '/home/hartzelg/tmp/spack-perl-cc/opt/spack/linux-centos7-x86_64/gcc-4.8.5/perl-5.24.1-35ejv4426dmzreum4ekdibu3ddmhquvi/lib/5.24.1/x86_64-linux',
    archname => 'x86_64-linux',
    cc => 'cc',
    # [...]
```
Is this a text file somewhere in the installation? Can we filter it post-install like we do for the MPI wrappers?
Look at the `mpich` or `openmpi` packages to see what needs to happen here.
@adamjstewart -- yes, here `.../opt/spack/linux-centos7-x86_64/gcc-4.8.5/perl-5.24.1-35ejv4426dmzreum4ekdibu3ddmhquvi/lib/5.24.1/x86_64-linux/Config.pm` in this perl (YYMV).

@tgamblin -- will do.


Resolving patch:
diff --git a/var/spack/repos/builtin/packages/perl/package.py b/var/spack/repos/builtin/packages/perl/package.py
--- a/var/spack/repos/builtin/packages/perl/package.py
+++ b/var/spack/repos/builtin/packages/perl/package.py
@@ -31,6 +31,7 @@
 # Date: September 6, 2015
 #
 from spack import *
+import os
 
 
 class Perl(Package):  # Perl doesn't use Autotools, it should subclass Package
@@ -160,3 +161,33 @@ def setup_dependent_package(self, module, dependent_spec):
         # if it does not exist already.
         if dependent_spec.package.is_extension:
             mkdirp(module.perl_lib_dir)
+
+    @run_after('install')
+    def filter_config_dot_pm(self):
+        """Run after install so that Config.pm records the compiler that Spack
+        built the package with.  If this isn't done, $Config{cc} will
+        be set to Spack's cc wrapper script.
+        """
+
+        kwargs = {'ignore_absent': True, 'backup': False, 'string': False}
+
+        # Find the actual path to the installed Config.pm file.
+        perl = Executable(join_path(prefix.bin, 'perl'))
+        config_dot_pm = perl('-MModule::Loaded', '-MConfig', '-e',
+                             'print is_loaded(Config)', output=str)
+
+        match = 'cc *=>.*'
+        substitute = "cc => '{cc}',".format(cc=self.compiler.cc)
+        filter_file(match, substitute, config_dot_pm, **kwargs)
+
+        # And the path Config_heavy.pl
+        d = os.path.dirname(config_dot_pm)
+        config_heavy = join_path(d, 'Config_heavy.pl')
+
+        match = '^cc=.*'
+        substitute = "cc='{cc}'".format(cc=self.compiler.cc)
+        filter_file(match, substitute, config_heavy, **kwargs)
+
+        match = '^ld=.*'
+        substitute = "ld='{ld}'".format(ld=self.compiler.cc)
+        filter_file(match, substitute, config_heavy, **kwargs)


Test patch: