Repository: easybuilders/easybuild-easyblocks

Issue:
Perl sanity check fails if prefix contains the string "perl"
When installing `Perl-5.28.1-GCCcore-8.2.0.eb` with EB 3.9.0 (also happens with EB 3.8.1) the sanity check fails with following error: 
```
== FAILED: Installation ended unsuccessfully (build directory: /software/build-tmp/Perl/5.28.1/GCCcore-8.2.0): build failed (first 300 chars): Sanity check failed: no (non-empty) directory found at 'lib/perl5/5.28.1' in /software/2019/software/perl/5.28.1-gcccore-8.2.0
== Results of the build can be found in the log file(s) /tmp/eb-2_vi5K/easybuild-Perl-5.28.1-20190426.135243.FZqzX.log
ERROR: Build of /software/system/easyconfigs/easybuild/easyconfigs/p/Perl/Perl-5.28.1-GCCcore-8.2.0.eb failed (err: "build failed (first 300 chars): Sanity check failed: no (non-empty) directory found at 'lib/perl5/5.28.1' in /software/2019/software/perl/5.28.1-gcccore-8.2.0")
```
The install folder misses the `perl5` folder:
```
[easybuild@clip-login-1 ~]$ ls -la /software/2019/software/perl/5.28.1-gcccore-8.2.0
total 28
drwxrwxr-x. 5 easybuild easybuild  4096 Apr 26 14:25 .
drwxrwxr-x. 3 easybuild easybuild  4096 Apr 26 14:25 ..
drwxr-xr-x. 2 easybuild easybuild 12288 Apr 26 14:35 bin
drwxr-xr-x. 4 easybuild easybuild  4096 Apr 26 14:25 lib
drwxr-xr-x. 4 easybuild easybuild  4096 Apr 26 14:25 man
```
The build log indicatges that botih `site_perl` as well as the `5.28.1` folder are directly installed into the `lib` folder and not into `perl5`:

```
Installation prefix to use for add-on modules and utilities? (~name ok) [/software/2019/software/perl/5.28.1-gcccore-8.2.0]  

The installation process will create a directory for
site-specific extensions and modules.  Most users find it convenient
to place all site-specific files in this directory rather than in the
main distribution directory.

Pathname for the site-specific library files? (~name ok) [/software/2019/software/perl/5.28.1-gcccore-8.2.0/lib/site_perl/5.28.1]  
```
According to https://metacpan.org/pod/distribution/perl/INSTALL#Common-Configure-options this seems to be expected behavior:

> If your prefix contains the string "perl", then the suggested directory structure is simplified. For example, if you use prefix=/opt/perl, then Configure will suggest /opt/perl/lib instead of /opt/perl/lib/perl5/


Discussion:
I think we have two options here:

* either we change the sanity check done for `Perl` to just check for `lib` rather than `lib/perl5/5.28.1`

* or we make sure that the installation always uses `lib/perl5`, regardless of whether or not the word `perl` is somewhere in the installation prefix or not (since changing the installation based on that is outright stupid)

@timeu Can you check whether including the following the your `Perl` easyconfig file fixes the installation?

```python
configopts = "-Dinstallstyle='lib/perl5' "
```

If so, we can hardwire this in the `Perl` easyblock to ensure that the installation is always done to `lib/perl%(major_version)s`.

Relevant bit from the `Perl` `Configure` script (which is 25k lines of shell...):

```sh
 7267 : determine installation style
 7268 : For now, try to deduce it from prefix unless it is already set.
 7269 : Reproduce behavior of 5.005 and earlier, maybe drop that in 5.7.
 7270 case "$installstyle" in
 7271 '') case "$prefix" in
 7272         *perl*) dflt='lib';;
 7273         *) dflt='lib/perl5' ;;
 7274     esac
 7275     ;;
 7276 *)  dflt="$installstyle" ;;
 7277 esac
 7278 : Probably not worth prompting for this since we prompt for all
 7279 : the directories individually, and the prompt would be too long and
 7280 : confusing anyway.
 7281 installstyle=$dflt
```
I tried it with the `configopts` setting but at least one extension fails with following error message:
```
== installing extension Module::Implementation 0.09 (20/289)...
== installing extension Module::Build 0.4224 (21/289)...
== FAILED: Installation ended unsuccessfully (build directory: /software/build-tmp/Perl/5.28.1/GCCcore-8.2.0): build failed (first 300 chars): cmd " perl Makefile.PL PREFIX=/software/2019/software/perl/5.28.1-gcccore-8.2.0 -Dinstallstyle='lib/perl5' " exited with exit code 255 and output:
Malformed argument '-Dinstallstyle=lib/perl5' at lib/Module/Build/Compat.pm line 277.

== Results of the build can be found in the log file(s) /tmp/eb-LdUx0T/easybuild-Perl-5.28.1-20190429.115208.tfuRs.log
ERROR: Build of /software/system/clip_easyconfig/Perl-5.28.1-GCCcore-8.2.0.eb failed (err: 'build failed (first 300 chars): cmd " perl Makefile.PL PREFIX=/software/2019/software/perl/5.28.1-gcccore-8.2.0 -Dinstallstyle=\'lib/perl5\' " exited with exit code 255 and output:\nMalformed argument \'-Dinstallstyle=lib/perl5\' at lib/Module/Build/Compat.pm line 277.\n')
```
@timeu Ah, that's probably because the `configopts` is then also picked up for the Perl modules being installed as extensions...

Please try and see if this helps (we'll work around it differently if we actually fix this issue in the `Perl` easyblock):

```python
configopts = "-Dinstallstyle='lib/perl5' "

exts_default_options = {'configopts': ''}
```

This just avoids that the `configopts` intended for Perl itself is also picked up for the extensions...
@boegel : 
Good news. With the additional `ext_defauilt_options` the installation worked:

```
== restore after iterating...
== postprocessing...
== sanity checking...
== cleaning up...
== creating module...
== permissions...
== packaging...
== COMPLETED: Installation ended successfully
== Results of the build can be found in the log file(s) /software/2019/software/perl/5.28.1-gcccore-8.2.0/easybuild/easybuild-Perl-5.28.1-20190502.140702.log
== Build succeeded for 1 out of 1
== Temporary log file(s) /tmp/eb-78crZI/easybuild-8GZ3zh.log* have been removed.
== Temporary directory /tmp/eb-78crZI has been removed.
```

Resolving patch:
diff --git a/easybuild/easyblocks/p/perl.py b/easybuild/easyblocks/p/perl.py
--- a/easybuild/easyblocks/p/perl.py
+++ b/easybuild/easyblocks/p/perl.py
@@ -53,6 +53,7 @@ def configure_step(self):
         """
         Configure Perl build: run ./Configure instead of ./configure with some different options
         """
+        majver = self.version.split('.')[0]
         configopts = [
             self.cfg['configopts'],
             '-Dcc="{0}"'.format(os.getenv('CC')),
@@ -64,6 +65,9 @@ def configure_step(self):
             '-Dinstallscript=%(installdir)s/bin',
             '-Dscriptdir=%(installdir)s/bin',
             '-Dscriptdirexp=%(installdir)s/bin',
+            # guarantee that the install directory has the form lib/perlX/
+            # see https://github.com/easybuilders/easybuild-easyblocks/issues/1700
+            "-Dinstallstyle='lib/perl%s'" % majver,
         ]
         if self.cfg['use_perl_threads']:
             configopts.append('-Dusethreads')


Test patch: