Skip to content
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

Add ability to set an order of groups #613

Merged
merged 11 commits into from
Apr 28, 2020

Conversation

Beniamiiin
Copy link
Contributor

@Beniamiiin Beniamiiin commented Jul 23, 2019

Hi @yonaskolb.

I implemented the option called groupOrder. It's for setting an order of groups. Currently, we can just set the groupSortPosition, but sometimes we wanna set directly order of groups.

Some examples

  1. Set the order of the main group, i.e. the project.

I have a project with a structure:

Test.xcodeproj
  Sources
  Resources
  Tests
  Configurations
  Products
  Frameworks

Without groupOrder option it will be sorted alphabetically, to set the order as above we can use the new option in this way:

options:
  groupsOrder: 
    - order: [Sources, Resources, Tests, Support files, Configurations]
  1. Set the order of groups whose names end with Screen.

I have a group with a structure:

Test.xcodeproj
  Sources
    PresentationLayer
      SplashScreen
        View
        Presenter
        Interactor
        Entities
        Assembly
  Resources
  Tests
  Configurations
  Products
  Frameworks

With out groupOrder option, it will be sorted alphabetically, to set the order as above we can use the new option in this way:

options:
  groupsOrder:
    - order: [Sources, Resources, Tests, Support files, Configurations]
    - pattern: '^.*Screen$'
      order: [View, Presenter, Interactor, Entities, Assembly]

@brentleyjones
Copy link
Collaborator

brentleyjones commented Jul 23, 2019

Is this only at the top level? How about being able to do it on sub-levels as well? Maybe that is covered by your second example, I'm not sure.

@Beniamiiin
Copy link
Contributor Author

Beniamiiin commented Jul 23, 2019

Is this only at the top level? How about being able to do it on sub-levels as well? Maybe that is covered by your second example, I'm not sure.

No, it's work on any level and you are right, it's covered by the second example. I'll update the example.

Copy link
Owner

@yonaskolb yonaskolb left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @Beniamiiin. How important is it to your team to have this sorting? Both for the top level and for sub groups?

Sources/XcodeGenKit/PBXProjGenerator.swift Outdated Show resolved Hide resolved
Sources/XcodeGenKit/PBXProjGenerator.swift Show resolved Hide resolved
Sources/ProjectSpec/StringExtensions.swift Outdated Show resolved Hide resolved
@@ -114,6 +114,7 @@ Note that target names can also be changed by adding a `name` property to a targ
- `none` - sorted alphabetically with all the other files
- `top` - at the top, before files
- `bottom` (default) - at the bottom, after other files
- [ ] **groupsOrder**: **[[GroupOrder]](#groupOrder)** - An order of groups.
Copy link
Owner

Choose a reason for hiding this comment

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

Not in love with the name groupsOrder, but I also can't think of something better right now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not only you, I don't like it too, but I couldn't find more lovely name :( I'll try to think about it again.

Copy link
Collaborator

Choose a reason for hiding this comment

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

How about groupOrdering?

} else {
if child1.nameOrPath != child2.nameOrPath {
return child1.nameOrPath.localizedStandardCompare(child2.nameOrPath) == .orderedAscending
if let groupOrder = project.options.groupsOrder.first(where: { group.nameOrPath == $0.pattern || group.nameOrPath.isMatch(to: $0.pattern) }) {
Copy link
Owner

Choose a reason for hiding this comment

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

nameOrPath evaluates to name ?? path ?? "". That means groups who have a different path than just the name won't be supported.
In either case doing something like Group1/Group2/* won't work as the name is just the end and the path is a relative path.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, so should I to use just name?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@yonaskolb I need your help. I don't understand what is the correct way to do it.

@brentleyjones
Copy link
Collaborator

How important is it to your team to have this sorting? Both for the top level and for sub groups?

I'll say for us that the top level is pretty important. We've gone the route of adding 1., 2. , etc. to the directory names to get the sorting. For context, we are grouping similar targets into directories (applications, experiences, capabilities, components, services, core frameworks, etc.), since we have a massive number of targets.

@Beniamiiin
Copy link
Contributor Author

Thanks for the PR @Beniamiiin. How important is it to your team to have this sorting? Both for the top level and for sub groups?

For us, it's important because currently, we use my fork with the implementation of this feature.

@brentleyjones
Copy link
Collaborator

brentleyjones commented Aug 29, 2019

@Beniamiiin @yonaskolb What is needed to move this forward? We personally would love this feature landed.

@Beniamiiin
Copy link
Contributor Author

@brentleyjones firstly I need some help from @yonaskolb to fix all review issues and secondly @yonaskolb should review the PR again.

@Beniamiiin
Copy link
Contributor Author

@yonaskolb are we gonna do something with this PR?

@Beniamiiin
Copy link
Contributor Author

@yonaskolb are we gonna do something with this PR?

@brentleyjones
Copy link
Collaborator

I'm still a big fan of this change as well. @yonaskolb, since you had some PR comments I'll leave it to you to re-review. Thanks!

@Beniamiiin
Copy link
Contributor Author

@yonaskolb I'm so sorry can you give us some information about this PR?

Copy link
Collaborator

@brentleyjones brentleyjones left a comment

Choose a reason for hiding this comment

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

Can you add some test fixtures? Showing how it doesn't affect ordering when the property isn't declared, and some that covers all of the functionality listed.

I'll give this a spin locally as well. If nothing comes up there, after the changes we should be good to go.

@@ -114,6 +114,7 @@ Note that target names can also be changed by adding a `name` property to a targ
- `none` - sorted alphabetically with all the other files
- `top` - at the top, before files
- `bottom` (default) - at the bottom, after other files
- [ ] **groupsOrder**: **[[GroupOrder]](#groupOrder)** - An order of groups.
Copy link
Collaborator

Choose a reason for hiding this comment

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

How about groupOrdering?

@brentleyjones
Copy link
Collaborator

It runs nicely with our project, so just looking for the requested changed and we should be good to go.

Comment on lines 592 to 599
for groupName in order {
guard let group = groups.first(where: { $0.nameOrPath == groupName }) else {
continue
}

filteredGroups.append(group)
groups.removeAll { $0 == group }
}
Copy link
Owner

Choose a reason for hiding this comment

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

I think this will cause performance issues in large projects that use a regex pattern, as there are a lot of nested loops here, but I guess it's up to the project author to take on that cost

Sources/XcodeGenKit/PBXProjGenerator.swift Show resolved Hide resolved
Docs/ProjectSpec.md Outdated Show resolved Hide resolved
@brentleyjones
Copy link
Collaborator

brentleyjones commented Apr 15, 2020

@Beniamiiin: after @yonaskolb's feedback is addressed and this is rebased on master, we can merge it. Thanks!

@Beniamiiin
Copy link
Contributor Author

@Beniamiiin: after @yonaskolb's feedback is addressed and this is rebased on master, we can merge it. Thanks!

@brentleyjones I'll do it at this weekend.

Beniamin Sarkisian added 2 commits April 25, 2020 16:30
@Beniamiiin
Copy link
Contributor Author

@yonaskolb can you review it again please

Copy link
Collaborator

@brentleyjones brentleyjones left a comment

Choose a reason for hiding this comment

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

Since this feature is gated behind people using it, and it works in it's current state, I say we merge this and address any issues in followup PRs.

@brentleyjones brentleyjones merged commit 0ad02b7 into yonaskolb:master Apr 28, 2020
@mthole
Copy link
Contributor

mthole commented Aug 13, 2020

@Beniamiiin Found this feature today. Very useful, thank you!

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