Fabrique

A build language for complex systems

 All Classes Namespaces Files Functions Variables Enumerations Enumerator Macros Pages
os.h
Go to the documentation of this file.
1 
2 /*
3  * Copyright (c) 2014 Jonathan Anderson
4  * All rights reserved.
5  *
6  * This software was developed by SRI International and the University of
7  * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237)
8  * ("CTSRD"), as part of the DARPA CRASH research programme.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in the
17  * documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29  * SUCH DAMAGE.
30  */
31 
32 #ifndef POSIX_H
33 #define POSIX_H
34 
35 #include <functional>
36 #include <string>
37 #include <vector>
38 
39 namespace fabrique {
40 
41 //
42 // File- and path-related predicates:
43 //
44 
46 bool FileIsExecutable(std::string path);
47 
49 bool FileIsSharedLibrary(std::string path);
50 
52 bool PathIsAbsolute(const std::string&);
53 
55 bool PathIsDirectory(std::string);
56 
58 bool PathIsFile(std::string);
59 
60 
61 //
62 // Other file- and path-related functions that might be used as arguments:
63 //
64 
65 typedef std::function<std::string (std::string, const std::vector<std::string>&)>
66  MissingFileReporter;
67 
69 MissingFileReporter DefaultFilename(std::string name = "");
70 
72 std::string FileNotFound(std::string name, const std::vector<std::string>& searchPaths);
73 
74 
75 //
76 // Filename and path manipulation:
77 //
78 
80 std::string AbsoluteDirectory(std::string name, bool createIfMissing = true);
81 
83 std::string AbsolutePath(std::string path);
84 
86 std::string BaseName(std::string path);
87 
89 std::string CreateDirCommand(std::string directory);
90 
92 std::string DirectoryOf(std::string filename, bool absolute = false);
93 
95 std::string FileExtension(std::string path);
96 
98 std::string FilenameComponent(std::string pathIncludingDirectory);
99 
101 std::string FindExecutable(std::string name, MissingFileReporter report = FileNotFound);
102 
110 std::string FindFile(std::string filename, const std::vector<std::string>& directories,
111  std::function<bool (const std::string&)> test = PathIsFile,
112  MissingFileReporter report = FileNotFound);
113 
115 std::string JoinPath(const std::string&, const std::string&);
116 
118 std::string JoinPath(const std::vector<std::string>&);
119 
121 std::string LibraryFilename(std::string name);
122 
128 std::vector<std::string> PluginSearchPaths(std::string executablePath);
129 
130 
131 //
132 // Fabrique modules:
133 //
134 
136 std::string FindModule(std::string srcroot, std::string subdir,
137  std::string filename);
138 
139 }
140 
141 #endif