Skip to content

[build-script] Determine HOST_CC in build-script #761

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

Conversation

modocache
Copy link
Contributor

SR-237 calls for build-script and build-script-impl to be merged. This commit takes another step towards that goal by moving the logic that finds the path to the clang and clang++ executables up into Python-land.

Rather than simply moving all of the logic into utils/build-script, this commit moves relevant functions into a new Python module, named buildcli. This has several benefits:

  • The logic can be tested. Whereas build-script-impl needed to be run in order to verify its behavior, the logic extracted out of it into buildcli can be tested in isolation.
  • The logic can be split up into several files without polluting the utils directory, which now contains many different files that are unrelated to build-script.

/cc @gottesmm and @jrose-apple, since they've commented on SR-237 in the past.

@modocache modocache force-pushed the sr-237-build-script-impl-merge-host-cc branch from c804cc9 to 00b9f7d Compare December 24, 2015 04:54
def _freebsd_release_date():
"""
Return the release date for FreeBSD operating system on this host.
If the release date cannot be ascertained, return 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 think it will return 0 instead, or sometimes throw an error, if sysctl returns a non-integer.

I'd just halt the execution at that point. There is no reasonable way a caller could recover from an error in this function. They either need the version and they call this function, or they don't, and they shouldn't be calling it.

@gribozavr
Copy link
Contributor

@modocache Awesome improvements!

@modocache modocache force-pushed the sr-237-build-script-impl-merge-host-cc branch 2 times, most recently from 9043cf5 to a7e10b6 Compare December 24, 2015 18:19
@modocache
Copy link
Contributor Author

@gribozavr Addressed your comments, except for the one about adding the unit tests to validation-test. That change may end up being a little more involved, so I think it's best to send it in another PR.

@@ -0,0 +1,10 @@
# builcli
Copy link
Contributor

Choose a reason for hiding this comment

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

Stale module name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch!

@gribozavr
Copy link
Contributor

@modocache Thank you! Unfortunately, one more issue with argument handling came up in my testing...

@modocache modocache force-pushed the sr-237-build-script-impl-merge-host-cc branch from a7e10b6 to 547b26c Compare December 24, 2015 21:13
@modocache
Copy link
Contributor Author

@gribozavr Good point, I'll update utils/build-script as per your suggestions.

I also realized I forgot to add the code headers you mentioned! I added the ones from #762, since it looks like that was just merged. Thanks!

@gribozavr gribozavr self-assigned this Dec 25, 2015
@modocache
Copy link
Contributor Author

@gribozavr I've added some logic to the argument parser that enables the backwards-compatibility you described. I wanted to make sure we could test the new behavior in isolation, which meant moving the argument parser itself. Hopefully the commits aren't so big that they're unreviewable... 😟

Let me know if you have any additional thoughts--and thanks for all the reviews!

@modocache modocache force-pushed the sr-237-build-script-impl-merge-host-cc branch from 67629c6 to 71deb46 Compare December 25, 2015 19:42
@modocache
Copy link
Contributor Author

A proposal to add Python unit tests to the validation tests is up at #778.

@gribozavr
Copy link
Contributor

@modocache Thanks! I think your patch will work, but... Sorry for sounding picky, but I think we can use a simpler approach. Subclassing of argparse.ArgumentParser seems strange to me (I don't feel like it was meant for subclassing), and _move_impl_args mutating the parsed arguments data structure after the fact seems error-prone (for example, because the information about the key in is duplicated).

What do you think about the following approach? Add a function in the module (so that it is testable) that accepts a command line and a list of options to migrate, and returns the rewritten command line, which is then passed to parse_args. Rewriting algorithm would be:

  1. Split the argument list on --, to get two lists, one is the build-script arguments, another is the build-script-impl arguments.
  2. Iterate over the build-script-impl argument list, and check if an option is marked for migration. If it is, append it to the build-script argument list verbatim.
  3. Concatenate two lists with -- in between.

@modocache modocache force-pushed the sr-237-build-script-impl-merge-host-cc branch from 71deb46 to e382cbe Compare December 26, 2015 17:24
@modocache
Copy link
Contributor Author

@gribozavr Updated as per your suggestions! 👍

I think I'd still like to move the argument parser out into its own module someday, though. We could probably discuss this on the mailing lists, in the comments on SR-237, or in another pull request. My reasoning is that it's pretty cool to be able to call parser.parse_args() from within a unit test to verify what values are set. Even with the test_migration.py tests from this pull request, I still had to manually call build-script--the unit tests showed the migrate_impl_args() function was working, but I couldn't be sure the argument parsing was the same as before.

Anyway, thanks for all the dedicated reviews!

@gribozavr
Copy link
Contributor

@modocache Yes, that would be definitely useful -- I was thinking about a feature in build-script that would validate all presets, for example. I wouldn't mind if you move it to a module in this PR, but it is the subclassing that looks strange -- I could imagine a function that accepts a list of command line arguments and returns a parsed representation as the API that the module should expose for this purpose.

@modocache
Copy link
Contributor Author

Ah, gotcha. Well, definitely expect more PRs on this topic, then! 😉

I feel like this one is in a pretty good state, though. I'm eager to merge it so I can add its tests to the validation tests from #778.

"""
for suffix in suffixes:
cc_path = which('clang{}'.format(suffix))
cxx_path = which('clang{}'.format(suffix))
Copy link
Contributor

Choose a reason for hiding this comment

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

This should say clang++ -- I'm getting strange linker errors because CMake is trying to link C++ programs with the C compiler.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops! Good catch, thanks--this was a typo. 😊

@gribozavr
Copy link
Contributor

@modocache Thank you! This patch is much simpler and I like it. There's one issue though, the C++ compiler name is not correct, see above.

@modocache modocache force-pushed the sr-237-build-script-impl-merge-host-cc branch from e382cbe to 7e6dfe2 Compare December 27, 2015 07:01
@modocache
Copy link
Contributor Author

@gribozavr Updated! Thanks.

https://bugs.swift.org/browse/SR-237 calls for `build-script` and
`build-script-impl` to be merged. This commit takes another step towards
that goal by moving the logic that finds the path to the `clang` and
`clang++` executables up into Python-land.

Rather than simply moving all of the logic into `utils/build-script`,
this commit moves relevant functions into a new Python module, named
`swift_build_support`. This has several benefits:

- The logic can be tested. Whereas `build-script-impl` needed to be run
  in order to verify its behavior, the logic extracted out of it into
  `swift_build_support` can be tested in isolation.
- The logic can be split up into several files without polluting the
  `utils` directory, which now contains many different files that are
  unrelated to `build-script`.
@modocache modocache force-pushed the sr-237-build-script-impl-merge-host-cc branch from 7e6dfe2 to ca3e11b Compare December 27, 2015 07:36
@modocache
Copy link
Contributor Author

Also went ahead and added the tests to validation-test. 👍

@trentxintong trentxintong assigned andreslp and unassigned gribozavr and andreslp Dec 27, 2015
@gribozavr gribozavr self-assigned this Dec 27, 2015
@gribozavr
Copy link
Contributor

@modocache Thank you! Your PR passes all tests I did. Merging.

gribozavr added a commit that referenced this pull request Dec 27, 2015
…-host-cc

[build-script] Determine HOST_CC in build-script
@gribozavr gribozavr merged commit afde6d3 into swiftlang:master Dec 27, 2015
@modocache modocache deleted the sr-237-build-script-impl-merge-host-cc branch December 27, 2015 17:32
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