23#include "llvm/Support/JSON.h"
24#include "llvm/Support/Path.h"
25#include "llvm/Support/PrettyStackTrace.h"
26#include "llvm/Support/VirtualFileSystem.h"
34static bool fromJSON(
const llvm::json::Value &Params,
37 llvm::json::ObjectMapper O(Params, P);
38 return O.mapOptional(
"system-include-directories",
42static bool fromJSON(
const llvm::json::Value &Params,
45 llvm::json::ObjectMapper O(Params, P);
46 return O.map(
"is-std-library", ModuleEntry.
IsStdlib) &&
48 O.map(
"source-path", ModuleEntry.
SourcePath) &&
49 O.mapOptional(
"local-arguments", ModuleEntry.
LocalArgs);
52static bool fromJSON(
const llvm::json::Value &Params,
54 llvm::json::ObjectMapper O(Params, P);
55 return O.map(
"modules", Manifest.
Modules);
61 auto ParsedOrErr = llvm::json::parse(Buffer);
63 return ParsedOrErr.takeError();
66 llvm::json::Path::Root Root;
67 if (!
fromJSON(*ParsedOrErr, Manifest, Root))
68 return Root.getError();
79 StringRef ManifestPath) {
80 StringRef ManifestDir = llvm::sys::path::parent_path(ManifestPath);
83 auto PrependManifestDir = [&](StringRef Path) {
84 TempPath = ManifestDir;
85 llvm::sys::path::append(TempPath, Path);
86 return std::string(TempPath);
89 for (
auto &Entry : ManifestEntries) {
90 Entry.SourcePath = PrependManifestDir(Entry.SourcePath);
94 for (
auto &IncludeDir : Entry.LocalArgs->SystemIncludeDirs)
95 IncludeDir = PrependManifestDir(IncludeDir);
101 llvm::vfs::FileSystem &VFS) {
102 auto MemBufOrErr =
VFS.getBufferForFile(ManifestPath);
104 return llvm::createFileError(ManifestPath, MemBufOrErr.getError());
106 auto ManifestOrErr =
parseManifest((*MemBufOrErr)->getBuffer());
108 return ManifestOrErr.takeError();
109 auto Manifest = std::move(*ManifestOrErr);
118 DerivedArgList &Args =
C.getArgs();
119 const OptTable &Opts =
C.getDriver().getOpts();
120 for (
const auto &Entry : ManifestEntries) {
122 makeInputArg(Args, Opts, Args.MakeArgString(Entry.SourcePath));
123 Inputs.emplace_back(types::TY_CXXModule, InputArg);
128 llvm::DenseMap<StringRef, const StdModuleManifest::Module *>;
134 for (
auto &Entry : ManifestEntries) {
135 [[maybe_unused]]
const bool Inserted =
136 ManifestEntryBySource.try_emplace(Entry.SourcePath, &Entry).second;
138 "Manifest defines multiple modules with the same source path.");
140 return ManifestEntryBySource;
149 if (
const auto It = ManifestEntryBySource.find(II.getFilename());
150 It != ManifestEntryBySource.end())
159 ArgStringList &CC1Args,
162 const DerivedArgList &TCArgs =
166 for (
const auto &IncludeDir : SystemIncludeDirs)
179 for (
auto &Job : Jobs) {
187 auto CC1Args = Job->getArguments();
189 CC1Args.push_back(
"-Wno-reserved-module-identifier");
190 if (Entry->LocalArgs)
192 Entry->LocalArgs->SystemIncludeDirs);
193 Job->replaceArguments(CC1Args);
199 llvm::PrettyStackTraceString CrashInfo(
"Running modules driver.");
201 auto Jobs =
C.getJobs().takeJobs();
214 for (
auto &Job : Jobs)
215 C.addCommand(std::move(Job));
Defines the Diagnostic-related interfaces.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
static const StdModuleManifest::Module * getManifestEntryForCommand(const Command &Job, const ManifestEntryLookup &ManifestEntryBySource)
Returns the manifest entry corresponding to Job, or nullptr if none exists.
static Expected< StdModuleManifest > parseManifest(StringRef Buffer)
Parses the Standard library module manifest from Buffer.
static void makeManifestPathsAbsolute(MutableArrayRef< StdModuleManifest::Module > ManifestEntries, StringRef ManifestPath)
Converts each file path in manifest from relative to absolute.
static void applyArgsForStdModuleManifestInputs(Compilation &C, const ManifestEntryLookup &ManifestEntryBySource, MutableArrayRef< std::unique_ptr< Command > > Jobs)
Apply command-line modifications specific for inputs originating from the Standard library module man...
static void addSystemIncludeDirsFromManifest(Compilation &C, Command &Job, ArgStringList &CC1Args, ArrayRef< std::string > SystemIncludeDirs)
Adds all SystemIncludeDirs to the CC1Args of Job.
static ManifestEntryLookup buildManifestLookupMap(ArrayRef< StdModuleManifest::Module > ManifestEntries)
Builds a mapping from a module's source path to its entry in the manifest.
static bool isCC1Job(const Command &Job)
llvm::DenseMap< StringRef, const StdModuleManifest::Module * > ManifestEntryLookup
This file defines functionality to support driver managed builds for compilations which use Clang mod...
const char * getOffloadingArch() const
OffloadKind getOffloadingDeviceKind() const
Command - An executable path/name and argument vector to execute.
const Action & getSource() const
getSource - Return the Action which caused the creation of this job.
const Tool & getCreator() const
getCreator - Return the Tool which caused the creation of this job.
const std::vector< InputInfo > & getInputInfos() const
Compilation - A set of tasks to perform for a single driver invocation.
@ VFS
Remove unused -ivfsoverlay arguments.
void buildStdModuleManifestInputs(ArrayRef< StdModuleManifest::Module > ManifestEntries, Compilation &C, InputList &Inputs)
Constructs compilation inputs for each module listed in the provided Standard library module manifest...
void runModulesDriver(Compilation &C, ArrayRef< StdModuleManifest::Module > ManifestEntries)
Scans the compilation inputs for module dependencies and adjusts the compilation to build and supply ...
llvm::Expected< StdModuleManifest > readStdModuleManifest(llvm::StringRef ManifestPath, llvm::vfs::FileSystem &VFS)
Reads the Standard library module manifest at ManifestPath.
static bool fromJSON(const llvm::json::Value &Params, StdModuleManifest::Module::LocalArguments &LocalArgs, llvm::json::Path P)
llvm::opt::Arg * makeInputArg(llvm::opt::DerivedArgList &Args, const llvm::opt::OptTable &Opts, StringRef Value, bool Claim=true)
Creates and adds a synthesized input argument.
llvm::SmallVector< InputTy, 16 > InputList
A list of inputs and their types for the given arguments.
The JSON file list parser is used to communicate input to InstallAPI.
std::vector< std::string > SystemIncludeDirs
std::optional< LocalArguments > LocalArgs
The parsed Standard library module manifest.
std::vector< Module > Modules