Skip to content

Commit c03ea7a

Browse files
authored
Merge pull request #32546 from dylansturg/add_swift_format_product
Add a build product and presets for swift-format.
2 parents 5a8fdaf + 3b168d8 commit c03ea7a

File tree

7 files changed

+133
-0
lines changed

7 files changed

+133
-0
lines changed

utils/build-presets.ini

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1706,6 +1706,22 @@ assertions
17061706
swiftsyntax
17071707
swiftsyntax-verify-generated-files
17081708

1709+
#===------------------------------------------------------------------------===#
1710+
# Test Swift Format
1711+
#===------------------------------------------------------------------------===#
1712+
1713+
[preset: buildbot_swiftformat_macos]
1714+
mixin-preset=mixin_swiftpm_package_macos_platform
1715+
release
1716+
assertions
1717+
swiftformat
1718+
1719+
[preset: buildbot_swiftformat_linux]
1720+
mixin-preset=mixin_swiftpm_package_linux_platform
1721+
release
1722+
assertions
1723+
swiftformat
1724+
17091725
#===------------------------------------------------------------------------===#
17101726
# Test Swift Stress Tester
17111727
#===------------------------------------------------------------------------===#

utils/build-script

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,8 @@ class BuildScriptInvocation(object):
868868
product_classes.append(products.SwiftSyntax)
869869
if self.args.build_skstresstester:
870870
product_classes.append(products.SKStressTester)
871+
if self.args.build_swiftformat:
872+
product_classes.append(products.SwiftFormat)
871873
if self.args.build_swiftevolve:
872874
product_classes.append(products.SwiftEvolve)
873875
if self.args.build_indexstoredb:

utils/build_swift/build_swift/driver_arguments.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ def _apply_default_arguments(args):
189189
args.test_indexstoredb = False
190190
args.test_sourcekitlsp = False
191191
args.test_skstresstester = False
192+
args.test_swiftformat = False
192193
args.test_swiftevolve = False
193194
args.test_toolchainbenchmarks = False
194195

@@ -572,6 +573,9 @@ def create_argument_parser():
572573
option(['--skstresstester'], store_true('build_skstresstester'),
573574
help='build the SourceKit stress tester')
574575

576+
option(['--swiftformat'], store_true('build_swiftformat'),
577+
help='build swift-format')
578+
575579
option(['--swiftevolve'], store_true('build_swiftevolve'),
576580
help='build the swift-evolve tool')
577581

@@ -1028,6 +1032,8 @@ def create_argument_parser():
10281032
help='skip testing PlaygroundSupport')
10291033
option('--skip-test-skstresstester', toggle_false('test_skstresstester'),
10301034
help='skip testing the SourceKit Stress tester')
1035+
option('--skip-test-swiftformat', toggle_false('test_swiftformat'),
1036+
help='skip testing swift-format')
10311037
option('--skip-test-swiftevolve', toggle_false('test_swiftevolve'),
10321038
help='skip testing SwiftEvolve')
10331039
option('--skip-test-toolchain-benchmarks',

utils/build_swift/resources/SwiftPM-Unified-Build.xcworkspace/contents.xcworkspacedata

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

utils/build_swift/tests/expected_options.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
'build_tensorflow_swift_apis': False,
9595
'build_libparser_only': False,
9696
'build_skstresstester': False,
97+
'build_swiftformat': False,
9798
'build_swiftevolve': False,
9899
'build_indexstoredb': False,
99100
'test_indexstoredb_sanitize_all': False,
@@ -237,6 +238,7 @@
237238
'test_indexstoredb': False,
238239
'test_sourcekitlsp': False,
239240
'test_skstresstester': False,
241+
'test_swiftformat': False,
240242
'test_swiftevolve': False,
241243
'test_toolchainbenchmarks': False,
242244
'tvos': False,
@@ -480,6 +482,7 @@ class BuildScriptImplOption(_BaseOption):
480482
SetTrueOption('--swiftsyntax', dest='build_swiftsyntax'),
481483
SetTrueOption('--build-libparser-only', dest='build_libparser_only'),
482484
SetTrueOption('--skstresstester', dest='build_skstresstester'),
485+
SetTrueOption('--swiftformat', dest='build_swiftformat'),
483486
SetTrueOption('--swiftevolve', dest='build_swiftevolve'),
484487
SetTrueOption('-B', dest='benchmark'),
485488
SetTrueOption('-S', dest='skip_build'),
@@ -598,6 +601,7 @@ class BuildScriptImplOption(_BaseOption):
598601
DisableOption('--skip-test-indexstore-db', dest='test_indexstoredb'),
599602
DisableOption('--skip-test-sourcekit-lsp', dest='test_sourcekitlsp'),
600603
DisableOption('--skip-test-skstresstester', dest='test_skstresstester'),
604+
DisableOption('--skip-test-swiftformat', dest='test_swiftformat'),
601605
DisableOption('--skip-test-swiftevolve', dest='test_swiftevolve'),
602606
DisableOption('--skip-test-toolchain-benchmarks',
603607
dest='test_toolchainbenchmarks'),

utils/swift_build_support/swift_build_support/products/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from .swift import Swift
2929
from .swiftdriver import SwiftDriver
3030
from .swiftevolve import SwiftEvolve
31+
from .swiftformat import SwiftFormat
3132
from .swiftinspect import SwiftInspect
3233
from .swiftpm import SwiftPM
3334
from .swiftsyntax import SwiftSyntax
@@ -49,6 +50,7 @@
4950
'PlaygroundSupport',
5051
'PythonKit',
5152
'Swift',
53+
'SwiftFormat',
5254
'SwiftInspect',
5355
'SwiftPM',
5456
'SwiftDriver',
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# swift_build_support/products/swiftformat.py -----------------*- python -*-
2+
#
3+
# This source file is part of the Swift.org open source project
4+
#
5+
# Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
6+
# Licensed under Apache License v2.0 with Runtime Library Exception
7+
#
8+
# See https://swift.org/LICENSE.txt for license information
9+
# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
#
11+
# ----------------------------------------------------------------------------
12+
13+
import os
14+
15+
from build_swift.build_swift.constants import MULTIROOT_DATA_FILE_PATH
16+
17+
from . import cmark
18+
from . import foundation
19+
from . import libcxx
20+
from . import libdispatch
21+
from . import libicu
22+
from . import llbuild
23+
from . import llvm
24+
from . import product
25+
from . import swift
26+
from . import swiftpm
27+
from . import swiftsyntax
28+
from . import xctest
29+
from .. import shell
30+
31+
32+
class SwiftFormat(product.Product):
33+
@classmethod
34+
def product_source_name(cls):
35+
"""product_source_name() -> str
36+
37+
The name of the source code directory of this product.
38+
"""
39+
return "swift-format"
40+
41+
@classmethod
42+
def is_build_script_impl_product(cls):
43+
return False
44+
45+
@classmethod
46+
def is_swiftpm_unified_build_product(cls):
47+
return True
48+
49+
def run_build_script_helper(self, action, additional_params=[]):
50+
script_path = os.path.join(
51+
self.source_dir, 'build-script-helper.py')
52+
53+
configuration = 'release' if self.is_release() else 'debug'
54+
55+
helper_cmd = [
56+
script_path,
57+
action,
58+
'--toolchain', self.install_toolchain_path(),
59+
'--configuration', configuration,
60+
'--build-path', self.build_dir,
61+
'--multiroot-data-file', MULTIROOT_DATA_FILE_PATH,
62+
# There might have been a Package.resolved created by other builds
63+
# or by the package being opened using Xcode. Discard that and
64+
# reset the dependencies to be local.
65+
'--update'
66+
]
67+
if self.args.verbose_build:
68+
helper_cmd.append('--verbose')
69+
helper_cmd.extend(additional_params)
70+
71+
shell.call(helper_cmd)
72+
73+
def should_build(self, host_target):
74+
return True
75+
76+
def build(self, host_target):
77+
self.run_build_script_helper('build')
78+
79+
def should_test(self, host_target):
80+
return self.args.test_swiftformat
81+
82+
def test(self, host_target):
83+
self.run_build_script_helper('test')
84+
85+
def should_install(self, host_target):
86+
return False
87+
88+
@classmethod
89+
def get_dependencies(cls):
90+
return [cmark.CMark,
91+
llvm.LLVM,
92+
libcxx.LibCXX,
93+
libicu.LibICU,
94+
swift.Swift,
95+
libdispatch.LibDispatch,
96+
foundation.Foundation,
97+
xctest.XCTest,
98+
llbuild.LLBuild,
99+
swiftpm.SwiftPM,
100+
swiftsyntax.SwiftSyntax]

0 commit comments

Comments
 (0)