[Lldb-commits] [lldb] r297585 - Make file / directory completion work properly on Windows.

2017-03-12 Thread Zachary Turner via lldb-commits
Author: zturner
Date: Sun Mar 12 13:18:50 2017
New Revision: 297585

URL: http://llvm.org/viewvc/llvm-project?rev=297585&view=rev
Log:
Make file / directory completion work properly on Windows.

There were a couple of problems with this function on Windows. Different
separators and differences in how tilde expressions are resolved for
starters, but in addition there was no clear indication of what the
function's inputs or outputs were supposed to be, and there were no tests
to demonstrate its use.

To more easily paper over the differences between Windows paths,
non-Windows paths, and tilde expressions, I've ported this function to use
LLVM-based directory iteration (in fact, I would like to eliminate all of
LLDB's directory iteration code entirely since LLVM's is cleaner / more
efficient (i.e. it invokes fewer stat calls)). and llvm's portable path
manipulation library.

Since file and directory completion assumes you are referring to files and
directories on your local machine, it's safe to assume the path syntax
properties of the host in doing so, so LLVM's APIs are perfect for this.

I've also added a fairly robust set of unit tests. Since you can't really
predict what users will be on your machine, or what their home directories
will be, I added an interface called TildeExpressionResolver, and in the
unit test I've mocked up a fake implementation that acts like a unix
password database. This allows us to configure some fake users and home
directories in the test, so we can exercise all of those hard-to-test
codepaths that normally otherwise depend on the host.

Differential Revision: https://reviews.llvm.org/D30789

Added:
lldb/trunk/include/lldb/Utility/TildeExpressionResolver.h
lldb/trunk/source/Utility/TildeExpressionResolver.cpp
lldb/trunk/unittests/Interpreter/TestCompletion.cpp
Modified:
lldb/trunk/include/lldb/Interpreter/CommandCompletions.h
lldb/trunk/source/Commands/CommandCompletions.cpp
lldb/trunk/source/Utility/CMakeLists.txt
lldb/trunk/unittests/Interpreter/CMakeLists.txt

Modified: lldb/trunk/include/lldb/Interpreter/CommandCompletions.h
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/CommandCompletions.h?rev=297585&r1=297584&r2=297585&view=diff
==
--- lldb/trunk/include/lldb/Interpreter/CommandCompletions.h (original)
+++ lldb/trunk/include/lldb/Interpreter/CommandCompletions.h Sun Mar 12 
13:18:50 2017
@@ -21,7 +21,10 @@
 #include "lldb/Utility/RegularExpression.h"
 #include "lldb/lldb-private.h"
 
+#include "llvm/ADT/Twine.h"
+
 namespace lldb_private {
+struct TildeExpressionResolver;
 class CommandCompletions {
 public:
   //--
@@ -76,12 +79,19 @@ public:
int max_return_elements, SearchFilter *searcher,
bool &word_complete, StringList &matches);
 
+  static int DiskFiles(const llvm::Twine &partial_file_name,
+   StringList &matches, TildeExpressionResolver &Resolver);
+
   static int DiskDirectories(CommandInterpreter &interpreter,
  llvm::StringRef partial_file_name,
  int match_start_point, int max_return_elements,
  SearchFilter *searcher, bool &word_complete,
  StringList &matches);
 
+  static int DiskDirectories(const llvm::Twine &partial_file_name,
+ StringList &matches,
+ TildeExpressionResolver &Resolver);
+
   static int SourceFiles(CommandInterpreter &interpreter,
  llvm::StringRef partial_file_name,
  int match_start_point, int max_return_elements,

Added: lldb/trunk/include/lldb/Utility/TildeExpressionResolver.h
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Utility/TildeExpressionResolver.h?rev=297585&view=auto
==
--- lldb/trunk/include/lldb/Utility/TildeExpressionResolver.h (added)
+++ lldb/trunk/include/lldb/Utility/TildeExpressionResolver.h Sun Mar 12 
13:18:50 2017
@@ -0,0 +1,57 @@
+//===- TildeExpressionResolver.h *- C++ 
-*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLDB_UTILITY_TILDE_EXPRESSION_RESOLVER_H
+#define LLDB_UTILITY_TILDE_EXPRESSION_RESOLVER_H
+
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/StringSet.h"
+
+namespace lldb_private {
+class TildeExpressionResolver {
+public:
+  virtual ~TildeExpressionResolver();
+
+  /// \brief Resolve a Tilde Expression contained according

[Lldb-commits] [PATCH] D30789: Make file and directory name completion work properly on Windows.

2017-03-12 Thread Zachary Turner via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL297585: Make file / directory completion work properly on 
Windows. (authored by zturner).

Changed prior to commit:
  https://reviews.llvm.org/D30789?vs=91361&id=91501#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D30789

Files:
  lldb/trunk/include/lldb/Interpreter/CommandCompletions.h
  lldb/trunk/include/lldb/Utility/TildeExpressionResolver.h
  lldb/trunk/source/Commands/CommandCompletions.cpp
  lldb/trunk/source/Utility/CMakeLists.txt
  lldb/trunk/source/Utility/TildeExpressionResolver.cpp
  lldb/trunk/unittests/Interpreter/CMakeLists.txt
  lldb/trunk/unittests/Interpreter/TestCompletion.cpp

Index: lldb/trunk/unittests/Interpreter/CMakeLists.txt
===
--- lldb/trunk/unittests/Interpreter/CMakeLists.txt
+++ lldb/trunk/unittests/Interpreter/CMakeLists.txt
@@ -1,5 +1,6 @@
 add_lldb_unittest(InterpreterTests
   TestArgs.cpp
+  TestCompletion.cpp
 
   LINK_LIBS
 lldbInterpreter
Index: lldb/trunk/unittests/Interpreter/TestCompletion.cpp
===
--- lldb/trunk/unittests/Interpreter/TestCompletion.cpp
+++ lldb/trunk/unittests/Interpreter/TestCompletion.cpp
@@ -0,0 +1,346 @@
+//===-- TestCompletion.cpp --*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "gtest/gtest.h"
+
+#include "lldb/Core/StringList.h"
+#include "lldb/Interpreter/CommandCompletions.h"
+#include "lldb/Utility/TildeExpressionResolver.h"
+
+#include "llvm/ADT/SmallString.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Support/raw_ostream.h"
+
+namespace fs = llvm::sys::fs;
+namespace path = llvm::sys::path;
+using namespace llvm;
+using namespace lldb_private;
+
+#define ASSERT_NO_ERROR(x) \
+  if (std::error_code ASSERT_NO_ERROR_ec = x) {\
+SmallString<128> MessageStorage;   \
+raw_svector_ostream Message(MessageStorage);   \
+Message << #x ": did not return errc::success.\n"  \
+<< "error number: " << ASSERT_NO_ERROR_ec.value() << "\n"  \
+<< "error message: " << ASSERT_NO_ERROR_ec.message() << "\n";  \
+GTEST_FATAL_FAILURE_(MessageStorage.c_str());  \
+  } else { \
+  }
+
+namespace {
+
+class MockTildeExpressionResolver : public TildeExpressionResolver {
+  StringRef CurrentUser;
+  StringMap UserDirectories;
+
+public:
+  explicit MockTildeExpressionResolver(StringRef CurrentUser, StringRef HomeDir)
+  : CurrentUser(CurrentUser) {
+UserDirectories.insert(std::make_pair(CurrentUser, HomeDir));
+  }
+
+  void AddKnownUser(StringRef User, StringRef HomeDir) {
+assert(UserDirectories.find(User) == UserDirectories.end());
+UserDirectories.insert(std::make_pair(User, HomeDir));
+  }
+
+  void Clear() {
+CurrentUser = StringRef();
+UserDirectories.clear();
+  }
+
+  void SetCurrentUser(StringRef User) {
+assert(UserDirectories.find(User) != UserDirectories.end());
+CurrentUser = User;
+  }
+
+  bool ResolveExact(StringRef Expr, SmallVectorImpl &Output) override {
+Output.clear();
+
+assert(!llvm::any_of(Expr, llvm::sys::path::is_separator));
+assert(Expr.empty() || Expr[0] == '~');
+Expr = Expr.drop_front();
+if (Expr.empty()) {
+  auto Dir = UserDirectories[CurrentUser];
+  Output.append(Dir.begin(), Dir.end());
+  return true;
+}
+
+for (const auto &User : UserDirectories) {
+  if (User.getKey() != Expr)
+continue;
+  Output.append(User.getValue().begin(), User.getValue().end());
+  return true;
+}
+return false;
+  }
+
+  bool ResolvePartial(StringRef Expr, StringSet<> &Output) override {
+Output.clear();
+
+assert(!llvm::any_of(Expr, llvm::sys::path::is_separator));
+assert(Expr.empty() || Expr[0] == '~');
+Expr = Expr.drop_front();
+
+SmallString<16> QualifiedName = "~";
+for (const auto &User : UserDirectories) {
+  if (!User.getKey().startswith(Expr))
+continue;
+  QualifiedName.resize(1);
+  QualifiedName.append(User.getKey().begin(), User.getKey().end());
+  Output.insert(QualifiedName);
+}
+
+return !Output.empty();
+  }
+};
+
+class CompletionTest : public testing::Test {
+protected:
+  /// Unique temporary directory in which all created filesystem entities must
+  /// be placed. It is removed at the end of the test suite.
+ 

[Lldb-commits] [lldb] r297589 - Revert "Make file / directory completion work properly on Windows."

2017-03-12 Thread Zachary Turner via lldb-commits
Author: zturner
Date: Sun Mar 12 15:01:37 2017
New Revision: 297589

URL: http://llvm.org/viewvc/llvm-project?rev=297589&view=rev
Log:
Revert "Make file / directory completion work properly on Windows."

This reverts commit a6a29374662716710f80c8ece96629751697841e.

It has a few compilation failures that I don't have time to fix
at the moment.

Removed:
lldb/trunk/include/lldb/Utility/TildeExpressionResolver.h
lldb/trunk/source/Utility/TildeExpressionResolver.cpp
lldb/trunk/unittests/Interpreter/TestCompletion.cpp
Modified:
lldb/trunk/include/lldb/Interpreter/CommandCompletions.h
lldb/trunk/source/Commands/CommandCompletions.cpp
lldb/trunk/source/Utility/CMakeLists.txt
lldb/trunk/unittests/Interpreter/CMakeLists.txt

Modified: lldb/trunk/include/lldb/Interpreter/CommandCompletions.h
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/CommandCompletions.h?rev=297589&r1=297588&r2=297589&view=diff
==
--- lldb/trunk/include/lldb/Interpreter/CommandCompletions.h (original)
+++ lldb/trunk/include/lldb/Interpreter/CommandCompletions.h Sun Mar 12 
15:01:37 2017
@@ -21,10 +21,7 @@
 #include "lldb/Utility/RegularExpression.h"
 #include "lldb/lldb-private.h"
 
-#include "llvm/ADT/Twine.h"
-
 namespace lldb_private {
-struct TildeExpressionResolver;
 class CommandCompletions {
 public:
   //--
@@ -79,19 +76,12 @@ public:
int max_return_elements, SearchFilter *searcher,
bool &word_complete, StringList &matches);
 
-  static int DiskFiles(const llvm::Twine &partial_file_name,
-   StringList &matches, TildeExpressionResolver &Resolver);
-
   static int DiskDirectories(CommandInterpreter &interpreter,
  llvm::StringRef partial_file_name,
  int match_start_point, int max_return_elements,
  SearchFilter *searcher, bool &word_complete,
  StringList &matches);
 
-  static int DiskDirectories(const llvm::Twine &partial_file_name,
- StringList &matches,
- TildeExpressionResolver &Resolver);
-
   static int SourceFiles(CommandInterpreter &interpreter,
  llvm::StringRef partial_file_name,
  int match_start_point, int max_return_elements,

Removed: lldb/trunk/include/lldb/Utility/TildeExpressionResolver.h
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Utility/TildeExpressionResolver.h?rev=297588&view=auto
==
--- lldb/trunk/include/lldb/Utility/TildeExpressionResolver.h (original)
+++ lldb/trunk/include/lldb/Utility/TildeExpressionResolver.h (removed)
@@ -1,57 +0,0 @@
-//===- TildeExpressionResolver.h *- C++ 
-*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===--===//
-
-#ifndef LLDB_UTILITY_TILDE_EXPRESSION_RESOLVER_H
-#define LLDB_UTILITY_TILDE_EXPRESSION_RESOLVER_H
-
-#include "llvm/ADT/SmallVector.h"
-#include "llvm/ADT/StringRef.h"
-#include "llvm/ADT/StringSet.h"
-
-namespace lldb_private {
-class TildeExpressionResolver {
-public:
-  virtual ~TildeExpressionResolver();
-
-  /// \brief Resolve a Tilde Expression contained according to bash rules.
-  ///
-  /// \param Expr Contains the tilde expression to resolve.  A valid tilde
-  /// expression must begin with a tilde and contain only non
-  /// separator characters.
-  ///
-  /// \param Output Contains the resolved tilde expression, or the original
-  ///   input if the tilde expression could not be resolved.
-  ///
-  /// \returns true if \p Expr was successfully resolved, false otherwise.
-  virtual bool ResolveExact(llvm::StringRef Expr,
-llvm::SmallVectorImpl &Output) = 0;
-
-  /// \brief Auto-complete a tilde expression with all matching values.
-  ///
-  /// \param Expr Contains the tilde expression prefix to resolve.  See
-  /// ResolveExact() for validity rules.
-  ///
-  /// \param Output Contains all matching home directories, each one
-  ///   itself unresolved (i.e. you need to call ResolveExact
-  ///   on each item to turn it into a real path).
-  ///
-  /// \returns true if there were any matches, false otherwise.
-  virtual bool ResolvePartial(llvm::StringRef Expr,
-  llvm::StringSet<> &Output) = 0;
-};
-
-class StandardTildeExpressionResolver : public TildeExpressionResolver {
-public:
-  bool ResolveExact(llvm::StringRef 

[Lldb-commits] [lldb] r297597 - Resubmit "Make file / directory completion work properly on Windows."

2017-03-12 Thread Zachary Turner via lldb-commits
Author: zturner
Date: Sun Mar 12 19:41:01 2017
New Revision: 297597

URL: http://llvm.org/viewvc/llvm-project?rev=297597&view=rev
Log:
Resubmit "Make file / directory completion work properly on Windows."

This fixes the compilation failures with the original patch.

Added:
lldb/trunk/include/lldb/Utility/TildeExpressionResolver.h
lldb/trunk/source/Utility/TildeExpressionResolver.cpp
lldb/trunk/unittests/Interpreter/TestCompletion.cpp
Modified:
lldb/trunk/include/lldb/Interpreter/CommandCompletions.h
lldb/trunk/source/Commands/CommandCompletions.cpp
lldb/trunk/source/Utility/CMakeLists.txt
lldb/trunk/unittests/Interpreter/CMakeLists.txt

Modified: lldb/trunk/include/lldb/Interpreter/CommandCompletions.h
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/CommandCompletions.h?rev=297597&r1=297596&r2=297597&view=diff
==
--- lldb/trunk/include/lldb/Interpreter/CommandCompletions.h (original)
+++ lldb/trunk/include/lldb/Interpreter/CommandCompletions.h Sun Mar 12 
19:41:01 2017
@@ -21,7 +21,10 @@
 #include "lldb/Utility/RegularExpression.h"
 #include "lldb/lldb-private.h"
 
+#include "llvm/ADT/Twine.h"
+
 namespace lldb_private {
+struct TildeExpressionResolver;
 class CommandCompletions {
 public:
   //--
@@ -76,12 +79,19 @@ public:
int max_return_elements, SearchFilter *searcher,
bool &word_complete, StringList &matches);
 
+  static int DiskFiles(const llvm::Twine &partial_file_name,
+   StringList &matches, TildeExpressionResolver &Resolver);
+
   static int DiskDirectories(CommandInterpreter &interpreter,
  llvm::StringRef partial_file_name,
  int match_start_point, int max_return_elements,
  SearchFilter *searcher, bool &word_complete,
  StringList &matches);
 
+  static int DiskDirectories(const llvm::Twine &partial_file_name,
+ StringList &matches,
+ TildeExpressionResolver &Resolver);
+
   static int SourceFiles(CommandInterpreter &interpreter,
  llvm::StringRef partial_file_name,
  int match_start_point, int max_return_elements,

Added: lldb/trunk/include/lldb/Utility/TildeExpressionResolver.h
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Utility/TildeExpressionResolver.h?rev=297597&view=auto
==
--- lldb/trunk/include/lldb/Utility/TildeExpressionResolver.h (added)
+++ lldb/trunk/include/lldb/Utility/TildeExpressionResolver.h Sun Mar 12 
19:41:01 2017
@@ -0,0 +1,57 @@
+//===- TildeExpressionResolver.h *- C++ 
-*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLDB_UTILITY_TILDE_EXPRESSION_RESOLVER_H
+#define LLDB_UTILITY_TILDE_EXPRESSION_RESOLVER_H
+
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/StringSet.h"
+
+namespace lldb_private {
+class TildeExpressionResolver {
+public:
+  virtual ~TildeExpressionResolver();
+
+  /// \brief Resolve a Tilde Expression contained according to bash rules.
+  ///
+  /// \param Expr Contains the tilde expression to resolve.  A valid tilde
+  /// expression must begin with a tilde and contain only non
+  /// separator characters.
+  ///
+  /// \param Output Contains the resolved tilde expression, or the original
+  ///   input if the tilde expression could not be resolved.
+  ///
+  /// \returns true if \p Expr was successfully resolved, false otherwise.
+  virtual bool ResolveExact(llvm::StringRef Expr,
+llvm::SmallVectorImpl &Output) = 0;
+
+  /// \brief Auto-complete a tilde expression with all matching values.
+  ///
+  /// \param Expr Contains the tilde expression prefix to resolve.  See
+  /// ResolveExact() for validity rules.
+  ///
+  /// \param Output Contains all matching home directories, each one
+  ///   itself unresolved (i.e. you need to call ResolveExact
+  ///   on each item to turn it into a real path).
+  ///
+  /// \returns true if there were any matches, false otherwise.
+  virtual bool ResolvePartial(llvm::StringRef Expr,
+  llvm::StringSet<> &Output) = 0;
+};
+
+class StandardTildeExpressionResolver : public TildeExpressionResolver {
+public:
+  bool ResolveExact(llvm::StringRef Expr,
+llvm::SmallVectorImpl &Output) override;
+ 

[Lldb-commits] [lldb] r297598 - Use LLVM for file / directory enumeration.

2017-03-12 Thread Zachary Turner via lldb-commits
Author: zturner
Date: Sun Mar 12 21:44:39 2017
New Revision: 297598

URL: http://llvm.org/viewvc/llvm-project?rev=297598&view=rev
Log:
Use LLVM for file / directory enumeration.

FileSpec::EnumerateDirectory has a bunch of platform-specific
gunk in it for posix and non-posix platforms. We can get rid
of all this by using LLVM's easy-to-use directory iterators.

Differential Revision: https://reviews.llvm.org/D30807

Modified:
lldb/trunk/include/lldb/Host/FileSpec.h
lldb/trunk/include/lldb/Interpreter/CommandCompletions.h
lldb/trunk/source/Commands/CommandCompletions.cpp
lldb/trunk/source/Host/common/FileSpec.cpp
lldb/trunk/source/Utility/TildeExpressionResolver.cpp

Modified: lldb/trunk/include/lldb/Host/FileSpec.h
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/FileSpec.h?rev=297598&r1=297597&r2=297598&view=diff
==
--- lldb/trunk/include/lldb/Host/FileSpec.h (original)
+++ lldb/trunk/include/lldb/Host/FileSpec.h Sun Mar 12 21:44:39 2017
@@ -564,28 +564,22 @@ public:
 // directory
 eEnumerateDirectoryResultEnter, // Recurse into the current entry if it is 
a
 // directory or symlink, or next if not
-eEnumerateDirectoryResultExit,  // Exit from the current directory at the
-// current level.
 eEnumerateDirectoryResultQuit   // Stop directory enumerations at any level
   };
 
   typedef EnumerateDirectoryResult (*EnumerateDirectoryCallbackType)(
   void *baton, llvm::sys::fs::file_type file_type, const FileSpec &spec);
 
-  static EnumerateDirectoryResult
-  EnumerateDirectory(llvm::StringRef dir_path, bool find_directories,
- bool find_files, bool find_other,
- EnumerateDirectoryCallbackType callback,
- void *callback_baton);
+  static void EnumerateDirectory(llvm::StringRef dir_path,
+ bool find_directories, bool find_files,
+ bool find_other,
+ EnumerateDirectoryCallbackType callback,
+ void *callback_baton);
 
   typedef std::function
   DirectoryCallback;
 
-  static EnumerateDirectoryResult
-  ForEachItemInDirectory(llvm::StringRef dir_path,
- DirectoryCallback const &callback);
-
 protected:
   //--
   // Member variables

Modified: lldb/trunk/include/lldb/Interpreter/CommandCompletions.h
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/CommandCompletions.h?rev=297598&r1=297597&r2=297598&view=diff
==
--- lldb/trunk/include/lldb/Interpreter/CommandCompletions.h (original)
+++ lldb/trunk/include/lldb/Interpreter/CommandCompletions.h Sun Mar 12 
21:44:39 2017
@@ -24,7 +24,7 @@
 #include "llvm/ADT/Twine.h"
 
 namespace lldb_private {
-struct TildeExpressionResolver;
+class TildeExpressionResolver;
 class CommandCompletions {
 public:
   //--

Modified: lldb/trunk/source/Commands/CommandCompletions.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandCompletions.cpp?rev=297598&r1=297597&r2=297598&view=diff
==
--- lldb/trunk/source/Commands/CommandCompletions.cpp (original)
+++ lldb/trunk/source/Commands/CommandCompletions.cpp Sun Mar 12 21:44:39 2017
@@ -195,7 +195,7 @@ static int DiskFilesOrDirectories(const
 // We have a match.
 
 fs::file_status st;
-if (EC = Entry.status(st))
+if ((EC = Entry.status(st)))
   continue;
 
 // If it's a symlink, then we treat it as a directory as long as the target

Modified: lldb/trunk/source/Host/common/FileSpec.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/FileSpec.cpp?rev=297598&r1=297597&r2=297598&view=diff
==
--- lldb/trunk/source/Host/common/FileSpec.cpp (original)
+++ lldb/trunk/source/Host/common/FileSpec.cpp Sun Mar 12 21:44:39 2017
@@ -7,21 +7,12 @@
 //
 
//===--===//
 
-#ifndef _WIN32
-#include 
-#else
-#include "lldb/Host/windows/windows.h"
-#endif
-#include 
-#ifndef _MSC_VER
-#include 
-#endif
 #include 
 #include 
 #include 
 
-#include "lldb/Host/Config.h" // Have to include this before we test the 
define...
-#ifdef LLDB_CONFIG_TILDE_RESOLVES_TO_USER
+#include "llvm/Config/llvm-config.h"
+#ifndef LLVM_ON_WIN32
 #include 
 #endif
 
@@ -159,7 +150,7 @@ size_t ParentPathEnd(llvm::StringRef pat
 // If you want to complete "~" to the list of users, pass it to
 // ResolvePartialUser

[Lldb-commits] [PATCH] D30807: Use LLVM's directory enumeration code

2017-03-12 Thread Zachary Turner via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL297598: Use LLVM for file / directory enumeration. (authored 
by zturner).

Changed prior to commit:
  https://reviews.llvm.org/D30807?vs=91260&id=91513#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D30807

Files:
  lldb/trunk/include/lldb/Host/FileSpec.h
  lldb/trunk/include/lldb/Interpreter/CommandCompletions.h
  lldb/trunk/source/Commands/CommandCompletions.cpp
  lldb/trunk/source/Host/common/FileSpec.cpp
  lldb/trunk/source/Utility/TildeExpressionResolver.cpp

Index: lldb/trunk/source/Utility/TildeExpressionResolver.cpp
===
--- lldb/trunk/source/Utility/TildeExpressionResolver.cpp
+++ lldb/trunk/source/Utility/TildeExpressionResolver.cpp
@@ -13,6 +13,10 @@
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
 
+#if !defined(LLVM_ON_WIN32)
+#include 
+#endif
+
 using namespace lldb_private;
 using namespace llvm;
 
@@ -46,7 +50,7 @@
   if (Expr.empty())
 return false;
 
-  SmallString<32> Buffer = "~";
+  SmallString<32> Buffer("~");
   setpwent();
   struct passwd *user_entry;
   Expr = Expr.drop_front();
Index: lldb/trunk/source/Commands/CommandCompletions.cpp
===
--- lldb/trunk/source/Commands/CommandCompletions.cpp
+++ lldb/trunk/source/Commands/CommandCompletions.cpp
@@ -195,7 +195,7 @@
 // We have a match.
 
 fs::file_status st;
-if (EC = Entry.status(st))
+if ((EC = Entry.status(st)))
   continue;
 
 // If it's a symlink, then we treat it as a directory as long as the target
Index: lldb/trunk/source/Host/common/FileSpec.cpp
===
--- lldb/trunk/source/Host/common/FileSpec.cpp
+++ lldb/trunk/source/Host/common/FileSpec.cpp
@@ -7,21 +7,12 @@
 //
 //===--===//
 
-#ifndef _WIN32
-#include 
-#else
-#include "lldb/Host/windows/windows.h"
-#endif
-#include 
-#ifndef _MSC_VER
-#include 
-#endif
 #include 
 #include 
 #include 
 
-#include "lldb/Host/Config.h" // Have to include this before we test the define...
-#ifdef LLDB_CONFIG_TILDE_RESOLVES_TO_USER
+#include "llvm/Config/llvm-config.h"
+#ifndef LLVM_ON_WIN32
 #include 
 #endif
 
@@ -159,7 +150,7 @@
 // If you want to complete "~" to the list of users, pass it to
 // ResolvePartialUsername.
 void FileSpec::ResolveUsername(llvm::SmallVectorImpl &path) {
-#if LLDB_CONFIG_TILDE_RESOLVES_TO_USER
+#ifndef LLVM_ON_WIN32
   if (path.empty() || path[0] != '~')
 return;
 
@@ -227,7 +218,7 @@
 
 size_t FileSpec::ResolvePartialUsername(llvm::StringRef partial_name,
 StringList &matches) {
-#ifdef LLDB_CONFIG_TILDE_RESOLVES_TO_USER
+#ifndef LLVM_ON_WIN32
   size_t extant_entries = matches.GetSize();
 
   setpwent();
@@ -251,17 +242,17 @@
 #else
   // Resolving home directories is not supported, just copy the path...
   return 0;
-#endif // #ifdef LLDB_CONFIG_TILDE_RESOLVES_TO_USER
+#endif // #ifdef LLVM_ON_WIN32
 }
 
 void FileSpec::Resolve(llvm::SmallVectorImpl &path) {
   if (path.empty())
 return;
 
-#ifdef LLDB_CONFIG_TILDE_RESOLVES_TO_USER
+#ifndef LLVM_ON_WIN32
   if (path[0] == '~')
 ResolveUsername(path);
-#endif // #ifdef LLDB_CONFIG_TILDE_RESOLVES_TO_USER
+#endif // #ifdef LLVM_ON_WIN32
 
   // Save a copy of the original path that's passed in
   llvm::SmallString<128> original_path(path.begin(), path.end());
@@ -776,235 +767,37 @@
   return m_filename.MemorySize() + m_directory.MemorySize();
 }
 
-FileSpec::EnumerateDirectoryResult
-FileSpec::ForEachItemInDirectory(llvm::StringRef dir_path,
- DirectoryCallback const &callback) {
-  if (dir_path.empty())
-return eEnumerateDirectoryResultNext;
-
-#ifdef _WIN32
-std::string szDir(dir_path);
-szDir += "\\*";
-
-std::wstring wszDir;
-if (!llvm::ConvertUTF8toWide(szDir, wszDir)) {
-  return eEnumerateDirectoryResultNext;
-}
-
-WIN32_FIND_DATAW ffd;
-HANDLE hFind = FindFirstFileW(wszDir.c_str(), &ffd);
-
-if (hFind == INVALID_HANDLE_VALUE) {
-  return eEnumerateDirectoryResultNext;
-}
-
-do {
-  namespace fs = llvm::sys::fs;
-  fs::file_type ft = fs::file_type::type_unknown;
-  if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
-size_t len = wcslen(ffd.cFileName);
-
-if (len == 1 && ffd.cFileName[0] == L'.')
-  continue;
-
-if (len == 2 && ffd.cFileName[0] == L'.' && ffd.cFileName[1] == L'.')
-  continue;
-
-ft = fs::file_type::directory_file;
-  } else if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DEVICE) {
-ft = fs::file_type::type_unknown;
-  } else {
-ft = fs::file_type::regular_file;
-  }
-
-  std::string fileName;
-  if (!llvm::convertWideToUTF8(ffd.cFileName, fileName)) {
-