New issue
Advanced search Search tips

Issue 809012 link

Starred by 1 user

Issue metadata

Status: Untriaged
Owner: ----
Cc:
EstimatedDays: ----
NextAction: ----
OS: ----
Pri: 3
Type: Bug



Sign in to add a comment

gn format: Sorting of sources should remove duplicates within a single sort range

Project Member Reported by jdoerrie@chromium.org, Feb 5 2018

Issue description

When running `git cl format` BUILD.gn files are formatted and source files are sorted according to their name. Ideally, this sort step should also remove duplicates from the list. For example, a dependency list of

deps = [
  "foo",
  "bar",
  "baz",
  "bar",
]

should be formatted as


deps = [
  "bar",
  "baz",
  "foo",
]

and not


deps = [
  "bar",
  "bar",
  "baz",
  "foo",
]

Admittedly this case is relatively rare, but I just hit it when rebasing a CL that is renaming directories.

Glancing at the source this should be fixed by adding a call to std::unique() following the std::sort() step in ListNode::SortList(). 

This wouldn't be able to remove duplicates spanning multiple SortRanges(), but I don't think that is necessarily a problem. 
 
Status: Available (was: Untriaged)
That seems somewhat reasonable to me. I'm a bit nervous about changing the contents of the file as written, but we do already add/remove commas.

I would be interested to know if there are m/any other checked in cases where this has happened. I guess there could be duplicate .h in sources, but presumably .cc would be noticed by link failure.

Additionally, we do not canonicalize the expression of deps (and I don't think we should do that) so this would only help for some types of unique-ing.

Status: Untriaged (was: Available)
Available, but no owner or component? Please find a component, as no one will ever find this without one.

Sign in to add a comment