-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcppkg.cpp
More file actions
170 lines (157 loc) · 7.38 KB
/
Copy pathcppkg.cpp
File metadata and controls
170 lines (157 loc) · 7.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#include <fmt/format.h>
#include <cppm/util/filesystem.h>
#include <cppm/util/optional.hpp>
#include <cppm/cppkg/cppkg.h>
#include <cppm/core/cppm_tool.hpp>
#include <range/v3/all.hpp>
#include <map>
#include <list>
#include <serdepp/adaptor/toml11.hpp>
namespace cppkg
{
using namespace fmt::literals;
cppm::core::Dependency parse(const std::string& name, std::string path) {
using namespace cppm;
using deps = std::map<std::string, core::Dependency>;
path = path != "" ? "{}/"_format(path) : "";
auto dep = serde::serialize<deps>(toml::parse("{}cppkg.toml"_format(path)));
dep[name].name = name;
return dep[name];
}
void init(const std::string& name) {
using namespace cppm::core;
Dependency dep;
dep.name = name; dep.type = cppkg_type::lib;
init(dep);
}
void init(cppm::core::Dependency& dep) {
using namespace cppm;
auto value = [](const std::string& str){ return "\"{}\""_format(str); };
//auto convert = [](const bool flag) { return flag ? "true" : "false"; };
util::panic(!fs::exists("cppkg.toml"), "existed cppkg.toml");
auto url_type = dep.git ? "git={}"_format(value(*dep.git)) : "url={}"_format(value(*dep.url));
auto is_branch = dep.branch ? "" : "#";
util::create("cppkg.toml");
util::write("cppkg.toml"
,"[{}]\n"_format(dep.name)
+"version={} #(require)\n"_format(value(dep.version))
+"type=\"{}\" #lib(default) | bin | cmake\n"_format(serde::to_string(dep.type))
+"description={} #(require)\n"_format(value(dep.description))
+"module={} #(require) if none_module=true -> no require\n"_format(value(*dep.module))
+"{} #(require)\n"_format(url_type)
+"{}branch={} #(optional & require git)\n"_format(is_branch, value(*dep.branch))
+"#link=private #default\n"
//+"#components={} #(optional)\n"_format(value(*dep.components))
//+"#none_module={} #(optional)\n"_format(convert(*dep.none_module))
//+"#helper={} #(optional)\n"_format(value(dep.helper))
//+"#load_path={} #(optional) (package_root) + /path/to/"_format(value(dep.load_path))
);
}
void build(const std::string& name) {
using namespace cppm;
auto dep = cppkg::parse(name);
auto dir_name = "{}/{}"_format(dep.name, dep.version);
util::panic(!fs::exists(dir_name), "existed {}"_format(dir_name));
fs::create_directories(dir_name);
fs::copy("cppkg.toml", dir_name+"/cppkg.toml");
fs::remove("cppkg.toml");
auto file = "{}/{}.cmake.in"_format(dir_name,dep.name);
util::write(file, core::cppm_download_package(dep));
fmt::print("[cppkg] Success to make {} package\n",dep.name);
}
void build() {
//using namespace cppm;
//std::optional<std::list<core::Dependency>> deps;
//toml::orm::parser(deps,"cppkg.toml");
//if(deps) {
// ranges::for_each(*deps, [](auto it){
//
// });
//}
//auto file = "{}/{}.cmake.in"_format(dir_name,dep.name);
//util::write(file, core::cppm_download_package(dep));
//fmt::print("[cppkg] Success to make {} package\n",dep.name);
}
void regist(const std::string& name) {
using namespace cppm;
core::Dependency dep;
cppkg::parse(name);
auto local_path = "{0}repo/local"_format(core::cppm_root());
auto pack_path = "{0}/{1}/{2}"_format(local_path, dep.name, dep.version);
if(!fs::exists(local_path)) fs::create_directories(pack_path);
if(fs::exists(pack_path)) fs::remove_all(pack_path);
util::recursive_copy(name,pack_path);
fmt::print("update {0}/{1} in local-repo [\"{2}\"]\n", dep.name, dep.version, pack_path);
}
Repos list() {
using namespace cppm;
auto root_path = "{0}repo"_format(core::cppm_root());
Repos cppkg_repos;
if(auto repos = util::file_list(root_path)) {
for(auto repo : *repos) {
auto rname = repo.path().filename().generic_string();
if(auto pkgs = util::file_list("{0}/{1}"_format(root_path,rname))) {
for(auto& pkg : *pkgs) {
auto pname = pkg.path().filename().generic_string();
if(pname == ".git" || pname == "README.md" || pname == "_cppm_test") continue;
if(auto versions = util::file_list("{0}/{1}/{2}"_format(root_path,rname,pname))) {
for(auto& ver : *versions) {
auto vname = ver.path().filename().generic_string();
cppkg_repos[rname].pkgs[pname].versions[vname] = "{0}/{1}/{2}/{3}"_format(root_path, rname, pname, vname);
}
}
}
}
}
}
return cppkg_repos;
}
dep_in_repo search(const std::string& name, const std::string& version) {
using namespace cppm;
auto cppkg_path = "{0}repo"_format(core::cppm_root());
auto repos = util::panic(util::file_list(cppkg_path), "can't find cppkg repos");
std::map<std::string,std::string> find_repos;
for(auto& repo : repos) {
auto repo_name = repo.path().filename().string();
if(version == "latest") {
auto target = "{0}/{1}/{2}"_format(cppkg_path,repo_name,name);
if(!fs::exists(target)) { continue; }
if(auto latest = Version::get_latest_version_folder(target)) {
find_repos[repo_name] = *latest;
}
}
else {
auto target = "{0}/{1}/{2}/{3}"_format(cppkg_path, repo_name, name, version);
if(fs::exists(target)) { find_repos[repo_name] = target; }
}
}
util::panic(!find_repos.empty(), "can't find {0}/{1} package"_format(name, version));
std::string path = "";
if (find_repos.find("cppkg") != find_repos.end()) path = find_repos["cppkg"];
else if (find_repos.find("local") != find_repos.end()) path = find_repos["local"];
else path = find_repos.begin()->second;
auto dep = cppkg::parse(name,path);
return {dep, path};
}
void install(cppm::core::Config& config, const dep_in_repo& depr) {
using namespace cppm;
fs::create_directory(config.path.thirdparty);
auto [dep, path] = depr;
if(dep.helper) {
fmt::print("{0}\n",*dep.helper);
fmt::print("Install {0} to {1}/Modules/\n",dep.helper, config.path.cmake);
if(!fs::exists("{0}/Modules/"_format(config.path.cmake))) {
fs::create_directories("{0}/Modules"_format(config.path.cmake));
}
fs::copy("{0}/{1}"_format(path,dep.helper)
,"{0}/Modules/{1}"_format(config.path.cmake,dep.helper));
}
util::recursive_copy(path,"{0}/{1}/{2}"_format(
config.path.thirdparty, dep.name, dep.version));
fmt::print("Install Cppkg {0}/{1}\n",dep.name, dep.version);
}
cppm::core::Dependency cppkg_auto_gen(std::string& path) {
cppm::core::Dependency dep;
return dep;
}
}