Skip to content

Add a new BuildDescription.load API for use in SourceKit-LSP #8286

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

Merged
merged 1 commit into from
Feb 18, 2025

Conversation

bnbarham
Copy link
Contributor

@bnbarham bnbarham commented Feb 8, 2025

Build tool plugins need to be built and run as part of the build plan generation. Replace the existing API taking a BuildPlan with one that generates it instead. This unfortunately exposes much more of the SwiftPM API than previously, but given it is all required to a generate a BuildPlan, this was really the case for all clients anyway.

Long term this module should be replaced by a long-running BSP server that can prepare and provide build settings in the one process.

Resolves rdar://102242345.

@bnbarham
Copy link
Contributor Author

bnbarham commented Feb 8, 2025

Still have to update the tests here, just wanted to kick off the SourceKit LSP tests before the weekend.

import PackageLoading
internal import PackageModel
import SPMBuildCore
import Workspace
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I think the convention is to only import what is used instead of whole module. Is that right, @MaxDesiatov ?

Copy link
Contributor Author

@bnbarham bnbarham Feb 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm open to changing it specifically for TSC (as a way of knowing which TSC APIs are being used), but there's really not point doing it for the SwiftPM APIs.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ideally, we would enabled "include what you use" (IWYU) against the project, and enforce it in CI.

https://github.com/swiftlang/swift/blob/main/docs/HowToGuides/RunningIncludeWhatYouUse.md

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no include what you use for Swift, it's a clang tool

private import class PackageLoading.ManifestLoader
internal import struct PackageModel.ToolsVersion
internal import protocol PackageModel.Toolchain
import Basics
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here I think.

Copy link
Contributor

@bkhouri bkhouri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would love to see automate tests added around the new API to ensure we don't regress in this area.

@bkhouri bkhouri added the needs tests This change needs test coverage label Feb 10, 2025
@bnbarham bnbarham force-pushed the plan-should-build-tool-plugins branch 2 times, most recently from 764b3b0 to 16e7747 Compare February 11, 2025 05:49
@bnbarham
Copy link
Contributor Author

swiftlang/sourcekit-lsp#1973

@swift-ci please test

@bnbarham
Copy link
Contributor Author

swiftlang/sourcekit-lsp#1973

@swift-ci please test Windows platform

Build tool plugins need to be built and run as part of the build plan
generation. Rather than relying on clients to do so, add a new API that
does both. This does unfortunately expose much more of the SwiftPM API
than previously, but given it is all required to a generate a
`BuildPlan`, this was really already the case.

Long term this module should be replaced by a long-running BSP server
that can prepare and provide build settings in the one process.

Resolves rdar://102242345.
@bnbarham
Copy link
Contributor Author

swiftlang/sourcekit-lsp#1973

@swift-ci please test

@bnbarham
Copy link
Contributor Author

swiftlang/sourcekit-lsp#1973

@swift-ci please test Windows platform

2 similar comments
@bnbarham
Copy link
Contributor Author

swiftlang/sourcekit-lsp#1973

@swift-ci please test Windows platform

@bnbarham
Copy link
Contributor Author

swiftlang/sourcekit-lsp#1973

@swift-ci please test Windows platform

)

let plan = try await operation.generatePlan()
return (BuildDescription(buildPlan: plan), bufferedOutput.bytes.description)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: The single test added validate a single load call, more specifically, the description, which is of type BuildDescription.

  • Do other tests exist which validate BuildOperation.generatePlan() in isolation?
  • Do other tests exists that validate bufferedOutput.bytes.description is populated as expected based on the inputs to BuildOperation and the action generatePlan()?

The test is only validation a single case for the BuildDescription. Can we add a test that validate the error: String , or do other tests validate the

Copy link
Contributor Author

@bnbarham bnbarham Feb 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generatePlan only has package visibility and is an internal implementation detail, I don't see a point adding a test for it.

outputStream is necessarily tested basically everywhere since it's how we output anything. Adding a test for it would just be testing BufferedOutputByteStream/ThreadSafeOutputByteStream, which seems pointless.

)
let scratchDirectory = tmpDir.appending(".build")

let loaded = try await BuildDescription.load(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Is there value in adding additional tests that will validate the BuildDescription.load behaves as expected considering different destination Build Parameter, different graph, filesystem layout, scratch directory?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is just calling into BuildOperation, which we have a billion other tests for. So no, I don't think there's particular value in that here.

@bnbarham bnbarham merged commit 71ab073 into swiftlang:main Feb 18, 2025
5 checks passed
@bnbarham bnbarham deleted the plan-should-build-tool-plugins branch February 18, 2025 23:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs tests This change needs test coverage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants