Sublime Text clang-format fails, bad working directory?

434 views
Skip to first unread message

James Cook

unread,
Jul 13, 2016, 1:55:41 PM7/13/16
to chromium-dev
I'm trying to get clang-format to work in sublime, following the instructions here:

This worked initially, but now when I hit my keybinding it deletes all the text in my editor buffer. I think the command is failing, so it produces no output, so Sublime puts an empty string in the buffer.

The Sublime error log shows:
b'Problem while looking for clang-format in Chromium source tree:\n  Could not find checkout in any parent of the current path.\n'

I traced this into to depot_tools/gclient_utils.py GetPrimarySolutionPath(), which uses os.getcwd() to look for your checkout to find the buildtools directory. For me, os.getwd() prints /opt/sublime_text, which is obviously not in my checkout.

I tried setting "binary" to the full path to depot_tools/clang-format in my copy of clang-format-sublime.py, but that didn't work (clang_format.py tries to do the lookup anyway, I think).

Does anyone know how to work around this?

James

Nico Weber

unread,
Jul 13, 2016, 1:59:37 PM7/13/16
to James Cook, chromium-dev

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

James Cook

unread,
Jul 13, 2016, 2:24:53 PM7/13/16
to Nico Weber, chromium-dev
I think that CL only affects clang-based code-completion, not clang-format.  I tried it anyway and got the same error. :-(

Nico Weber

unread,
Jul 13, 2016, 2:39:03 PM7/13/16
to James Cook, chromium-dev
Hm. I don't use sublime. Does adding "working_dir": "${project_path}" to the key bindings entry work?

James Cook

unread,
Jul 13, 2016, 5:41:57 PM7/13/16
to Nico Weber, chromium-dev
Sadly, that doesn't work either. I'm guessing sublime doesn't support adding working_dir to keybindings, just for build steps.

James Cook

unread,
Jul 13, 2016, 5:58:40 PM7/13/16
to Nico Weber, chromium-dev
I found a workaround, although it makes me nervous:

You can apparently hard-code the buildtools directory using an environment variable, CHROMIUM_BUILDTOOLS_PATH:

The comment says this is "highly unsupported". Anyone know if there's a better way?

Sunny Sachanandani

unread,
Oct 28, 2016, 10:33:46 PM10/28/16
to jame...@chromium.org, Nico Weber, chromium-dev
Sorry for reviving this thread but I had this problem without out of the blue without updating ST. It happened because I uninstalled the SublimeLinter(-cpplint) packages and somehow that package was changing the working directory so that clang-format worked.

Any way to fix this I added a cwd=os.path.dirname(self.view.file_name()) to the Popen call in the plugin and that seems to work OK (% error checking).
Reply all
Reply to author
Forward
0 new messages