Skip to content

[CMake] Make GNU-style response files for long argument lists #18958

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
Oct 24, 2018

Conversation

jrose-apple
Copy link
Contributor

...i.e. an actual shell-like argument list, rather than a semicolon-separated list (CMake's internal stringification mechanism for lists). Apart from being a little easier to read, this also works directly with the response file support in swiftc itself now (not depending on utils/line-directive).

(It's still not quite enough to expand on a command-line, though, since that will escape the quotes. The 'sed' command can get around that: $(sed "s/'//g" foo.txt).)

@jrose-apple
Copy link
Contributor Author

@swift-ci Please smoke test

string(RANDOM file_name)
set(file_path "${CMAKE_CURRENT_BINARY_DIR}/${file_name}.txt")
file(WRITE "${file_path}" "${source_files}")
string(REPLACE ";" "'\n'" source_files_quoted "${source_files}")
file(WRITE "${file_path}" "'${source_files_quoted}'")
Copy link
Member

Choose a reason for hiding this comment

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

Im worried about how this expansion works on Windows. The shell escaping there is weird and the quoting here I believe will go wrong. Note that shlex behaves differently on Windows and unices, so the behaviour of the quoting is relevant to that too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

One of shlex's arguments is whether it behaves POSIXly, which I passed True to. Still, I'd love to test this on a Windows machine; I just don't have one available today.

# "Make an iterator out of shlex.shlex.get_token, then consume items
# until it returns None." (Then eagerly convert the result to a list so
# that we can close the file.)
return list(iter(shlex.shlex(files, file_path, True).get_token, None))
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd prefer for the True value we use a named argument, if that's shell it makes it much easier to understand what's going on here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd love to as well; unfortunately shlex doesn't document a name.

Copy link
Contributor

@Rostepher Rostepher Aug 28, 2018

Choose a reason for hiding this comment

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

I believe the name is posix, the function (well, class constructor) signature is shlex.shlex(instream=None, infile=None, posix=False), source Lib/shlex.py:23

...i.e. an actual shell-like argument list, rather than a
semicolon-separated list (CMake's internal stringification mechanism
for lists). Apart from being a little easier to read, this also works
directly with the response file support in swiftc itself now (not
depending on utils/line-directive).

(It's still not /quite/ enough to expand on a command-line, though,
since that will escape the quotes. The 'sed' command can get around
that: $(sed "s/'//g" foo.txt).)
@jrose-apple
Copy link
Contributor Author

@swift-ci Please clean smoke test

@jrose-apple
Copy link
Contributor Author

Did either of you have further comments?

@jrose-apple
Copy link
Contributor Author

@Rostepher @compnerd ping

@Rostepher
Copy link
Contributor

This looks good to me, I have no further comments nor suggestions. 👍

@jrose-apple
Copy link
Contributor Author

@compnerd, any further thoughts?

@compnerd
Copy link
Member

@jrose-apple - sorry, forgot about this. Lets go ahead and merge this. If there are problems with Windows, we can fix them then.

@jrose-apple
Copy link
Contributor Author

Let's make sure this still integrates cleanly.

@swift-ci Please smoke test

@jrose-apple jrose-apple merged commit 6cd7803 into swiftlang:master Oct 24, 2018
@jrose-apple jrose-apple deleted the stimulus branch October 24, 2018 02:46
rockbruno pushed a commit to rockbruno/swift that referenced this pull request Oct 24, 2018
…ang#18958)

...i.e. an actual shell-like argument list, rather than a
semicolon-separated list (CMake's internal stringification mechanism
for lists). Apart from being a little easier to read, this also works
directly with the response file support in swiftc itself now (not
depending on utils/line-directive).

(It's still not /quite/ enough to expand on a command-line, though,
since that will escape the quotes. The 'sed' command can get around
that: $(sed "s/'//g" foo.txt).)
davidungar pushed a commit to davidungar/swift that referenced this pull request Oct 26, 2018
…ang#18958)

...i.e. an actual shell-like argument list, rather than a
semicolon-separated list (CMake's internal stringification mechanism
for lists). Apart from being a little easier to read, this also works
directly with the response file support in swiftc itself now (not
depending on utils/line-directive).

(It's still not /quite/ enough to expand on a command-line, though,
since that will escape the quotes. The 'sed' command can get around
that: $(sed "s/'//g" foo.txt).)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants