<div dir="ltr">FYI:  This broke the Windows build (which doesn't have getuid), and the fix wasn't immediately obvious, so I reverted the change.<div><br></div><div>Adrian.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Oct 26, 2015 at 1:33 PM, Sean Callanan via lldb-commits <span dir="ltr"><<a href="mailto:lldb-commits@lists.llvm.org" target="_blank">lldb-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: spyffe<br>
Date: Mon Oct 26 15:33:24 2015<br>
New Revision: 251340<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=251340&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=251340&view=rev</a><br>
Log:<br>
Clang module compilation options need to be per-platform.<br>
<br>
On UNIX (but not Darwin) the username needs to be respected when creating a<br>
temporary module directory, so that different users don't pollute each others'<br>
module caches.<br>
<br>
Modified:<br>
    lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp<br>
    lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp<br>
    lldb/trunk/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp<br>
    lldb/trunk/source/Plugins/Platform/POSIX/PlatformPOSIX.h<br>
    lldb/trunk/source/Target/Platform.cpp<br>
<br>
Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp?rev=251340&r1=251339&r2=251340&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp?rev=251340&r1=251339&r2=251340&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp (original)<br>
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp Mon Oct 26 15:33:24 2015<br>
@@ -641,18 +641,7 @@ ClangModulesDeclVendor::Create(Target &t<br>
     compiler_invocation_arguments.push_back(ModuleImportBufferName);<br>
<br>
     // Add additional search paths with { "-I", path } or { "-F", path } here.<br>
-<br>
-    {<br>
-        llvm::SmallString<128> DefaultModuleCache;<br>
-        const bool erased_on_reboot = false;<br>
-        llvm::sys::path::system_temp_directory(erased_on_reboot, DefaultModuleCache);<br>
-        llvm::sys::path::append(DefaultModuleCache, "org.llvm.clang");<br>
-        llvm::sys::path::append(DefaultModuleCache, "ModuleCache");<br>
-        std::string module_cache_argument("-fmodules-cache-path=");<br>
-        module_cache_argument.append(DefaultModuleCache.str().str());<br>
-        compiler_invocation_arguments.push_back(module_cache_argument);<br>
-    }<br>
-<br>
+<br>
     FileSpecList &module_search_paths = target.GetClangModuleSearchPaths();<br>
<br>
     for (size_t spi = 0, spe = module_search_paths.GetSize(); spi < spe; ++spi)<br>
<br>
Modified: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp?rev=251340&r1=251339&r2=251340&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp?rev=251340&r1=251339&r2=251340&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp (original)<br>
+++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp Mon Oct 26 15:33:24 2015<br>
@@ -35,6 +35,10 @@<br>
 #include "lldb/Target/Target.h"<br>
 #include "llvm/ADT/STLExtras.h"<br>
<br>
+#include "llvm/ADT/StringExtras.h"<br>
+#include "llvm/ADT/SmallString.h"<br>
+#include "llvm/Support/Path.h"<br>
+<br>
 using namespace lldb;<br>
 using namespace lldb_private;<br>
<br>
@@ -1476,6 +1480,17 @@ PlatformDarwin::AddClangModuleCompilatio<br>
                    apple_arguments.begin(),<br>
                    apple_arguments.end());<br>
<br>
+    {<br>
+        llvm::SmallString<128> DefaultModuleCache;<br>
+        const bool erased_on_reboot = false;<br>
+        llvm::sys::path::system_temp_directory(erased_on_reboot, DefaultModuleCache);<br>
+        llvm::sys::path::append(DefaultModuleCache, "org.llvm.clang");<br>
+        llvm::sys::path::append(DefaultModuleCache, "ModuleCache");<br>
+        std::string module_cache_argument("-fmodules-cache-path=");<br>
+        module_cache_argument.append(DefaultModuleCache.str().str());<br>
+        options.push_back(module_cache_argument);<br>
+    }<br>
+<br>
     StreamString minimum_version_option;<br>
     uint32_t versions[3] = { 0, 0, 0 };<br>
     bool use_current_os_version = false;<br>
<br>
Modified: lldb/trunk/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp?rev=251340&r1=251339&r2=251340&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp?rev=251340&r1=251339&r2=251340&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp (original)<br>
+++ lldb/trunk/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp Mon Oct 26 15:33:24 2015<br>
@@ -27,6 +27,10 @@<br>
 #include "lldb/Target/Process.h"<br>
 #include "lldb/Target/ProcessLaunchInfo.h"<br>
<br>
+#include "llvm/ADT/StringExtras.h"<br>
+#include "llvm/ADT/SmallString.h"<br>
+#include "llvm/Support/Path.h"<br>
+<br>
 using namespace lldb;<br>
 using namespace lldb_private;<br>
<br>
@@ -848,4 +852,64 @@ void<br>
 PlatformPOSIX::CalculateTrapHandlerSymbolNames ()<br>
 {<br>
     m_trap_handlers.push_back (ConstString ("_sigtramp"));<br>
-}<br>
+}<br>
+<br>
+static bool isAlphanumeric(const char c)<br>
+{<br>
+    return ((c >= '0' && c <= '9') ||<br>
+            (c >= 'a' && c <= 'z') ||<br>
+            (c >= 'A' && c <= 'Z'));<br>
+}<br>
+<br>
+static void appendUserToPath(llvm::SmallVectorImpl<char> &Result)<br>
+{<br>
+    const char *username = getenv("LOGNAME");<br>
+<br>
+    if (username)<br>
+    {<br>
+        // Validate that LoginName can be used in a path, and get its length.<br>
+        size_t Len = 0;<br>
+        for (const char *P = username; *P; ++P, ++Len) {<br>
+            if (!isAlphanumeric(*P) && *P != '_') {<br>
+                username = nullptr;<br>
+                break;<br>
+            }<br>
+        }<br>
+<br>
+        if (username && Len > 0) {<br>
+            Result.append(username, username + Len);<br>
+            return;<br>
+        }<br>
+    }<br>
+<br>
+    // Fallback to user id.<br>
+    std::string UID = llvm::utostr(getuid());<br>
+<br>
+    Result.append(UID.begin(), UID.end());<br>
+}<br>
+<br>
+void<br>
+PlatformPOSIX::AddClangModuleCompilationOptions (Target *target, std::vector<std::string> &options)<br>
+{<br>
+    std::vector<std::string> default_compilation_options =<br>
+    {<br>
+        "-x", "c++", "-Xclang", "-nostdsysteminc", "-Xclang", "-nostdsysteminc"<br>
+    };<br>
+<br>
+    options.insert(options.end(),<br>
+                   default_compilation_options.begin(),<br>
+                   default_compilation_options.end());<br>
+<br>
+    {<br>
+        llvm::SmallString<128> DefaultModuleCache;<br>
+        const bool erased_on_reboot = false;<br>
+        llvm::sys::path::system_temp_directory(erased_on_reboot, DefaultModuleCache);<br>
+        llvm::sys::path::append(DefaultModuleCache, "org.llvm.clang.");<br>
+        appendUserToPath(DefaultModuleCache);<br>
+        llvm::sys::path::append(DefaultModuleCache, "ModuleCache");<br>
+        std::string module_cache_argument("-fmodules-cache-path=");<br>
+        module_cache_argument.append(DefaultModuleCache.str().str());<br>
+        options.push_back(module_cache_argument);<br>
+    }<br>
+}<br>
+<br>
<br>
Modified: lldb/trunk/source/Plugins/Platform/POSIX/PlatformPOSIX.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/POSIX/PlatformPOSIX.h?rev=251340&r1=251339&r2=251340&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/POSIX/PlatformPOSIX.h?rev=251340&r1=251339&r2=251340&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/source/Plugins/Platform/POSIX/PlatformPOSIX.h (original)<br>
+++ lldb/trunk/source/Plugins/Platform/POSIX/PlatformPOSIX.h Mon Oct 26 15:33:24 2015<br>
@@ -176,6 +176,9 @@ public:<br>
     lldb_private::Error<br>
     DisconnectRemote () override;<br>
<br>
+    void<br>
+    AddClangModuleCompilationOptions (lldb_private::Target *target, std::vector<std::string> &options) override;<br>
+<br>
 protected:<br>
     std::unique_ptr<lldb_private::OptionGroupOptions> m_options;<br>
<br>
<br>
Modified: lldb/trunk/source/Target/Platform.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Platform.cpp?rev=251340&r1=251339&r2=251340&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Platform.cpp?rev=251340&r1=251339&r2=251340&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/source/Target/Platform.cpp (original)<br>
+++ lldb/trunk/source/Target/Platform.cpp Mon Oct 26 15:33:24 2015<br>
@@ -38,12 +38,13 @@<br>
 #include "lldb/Target/Target.h"<br>
 #include "lldb/Target/UnixSignals.h"<br>
 #include "lldb/Utility/Utils.h"<br>
+#include "llvm/ADT/StringExtras.h"<br>
+#include "llvm/ADT/SmallString.h"<br>
 #include "llvm/Support/FileSystem.h"<br>
 #include "llvm/Support/Path.h"<br>
<br>
 #include "Utility/ModuleCache.h"<br>
<br>
-<br>
 // Define these constants from POSIX mman.h rather than include the file<br>
 // so that they will be correct even when compiled on Linux.<br>
 #define MAP_PRIVATE 2<br>
@@ -621,6 +622,17 @@ Platform::AddClangModuleCompilationOptio<br>
     options.insert(options.end(),<br>
                    default_compilation_options.begin(),<br>
                    default_compilation_options.end());<br>
+<br>
+    {<br>
+        llvm::SmallString<128> DefaultModuleCache;<br>
+        const bool erased_on_reboot = false;<br>
+        llvm::sys::path::system_temp_directory(erased_on_reboot, DefaultModuleCache);<br>
+        llvm::sys::path::append(DefaultModuleCache, "org.llvm.clang");<br>
+        llvm::sys::path::append(DefaultModuleCache, "ModuleCache");<br>
+        std::string module_cache_argument("-fmodules-cache-path=");<br>
+        module_cache_argument.append(DefaultModuleCache.str().str());<br>
+        options.push_back(module_cache_argument);<br>
+    }<br>
 }<br>
<br>
<br>
<br>
<br>
_______________________________________________<br>
lldb-commits mailing list<br>
<a href="mailto:lldb-commits@lists.llvm.org">lldb-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits</a><br>
</blockquote></div><br></div>