Repository: spack/spack

Issue:
Can't install r-rcpp (something odd with Makeconf vs/and Makeconf.spack?)
I'm having trouble building r-rcpp.  Here's what's happening (check out the line just before those that being 'g++: error:' and the 'g++: error:' lines themselves):

```
[throgg@spack-central spack]$ spack install -v r-rcpp
==> Installing r-rcpp
==> R is already installed in /home/throgg/spack/opt/spack/linux-centos7-x86_64/gcc-5.4.0/R-3.3.1-jw6b5cxsuwmiuepqaboaum7jx45i36py
==> Already downloaded /home/throgg/spack/var/spack/stage/r-rcpp-0.12.6-uyk74pfyiunrhwlpuy756vqz6megyxeq/r-rcpp-0.12.6.tar.gz
==> Already staged r-rcpp-0.12.6-uyk74pfyiunrhwlpuy756vqz6megyxeq in /home/throgg/spack/var/spack/stage/r-rcpp-0.12.6-uyk74pfyiunrhwlpuy756vqz6megyxeq
==> No patches needed for r-rcpp
==> Building r-rcpp
==> '/home/throgg/spack/opt/spack/linux-centos7-x86_64/gcc-5.4.0/R-3.3.1-jw6b5cxsuwmiuepqaboaum7jx45i36py/bin/R' 'CMD' 'INSTALL' '--library=/home/throgg/spack/opt/spack/linux-centos7-x86_64/gcc-5.4.0/r-rcpp-0.12.6-uyk74pfyiunrhwlpuy756vqz6megyxeq/rlib/R/library' '/home/throgg/spack/var/spack/stage/r-rcpp-0.12.6-uyk74pfyiunrhwlpuy756vqz6megyxeq/Rcpp'
* installing *source* package ‘Rcpp’ ...
** package ‘Rcpp’ successfully unpacked and MD5 sums checked
** libs
/home/throgg/spack/opt/spack/linux-centos7-x86_64/gcc-5.4.0/R-3.3.1-jw6b5cxsuwmiuepqaboaum7jx45i36py/rlib/R/etc/Makeconf.spack:132: warning: overriding recipe for target `.c.o'
/home/throgg/spack/opt/spack/linux-centos7-x86_64/gcc-5.4.0/R-3.3.1-jw6b5cxsuwmiuepqaboaum7jx45i36py/rlib/R/etc/Makeconf:132: warning: ignoring old recipe for target `.c.o'
/home/throgg/spack/opt/spack/linux-centos7-x86_64/gcc-5.4.0/R-3.3.1-jw6b5cxsuwmiuepqaboaum7jx45i36py/rlib/R/etc/Makeconf.spack:134: warning: overriding recipe for target `.c.d'
/home/throgg/spack/opt/spack/linux-centos7-x86_64/gcc-5.4.0/R-3.3.1-jw6b5cxsuwmiuepqaboaum7jx45i36py/rlib/R/etc/Makeconf:134: warning: ignoring old recipe for target `.c.d'
/home/throgg/spack/opt/spack/linux-centos7-x86_64/gcc-5.4.0/R-3.3.1-jw6b5cxsuwmiuepqaboaum7jx45i36py/rlib/R/etc/Makeconf.spack:137: warning: overriding recipe for target `.cc.o'
/home/throgg/spack/opt/spack/linux-centos7-x86_64/gcc-5.4.0/R-3.3.1-jw6b5cxsuwmiuepqaboaum7jx45i36py/rlib/R/etc/Makeconf:137: warning: ignoring old recipe for target `.cc.o'
/home/throgg/spack/opt/spack/linux-centos7-x86_64/gcc-5.4.0/R-3.3.1-jw6b5cxsuwmiuepqaboaum7jx45i36py/rlib/R/etc/Makeconf.spack:139: warning: overriding recipe for target `.cpp.o'
/home/throgg/spack/opt/spack/linux-centos7-x86_64/gcc-5.4.0/R-3.3.1-jw6b5cxsuwmiuepqaboaum7jx45i36py/rlib/R/etc/Makeconf:139: warning: ignoring old recipe for target `.cpp.o'
/home/throgg/spack/opt/spack/linux-centos7-x86_64/gcc-5.4.0/R-3.3.1-jw6b5cxsuwmiuepqaboaum7jx45i36py/rlib/R/etc/Makeconf.spack:141: warning: overriding recipe for target `.cc.d'
/home/throgg/spack/opt/spack/linux-centos7-x86_64/gcc-5.4.0/R-3.3.1-jw6b5cxsuwmiuepqaboaum7jx45i36py/rlib/R/etc/Makeconf:141: warning: ignoring old recipe for target `.cc.d'
/home/throgg/spack/opt/spack/linux-centos7-x86_64/gcc-5.4.0/R-3.3.1-jw6b5cxsuwmiuepqaboaum7jx45i36py/rlib/R/etc/Makeconf.spack:144: warning: overriding recipe for target `.cpp.d'
/home/throgg/spack/opt/spack/linux-centos7-x86_64/gcc-5.4.0/R-3.3.1-jw6b5cxsuwmiuepqaboaum7jx45i36py/rlib/R/etc/Makeconf:144: warning: ignoring old recipe for target `.cpp.d'
/home/throgg/spack/opt/spack/linux-centos7-x86_64/gcc-5.4.0/R-3.3.1-jw6b5cxsuwmiuepqaboaum7jx45i36py/rlib/R/etc/Makeconf.spack:147: warning: overriding recipe for target `.m.o'
/home/throgg/spack/opt/spack/linux-centos7-x86_64/gcc-5.4.0/R-3.3.1-jw6b5cxsuwmiuepqaboaum7jx45i36py/rlib/R/etc/Makeconf:147: warning: ignoring old recipe for target `.m.o'
/home/throgg/spack/opt/spack/linux-centos7-x86_64/gcc-5.4.0/R-3.3.1-jw6b5cxsuwmiuepqaboaum7jx45i36py/rlib/R/etc/Makeconf.spack:149: warning: overriding recipe for target `.m.d'
/home/throgg/spack/opt/spack/linux-centos7-x86_64/gcc-5.4.0/R-3.3.1-jw6b5cxsuwmiuepqaboaum7jx45i36py/rlib/R/etc/Makeconf:149: warning: ignoring old recipe for target `.m.d'
/home/throgg/spack/opt/spack/linux-centos7-x86_64/gcc-5.4.0/R-3.3.1-jw6b5cxsuwmiuepqaboaum7jx45i36py/rlib/R/etc/Makeconf.spack:152: warning: overriding recipe for target `.mm.o'
/home/throgg/spack/opt/spack/linux-centos7-x86_64/gcc-5.4.0/R-3.3.1-jw6b5cxsuwmiuepqaboaum7jx45i36py/rlib/R/etc/Makeconf:152: warning: ignoring old recipe for target `.mm.o'
/home/throgg/spack/opt/spack/linux-centos7-x86_64/gcc-5.4.0/R-3.3.1-jw6b5cxsuwmiuepqaboaum7jx45i36py/rlib/R/etc/Makeconf.spack:154: warning: overriding recipe for target `.M.o'
/home/throgg/spack/opt/spack/linux-centos7-x86_64/gcc-5.4.0/R-3.3.1-jw6b5cxsuwmiuepqaboaum7jx45i36py/rlib/R/etc/Makeconf:154: warning: ignoring old recipe for target `.M.o'
/home/throgg/spack/opt/spack/linux-centos7-x86_64/gcc-5.4.0/R-3.3.1-jw6b5cxsuwmiuepqaboaum7jx45i36py/rlib/R/etc/Makeconf.spack:156: warning: overriding recipe for target `.f.o'
/home/throgg/spack/opt/spack/linux-centos7-x86_64/gcc-5.4.0/R-3.3.1-jw6b5cxsuwmiuepqaboaum7jx45i36py/rlib/R/etc/Makeconf:156: warning: ignoring old recipe for target `.f.o'
/home/throgg/spack/opt/spack/linux-centos7-x86_64/gcc-5.4.0/R-3.3.1-jw6b5cxsuwmiuepqaboaum7jx45i36py/rlib/R/etc/Makeconf.spack:158: warning: overriding recipe for target `.f95.o'
/home/throgg/spack/opt/spack/linux-centos7-x86_64/gcc-5.4.0/R-3.3.1-jw6b5cxsuwmiuepqaboaum7jx45i36py/rlib/R/etc/Makeconf:158: warning: ignoring old recipe for target `.f95.o'
/home/throgg/spack/opt/spack/linux-centos7-x86_64/gcc-5.4.0/R-3.3.1-jw6b5cxsuwmiuepqaboaum7jx45i36py/rlib/R/etc/Makeconf.spack:160: warning: overriding recipe for target `.f90.o'
/home/throgg/spack/opt/spack/linux-centos7-x86_64/gcc-5.4.0/R-3.3.1-jw6b5cxsuwmiuepqaboaum7jx45i36py/rlib/R/etc/Makeconf:160: warning: ignoring old recipe for target `.f90.o'
/home/throgg/spack/lib/spack/env/gcc/g++ -shared -L/home/throgg/spack/opt/spack/linux-centos7-x86_64/gcc-5.4.0/R-3.3.1-jw6b5cxsuwmiuepqaboaum7jx45i36py/rlib/R/lib -L/usr/local/lib64 -o Rcpp.so Date.o Module.o Rcpp_init.o api.o attributes.o barrier.o SHLIB_LIBADD = -L/home/throgg/spack/opt/spack/linux-centos7-x86_64/gcc-5.4.0/R-3.3.1-jw6b5cxsuwmiuepqaboaum7jx45i36py/rlib/R/lib -lR
g++: error: SHLIB_LIBADD: No such file or directory
g++: error: =: No such file or directory
make: *** [Rcpp.so] Error 1
ERROR: compilation failed for package ‘Rcpp’
* removing ‘/home/throgg/spack/opt/spack/linux-centos7-x86_64/gcc-5.4.0/r-rcpp-0.12.6-uyk74pfyiunrhwlpuy756vqz6megyxeq/rlib/R/library/Rcpp’
==> Error: Command exited with status 1:
'/home/throgg/spack/opt/spack/linux-centos7-x86_64/gcc-5.4.0/R-3.3.1-jw6b5cxsuwmiuepqaboaum7jx45i36py/bin/R' 'CMD' 'INSTALL' '--library=/home/throgg/spack/opt/spack/linux-centos7-x86_64/gcc-5.4.0/r-rcpp-0.12.6-uyk74pfyiunrhwlpuy756vqz6megyxeq/rlib/R/library' '/home/throgg/spack/var/spack/stage/r-rcpp-0.12.6-uyk74pfyiunrhwlpuy756vqz6megyxeq/Rcpp'

See build log for details:
  /tmp/throgg/spack-stage/spack-stage-OhkFfh/Rcpp/spack-build.out

/home/throgg/spack/var/spack/repos/builtin/packages/r-rcpp/package.py:50, in install:
     48       def install(self, spec, prefix):
     49           R('CMD', 'INSTALL', '--library={0}'.format(self.module.r_lib_dir),
  >> 50             self.stage.source_path)
==> Error: Installation process had nonzero exit code : 256
```

Clearly the the string 'SHLIB_LDDADD =' should not be getting interpolated literally in the link line.

While poking psuedo-randomly around at it, I assigned different values to the variable in both Makeconf and Makeconf.spack and discovered that the value being used is the value in Makeconf.  I thought that this setting of R_MAKEVARS_SITE would make the Makeconf.spack value "win".

```
[throgg@spack-central spack]$ spack env r-rcpp bash
[throgg@spack-central spack]$ printenv | egrep '^R'
R_MAKEVARS_SITE=/home/throgg/spack/opt/spack/linux-centos7-x86_64/gcc-5.4.0/R-3.3.1-jw6b5cxsuwmiuepqaboaum7jx45i36py/rlib/R/etc/Makeconf.spack
R_LIBS=/home/throgg/spack/opt/spack/linux-centos7-x86_64/gcc-5.4.0/r-rcpp-0.12.6-uyk74pfyiunrhwlpuy756vqz6megyxeq/rlib/R/library
[throgg@spack-central spack]$
```

It's also odd that there are all of those warnings involving  Makeconf.spack and Makeconf before R tries to link the library.



Discussion:
@glennpj?

There seem to be a lot of white space differences between Makeconf and Makeconf.spack, but the only "beefy" ones seem to be the compiler settings.

The comments in the R/package.py suggest that we want to use the "corrected" settings in Makeconf, so I think that [setting R_MAKEVARS_SITE here](https://github.com/LLNL/spack/blob/develop/var/spack/repos/builtin/packages/R/package.py#L139-L140) is probably not the right thing.

Commenting it out quiets all warnings at the top of the `spack install` output, but doesn't change my "real" probley.

Hmmm.  If I tack a space onto the end of line 97 of the Makeconf that's installed in the R tree, then things work (also have the R_MAKEVARS_SITE bit commented out).

`"SHLIB_LIBADD = "`

filter_file seems to be trimming trailing whitespace, which doesn't Do The Right Thing here.

R outputs the file with spaces around all '=' so there should be whitespace there. The filtering is removing the whitespace due to commit 14d861a from PR #1414, that added `line.rstrip()`

```
-        shutil.copy(filename, backup_filename)
 +        # Create backup file. Don't overwrite an existing backup
 +        # file in case this file is being filtered multiple times.
 +        if not os.path.exists(backup_filename):
 +            shutil.copy(filename, backup_filename)
 +
          try:
 -            with closing(open(backup_filename)) as infile:
 -                with closing(open(filename, 'w')) as outfile:
 -                    for line in infile:
 -                        foo = re.sub(regex, repl, line)
 -                        outfile.write(foo)
 +            for line in fileinput.input(filename, inplace=True):
 +                print(re.sub(regex, repl, line.rstrip()))
```


Resolving patch:
diff --git a/lib/spack/llnl/util/filesystem.py b/lib/spack/llnl/util/filesystem.py
--- a/lib/spack/llnl/util/filesystem.py
+++ b/lib/spack/llnl/util/filesystem.py
@@ -93,7 +93,7 @@ def groupid_to_group(x):
 
         try:
             for line in fileinput.input(filename, inplace=True):
-                print(re.sub(regex, repl, line.rstrip()))
+                print(re.sub(regex, repl, line.rstrip('\n')))
         except:
             # clean up the original file on failure.
             shutil.move(backup_filename, filename)


Test patch: