Linker: ignore empty paths in addEnvPaths
authorÖmer Sinan Ağacan <omeragacan@gmail.com>
Fri, 26 Jan 2018 18:09:17 +0000 (13:09 -0500)
committerBen Gamari <ben@smart-cactus.org>
Fri, 26 Jan 2018 19:37:28 +0000 (14:37 -0500)
commitcacba075d72473511f6924c6505952ff12a20316
tree165c260cbb82b54a386a18167c7f138c53f7fcc3
parentcbdea95938bf09e8e3e7be31918549224d171873
Linker: ignore empty paths in addEnvPaths

Previously `splitEnv` worked like this:

    > splitEnv "foo:::bar::baz:"
    ["foo","","","bar","","baz",""]

with this patch:

    > splitEnv working_dir "foo:::bar:baz:"
    ["foo",working_dir,working_dir"bar","baz",working_dir]

This fixes #14695, where having a trailing `:` in the env variable
caused ghci to pass empty `-B` parameter to `gcc`, which in turned
caused the next parameter (`--print-file-name`) to be considered as the
argument to `-B`. As a result ghci did not work.

The `working_dir` argument is to have a similar behavior with POSIX:
according to chapter 8.3 zero-length prefix means current working
directory.

Reviewers: hvr, bgamari, AndreasK, simonmar

Reviewed By: bgamari, AndreasK, simonmar

Subscribers: AndreasK, rwbarton, thomie, carter

GHC Trac Issues: #14695

Differential Revision: https://phabricator.haskell.org/D4330
compiler/ghci/Linker.hs
testsuite/tests/rts/Makefile
testsuite/tests/rts/all.T