]> git.tdb.fi Git - builder.git/blob - source/virtualfilesystem.h
Move library mode into BuildInfo
[builder.git] / source / virtualfilesystem.h
1 #ifndef VIRTUALFILESYSTEM_H_
2 #define VIRTUALFILESYSTEM_H_
3
4 #include <list>
5 #include <map>
6 #include <msp/fs/path.h>
7 #include "buildinfo.h"
8
9 class Builder;
10 class FileTarget;
11 class Pattern;
12
13 /**
14 Provides access to the filesystem in a way that takes known targets into
15 account.  Thus, targets may be returned for files that do not exist yet if it's
16 possible to build them.
17 */
18 class VirtualFileSystem
19 {
20 public:
21         typedef std::list<Msp::FS::Path> SearchPath;
22
23 private:
24         typedef std::map<Msp::FS::Path, FileTarget *> TargetMap;
25
26         Builder &builder;
27         TargetMap 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. */
43         FileTarget *find_header(const std::string &, const SearchPath &);
44
45         /** Locates a library.  The library name should be the same as what would be
46         used in linking with the library.  If a file is found but no target is
47         associated with it, a new package-less target of appropriate type is
48         created. */
49         FileTarget *find_library(const std::string &, const SearchPath &, BuildInfo::LibraryMode);
50
51         /** Locates a binary.  The normal search path for binaries is used (usually
52         this means the PATH environment variable).  If a file is found but no target
53         is associated with it, a new package-less Executable target is created. */
54         FileTarget *find_binary(const std::string &);
55
56 private:
57         bool file_exists(const Msp::FS::Path &);
58 };
59
60 #endif