1/****************************************************************************
2 * Copyright (C) 2012-2016 Woboq GmbH
3 * Olivier Goffart <contact at woboq.com>
4 * https://woboq.com/codebrowser.html
5 *
6 * This file is part of the Woboq Code Browser.
7 *
8 * Commercial License Usage:
9 * Licensees holding valid commercial licenses provided by Woboq may use
10 * this file in accordance with the terms contained in a written agreement
11 * between the licensee and Woboq.
12 * For further information see https://woboq.com/codebrowser.html
13 *
14 * Alternatively, this work may be used under a Creative Commons
15 * Attribution-NonCommercial-ShareAlike 3.0 (CC-BY-NC-SA 3.0) License.
16 * http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_US
17 * This license does not allow you to use the code browser to assist the
18 * development of your commercial software. If you intent to do so, consider
19 * purchasing a commercial licence.
20 ****************************************************************************/
21
22#pragma once
23
24#include <llvm/ADT/StringRef.h>
25#include <string>
26#include <vector>
27#include <unordered_map>
28
29struct ProjectInfo {
30 std::string name;
31 std::string source_path;
32// std::string description;
33// std::string version_info;
34// std::string repo_url; //may contains tags;
35 std::string revision;
36
37 std::string external_root_url;
38
39 //TODO
40 std::string fileRepoUrl(const std::string &file) const { return {}; }
41 enum Type { Normal,
42 Internal, //includes and stuffs
43 External, //links to external projects somewhere else, do not generate refs or anything,
44 // and link to a different ref source
45 } type = Normal;
46
47 ProjectInfo(std::string name, std::string source_path, Type t = Normal)
48 : name(std::move(name)), source_path(std::move(source_path)), type(t) {}
49 ProjectInfo(std::string name, std::string source_path, std::string rev)
50 : name(std::move(name)), source_path(std::move(source_path)), revision(std::move(rev)) {}
51};
52
53struct ProjectManager {
54 explicit ProjectManager(std::string outputPrefix, std::string _dataPath);
55
56 bool addProject(ProjectInfo info);
57
58 std::vector<ProjectInfo> projects;
59
60 std::string outputPrefix;
61 std::string dataPath;
62
63 // the file name need to be canonicalized
64 ProjectInfo *projectForFile(llvm::StringRef filename); // don't keep a cache
65
66 // return true if the filename should be proesseded.
67 // 'project' is the value returned by projectForFile
68 bool shouldProcess(llvm::StringRef filename, ProjectInfo *project);
69
70 std::string includeRecovery(llvm::StringRef includeName, llvm::StringRef from);
71
72private:
73 static std::vector<ProjectInfo> systemProjects();
74
75 std::unordered_multimap<std::string, std::string> includeRecoveryCache;
76};
77