Skip to content

Commit e225bfb

Browse files
committed
Add a build prodct for swift-format.
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.
1 parent b1b60fb commit e225bfb

File tree

7 files changed

+141
-0
lines changed

7 files changed

+141
-0
lines changed

utils/build-presets.ini

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1701,6 +1701,26 @@ assertions
17011701
swiftsyntax
17021702
swiftsyntax-verify-generated-files
17031703

1704+
#===------------------------------------------------------------------------===#
1705+
# Test Swift Format
1706+
#===------------------------------------------------------------------------===#
1707+
1708+
[preset: buildbot_swiftformat_macos]
1709+
mixin-preset=mixin_swiftpm_package_macos_platform
1710+
release
1711+
assertions
1712+
swiftsyntax
1713+
swiftsyntax-verify-generated-files
1714+
swiftformat
1715+
1716+
[preset: buildbot_swiftformat_linux]
1717+
mixin-preset=mixin_swiftpm_package_linux_platform
1718+
release
1719+
assertions
1720+
swiftsyntax
1721+
swiftsyntax-verify-generated-files
1722+
swiftformat
1723+
17041724
#===------------------------------------------------------------------------===#
17051725
# Test Swift Stress Tester
17061726
#===------------------------------------------------------------------------===#

utils/build-script

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,8 @@ class BuildScriptInvocation(object):
861861
product_classes.append(products.SwiftSyntax)
862862
if self.args.build_skstresstester:
863863
product_classes.append(products.SKStressTester)
864+
if self.args.build_swiftformat:
865+
product_classes.append(products.SwiftFormat)
864866
if self.args.build_swiftevolve:
865867
product_classes.append(products.SwiftEvolve)
866868
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
@@ -188,6 +188,7 @@ def _apply_default_arguments(args):
188188
args.test_indexstoredb = False
189189
args.test_sourcekitlsp = False
190190
args.test_skstresstester = False
191+
args.test_swiftformat = False
191192
args.test_swiftevolve = False
192193
args.test_toolchainbenchmarks = False
193194

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

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

@@ -1020,6 +1024,8 @@ def create_argument_parser():
10201024
help='skip testing PlaygroundSupport')
10211025
option('--skip-test-skstresstester', toggle_false('test_skstresstester'),
10221026
help='skip testing the SourceKit Stress tester')
1027+
option('--skip-test-swiftformat', toggle_false('test_swiftformat'),
1028+
help='skip testing swift-format')
10231029
option('--skip-test-swiftevolve', toggle_false('test_swiftevolve'),
10241030
help='skip testing SwiftEvolve')
10251031
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
@@ -93,6 +93,7 @@
9393
'build_tensorflow_swift_apis': False,
9494
'build_libparser_only': False,
9595
'build_skstresstester': False,
96+
'build_swiftformat': False,
9697
'build_swiftevolve': False,
9798
'build_indexstoredb': False,
9899
'test_indexstoredb_sanitize_all': False,
@@ -234,6 +235,7 @@
234235
'test_indexstoredb': False,
235236
'test_sourcekitlsp': False,
236237
'test_skstresstester': False,
238+
'test_swiftformat': False,
237239
'test_swiftevolve': False,
238240
'test_toolchainbenchmarks': False,
239241
'tvos': False,
@@ -476,6 +478,7 @@ class BuildScriptImplOption(_BaseOption):
476478
SetTrueOption('--swiftsyntax', dest='build_swiftsyntax'),
477479
SetTrueOption('--build-libparser-only', dest='build_libparser_only'),
478480
SetTrueOption('--skstresstester', dest='build_skstresstester'),
481+
SetTrueOption('--swiftformat', dest='build_swiftformat'),
479482
SetTrueOption('--swiftevolve', dest='build_swiftevolve'),
480483
SetTrueOption('-B', dest='benchmark'),
481484
SetTrueOption('-S', dest='skip_build'),
@@ -592,6 +595,7 @@ class BuildScriptImplOption(_BaseOption):
592595
DisableOption('--skip-test-indexstore-db', dest='test_indexstoredb'),
593596
DisableOption('--skip-test-sourcekit-lsp', dest='test_sourcekitlsp'),
594597
DisableOption('--skip-test-skstresstester', dest='test_skstresstester'),
598+
DisableOption('--skip-test-swiftformat', dest='test_swiftformat'),
595599
DisableOption('--skip-test-swiftevolve', dest='test_swiftevolve'),
596600
DisableOption('--skip-test-toolchain-benchmarks',
597601
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 .swiftevolve import SwiftEvolve
3030
from .swiftinspect import SwiftInspect
31+
from .swiftformat import SwiftFormat
3132
from .swiftpm import SwiftPM
3233
from .swiftsyntax import SwiftSyntax
3334
from .tensorflow import TensorFlowSwiftAPIs
@@ -49,6 +50,7 @@
4950
'PythonKit',
5051
'Swift',
5152
'SwiftInspect',
53+
'SwiftFormat',
5254
'SwiftPM',
5355
'TensorFlowSwiftAPIs',
5456
'XCTest',
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
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+
import platform
15+
16+
from build_swift.build_swift.constants import MULTIROOT_DATA_FILE_PATH
17+
18+
from . import cmark
19+
from . import foundation
20+
from . import libcxx
21+
from . import libdispatch
22+
from . import libicu
23+
from . import llbuild
24+
from . import llvm
25+
from . import product
26+
from . import swift
27+
from . import swiftpm
28+
from . import swiftsyntax
29+
from . import xctest
30+
from .. import shell
31+
32+
33+
class SwiftFormat(product.Product):
34+
@classmethod
35+
def product_source_name(cls):
36+
"""product_source_name() -> str
37+
38+
The name of the source code directory of this product.
39+
"""
40+
return "swift-format"
41+
42+
@classmethod
43+
def is_build_script_impl_product(cls):
44+
return False
45+
46+
@classmethod
47+
def is_swiftpm_unified_build_product(cls):
48+
return True
49+
50+
def package_name(self):
51+
return 'SwiftFormat'
52+
53+
def run_build_script_helper(self, action, additional_params=[]):
54+
script_path = os.path.join(
55+
self.source_dir, 'build-script-helper.py')
56+
57+
configuration = 'release' if self.is_release() else 'debug'
58+
59+
helper_cmd = [
60+
script_path,
61+
action,
62+
'--toolchain', self.install_toolchain_path(),
63+
'--config', configuration,
64+
'--build-path', self.build_dir,
65+
'--multiroot-data-file', MULTIROOT_DATA_FILE_PATH,
66+
# There might have been a Package.resolved created by other builds
67+
# or by the package being opened using Xcode. Discard that and
68+
# reset the dependencies to be local.
69+
'--update'
70+
]
71+
if self.args.verbose_build:
72+
helper_cmd.append('--verbose')
73+
helper_cmd.extend(additional_params)
74+
75+
shell.call(helper_cmd)
76+
77+
def should_build(self, host_target):
78+
return True
79+
80+
def build(self, host_target):
81+
self.run_build_script_helper('build')
82+
83+
def should_test(self, host_target):
84+
return self.args.test_swiftformat
85+
86+
def test(self, host_target):
87+
self.run_build_script_helper('test')
88+
89+
def should_install(self, host_target):
90+
return False
91+
92+
@classmethod
93+
def get_dependencies(cls):
94+
return [cmark.CMark,
95+
llvm.LLVM,
96+
libcxx.LibCXX,
97+
libicu.LibICU,
98+
swift.Swift,
99+
libdispatch.LibDispatch,
100+
foundation.Foundation,
101+
xctest.XCTest,
102+
llbuild.LLBuild,
103+
swiftpm.SwiftPM,
104+
swiftsyntax.SwiftSyntax]

0 commit comments

Comments
 (0)