op::optional for op::delete

--redownload, --redecompress, --clean, --dry and --verbose
implemented clean for 7z
This commit is contained in:
isanae
2020-05-02 04:03:20 -04:00
parent b9b939ead8
commit 748735d1e8
14 changed files with 128 additions and 58 deletions
+30 -4
View File
@@ -101,16 +101,42 @@ const std::string& get_conf(const std::string& name)
return itor->second;
}
bool g_redownload = false;
bool g_redecompress = false;
bool g_clean = false;
bool g_dry = false;
bool g_verbose = false;
bool conf::verbose() { return g_verbose; }
bool conf::dry() { return g_dry; }
bool conf::redownload() { return g_redownload; }
bool conf::redecompress() { return g_redecompress; }
bool conf::clean() { return g_clean; }
bool conf::verbose() { return true; }
bool conf::dry() { return false; }
std::string conf::mo_org() { return "ModOrganizer2"; }
std::string conf::mo_branch() { return "master"; }
bool conf::clean() { return g_clean; }
void conf::set_clean(bool b) { g_clean = b; }
void conf::set(int argc, char** argv)
{
for (int i=0; i<argc; ++i)
{
const std::string a = argv[i];
if (a == "--redownload")
g_redownload = true;
else if (a == "--redecompress")
g_redecompress = true;
else if (a == "--clean")
g_clean = true;
else if (a == "--dry")
g_dry = true;
else if (a == "--verbose")
g_verbose = true;
else if (a.starts_with("--"))
bail_out("unknown option " + a);
}
}
fs::path third_party::sevenz() { return "7z"; }
fs::path third_party::jom() { return "jom"; }
+6 -3
View File
@@ -5,13 +5,16 @@ namespace mob
struct conf
{
static void set(int argc, char** argv);
static bool verbose();
static bool dry();
static bool redownload();
static bool redecompress();
static bool clean();
static std::string mo_org();
static std::string mo_branch();
static bool clean();
static void set_clean(bool b);
};
struct third_party
+3 -3
View File
@@ -67,13 +67,13 @@ int run(int argc, char** argv)
{
std::vector<std::string> tasks;
conf::set(argc, argv);
for (int i=1; i<argc; ++i)
{
const std::string arg = argv[i];
if (arg == "--clean")
conf::set_clean(true);
else
if (!arg.starts_with("--"))
tasks.push_back(arg);
}
+25 -9
View File
@@ -24,11 +24,22 @@ void op::create_directories(const fs::path& p)
do_create_directories(p);
}
void op::delete_directory(const fs::path& p)
void op::delete_directory(const fs::path& p, flags f)
{
debug("deleting directory " + p.string());
check(p);
if (!fs::exists(p))
{
if (f & optional)
{
debug("not deleting directory " + p.string() + ", doesn't exist");
return;
}
bail_out("can't delete directory " + p.string() + ", doesn't exist");
}
if (fs::exists(p) && !fs::is_directory(p))
bail_out(p.string() + " is not a directory");
@@ -36,14 +47,22 @@ void op::delete_directory(const fs::path& p)
do_delete_directory(p);
}
void op::delete_file(const fs::path& p)
void op::delete_file(const fs::path& p, flags f)
{
if (!fs::exists(p))
return;
debug("deleting file " + p.string());
check(p);
if (!fs::exists(p))
{
if (f & optional)
{
debug("not deleting file " + p.string() + ", doesn't exist");
return;
}
bail_out("can't delete file " + p.string() + ", doesn't exist");
}
if (fs::exists(p) && !fs::is_regular_file(p))
bail_out("can't delete " + p.string() + ", not a file");
@@ -166,7 +185,7 @@ void op::move_to_directory(const fs::path& src, const fs::path& dest_dir)
}
void op::copy_file_to_dir_if_better(
const fs::path& file, const fs::path& dir, copy_flags f)
const fs::path& file, const fs::path& dir, flags f)
{
check(file);
check(dir);
@@ -236,9 +255,6 @@ void op::do_create_directories(const fs::path& p)
void op::do_delete_directory(const fs::path& p)
{
if (!fs::exists(p))
return;
std::error_code ec;
fs::remove_all(p, ec);
+5 -6
View File
@@ -8,23 +8,22 @@ namespace mob
class op
{
public:
enum copy_flags
enum flags
{
no_copy_flags=0,
noflags = 0,
optional = 1
};
static void touch(const fs::path& p);
static void create_directories(const fs::path& p);
static void delete_directory(const fs::path& p);
static void delete_file(const fs::path& p);
static void delete_directory(const fs::path& p, flags f=noflags);
static void delete_file(const fs::path& p, flags f=noflags);
static void remove_readonly(const fs::path& first);
static void rename(const fs::path& src, const fs::path& dest);
static void move_to_directory(const fs::path& src, const fs::path& dest_dir);
static void copy_file_to_dir_if_better(
const fs::path& file, const fs::path& dest_dir,
copy_flags f=no_copy_flags);
const fs::path& file, const fs::path& dest_dir, flags f=noflags);
private:
static void do_touch(const fs::path& p);
+5 -6
View File
@@ -14,6 +14,11 @@ fs::path openssl::source_path()
return paths::build() / ("openssl-" + versions::openssl());
}
fs::path openssl::build_path()
{
return source_path() / "build";
}
void openssl::do_fetch()
{
const auto file = run_tool(downloader(source_url()));
@@ -104,12 +109,6 @@ fs::path openssl::include_path()
return openssl::source_path() / "include";
}
fs::path openssl::build_path()
{
return source_path() / "build";
}
url openssl::source_url()
{
return
+7 -8
View File
@@ -14,6 +14,11 @@ fs::path pyqt::source_path()
return paths::build() / ("PyQt5-" + versions::pyqt());
}
fs::path pyqt::build_path()
{
return source_path() / "build";
}
void pyqt::do_fetch()
{
const auto file = run_tool(downloader(source_url()));
@@ -64,8 +69,7 @@ void pyqt::do_build_and_install()
// sip-install.exe has trouble with deleting the build/ directory and
// trying to recreate it to fast, giving an access denied error; do it
// here instead
if (fs::exists(source_path() / "build"))
op::delete_directory(source_path() / "build");
op::delete_directory(source_path() / "build", op::optional);
run_tool(process_runner(process()
.binary(sip::sip_install_exe())
@@ -73,7 +77,7 @@ void pyqt::do_build_and_install()
.arg("--verbose")
.arg("--pep484-pyi")
.arg("--link-full-dll")
.arg("--build-dir", build_dir())
.arg("--build-dir", build_path())
.arg("--enable", "pylupdate") // these are not in modules so they
.arg("--enable", "pyrcc") // don't get copied below
.args(zip(repeat("--enable"), modules))
@@ -139,11 +143,6 @@ url pyqt::source_url()
"PyQt5-" + versions::pyqt() + ".tar.gz";
}
fs::path pyqt::build_dir()
{
return source_path() / "build";
}
fs::path pyqt::sip_install_file()
{
return "PyQt5_sip-" + versions::pyqt_sip() + ".tar.gz";
+5 -5
View File
@@ -42,6 +42,11 @@ fs::path python::source_path()
return paths::build() / ("python-" + s);
}
fs::path python::build_path()
{
return source_path() / "PCBuild" / "amd64";
}
void python::do_fetch()
{
run_tool(git_clone()
@@ -121,11 +126,6 @@ void python::install_pip()
.arg("-m", "ensurepip")));
}
fs::path python::build_path()
{
return source_path() / "PCBuild" / "amd64";
}
fs::path python::python_exe()
{
return build_path() / "python.exe";
+5
View File
@@ -37,6 +37,11 @@ void sevenz::do_build_and_install()
paths::install_dlls());
}
void sevenz::do_clean()
{
op::delete_directory(module_to_build() / "x64", op::optional);
}
url sevenz::source_url()
{
return "https://www.7-zip.org/a/7z" + version_for_url() + "-src.7z";
+9 -1
View File
@@ -1,7 +1,8 @@
#include "pch.h"
#include "task.h"
#include "../conf.h"
#include "../op.h"
#include "../tools.h"
#include "../utility.h"
namespace mob
{
@@ -85,6 +86,9 @@ void task::run()
{
try
{
if (conf::clean())
clean();
check_interrupted();
fetch();
check_interrupted();
@@ -136,6 +140,10 @@ void task::build_and_install()
do_build_and_install();
}
void task::clean()
{
do_clean();
}
void task::check_interrupted()
{
+6 -2
View File
@@ -29,21 +29,25 @@ public:
static void interrupt_all();
const std::string& name() const;
virtual fs::path get_source_path() const = 0;
void run();
void interrupt();
void join();
void fetch();
void build_and_install();
void clean();
protected:
task(std::string name);
void check_interrupted();
virtual void do_fetch() {};
virtual void do_build_and_install() {};
virtual void do_fetch() {}
virtual void do_build_and_install() {}
virtual void do_clean() {}
template <class Tool>
auto run_tool(Tool&& t)
+4 -3
View File
@@ -181,6 +181,7 @@ class openssl : public basic_task<openssl>
{
public:
openssl();
static fs::path source_path();
static fs::path include_path();
@@ -195,8 +196,8 @@ private:
void copy_dlls_to(const fs::path& dir);
void copy_pdbs_to(const fs::path& dir);
static fs::path build_path();
static url source_url();
static fs::path build_path();
static std::vector<std::string> output_names();
static std::smatch parse_version();
static std::string version_no_tags();
@@ -208,7 +209,6 @@ class pyqt : public basic_task<pyqt>
{
public:
pyqt();
static fs::path source_path();
protected:
@@ -216,8 +216,8 @@ protected:
void do_build_and_install() override;
static url source_url();
static fs::path build_dir();
static fs::path sip_install_file();
static fs::path build_path();
};
@@ -278,6 +278,7 @@ public:
protected:
void do_fetch() override;
void do_build_and_install() override;
void do_clean() override;
private:
static url source_url();
+16 -4
View File
@@ -126,7 +126,12 @@ void downloader::do_run()
for (auto&& u : urls_)
{
const auto file = path_for_url(u);
if (fs::exists(file))
if (conf::redownload())
{
op::delete_file(file, op::optional);
}
else if (fs::exists(file))
{
file_ = file;
debug("download " + file_.string() + " already exists");
@@ -281,7 +286,11 @@ decompresser& decompresser::output(const fs::path& dir)
void decompresser::do_run()
{
if (fs::exists(interrupt_file()))
if (conf::redecompress())
{
op::delete_directory(where_, op::optional);
}
else if (fs::exists(interrupt_file()))
{
debug("found interrupt file " + interrupt_file().string());
info("previous decompression was interrupted; resuming");
@@ -559,8 +568,11 @@ void cmake::do_run()
{
for (auto&& [k, g] : all_generators())
{
op::delete_directory(root_ / g.output_dir(arch::x86));
op::delete_directory(root_ / g.output_dir(arch::x64));
op::delete_directory(
root_ / g.output_dir(arch::x86), op::optional);
op::delete_directory(
root_ / g.output_dir(arch::x64), op::optional);
}
}
+2 -4
View File
@@ -170,8 +170,7 @@ file_deleter::~file_deleter()
void file_deleter::delete_now()
{
if (fs::exists(p_))
op::delete_file(p_);
op::delete_file(p_, op::optional);
}
void file_deleter::cancel()
@@ -193,8 +192,7 @@ directory_deleter::~directory_deleter()
void directory_deleter::delete_now()
{
if (fs::exists(p_))
op::delete_directory(p_);
op::delete_directory(p_, op::optional);
}
void directory_deleter::cancel()