Skip to content

BUG: parse shell escaping in extra_compile_args and extra_link_args #12925

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 25, 2019

Conversation

eric-wieser
Copy link
Member

@eric-wieser eric-wieser commented Feb 4, 2019

Thanks to a change in exec_command, these strings are no longer passed onto the shell.
Since config files do not support list values, our best bet is to perform shell-splitting immediately.

Likely fixes gh-12659

Backport here

Note that azure CI fails because this doesn't contain either of #12903 or #12909, in the interest of having a common merge base for backporting. Had we taken the merge-base approach in those PRs, it would be possible to merge the commit in directly.


To be clear: this is blocked by a decision on #12979

@rgommers
Copy link
Member

rgommers commented Feb 4, 2019

LGTM, thanks @eric-wieser. Would be good to get confirmation from @thisco-de that it fixes things for him before merging.

@thisco-de
Copy link

Sorry for the late response, but I haven't had the chance to get back on this any earlier. I can confirm, though, that Eric's patches in eric-wieser:distutils-shlex-split indeed allow me to build numpy and scipy with my old .numpy-site.cfg again.

However, what is still weird, though, is that my LDFLAGS get prepended to the argurments of gfortran when building scipy.fftpack._fftpack, if NPY_DISTUTILS_APPEND_FLAGS=1 is set in the environment. Since GCC's linker options are not compatible with the arguments of gfortran, building scipy obviously terminates with an error. But I guess this might rather be a completely unrelated issue and unfortunately I haven't had the chance to dig deeper into this. Hence, unless you two immediately have a clue by what this might be caused, I guess it would be best to have a separate issue and a separate patch for this as soon as it becomes clear what causes this behavior.

Anyway, the fixes above appear to address the original issue properly on my side. Thank you, guys!

@mattip
Copy link
Member

mattip commented Feb 7, 2019

Tests fail on windows

@charris
Copy link
Member

charris commented Feb 10, 2019

@eric-wieser Ping. The failures look like they may be a problem with the test.

@eric-wieser
Copy link
Member Author

Yep, looks like the test needs to shlex.quote when generating the site.cfg file.

@thisco-de
Copy link

OK, here is a small update on my problem with NPY_DISTUTILS_APPEND_FLAGS=1 and gfortran as mentioned above: The LDFLAGS are given in the format -Wl,-a -Wl,-b -Wl,-c in my environment, such that - whenever gcc invokes ld - the command line parameters -a -b -c get passed to ld (cf. GCC: Options for Linking).

The environment variable LDFLAGS on the other hand also is used by numpy.distutils.fcompiler.__init__ to determine the linker flags for gfortran and LDFLAGS appears to be split up at the , (haven't actually tracked it down to that point). The resulting array of parameters then gets passed to gfortran subsequently. I tried to test, whether it would be of any help to remove the -Wl, from LDFLAGS and pass in the parameters in the form of -a -b -c directly via the environment variable. But then, consequently, gcc complains when building scipy.

I am not sure if this is actually related to the problem or rather worth another issue. However, from my point of view numpy.distutils should not split LDFLAGS at the , in the string (if it does), but only at the spaces (unlike the libraries option in site.cfg, for which the enumeration is separated by ,).

@eric-wieser eric-wieser force-pushed the distutils-shlex-split branch from 2c1fcc3 to 31e74d7 Compare February 17, 2019 01:04
@eric-wieser
Copy link
Member Author

eric-wieser commented Feb 17, 2019

Sorry for the delay, updated with hopefully fixed tests.

Note that there is a behavior change here - previously, extra_link_args was interpreted differently on posix vs windows systems. As this PR is currently written, posix conventions are used in both places.

Is this a desirable change, or should I try and preserve the old behavior (see: #12979)

@eric-wieser eric-wieser force-pushed the distutils-shlex-split branch 2 times, most recently from dccb635 to 59eba9f Compare February 17, 2019 04:45
subprocess.list2cmdline([sys.executable, '-c', 'import sys;print(sys.argv)']), cmd
)
ret = subprocess.check_output(full_cmd)
return ast.literal_eval(ret)
Copy link
Member Author

@eric-wieser eric-wieser Feb 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did not mean to commit this...

In #12979 I opted for json instead, since that's more robust to unicode without depending on console encodings.

@eric-wieser
Copy link
Member Author

Updated with better windows behavior that is less likely to cause problems

Thanks to a change in exec_command, these strings are no longer passed onto the shell.
Since config files do not support list values, our best bet is to perform shell-splitting immediately.

This brings the behavior back in line a little to how it was before.

On windows systems, the behavior has changed. Previously it was treated as a single argument unless it contained quotes, resulting in the following weird behavior:

    # passes as one argument, preserving spaces
    extra_link_args=-Wl,rpath=A:/path/with spaces
    # passes as two arguments, preserving spaces
    extra_link_args="-Wl,rpath=A:\path\with spaces" -lgfortran
    # passes as one long quoted argument (surprising and undesirable)
    extra_link_args=-Wl,rpath=A:\path\without_spaces -lgfortran

Now it behaves as windows escaping via subprocess (but _not_ via cmd) normally would:

    # Passed as two separate arguments (probably not as intended, but should be expected)
    extra_link_args=-Wl,rpath=A:/path/with spaces
    # passes as two arguments, preserving spaces
    extra_link_args="-Wl,rpath=A:\path\with spaces" -lgfortran
    # passes as two arguments
    extra_link_args=-Wl,rpath=A:\path\without_spaces -lgfortran

Fixes numpygh-12659
@eric-wieser eric-wieser force-pushed the distutils-shlex-split branch from b5f8d5d to 00ccdfc Compare February 24, 2019 20:32
@charris charris merged commit 7aebced into numpy:master Feb 25, 2019
@charris
Copy link
Member

charris commented Feb 25, 2019

Let's give this a shot. Thanks Eric.

@charris charris removed the 09 - Backport-Candidate PRs tagged should be backported label Feb 25, 2019
@charris charris removed this from the 1.16.2 release milestone Feb 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Some package builds fail with 1.16.0rc1 distutils
5 participants