]> git.tdb.fi Git - builder.git/blob - source/lib/virtualfilesystem.h
Add visibility decorations to the library and plugins
[builder.git] / source / lib / virtualfilesystem.h
1 #ifndef VIRTUALFILESYSTEM_H_
2 #define VIRTUALFILESYSTEM_H_
3
4 #include <map>
5 #include <set>
6 #include <vector>
7 #include <msp/fs/path.h>
8 #include "buildinfo.h"
9 #include "libbuilder_api.h"
10
11 class Builder;
12 class FileTarget;
13 class Pattern;
14 class Tool;
15
16 /**
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.
20 */
21 class LIBBUILDER_API VirtualFileSystem
22 {
23 public:
24         using SearchPath = std::vector<Msp::FS::Path>;
25
26 private:
27         Builder &builder;
28         std::map<Msp::FS::Path, FileTarget *> targets;
29         std::set<Msp::FS::Path> nonexistent;
30         SearchPath sys_bin_path;
31
32 public:
33         VirtualFileSystem(Builder &b): builder(b) { }
34
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;
38
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 *);
42
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);
47
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
52         is also searched. */
53         FileTarget *find_library(const std::string &, const SearchPath &, BuildInfo::LibraryMode, bool use_syspath = true);
54
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 &);
59
60 private:
61         bool file_exists(const Msp::FS::Path &);
62 };
63
64 #endif