1 #ifndef VIRTUALFILESYSTEM_H_
2 #define VIRTUALFILESYSTEM_H_
7 #include <msp/fs/path.h>
9 #include "libbuilder_api.h"
17 Provides access to the filesystem in a way that takes known targets into
18 account. Thus, targets may be returned for files that do not exist yet if it's
19 possible to build them.
21 class LIBBUILDER_API VirtualFileSystem
24 using SearchPath = std::vector<Msp::FS::Path>;
28 std::map<Msp::FS::Path, FileTarget *> targets;
29 std::set<Msp::FS::Path> nonexistent;
30 SearchPath sys_bin_path;
33 VirtualFileSystem(Builder &b): builder(b) { }
35 /** Gets an existing target associated with a path. If no target has claimed
36 that path, 0 is returned. */
37 FileTarget *get_target(const Msp::FS::Path &) const;
39 /** Registers a target with the VFS. A target may be registered at multiple
40 paths if building it results in multiple files. */
41 void register_path(const Msp::FS::Path &, FileTarget *);
43 /** Locates a source file. If a file is found but no target is associated
44 with it, a new package-less target is created with the appropriate tool. If
45 use_syspath is true, the system path reported by the tool is also searched. */
46 FileTarget *find_header(const std::string &, Tool *, const SearchPath &, bool use_syspath = true);
48 /** Locates a library. The library name should be the same as what would be
49 used in linking with the library. If a file is found but no target is
50 associated with it, a new package-less target of appropriate type is
51 created. If use_syspath is true, the system path reported by the LINK tool
53 FileTarget *find_library(const std::string &, const SearchPath &, BuildInfo::LibraryMode, bool use_syspath = true);
55 /** Locates a binary. The normal search path for binaries is used (usually
56 this means the PATH environment variable). If a file is found but no target
57 is associated with it, a new package-less Executable target is created. */
58 FileTarget *find_binary(const std::string &);
61 bool file_exists(const Msp::FS::Path &);