Skip to content

Commit 7c251b2

Browse files
authored
Merge pull request #62584 from ahoppen/ahoppen/lint-swiftsyntax
[build] Verify that SwiftSyntax is correctly formatted
2 parents 26cf4b4 + a1a0cad commit 7c251b2

File tree

4 files changed

+27
-3
lines changed

4 files changed

+27
-3
lines changed

utils/build-presets.ini

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1815,6 +1815,7 @@ release
18151815
assertions
18161816
swiftsyntax
18171817
swiftsyntax-verify-generated-files
1818+
swiftsyntax-lint
18181819
swiftformat
18191820
skstresstester
18201821
swiftevolve
@@ -1828,6 +1829,7 @@ assertions
18281829
swiftsyntax
18291830
sourcekit-lsp
18301831
swiftsyntax-verify-generated-files
1832+
swiftsyntax-lint
18311833
swiftformat
18321834

18331835
#===------------------------------------------------------------------------===#
@@ -1838,13 +1840,17 @@ swiftformat
18381840
mixin-preset=mixin_swiftpm_package_macos_platform
18391841
release
18401842
assertions
1843+
swiftsyntax
18411844
swiftformat
1845+
swiftsyntax-lint
18421846

18431847
[preset: buildbot_swiftformat_linux]
18441848
mixin-preset=mixin_swiftpm_package_linux_platform
18451849
release
18461850
assertions
1851+
swiftsyntax
18471852
swiftformat
1853+
swiftsyntax-lint
18481854

18491855
#===------------------------------------------------------------------------===#
18501856
# Test Swift Stress Tester

utils/build_swift/build_swift/driver_arguments.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,9 @@ def create_argument_parser():
709709
toggle_true('swiftsyntax_verify_generated_files'),
710710
help='set to verify that the generated files in the source tree '
711711
'match the ones that would be generated from current main')
712+
option('--swiftsyntax-lint',
713+
toggle_true('swiftsyntax_lint'),
714+
help='verify that swift-syntax Source code is formatted correctly')
712715
option(['--install-sourcekit-lsp'], toggle_true('install_sourcekitlsp'),
713716
help='install SourceKitLSP')
714717
option(['--install-swiftformat'], toggle_true('install_swiftformat'),

utils/build_swift/tests/expected_options.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@
108108
'install_swift_driver': False,
109109
'install_swiftdocc': False,
110110
'swiftsyntax_verify_generated_files': False,
111+
'swiftsyntax_lint': False,
111112
'install_playgroundsupport': False,
112113
'install_sourcekitlsp': False,
113114
'install_swiftformat': False,
@@ -594,6 +595,8 @@ class BuildScriptImplOption(_BaseOption):
594595
EnableOption('--install-swiftsyntax', dest='install_swiftsyntax'),
595596
EnableOption('--swiftsyntax-verify-generated-files',
596597
dest='swiftsyntax_verify_generated_files'),
598+
EnableOption('--swiftsyntax-lint',
599+
dest='swiftsyntax_lint'),
597600
EnableOption('--install-swiftpm', dest='install_swiftpm'),
598601
EnableOption('--install-swift-driver', dest='install_swift_driver'),
599602
EnableOption('--install-sourcekit-lsp', dest='install_sourcekitlsp'),

utils/swift_build_support/swift_build_support/products/swiftformat.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,20 @@ def is_before_build_script_impl_product(cls):
5050
def is_swiftpm_unified_build_product(cls):
5151
return True
5252

53+
def configuration(self):
54+
return 'release' if self.is_release() else 'debug'
55+
5356
def run_build_script_helper(self, action, host_target, additional_params=[]):
5457
script_path = os.path.join(
5558
self.source_dir, 'build-script-helper.py')
5659

5760
install_destdir = self.host_install_destdir(host_target)
5861

59-
configuration = 'release' if self.is_release() else 'debug'
60-
6162
helper_cmd = [
6263
script_path,
6364
action,
6465
'--toolchain', self.install_toolchain_path(host_target),
65-
'--configuration', configuration,
66+
'--configuration', self.configuration(),
6667
'--build-path', self.build_dir,
6768
'--multiroot-data-file', MULTIROOT_DATA_FILE_PATH,
6869
# There might have been a Package.resolved created by other builds
@@ -84,6 +85,17 @@ def should_build(self, host_target):
8485

8586
def build(self, host_target):
8687
self.run_build_script_helper('build', host_target)
88+
if self.args.swiftsyntax_lint:
89+
self.lint_swiftsyntax()
90+
91+
def lint_swiftsyntax(self):
92+
linting_cmd = [
93+
os.path.join(os.path.dirname(self.source_dir), 'swift-syntax', 'format.py'),
94+
'--lint',
95+
'--swift-format', os.path.join(self.build_dir, self.configuration(),
96+
'swift-format'),
97+
]
98+
shell.call(linting_cmd)
8799

88100
def should_test(self, host_target):
89101
return self.args.test_swiftformat

0 commit comments

Comments
 (0)