[PATCH] D50147: clang-format: support external styles

Francois Ferrand via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 29 10:41:09 PDT 2018


Typz added a comment.

In https://reviews.llvm.org/D50147#1272742, @sammccall wrote:

> Being able to discover the right style from the filesystem is powerful, and if I was going to use this flag, I'd consider symlinking the style-file to `subproject/.clang_format` instead. That way the setting is persistent and available to all tools, rather than us needing to get it right on each invocation.


I did not think of this solution. However:

- I am not sure how it works when the .clang-format link is stored in SCM: not sure git will allow storing a link which points outside of the repo... But it may be worth trying, it could be an alternative
- Making a symlink will hardcode the full path of the style, which may not suit different users: maybe in some cases the styles could be installed per-user (as users do not have root permissions), which they would be installed system-wide (in containers used for CI builds, where we may not know which user will actually run the build)
- Making a symlink will definitely not be portable to different OS : esp. on Windows, the path would probably not be the same
- I am not sure a symlink can point to a "~"-relative path, and automatically perform the user HOME path resolution



================
Comment at: lib/Format/Format.cpp:938
+  const llvm::SmallVector<Twine, 3> paths = {
+    {"/usr/local/share/clang-format/", Name},
+    {"~/.local/share/clang-format/", Name},
----------------
sammccall wrote:
> I'm not sure these prefixes are a good idea - can you explain what the purpose is, and why the simpler model of just using the path doesn't work?
> 
> Certainly this needs some more thought about how it would work on windows etc. I'd suggest limiting this patch to filenames.
the goal is actually to store these "base" styles in some global folder, so that multiple projects can reference it (through their own .clang-format file), without having to make any copy.

The idea is that the project is under SCM, and simply includes a reference to the style: in its own .clang-format, which would ideally only contain a single //basedOn// tag. The styles are defined globally, then each project only indicates which styles in uses.

But indeed, the 'HOME' folder on windows is probably not this one...


Repository:
  rC Clang

https://reviews.llvm.org/D50147





More information about the cfe-commits mailing list