Skip to content

Reference swift-syntax from CodeGeneration using path instead of HEAD checkout #1897

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
Jul 18, 2023

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Jul 11, 2023

The HEAD checkout has been causing more issues than it solved recently. I think it’s better to define CodeGeneration to directly reference the parent swift-syntax package and encourage developers of CodeGeneration to modify their local Package.swift to pull a version of swift-syntax from GitHub when making significant changes.

@ahoppen ahoppen requested a review from bnbarham July 11, 2023 22:17
@ahoppen
Copy link
Member Author

ahoppen commented Jul 11, 2023

@swift-ci Please test

Comment on lines 15 to 25
.package(url: "..", revision: "HEAD")
.package(path: "..")
Copy link
Contributor

Choose a reason for hiding this comment

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

My preference would be to move this out and then have an environment variable to control it. Then the README can just have something like "Run `SOME_ENV_VAR=1 swift ..." rather than the "change the dependency from...".

Copy link
Member Author

Choose a reason for hiding this comment

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

The problem with environment variables is that you can’t control them when opening the project in Xcode.

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe this is a stupid idea, but how about leaving a documentation comment in the Package.swift file that carries the same information as the README? We could leave commented code with a dependency to the remote repository, something like this:

  dependencies: [
    .package(path: "..")
//    .package(url: "https://github.com/apple/swift-syntax", branch: "main")
  ],

Yes, it's not the most elegant solution, but it's practical. Developers wouldn't have to repeatedly visit the README to copy and paste this code. Considering this is just for CodeGeneration SwiftPM, maybe we don't need anything fancy, just something that aids in accelerating development?"

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I think leaving that information in CodeGeneration/Package.swift makes sense to me.

Copy link
Contributor

Choose a reason for hiding this comment

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

Or if we would prefer to avoid commenting code we could use an enum.

fileprivate enum SwiftSyntaxDependency {
  case local
  case remote

  fileprivate var package: Package.Dependency {
    switch self {
    case .local:
      return .package(url: "..", revision: "HEAD")
    case .remote:
      return .package(url: "https://github.com/apple/swift-syntax", branch: "main")
    }
  }
}

(...)
  products: [
    .executable(name: "generate-swiftsyntax", targets: ["generate-swiftsyntax"])
  ],
  dependencies: [
    SwiftSyntaxDependency.local.package
  ],
  targets: [
    .executableTarget(
      name: "generate-swiftsyntax",
(...)

Copy link
Contributor

Choose a reason for hiding this comment

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

The problem with environment variables is that you can’t control them when opening the project in Xcode.

That's true, but also in that case you can still edit the package directly. So I'd still prefer it, even if we keep that in the README. I like @Matejkob suggestions, but I would still control it with an environment variable rather than hardcode to local/remote.

… checkout

The HEAD checkout has been causing more issues than it solved recently. I think it’s better to define `CodeGeneration` to directly reference the parent swift-syntax package and encourage developers of `CodeGeneration` to modify their local `Package.swift` to pull a version of swift-syntax from GitHub when making significant changes.
@ahoppen ahoppen force-pushed the ahoppen/path-reference branch from a271c3a to d9f2f3a Compare July 18, 2023 15:06
@ahoppen
Copy link
Member Author

ahoppen commented Jul 18, 2023

@swift-ci Please test

@ahoppen ahoppen enabled auto-merge July 18, 2023 15:07
@ahoppen ahoppen merged commit 9cab487 into swiftlang:main Jul 18, 2023
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.

3 participants