]> git.tdb.fi Git - builder.git/blob - source/virtualfilesystem.h
Remove most container typedefs and refactor others
[builder.git] / source / virtualfilesystem.h
1 #ifndef VIRTUALFILESYSTEM_H_
2 #define VIRTUALFILESYSTEM_H_
3
4 #include <list>
5 #include <map>
6 #include <set>
7 #include <msp/fs/path.h>
8 #include "buildinfo.h"
9
10 class Builder;
11 class FileTarget;
12 class Pattern;
13 class Tool;
14
15 /**
16 Provides access to the filesystem in a way that takes known targets into
17 account.  Thus, targets may be returned for files that do not exist yet if it's
18 possible to build them.
19 */
20 class VirtualFileSystem
21 {
22 public:
23         using SearchPath = std::list<Msp::FS::Path>;
24
25 private:
26         Builder &builder;
27         std::map<Msp::FS::Path, FileTarget *> targets;
28         std::set<Msp::FS::Path> nonexistent;
29
30 public:
31         VirtualFileSystem(Builder &);
32
33         /** Gets an existing target associated with a path.  If no target has claimed
34         that path, 0 is returned. */
35         FileTarget *get_target(const Msp::FS::Path &) const;
36
37         /** Registers a target with the VFS.  A target may be registered at multiple
38         paths if building it results in multiple files. */
39         void register_path(const Msp::FS::Path &, FileTarget *);
40
41         /** Locates a source file.  If a file is found but no target is associated
42         with it, a new package-less target is created with the appropriate tool.  If
43         use_syspath is true, the system path reported by the tool is also searched. */
44         FileTarget *find_header(const std::string &, Tool *, const SearchPath &, bool use_syspath = true);
45
46         /** Locates a library.  The library name should be the same as what would be
47         used in linking with the library.  If a file is found but no target is
48         associated with it, a new package-less target of appropriate type is
49         created.  If use_syspath is true, the system path reported by the LINK tool
50         is also searched. */
51         FileTarget *find_library(const std::string &, const SearchPath &, BuildInfo::LibraryMode, bool use_syspath = true);
52
53         /** Locates a binary.  The normal search path for binaries is used (usually
54         this means the PATH environment variable).  If a file is found but no target
55         is associated with it, a new package-less Executable target is created. */
56         FileTarget *find_binary(const std::string &);
57
58 private:
59         bool file_exists(const Msp::FS::Path &);
60 };
61
62 #endif