Skip to content

set 'no group' for local packages  #1209

Description

@MartinP7r

Is there a way to set no group for a local package?
At the moment there's the group option for local packages and localPackagesGroup, but neither can be set to something that allows a package to sit at the projects root without a group.

Activity

  1. MartinP7r commented on Jul 7, 2022

    @MartinP7r
    Author

    I believe this has similarity to #1118

  2. hiltonc commented on Oct 13, 2023

    @hiltonc
    Contributor

    I would like this behavior as well. Currently the best I can do is put the local packages in a top-level folder, like:

    /MyProject
      /Packages
        /Package1
        /Package2
    

    What I want is:

    /MyProject
      /Package1
      /Package2
    

    Looking at

    func createLocalPackage(path: Path, group: Path?) throws {
    var pbxGroup: PBXGroup?
    if let location = group {
    let fullLocationPath = project.basePath + location
    pbxGroup = getGroup(path: fullLocationPath, mergingChildren: [], createIntermediateGroups: true, hasCustomParent: false, isBaseGroup: true)
    }
    if localPackageGroup == nil && group == nil {
    let groupName = project.options.localPackagesGroup ?? "Packages"
    localPackageGroup = addObject(PBXGroup(sourceTree: .sourceRoot, name: groupName))
    rootGroups.insert(localPackageGroup!)
    }
    let absolutePath = project.basePath + path.normalize()
    // Get the local package's relative path from the project root
    let fileReferencePath = try? absolutePath.relativePath(from: projectDirectory ?? project.basePath).string
    let fileReference = addObject(
    PBXFileReference(
    sourceTree: .sourceRoot,
    name: absolutePath.lastComponent,
    lastKnownFileType: "folder",
    path: fileReferencePath
    )
    )
    if let pbxGroup = pbxGroup {
    pbxGroup.children.append(fileReference)
    } else {
    localPackageGroup!.children.append(fileReference)
    }
    }
    I don't see a way to configure the package's group and localPackagesGroup that doesn't put it in at least one folder.

  3. hiltonc commented on Oct 13, 2023

    @hiltonc
    Contributor

    I don't see an obvious change to the API, other than accepting "" for group or localPackageGroup. I'm not aware of that being a precedent anywhere else in the API though.

    I'm willing to open a PR to add this capability if we can agree on a config option for it.

  4. yonaskolb commented on Oct 31, 2023

    @yonaskolb
    Owner

    @hiltonc I'm happy with that solution (setting group to "") or allowing options.localPackagesGroup to be "", if you'd like to make a PR

  5. hiltonc commented on Nov 6, 2023

    @hiltonc
    Contributor

    @yonaskolb Thanks, I added support for both options in #1413.

  6. MartinP7r commented on Nov 27, 2023

    @MartinP7r
    Author

    Thank you @hiltonc!

  7. MartinP7r commented on Dec 6, 2023

    @MartinP7r
    Author

    @yonaskolb would you be able to review or assign/recommend someone able to review?

  8. vahan3x commented on Jul 17, 2026

    @vahan3x

    The resolution here (options.localPackagesGroup: "") only relocates the local-package folder reference to the project root - it can't remove it. Local packages still get a dual representation: the XCLocalSwiftPackageReference under Package Dependencies plus a browsable folder PBXFileReference in the navigator. When you add a local package through Xcode's own "Add Package Dependencies… > Add Local", only the Package Dependencies entry is created without a duplicate group inside the main project.

    I'd like to propose a new global option to match that behaviour:

    options:
    createLocalPackageGroups: false # default: true
    When false, XcodeGen still emits the XCLocalSwiftPackageReference (Package Dependencies stays populated) but skips creating the folder reference/group for all local packages. Default true keeps current output byte-for-byte, so it's fully backward compatible and a minimal diff - the folder is only created in one place (SourceGenerator.createLocalPackage), so it's a single gated call.

    I have a working implementation with tests and docs ready to submit as a PR. @yonaskolb would you take this, or would you prefer a different name/shape (e.g. a per-package group: none-style key instead of a global option)?

    Screenshots
    Current My change
    Image Image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions