[PATCH] D34252: Add arbitrary file/path support to clang-format style file selection

2020-05-14 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

I think we can abandon this revision now we support --style=file:


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D34252/new/

https://reviews.llvm.org/D34252



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34252: Add arbitrary file/path support to clang-format style file selection

2019-12-05 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

I recently hit this issue where I was clang-formatting generated code out of a 
source tree, which was then copied into a source tree. This failed my post 
build clang-format validation check and I couldn't understand why. it was only 
later I realised that unless I have the same .clang-format file locally when I 
clang-format the generated files or if I only clang-format them after I've 
copied them in will this work.

A patch like this (and this isn't the only one I've seen like this that lets me 
point clang-format to a specifc .clang-format file would have helped here.) are 
you interested in this patch or something like this still?  (I realize its a 
long time since you got a response)


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D34252/new/

https://reviews.llvm.org/D34252



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D34252: Add arbitrary file/path support to clang-format style file selection

2017-06-19 Thread Manuel Klimek via cfe-commits
On Fri, Jun 16, 2017 at 8:26 PM Dan Ciliske via Phabricator <
revi...@reviews.llvm.org> wrote:

> dciliske added a comment.
>
> So... how should I get something added? That patch has been sitting for a
> couple weeks.
>
> Should I work on that patch? If so, how do I work on it? This is the first
> time I'm working on a large OSS project.
>

First, ping that thread, link to your patch here, and ask whether the
author on the other thread is intending to make progress.


>
>
> https://reviews.llvm.org/D34252
>
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34252: Add arbitrary file/path support to clang-format style file selection

2017-06-16 Thread Dan Ciliske via Phabricator via cfe-commits
dciliske added a comment.

So... how should I get something added? That patch has been sitting for a 
couple weeks.

Should I work on that patch? If so, how do I work on it? This is the first time 
I'm working on a large OSS project.


https://reviews.llvm.org/D34252



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34252: Add arbitrary file/path support to clang-format style file selection

2017-06-16 Thread Eric Liu via Phabricator via cfe-commits
ioeric added a comment.

Hi Dan, thanks for the patch! https://reviews.llvm.org/D33560, which adds the 
same feature, is already under review :)


https://reviews.llvm.org/D34252



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34252: Add arbitrary file/path support to clang-format style file selection

2017-06-15 Thread Dan Ciliske via Phabricator via cfe-commits
dciliske created this revision.
Herald added a subscriber: klimek.

The Format library has no way to specify a specific file to be used as the 
style source. It climbs the path looking for ‘.clang_format’. This patch adds 
the ability to specify a specific file to use for clang Format utilities.

This patch is in direct response to 
https://bugs.llvm.org//show_bug.cgi?id=28107 (along with my own personal need).

New style argument feature:

  Use -style=file, to load style
  configuration from an explicitly defined file.


https://reviews.llvm.org/D34252

Files:
  lib/Format/Format.cpp


Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -1967,6 +1967,8 @@
 ".clang-format file located in one of the parent\n"
 "directories of the source file (or current\n"
 "directory for stdin).\n"
+"Use -style=file, to load style \n"
+"configuration from an explicitly defined file.\n"
 "Use -style=\"{key: value, ...}\" to set specific\n"
 "parameters, e.g.:\n"
 "  -style=\"{BasedOnStyle: llvm, IndentWidth: 8}\"";
@@ -2014,8 +2016,44 @@
   }
 
   if (!StyleName.equals_lower("file")) {
+SmallString<128> ConfigFile(StyleName.substr(5));
+if (StyleName.startswith_lower("file,")) {
+  DEBUG(llvm::dbgs() << "Trying explicit file" << ConfigFile << "...\n");
+
+  auto Status = FS->status(ConfigFile.str());
+  bool FoundConfigFile =
+Status && (Status->getType() == 
llvm::sys::fs::file_type::regular_file);
+  if (FoundConfigFile) {
+llvm::ErrorOr Text =
+  FS->getBufferForFile(ConfigFile.str());
+if (std::error_code EC = Text.getError()) {
+  DEBUG(llvm::dbgs() << "Text Error getting contents.\n");
+  return make_string_error(EC.message());
+}
+if (std::error_code ec =
+parseConfiguration(Text.get()->getBuffer(), )) {
+  if (ec == ParseError::Unsuitable) {
+
+DEBUG(llvm::dbgs() << "Config file error.\n");
+return make_string_error(
+"Configuration file does not support " +
+getLanguageName(Style.Language) + ": " +
+ConfigFile);
+  }
+  DEBUG(llvm::dbgs() << "Error reading " << ConfigFile << ".\n");
+  return make_string_error("Error reading " + ConfigFile + ": " +
+  ec.message());
+}
+DEBUG(llvm::dbgs() << "Using configuration file " << ConfigFile << 
"\n");
+return Style;
+  }
+  DEBUG(llvm::dbgs() << "Could not find file: " << ConfigFile << "\n");
+  return FallbackStyle;
+}
 if (!getPredefinedStyle(StyleName, Style.Language, ))
   return make_string_error("Invalid value for -style");
+
+DEBUG(llvm::dbgs() << "Using configuration file " << ConfigFile << "\n");
 return Style;
   }
 


Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -1967,6 +1967,8 @@
 ".clang-format file located in one of the parent\n"
 "directories of the source file (or current\n"
 "directory for stdin).\n"
+"Use -style=file, to load style \n"
+"configuration from an explicitly defined file.\n"
 "Use -style=\"{key: value, ...}\" to set specific\n"
 "parameters, e.g.:\n"
 "  -style=\"{BasedOnStyle: llvm, IndentWidth: 8}\"";
@@ -2014,8 +2016,44 @@
   }
 
   if (!StyleName.equals_lower("file")) {
+SmallString<128> ConfigFile(StyleName.substr(5));
+if (StyleName.startswith_lower("file,")) {
+  DEBUG(llvm::dbgs() << "Trying explicit file" << ConfigFile << "...\n");
+
+  auto Status = FS->status(ConfigFile.str());
+  bool FoundConfigFile =
+Status && (Status->getType() == llvm::sys::fs::file_type::regular_file);
+  if (FoundConfigFile) {
+llvm::ErrorOr Text =
+  FS->getBufferForFile(ConfigFile.str());
+if (std::error_code EC = Text.getError()) {
+  DEBUG(llvm::dbgs() << "Text Error getting contents.\n");
+  return make_string_error(EC.message());
+}
+if (std::error_code ec =
+parseConfiguration(Text.get()->getBuffer(), )) {
+  if (ec == ParseError::Unsuitable) {
+
+DEBUG(llvm::dbgs() << "Config file error.\n");
+return make_string_error(
+"Configuration file does not support " +
+getLanguageName(Style.Language) + ": " +
+ConfigFile);
+  }
+  DEBUG(llvm::dbgs() << "Error reading " << ConfigFile << ".\n");
+  return make_string_error("Error reading " + ConfigFile + ": " +
+  ec.message());
+}
+DEBUG(llvm::dbgs() << "Using configuration file " << ConfigFile << "\n");
+return Style;
+  }
+  DEBUG(llvm::dbgs() << "Could not find file: " << ConfigFile << "\n");
+