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