-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Add a build product and presets for swift-format. #32546
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
Add a build product and presets for swift-format. #32546
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a quick drive by I noticed when reading the commit stream. Don't treat this as a true review.
@@ -571,6 +572,9 @@ def create_argument_parser(): | |||
option(['--skstresstester'], store_true('build_skstresstester'), | |||
help='build the SourceKit stress tester') | |||
|
|||
option(['--swiftformat '], store_true('build_swiftformat'), | |||
help='build the SourceKit stress tester') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The help comments here and below need to be updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops. Thanks!
This product supports building and testing swift-format, forwarding the commands to a build script inside of swift-format's repo to handle actually invoking Swift PM. There are new command line options to support the swift-format product: `--swiftformat`: Enables building swift-format. `--skip-test-swiftformat': Disables running tests for swift-format after building. Installing is intentionally not implemented because swift-format isn't ready to be installed as part of the Swift toolchain.
utils/build-presets.ini
Outdated
release | ||
assertions | ||
swiftsyntax | ||
swiftsyntax-verify-generated-files |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does --swiftsyntax
run tests? If so, these new presets should skip them.
@akyrtzi is --swiftsyntax-verify-generated-files
relevant for swift-format, or just for swift syntax itself?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is only useful for swift
/ swift-syntax
testing. (/cc @ahoppen).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comments in this file suggest this is used to verify the checked-in generated files are correct, since they won't be generated. I guess it's safe to assume that the checked-in generated files are safe to use in this context without verifying them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it's safe to assume that the checked-in generated files are safe to use in this context without verifying them?
I believe so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good. I have deleted this step, and added skip-test-swiftsyntax
to also skip running swiftsyntax tests.
class SwiftFormat(product.Product): | ||
@classmethod | ||
def product_source_name(cls): | ||
"""product_source_name() -> str |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a python expert - are doc strings inherited from super classes? If so, I would drop this duplicate copy of the doc string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are doc strings inherited from super classes?
It depends on the version of Python you're using. Inheritance for docstrings was added in Python 3 (I think 3.5, but can't recall or find a reference quickly). I believe this project uses Python 2.X so doc strings aren't inherited in this context.
For additional context, note that the other Product
subclasses duplicate this doc string as well.
Let me know if you would prefer that I delete the doc string or otherwise refer to the superclass' doc string. If so, you may want to apply the same to the other Product
subclasses.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note that the other Product subclasses duplicate this doc string as well.
Yeah, it looks like we're inconsistent about this in two different ways:
- Not all products duplicate doc strings
- For products that do, they are not duplicating the doc strings for all methods, just some (e.g. this one).
Anyway, I won't hold up the patch over this - we can clean it up separately across all products.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree there's inconsistency here. I'm fine with whatever approach you prefer. I don't write Python very often so I can't claim to know what's the best practice here.
# There might have been a Package.resolved created by other builds | ||
# or by the package being opened using Xcode. Discard that and | ||
# reset the dependencies to be local. | ||
'--update' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--update
seems suspect to run during testing when it is expected to use local sources. @nathawes I see this is copied from the stress tester - can you explain when there would be a package.resolved created? Opening it in Xcode in particular would create a resolved file in a location used by Xcode, not where it is for command-line builds.
There was a problem hiding this 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 off of the top of my head, but we tell contributors they can invoke build-script-helper themselves passing a swift.org toolchain path in addition to using it to to get swiftpm to generate an Xcode project the old way (we add additional search paths via an .xcconfig file), so my guess would be one of those does it. Looks like Alex added this in #28005. @ahoppen is that what was creating the problematic package.resolved here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For what it's worth, I'm okay with taking this change without resolving this issue, since it's evidently not causing problems for the stress tester. But we should figure it out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue is what’s described in the comment above it 😉. Maybe a little more context.
- You build
swift-format
using this build script,Package.resolved
gets set to the local dependencies. - You open the project in Xcode.
SWIFTCI_USE_LOCAL_DEPS
is not set and thusPackage.resolved
gets reset to use remote dependencies. - You run a build using this script again. Without the
--update
option (which again re-generatesPackage.resolved
), we are now trying to create a unified build of a local SwiftSyntax and a swift-format that takes a remote dependency.
I can’t recall the exact error scenario, but possible options include:
- SwiftPM isn’t happy if the versions of SwiftSyntax don’t refer to the same source code
- I wanted to make sure that we are definitely using the local dependency and are never stuck on a remote dependency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, Xcode will use its own Package.resolved that would not interfere with the local build. However, I suppose if you built from command-line using swift build
it would do the same thing you are describing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@benlangmuir Does it? I’m fairly sure, Xcode uses the same Package.resolved
. Otherwise there also wouldn’t be any point in checking Package.resolved
into source control (for other projects).
utils/swift_build_support/swift_build_support/products/swiftformat.py
Outdated
Show resolved
Hide resolved
- Remove unused `package_name` method. - Disable swift-syntax tests in swift-format builder preset.
@swift-ci please test |
@swift-ci please test macOS |
Build failed |
Please take a look at the python failures:
Lint:
build_swift:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks good to me, I wrote a couple suggestions and explanations inline.
script_path, | ||
action, | ||
'--toolchain', self.install_toolchain_path(), | ||
'--config', configuration, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you named this parameter --configuration
, not --config
in build-script-helper.py
of swift-format
. I am slightly inclined to change the parameter definition in the swift-format
so it’s the same as for the stress tester, but don’t have strong opinions on it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, but it should be the other way: we should update the stress tester to use --configuration
to match the swift-build option name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for catching this. I updated the name here.
# There might have been a Package.resolved created by other builds | ||
# or by the package being opened using Xcode. Discard that and | ||
# reset the dependencies to be local. | ||
'--update' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue is what’s described in the comment above it 😉. Maybe a little more context.
- You build
swift-format
using this build script,Package.resolved
gets set to the local dependencies. - You open the project in Xcode.
SWIFTCI_USE_LOCAL_DEPS
is not set and thusPackage.resolved
gets reset to use remote dependencies. - You run a build using this script again. Without the
--update
option (which again re-generatesPackage.resolved
), we are now trying to create a unified build of a local SwiftSyntax and a swift-format that takes a remote dependency.
I can’t recall the exact error scenario, but possible options include:
- SwiftPM isn’t happy if the versions of SwiftSyntax don’t refer to the same source code
- I wanted to make sure that we are definitely using the local dependency and are never stuck on a remote dependency.
- Fix extra space in build-script arg to build swift-format. - Fix python lint errors in `swiftformat.py`. - Remove swiftsyntax from swiftformat build preset.
@swift-ci please test |
1 similar comment
@swift-ci please test |
@benlangmuir Can you merge this? Or can anyone else? Thanks! |
There are 2 related changes here:
Product
that builds and tests swift-format by calling its helper script, added in swift-format PR 207.These changes allow building & testing swift-format as part of the Swift project, so that swift-format can be added to the Swift project's CI bots.
New Flags
There are new command line options to support the swift-format product:
--swiftformat
: Enables building swift-format.--skip-test-swiftformat
: Disables running tests for swift-format after building.Installing
Installing is intentionally not implemented because swift-format isn't ready to be installed as part of the Swift toolchain.
Background
This PR implements steps 5 and 6 of the instructions to get swift-format ready to be built using Swift's CI bots:
https://forums.swift.org/t/testing-swift-format-as-part-of-swift-s-ci-infrastructure/30619