This worked for me:~/trunk/src/platform2 $ clang-format -style=Chromium buffet/main.cc > buffet/main_formatted.ccAnd 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.
AlexOn 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.hTraceback (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 maintool = FindClangFormatToolInChromiumTree()File "/usr/local/google/home/mcolagrosso/depot_tools/clang_format.py", line 28, in FindClangFormatToolInChromiumTreebin_path = gclient_utils.GetBuildtoolsPlatformBinaryPath()File "/usr/local/google/home/mcolagrosso/depot_tools/gclient_utils.py", line 715, in GetBuildtoolsPlatformBinaryPathbuildtools_path = GetBuildtoolsPath()File "/usr/local/google/home/mcolagrosso/depot_tools/gclient_utils.py", line 703, in GetBuildtoolsPathbuildtools_path = os.path.join(primary_solution, 'buildtools')File "/usr/lib/python2.7/posixpath.py", line 77, in joinelif 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.hProblem while looking for clang-format in Chromium source tree:Could not find checkout in any parent of the current path.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
--
--
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:
--
--
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.
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 maintool = FindClangFormatToolInChromiumTree()File "/usr/local/google/home/mcolagrosso/depot_tools/clang_format.py", line 28, in FindClangFormatToolInChromiumTreebin_path = gclient_utils.GetBuildtoolsPlatformBinaryPath()File "/usr/local/google/home/mcolagrosso/depot_tools/gclient_utils.py", line 715, in GetBuildtoolsPlatformBinaryPathbuildtools_path = GetBuildtoolsPath()File "/usr/local/google/home/mcolagrosso/depot_tools/gclient_utils.py", line 703, in GetBuildtoolsPathbuildtools_path = os.path.join(primary_solution, 'buildtools')File "/usr/lib/python2.7/posixpath.py", line 77, in joinelif 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:
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?
Interestingly mine in different directories too (/work/chrome and /work/chromiumos) and it still somehow works.
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