compilation
This commit is contained in:
50
src/main.cc
50
src/main.cc
@@ -1,18 +1,56 @@
|
||||
#include "parser.h"
|
||||
#include "util.h"
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <sys/stat.h>
|
||||
#include <thread>
|
||||
|
||||
int main() {
|
||||
if (geteuid() != 0) {
|
||||
std::cerr << "This program needs to be ran as root.\n";
|
||||
return 1;
|
||||
}
|
||||
mkdir("/tmp/shrap", 0777);
|
||||
|
||||
std::ifstream file("zlib.shrap");
|
||||
if (!file) {
|
||||
std::cerr << "Error opening file\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::stringstream buffer;
|
||||
buffer << file.rdbuf();
|
||||
Expr pkg = Expr::parse(file);
|
||||
|
||||
Expr pkg = Expr::parse(buffer.str());
|
||||
std::cout << pkg.get("name").value << std::endl;
|
||||
}
|
||||
Expr src = pkg.get("src").children[0];
|
||||
std::string src_type = src.children[0].value;
|
||||
std::string src_url = src.children[1].value;
|
||||
std::string src_path = "/tmp/shrap/" + src.children[2].value;
|
||||
|
||||
if (src_type == "tar") {
|
||||
std::string archive_path = "/tmp/shrap/" + Util::basename(src_url);
|
||||
|
||||
// TODO: replace wget with a library for zero runtime dependencies
|
||||
Util::shell_command("wget -O " + archive_path + " " + src_url);
|
||||
|
||||
// TODO: check archive hash from src.children[3].value
|
||||
|
||||
Util::shell_command("tar xf " + archive_path + " -C /tmp/shrap/");
|
||||
} else {
|
||||
std::cerr << "ERROR: unrecognized src type: " << src_type << "\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::string jobs = std::to_string(std::thread::hardware_concurrency());
|
||||
|
||||
for (const auto &step : pkg.get("build").children) {
|
||||
std::string step_type = step.children[0].value;
|
||||
|
||||
if (step_type == "configure_make") {
|
||||
Util::shell_command("./configure --prefix=/usr", src_path);
|
||||
Util::shell_command("make -j " + jobs, src_path);
|
||||
Util::shell_command("make install", src_path);
|
||||
} else {
|
||||
std::cerr << "ERROR: unrecognized step type: " << step_type << "\n";
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user