Skip to content

Support building swift-format as part of Swift #207

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
Jun 24, 2020

Conversation

dylansturg
Copy link
Contributor

There are 3 changes to support building swift-format as part of the Swift project:

  • Migrate other Swift project dependencies (swift-syntax and swift-argument-parser) to depend upon the master branches of those projects, so that they can be built as part of a single checkout.
  • Create a build script that can be invoked by the Swift project's build system to build and test swift-format.
  • Conditionally support building with local checkouts of Swift project dependencies (swift-syntax and swift-argument-parser).

When developing just for swift-format, it's still possible to use a recent DEV snapshot of the Swift toolchain to build and test without using local checkouts of the dependencies. That is the default behavior used by the Swift PM package (see the dependencies added with and without the SWIFTCI_USE_LOCAL_DEPS env var.

I ran into some trouble when using multiroot-data-file for Swift PM when combining swift-format with the other swift-syntax dependent projects, because the other projects rely on test discovery. Test discovery seems to work fine for swift-format, so I've enabled it when using the build script. The LinuxMain testing support file is preserved because other existing workflows rely on that file to test on Linux when test discovery isn't supported.

This follows the instructions for incorporating swift-format into the Swift project's CI system:
https://forums.swift.org/t/testing-swift-format-as-part-of-swift-s-ci-infrastructure/30619

Open Question

I'm not sure what is the best way to document the fact that master branch now depends on the latest build of Swift as opposed to a specific snapshot. I updated the README to note that the latest snapshot is necessary, but let me know if you think of a better way to document that.

Copy link
Member

@allevato allevato left a comment

Choose a reason for hiding this comment

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

I'm not sure what is the best way to document the fact that master branch now depends on the latest build of Swift as opposed to a specific snapshot. I updated the README to note that the latest snapshot is necessary, but let me know if you think of a better way to document that.

I wonder if that table cell should just say "Swift at master". "Latest development snapshot" will be true most of the time, except in cases where someone merges a breaking change to apple/swift master that propagates down to apple/swift-syntax and apple/swift-format. In those cases, someone would have to build against a master checkout until a new toolchain snapshot is available (usually within a day, but could be delayed if there are other build breakages).

Otherwise this looks good to me, but I'm gonna hand it off to @akyrtzi to really review it since he's more familiar with these build scripts. 😄

@dylansturg
Copy link
Contributor Author

I wonder if that table cell should just say "Swift at master".

That sounds like a good idea to me. I updated it.

@akyrtzi
Copy link
Contributor

akyrtzi commented Jun 24, 2020

@benlangmuir could you take a look at the build-script changes?
Also /cc @ahoppen for fyi

Package.resolved Outdated
"version": "0.0.4"
"branch": "master",
"revision": "eb51f949cdd0c9d88abba9ce79d37eb7ea1231d0",
"version": null

Choose a reason for hiding this comment

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

Now that your dependencies are on branches rather than tags/versions, does it still make sense to have Package.resolved file checked in? Our CI system will build this against ToT for each dependency, but if a user checks it out or uses it as a dependency they will get whatever version is stamped here. That seems like it will cause mismatches.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@allevato Is it safe to delete this?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, it should be deleted and added to .gitignore. Swift Package Manager will regenerate it when it does the checkout, but if it exists already it will be used, so we don't want wrong revisions to leak to users.

Copy link
Member

Choose a reason for hiding this comment

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

Please make sure to add Package.resolved to .gitignore as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Overlooked that, thanks.

def parse_args(args):
parser = argparse.ArgumentParser(prog='BUILD-SCRIPT-HELPER.PY')

parser.add_argument('--package-dir', default='')

Choose a reason for hiding this comment

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

Please use --package-path to match swift build as well as other build-script-helper scripts such as sourcekit-lsp.

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've renamed this param and the others that you flagged.

Just FYI - these names were taken from an existing build-script-helper.py, so you or someone else may want to rename the params on that script for consistency.

Copy link
Contributor

Choose a reason for hiding this comment

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

Just FYI - these names were taken from an existing build-script-helper.py, so you or someone else may want to rename the params on that script for consistency.

/cc @nathawes

…syntax.

The build script will be used by the Swift project's build system to build & test swift-format, and eventually install it into the Swift toolchain. This script is based on other Swift projects (e.g. swift-syntax and source-kit-stress-tester.

Local deps allow building swift-format based on a local checkout of swift-syntax, instead of a tagged or released version from GitHub. This allows building and testing swift-format against a true HEAD version of all other Swift projects.
Copy link
Member

@allevato allevato left a comment

Choose a reason for hiding this comment

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

🎉

@allevato allevato merged commit 470b634 into swiftlang:master Jun 24, 2020
@dylansturg dylansturg deleted the build_script branch June 24, 2020 23:07
Copy link
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

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

I haven’t looked at every line specifically, but looks good to me (at least according to my own notes in the forum post). 👍🏽

aaditya-chandrasekhar pushed a commit to val-verde/swift-format that referenced this pull request May 20, 2021
* Add CI job for macOS 11 (Big Sur)

* Add bottle job for macOS Big Sur in publish workflow
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.

5 participants