Re: [cros-dev] Re: Running clang-format

168 views
Skip to first unread message

Jorge Lucangeli Obes

unread,
Apr 13, 2015, 5:21:38 PM4/13/15
to Mike Colagrosso, Simran Basi, chromium-os-dev, chromium-dev, Alex Vakulenko
On Mon, Apr 13, 2015 at 1:18 PM, 'Alex Vakulenko' via Chromium OS dev <chromiu...@chromium.org> wrote:
This worked for me:

 ~/trunk/src/platform2 $ clang-format -style=Chromium buffet/main.cc > buffet/main_formatted.cc

And here is what I do to format the files in my current commit (after the patch committed to git):

~/trunk/src/platform2 $ git clang-format --style=Chromium HEAD^

And I have no errors when running either.


I run clang-format from SublimeText with no errors either. What editor are you using Mike?
 
Alex

On Mon, Apr 13, 2015 at 1:10 PM, 'Simran Basi' via Chromium OS dev <chromiu...@chromium.org> wrote:
I've actually never ran clang-format.

Someone on chromium-dev or chromium-os-dev might be able to help.

On Mon, Apr 13, 2015 at 12:44 PM, Mike Colagrosso <mcola...@google.com> wrote:
A code-format issue came up in a CL, so I'm trying to learn how to use clang-format. I have depot_tools installed, but I get an error when I run that version of clang-format. Do you use clang-format or other ideas how to debug my depot_tools problem?

Here's what I get when I run it:

$ clang-format container.h                                                                                                                                           
Traceback (most recent call last):
  File "/usr/local/google/home/mcolagrosso/depot_tools/clang_format.py", line 70, in <module>
    sys.exit(main(sys.argv[1:]))
  File "/usr/local/google/home/mcolagrosso/depot_tools/clang_format.py", line 54, in main
    tool = FindClangFormatToolInChromiumTree()
  File "/usr/local/google/home/mcolagrosso/depot_tools/clang_format.py", line 28, in FindClangFormatToolInChromiumTree
    bin_path = gclient_utils.GetBuildtoolsPlatformBinaryPath()
  File "/usr/local/google/home/mcolagrosso/depot_tools/gclient_utils.py", line 715, in GetBuildtoolsPlatformBinaryPath
    buildtools_path = GetBuildtoolsPath()
  File "/usr/local/google/home/mcolagrosso/depot_tools/gclient_utils.py", line 703, in GetBuildtoolsPath
    buildtools_path = os.path.join(primary_solution, 'buildtools')
  File "/usr/lib/python2.7/posixpath.py", line 77, in join
    elif path == '' or path.endswith('/'):
AttributeError: 'NoneType' object has no attribute 'endswith'

It's failing on line 701 of this file:


Thinking I didn't need a "primary_solution" path, I hacked up that file to return None, but no luck:

$ clang-format container.h 
Problem while looking for clang-format in Chromium source tree:
  Could not find checkout in any parent of the current path.


--
--
Chromium OS Developers mailing list: chromiu...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-os-dev?hl=en

To unsubscribe from this group and stop receiving emails from it, send an email to chromium-os-d...@chromium.org.

--
--
Chromium OS Developers mailing list: chromiu...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-os-dev?hl=en


Nico Weber

unread,
Apr 13, 2015, 5:31:24 PM4/13/15
to Jorge Lucangeli Obes, Mike Colagrosso, Simran Basi, chromium-os-dev, chromium-dev, Alex Vakulenko
See https://code.google.com/p/chromium/wiki/ClangFormat for how to run clang-format. The usual way is to commit your stuff to your branch and then run `git cl format`.

--
--
Chromium Developers mailing list: chromi...@chromium.org

View archives, change email options, or unsubscribe:

Vladimir Levin

unread,
Apr 13, 2015, 5:33:34 PM4/13/15
to jor...@chromium.org, Mike Colagrosso, Simran Basi, chromium-os-dev, chromium-dev, Alex Vakulenko
I might be off, but are you running this from a chromium checkout? AFAIK, gclient's clang-format runs an actual clang-format binary in src/buildtools/{os}/clang-format

Here's the one it runs for me:
src$ find buildtools/ -name clang-format
buildtools/linux64/clang-format

On Mon, Apr 13, 2015 at 2:20 PM, Jorge Lucangeli Obes <jor...@chromium.org> wrote:

--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev

To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev...@chromium.org.

Nico Weber

unread,
Apr 13, 2015, 5:44:50 PM4/13/15
to Mike Colagrosso, Jorge Lucangeli Obes, Simran Basi, chromium-os-dev, chromium-dev, Alex Vakulenko
The way the clang-format in depot_tools works is that it tries to find the chromium repo root relative to your current directory, and then runs that_director/buildtools/linux64/clang-format (assuming you're on linux) which contains the "real" clang-format executable. Maybe you don't have that directory for some reasons?

On Mon, Apr 13, 2015 at 2:41 PM, Mike Colagrosso <mcola...@google.com> wrote:
Thanks for your replies, Alex, Jorge, and Nico. To clarify, it's the version of clang-format in ~/depot_tools/clang-format that is failing for me. For example, the commands you pasted above, Alex, fail with the same AttributeError: 'NoneType' object has no attribute 'endswith'. So does `git cl format`, Nico.

$ cd ~/chromiumos/src/platform2

$ which clang-format
/usr/local/google/home/mcolagrosso/depot_tools/clang-format

$ clang-format -style=Chromium buffet/main.cc
Traceback (most recent call last):
  File "/usr/local/google/home/mcolagrosso/depot_tools/clang_format.py", line 70, in <module>
    sys.exit(main(sys.argv[1:]))
  File "/usr/local/google/home/mcolagrosso/depot_tools/clang_format.py", line 54, in main
    tool = FindClangFormatToolInChromiumTree()
  File "/usr/local/google/home/mcolagrosso/depot_tools/clang_format.py", line 28, in FindClangFormatToolInChromiumTree
    bin_path = gclient_utils.GetBuildtoolsPlatformBinaryPath()
  File "/usr/local/google/home/mcolagrosso/depot_tools/gclient_utils.py", line 715, in GetBuildtoolsPlatformBinaryPath
    buildtools_path = GetBuildtoolsPath()
  File "/usr/local/google/home/mcolagrosso/depot_tools/gclient_utils.py", line 703, in GetBuildtoolsPath
    buildtools_path = os.path.join(primary_solution, 'buildtools')
  File "/usr/lib/python2.7/posixpath.py", line 77, in join
    elif path == '' or path.endswith('/'):
AttributeError: 'NoneType' object has no attribute 'endswith'

$ /usr/bin/clang-format -style=Chromium buffet/main.cc
// Copyright 2014 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
[...] (rest of the file)

I must have made a mistake in my depot_tools installation or Chromium OS checkout. The functions that are failing from the traceback above are FindClangFormatToolInChromiumTree, GetBuildtoolsPlatformBinaryPath, etc. Any idea where those files should be?

I followed these instructions for depot_tools:


and this Chromium OS developer guide:




Jorge Lucangeli Obes

unread,
Apr 13, 2015, 5:47:29 PM4/13/15
to Mike Colagrosso, Simran Basi, chromium-os-dev, chromium-dev, Alex Vakulenko, Nico Weber
On Mon, Apr 13, 2015 at 2:44 PM, Nico Weber <tha...@chromium.org> wrote:
The way the clang-format in depot_tools works is that it tries to find the chromium repo root relative to your current directory, and then runs that_director/buildtools/linux64/clang-format (assuming you're on linux) which contains the "real" clang-format executable. Maybe you don't have that directory for some reasons?


Yeah, I think the problem is that Mike doesn't have a chromium checkout. Mike, feel free to ping me off list if you want to set that up.

Alex Vakulenko

unread,
Apr 13, 2015, 6:07:15 PM4/13/15
to Jorge Lucangeli Obes, Mike Colagrosso, Simran Basi, chromium-os-dev, chromium-dev, Nico Weber
Hmm, maybe that's the key. Because I do have Chromium checkout on my machine, along with CrOS.

Chris Masone

unread,
Apr 13, 2015, 8:49:32 PM4/13/15
to Alex Vakulenko, Jorge Lucangeli Obes, Mike Colagrosso, Simran Basi, chromium-os-dev, chromium-dev, Nico Weber
I do too, but they're in separate directory trees. So when I'm over in a CrOS repo, the tool can't find the root of the chromium checkout I have.

Is there any way to just tell it where that root is, Nico? Some kind of env var I can export?

Nico Weber

unread,
Apr 13, 2015, 8:51:15 PM4/13/15
to Chris Masone, Alex Vakulenko, Jorge Lucangeli Obes, Mike Colagrosso, Simran Basi, chromium-os-dev, chromium-dev
I think git cl format first looks for clang-format on the PATH, so if you add path/to/chromium/src/buildtools/linux64 to your path in front of depot_tools, that'd probably do the trick.

Alex Vakulenko

unread,
Apr 13, 2015, 8:52:16 PM4/13/15
to Chris Masone, chromium-os-dev, Simran Basi, chromium-dev, Jorge Lucangeli Obes, Nico Weber, Mike Colagrosso

Interestingly mine in different directories too (/work/chrome and /work/chromiumos) and it still somehow works.

Mike

unread,
Apr 14, 2015, 12:12:14 PM4/14/15
to chromiu...@chromium.org, cma...@chromium.org, sb...@google.com, chromi...@chromium.org, jor...@chromium.org, tha...@chromium.org
Thanks for the replies, Nico, Jorge, Alex, and Chris. I tried two things that didn't work and one that did.

* Adding path/to/chromium/src/buildtools/linux64 to the front of that PATH didn't work. I get the same error (AttributeError: 'NoneType' object has no attribute 'endswith'.)

* I saw these chromium LinuxBuildInstructions, which says that I must run chrome_set_ver --runhooks, but that didn't work:

cd chromiumos/src/platform2
chrome_set_ver --runhooks
ERROR: Couldn't find the chromite tool chromite.bin.chrome_set_ver.

Please change to a directory inside your Chromium OS source tree
and retry.  If you need to setup a Chromium OS source tree, see

* What did work, despite the scary warning in gclient_utils.py:

  # Overriding the build tools path by environment is highly unsupported and may
  # break without warning.  Do not rely on this for anything important.
  override = os.environ.get('CHROMIUM_BUILDTOOLS_PATH')

was setting the CHROMIUM_BUILDTOOLS_PATH environment variable to path/to/chromium/src/buildtools.
Alex

To unsubscribe from this group and stop receiving emails from it, send an email to chromium-os-dev+unsubscribe@chromium.org.

--
--
Chromium OS Developers mailing list: chromiu...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-os-dev?hl=en

--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
Reply all
Reply to author
Forward
0 new messages