-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
# swift_build_support/products/swiftformat.py -----------------*- python -*- | ||
# | ||
# This source file is part of the Swift.org open source project | ||
# | ||
# Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors | ||
# Licensed under Apache License v2.0 with Runtime Library Exception | ||
# | ||
# See https://swift.org/LICENSE.txt for license information | ||
# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors | ||
# | ||
# ---------------------------------------------------------------------------- | ||
|
||
import os | ||
|
||
from build_swift.build_swift.constants import MULTIROOT_DATA_FILE_PATH | ||
|
||
from . import cmark | ||
from . import foundation | ||
from . import libcxx | ||
from . import libdispatch | ||
from . import libicu | ||
from . import llbuild | ||
from . import llvm | ||
from . import product | ||
from . import swift | ||
from . import swiftpm | ||
from . import swiftsyntax | ||
from . import xctest | ||
from .. import shell | ||
|
||
|
||
class SwiftFormat(product.Product): | ||
@classmethod | ||
def product_source_name(cls): | ||
"""product_source_name() -> str | ||
|
||
The name of the source code directory of this product. | ||
""" | ||
return "swift-format" | ||
|
||
@classmethod | ||
def is_build_script_impl_product(cls): | ||
return False | ||
|
||
@classmethod | ||
def is_swiftpm_unified_build_product(cls): | ||
return True | ||
|
||
def run_build_script_helper(self, action, additional_params=[]): | ||
script_path = os.path.join( | ||
self.source_dir, 'build-script-helper.py') | ||
|
||
configuration = 'release' if self.is_release() else 'debug' | ||
|
||
helper_cmd = [ | ||
script_path, | ||
action, | ||
'--toolchain', self.install_toolchain_path(), | ||
'--configuration', configuration, | ||
'--build-path', self.build_dir, | ||
'--multiroot-data-file', MULTIROOT_DATA_FILE_PATH, | ||
# 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 commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 commentThe 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.
I can’t recall the exact error scenario, but possible options include:
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @benlangmuir Does it? I’m fairly sure, Xcode uses the same |
||
] | ||
if self.args.verbose_build: | ||
helper_cmd.append('--verbose') | ||
helper_cmd.extend(additional_params) | ||
|
||
shell.call(helper_cmd) | ||
|
||
def should_build(self, host_target): | ||
return True | ||
|
||
def build(self, host_target): | ||
self.run_build_script_helper('build') | ||
|
||
def should_test(self, host_target): | ||
return self.args.test_swiftformat | ||
|
||
def test(self, host_target): | ||
self.run_build_script_helper('test') | ||
|
||
def should_install(self, host_target): | ||
return False | ||
|
||
@classmethod | ||
def get_dependencies(cls): | ||
return [cmark.CMark, | ||
llvm.LLVM, | ||
libcxx.LibCXX, | ||
libicu.LibICU, | ||
swift.Swift, | ||
libdispatch.LibDispatch, | ||
foundation.Foundation, | ||
xctest.XCTest, | ||
llbuild.LLBuild, | ||
swiftpm.SwiftPM, | ||
swiftsyntax.SwiftSyntax] |
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.
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.
Yeah, it looks like we're inconsistent about this in two different ways:
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.