From 57cc7c28b91bed3785d1de8405048752d0ed1d38 Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Sat, 21 Dec 2024 17:30:06 +0000 Subject: [PATCH] CI: Add `--sourcekit-lsp-verify-generated-files` build-script option To verify that autogenerated files in the source tree match the ones that would be generated from source. --- utils/build-presets.ini | 1 + .../build_swift/driver_arguments.py | 4 ++++ utils/build_swift/tests/expected_options.py | 3 +++ .../products/sourcekitlsp.py | 20 +++++++++++++++++++ 4 files changed, 28 insertions(+) diff --git a/utils/build-presets.ini b/utils/build-presets.ini index 884f64a260830..82890e4d75eba 100644 --- a/utils/build-presets.ini +++ b/utils/build-presets.ini @@ -2055,6 +2055,7 @@ sourcekit-lsp swiftformat install-swiftformat sourcekit-lsp-lint +sourcekit-lsp-verify-generated-files [preset: buildbot_sourcekitlsp_linux,no_sanitize] mixin-preset=mixin_swiftpm_package_linux_platform diff --git a/utils/build_swift/build_swift/driver_arguments.py b/utils/build_swift/build_swift/driver_arguments.py index 6d5759cab41a3..8210509489ec3 100644 --- a/utils/build_swift/build_swift/driver_arguments.py +++ b/utils/build_swift/build_swift/driver_arguments.py @@ -766,6 +766,10 @@ def create_argument_parser(): option('--test-sourcekit-lsp-sanitize-all', toggle_true('test_sourcekitlsp_sanitize_all'), help='run sourcekit-lsp tests under all sanitizers') + option('--sourcekit-lsp-verify-generated-files', + toggle_true('sourcekitlsp_verify_generated_files'), + help='set to verify that the generated files in the source tree ' + + 'match the ones that would be generated from current main') option('--sourcekit-lsp-lint', toggle_true('sourcekitlsp_lint'), help='verify that sourcekit-lsp Source code is formatted correctly') diff --git a/utils/build_swift/tests/expected_options.py b/utils/build_swift/tests/expected_options.py index e1faa5a8769aa..8a5edc190299e 100644 --- a/utils/build_swift/tests/expected_options.py +++ b/utils/build_swift/tests/expected_options.py @@ -109,6 +109,7 @@ 'test_indexstoredb_sanitize_all': False, 'test_sourcekitlsp_sanitize_all': False, 'build_sourcekitlsp': False, + 'sourcekitlsp_verify_generated_files': False, 'sourcekitlsp_lint': False, 'install_llvm': False, 'install_static_linux_config': False, @@ -652,6 +653,8 @@ class BuildScriptImplOption(_BaseOption): EnableOption('--sourcekit-lsp', dest='build_sourcekitlsp'), EnableOption('--test-sourcekit-lsp-sanitize-all', dest='test_sourcekitlsp_sanitize_all'), + EnableOption('--sourcekit-lsp-verify-generated-files', + dest='sourcekitlsp_verify_generated_files'), EnableOption('--sourcekit-lsp-lint', dest='sourcekitlsp_lint'), EnableOption('--install-llvm', dest='install_llvm'), diff --git a/utils/swift_build_support/swift_build_support/products/sourcekitlsp.py b/utils/swift_build_support/swift_build_support/products/sourcekitlsp.py index 6b3adf7fabecc..89122f50bf81e 100644 --- a/utils/swift_build_support/swift_build_support/products/sourcekitlsp.py +++ b/utils/swift_build_support/swift_build_support/products/sourcekitlsp.py @@ -48,6 +48,22 @@ def is_swiftpm_unified_build_product(cls): def should_build(self, host_target): return True + def _run_swift_syntax_dev_utils(self, host_target, command, arguments=[]): + sourcekit_lsp_dev_utils = os.path.join(self.source_dir, 'SourceKitLSPDevUtils') + + run_cmd = [ + os.path.join(self.install_toolchain_path(host_target), "bin", "swift"), + 'run', + '--package-path', sourcekit_lsp_dev_utils, + 'sourcekit-lsp-dev-utils', + command, + ] + arguments + + env = dict(os.environ) + env["SWIFTCI_USE_LOCAL_DEPS"] = "1" + + shell.call(run_cmd, env=env) + def _for_each_host_target(self, base_target, body): body(base_target) @@ -58,6 +74,10 @@ def _for_each_host_target(self, base_target, body): body(target) def build(self, host_target): + if self.args.sourcekitlsp_verify_generated_files: + self._run_swift_syntax_dev_utils( + host_target, 'verify-config-schema') + self._for_each_host_target( host_target, lambda target: self.run_build_script_helper('build', host_target, target)