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