Skip to content

Append working directory to swift compiler args when presented in build settings #260

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 4 commits into from
Apr 10, 2020

Conversation

ghvg1313
Copy link
Contributor

@ghvg1313 ghvg1313 commented Apr 2, 2020

Currently there's no explicit api for sourcekit to recognize swift's working-directory other than through compiler args
When build server contains such setting, inject the correct args in place.

@ghvg1313 ghvg1313 requested a review from benlangmuir as a code owner April 2, 2020 21:43
@benlangmuir
Copy link
Contributor

Currently this is only applied to the BuildServerBuildSystem, but it probably also should be done in at least the CompilationDatabaseBuildSystem as well. Maybe we should handle this in the SwiftLanguageServer code so that it applies to all sources of compiler arguments? @akyrtzi any concerns about that approach?

@rmaz
Copy link
Contributor

rmaz commented Apr 2, 2020

I agree, the changes should be done in SwiftLanguageServer. I think longer term it would be ideal to remove the buildSystem.settings() function entirely, something like the approach in #183.

@akyrtzi
Copy link
Contributor

akyrtzi commented Apr 2, 2020

Maybe we should handle this in the SwiftLanguageServer code so that it applies to all sources of compiler arguments? @akyrtzi any concerns about that approach?

Seems like the right approach.

@ghvg1313
Copy link
Contributor Author

ghvg1313 commented Apr 3, 2020

@benlangmuir Thanks for the suggestion, now mutating args in SwiftLanguageServer itself
as @rmaz point out, this is more like a short term patch, would love to get this sorted out with #183

@@ -99,7 +99,7 @@ extension SwiftLanguageServer {

// FIXME: SourceKit should probably cache this for us.
if let settings = self.buildSettingsByFile[uri] {
skreq[keys.compilerargs] = settings.compilerArguments
skreq[keys.compilerargs] = settings.getSwiftCompilerArguments()
Copy link
Contributor

Choose a reason for hiding this comment

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

Rather than do this every time, which is easy to forget, let's mutate the settings from the build system before we put them in self.buildSettingsByFile. I think there are two places (one synchronous call to settings and then one in the document update settings method.

Copy link
Contributor Author

@ghvg1313 ghvg1313 Apr 6, 2020

Choose a reason for hiding this comment

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

Mutating it would break the equity check against the build server setting in openDocument in swift language server
A nicer solution is to encapsulate buildSettingsByFile in swift language server and has its own equality check and setter, or, If we think this is the only way to sync the build server working directory setting, maybe we should change FileBuildSettings's init method directly?

// but not in the actual compiler args.
extension FileBuildSettings {

func getSwiftCompilerArguments() -> [String] {
Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest something like swiftCompilerArgumentsWithWorkingDirectory. Also, is this really a "FIXME" in the comment above? What would you do differently here? I would work that comment into the documentation comment for this API.

//
//===----------------------------------------------------------------------===//

@testable import SKCore
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't allow @testable imports, because it requires building in a way that's not compatible with how we want to distribute our binary. Feel free to make the API public to test it, but please (1) add an underscore, and (2) add "public for testing" at the front of its documentation comment.

@benlangmuir
Copy link
Contributor

Ah I missed that comment - what particularly would #183 help with here? It would mean we only need one place to accept arguments from the build system (the delegate method), but we'd still need to modify them to add the working directory, no?

@ghvg1313 ghvg1313 force-pushed the swift-working-directory branch from 57f7f43 to 3a9f27b Compare April 7, 2020 00:14
@ghvg1313
Copy link
Contributor Author

ghvg1313 commented Apr 7, 2020

@benlangmuir ping for review, changed logic to the file setting model now

Copy link
Contributor

@benlangmuir benlangmuir left a comment

Choose a reason for hiding this comment

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

Okay, this seems like the least bad answer. Please update linux main (swift test --generate-linuxmain) and the copyright year in the new file; otherwise LGTM.

//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
Copy link
Contributor

Choose a reason for hiding this comment

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

2020

@ghvg1313
Copy link
Contributor Author

ghvg1313 commented Apr 7, 2020

@swift-ci test

@benlangmuir
Copy link
Contributor

@swift-ci please test

1 similar comment
@benlangmuir
Copy link
Contributor

@swift-ci please test

@benlangmuir
Copy link
Contributor

@swift-ci please test Linux

@benlangmuir
Copy link
Contributor

BuildServerBuildSystemTests.swift:44: error: -[SKCoreTests.BuildServerBuildSystemTests testSettings] : XCTAssertEqual failed: ("Optional(["-a", "-b", "-working-directory", "/path/to/some"])") is not equal to ("Optional(["-a", "-b"])")

@ghvg1313
Copy link
Contributor Author

ghvg1313 commented Apr 7, 2020

@swift-ci test

@benlangmuir
Copy link
Contributor

@swift-ci please test

1 similar comment
@benlangmuir
Copy link
Contributor

@swift-ci please test

@benlangmuir
Copy link
Contributor

CompilationDatabaseTests.swift:203: error: -[SKCoreTests.CompilationDatabaseTests testCompilationDatabaseBuildSystem] : XCTAssertEqual failed: ("Optional(["-swift-version", "4", "/a/a.swift", "-working-directory", "/a"])") is not equal to ("Optional(["-swift-version", "4", "/a/a.swift"])")

@benlangmuir
Copy link
Contributor

@swift-ci please test

@ghvg1313
Copy link
Contributor Author

@benlangmuir Safe to merge?

@benlangmuir benlangmuir merged commit ca96138 into swiftlang:master Apr 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants