2020-04-29 22:10:55 -04:00
|
|
|
#include "pch.h"
|
|
|
|
|
#include "tasks.h"
|
|
|
|
|
|
2020-05-02 03:12:34 -04:00
|
|
|
namespace mob
|
2020-04-29 22:10:55 -04:00
|
|
|
{
|
|
|
|
|
|
|
|
|
|
openssl::openssl()
|
|
|
|
|
: basic_task("openssl")
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-17 14:14:29 -04:00
|
|
|
std::string openssl::version()
|
2020-05-07 11:08:33 -04:00
|
|
|
{
|
2020-05-17 15:50:15 -04:00
|
|
|
return conf::version_by_name("openssl");
|
2020-05-07 11:08:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool openssl::prebuilt()
|
|
|
|
|
{
|
2020-05-17 15:50:15 -04:00
|
|
|
return conf::prebuilt_by_name("openssl");
|
2020-05-07 11:08:33 -04:00
|
|
|
}
|
|
|
|
|
|
2020-04-29 22:10:55 -04:00
|
|
|
fs::path openssl::source_path()
|
|
|
|
|
{
|
2020-05-07 11:08:33 -04:00
|
|
|
return paths::build() / ("openssl-" + version());
|
2020-04-29 22:10:55 -04:00
|
|
|
}
|
|
|
|
|
|
2020-05-02 04:03:20 -04:00
|
|
|
fs::path openssl::build_path()
|
|
|
|
|
{
|
|
|
|
|
return source_path() / "build";
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-07 15:59:29 -04:00
|
|
|
fs::path openssl::bin_path()
|
|
|
|
|
{
|
|
|
|
|
return build_path() / "bin";
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-25 00:31:49 -04:00
|
|
|
void openssl::do_clean(clean c)
|
2020-05-04 06:41:44 -04:00
|
|
|
{
|
2020-05-25 01:24:56 -04:00
|
|
|
instrument<times::clean>([&]
|
2020-05-20 05:41:19 -04:00
|
|
|
{
|
2020-05-25 01:24:56 -04:00
|
|
|
if (prebuilt())
|
2020-05-25 00:31:49 -04:00
|
|
|
{
|
2020-05-25 01:24:56 -04:00
|
|
|
if (is_set(c, clean::redownload))
|
|
|
|
|
run_tool(downloader(prebuilt_url(), downloader::clean));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (is_set(c, clean::redownload))
|
|
|
|
|
run_tool(downloader(source_url(), downloader::clean));
|
2020-05-25 01:43:16 -04:00
|
|
|
}
|
2020-05-25 01:24:56 -04:00
|
|
|
|
2020-05-25 01:43:16 -04:00
|
|
|
if (is_any_set(c, clean::reextract|clean::reconfigure|clean::rebuild))
|
|
|
|
|
{
|
|
|
|
|
cx().trace(context::reextract, "deleting {}", source_path());
|
|
|
|
|
op::delete_directory(cx(), source_path(), op::optional);
|
|
|
|
|
return;
|
2020-05-25 01:24:56 -04:00
|
|
|
}
|
|
|
|
|
});
|
2020-05-04 06:41:44 -04:00
|
|
|
}
|
|
|
|
|
|
2020-04-29 22:10:55 -04:00
|
|
|
void openssl::do_fetch()
|
2020-05-07 13:55:40 -04:00
|
|
|
{
|
|
|
|
|
if (prebuilt())
|
|
|
|
|
fetch_prebuilt();
|
|
|
|
|
else
|
|
|
|
|
fetch_from_source();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void openssl::do_build_and_install()
|
|
|
|
|
{
|
|
|
|
|
if (prebuilt())
|
|
|
|
|
build_and_install_prebuilt();
|
|
|
|
|
else
|
|
|
|
|
build_and_install_from_source();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void openssl::fetch_prebuilt()
|
|
|
|
|
{
|
|
|
|
|
cx().trace(context::generic, "using prebuilt openssl");
|
|
|
|
|
|
2020-05-21 04:45:49 -04:00
|
|
|
const auto file = instrument<times::fetch>([&]
|
2020-05-20 05:41:19 -04:00
|
|
|
{
|
|
|
|
|
return run_tool(downloader(prebuilt_url()));
|
|
|
|
|
});
|
2020-05-07 13:55:40 -04:00
|
|
|
|
2020-05-21 04:45:49 -04:00
|
|
|
instrument<times::extract>([&]
|
2020-05-20 05:41:19 -04:00
|
|
|
{
|
|
|
|
|
run_tool(extractor()
|
|
|
|
|
.file(file)
|
|
|
|
|
.output(source_path()));
|
|
|
|
|
});
|
2020-05-07 13:55:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void openssl::fetch_from_source()
|
2020-04-29 22:10:55 -04:00
|
|
|
{
|
2020-05-21 04:45:49 -04:00
|
|
|
const auto file = instrument<times::fetch>([&]
|
2020-05-20 05:41:19 -04:00
|
|
|
{
|
|
|
|
|
return run_tool(downloader(source_url()));
|
|
|
|
|
});
|
2020-04-29 22:10:55 -04:00
|
|
|
|
2020-05-21 04:45:49 -04:00
|
|
|
instrument<times::extract>([&]
|
2020-05-20 05:41:19 -04:00
|
|
|
{
|
|
|
|
|
run_tool(extractor()
|
|
|
|
|
.file(file)
|
|
|
|
|
.output(source_path()));
|
|
|
|
|
});
|
2020-04-29 22:10:55 -04:00
|
|
|
}
|
|
|
|
|
|
2020-05-07 13:55:40 -04:00
|
|
|
void openssl::build_and_install_prebuilt()
|
|
|
|
|
{
|
2020-05-21 04:45:49 -04:00
|
|
|
instrument<times::install>([&]
|
2020-05-20 05:41:19 -04:00
|
|
|
{
|
|
|
|
|
copy_files();
|
|
|
|
|
});
|
2020-05-07 13:55:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void openssl::build_and_install_from_source()
|
2020-04-29 22:10:55 -04:00
|
|
|
{
|
2020-05-21 04:45:49 -04:00
|
|
|
instrument<times::configure>([&]
|
2020-05-20 05:41:19 -04:00
|
|
|
{
|
|
|
|
|
if (fs::exists(source_path() / "makefile"))
|
|
|
|
|
cx().trace(context::bypass, "openssl already configured");
|
|
|
|
|
else
|
|
|
|
|
configure();
|
|
|
|
|
});
|
2020-04-29 22:10:55 -04:00
|
|
|
|
2020-05-21 04:45:49 -04:00
|
|
|
instrument<times::build>([&]
|
2020-05-20 05:41:19 -04:00
|
|
|
{
|
|
|
|
|
install_engines();
|
|
|
|
|
});
|
2020-05-07 13:55:40 -04:00
|
|
|
|
2020-05-21 04:45:49 -04:00
|
|
|
instrument<times::install>([&]
|
2020-05-20 05:41:19 -04:00
|
|
|
{
|
|
|
|
|
op::copy_file_to_dir_if_better(cx(),
|
|
|
|
|
source_path() / "ms" / "applink.c",
|
|
|
|
|
include_path());
|
2020-05-07 13:55:40 -04:00
|
|
|
|
2020-05-20 05:41:19 -04:00
|
|
|
copy_files();
|
|
|
|
|
});
|
2020-04-29 22:10:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void openssl::configure()
|
|
|
|
|
{
|
2020-05-02 02:41:34 -04:00
|
|
|
run_tool(process_runner(process()
|
2020-05-17 12:47:44 -04:00
|
|
|
.binary(perl::binary())
|
2020-04-29 22:10:55 -04:00
|
|
|
.arg("Configure")
|
2020-05-13 11:51:48 -04:00
|
|
|
.arg("VC-WIN64A")
|
2020-04-29 22:10:55 -04:00
|
|
|
.arg("--openssldir=", build_path())
|
|
|
|
|
.arg("--prefix=", build_path())
|
|
|
|
|
.arg("-FS")
|
|
|
|
|
.arg("-MP1")
|
2020-05-13 11:51:48 -04:00
|
|
|
.arg("-wd4566")
|
2020-05-02 02:41:34 -04:00
|
|
|
.cwd(source_path())
|
|
|
|
|
.env(env::vs(arch::x64))));
|
2020-04-29 22:10:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void openssl::install_engines()
|
|
|
|
|
{
|
2020-05-04 06:41:44 -04:00
|
|
|
const int max_tries = 3;
|
|
|
|
|
|
|
|
|
|
for (int tries=0; tries<max_tries; ++tries)
|
2020-04-29 22:10:55 -04:00
|
|
|
{
|
2020-05-07 18:19:25 -04:00
|
|
|
const int exit_code = run_tool(jom()
|
2020-04-29 22:10:55 -04:00
|
|
|
.path(source_path())
|
|
|
|
|
.target("install_engines")
|
2020-05-02 02:41:34 -04:00
|
|
|
.flag(jom::allow_failure));
|
2020-04-29 22:10:55 -04:00
|
|
|
|
|
|
|
|
if (exit_code == 0)
|
|
|
|
|
return;
|
2020-05-04 06:41:44 -04:00
|
|
|
|
|
|
|
|
cx().debug(context::generic,
|
|
|
|
|
"jom /J regularly fails with openssh because of race conditions; "
|
|
|
|
|
"trying again");
|
2020-04-29 22:10:55 -04:00
|
|
|
}
|
|
|
|
|
|
2020-05-04 06:41:44 -04:00
|
|
|
cx().debug(context::generic,
|
2020-05-11 07:44:37 -04:00
|
|
|
"jom /J has failed more than {} times, "
|
|
|
|
|
"restarting one last time without /J; that one should work",
|
|
|
|
|
max_tries);
|
2020-05-04 06:41:44 -04:00
|
|
|
|
2020-04-29 22:10:55 -04:00
|
|
|
run_tool(jom()
|
|
|
|
|
.path(source_path())
|
|
|
|
|
.target("install_engines")
|
|
|
|
|
.flag(jom::single_job));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void openssl::copy_files()
|
|
|
|
|
{
|
|
|
|
|
copy_dlls_to(paths::install_dlls());
|
|
|
|
|
copy_pdbs_to(paths::install_pdbs());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void openssl::copy_dlls_to(const fs::path& dir)
|
|
|
|
|
{
|
|
|
|
|
for (auto&& name : output_names())
|
|
|
|
|
{
|
2020-05-04 05:38:23 -04:00
|
|
|
op::copy_file_to_dir_if_better(cx(),
|
2020-05-07 15:59:29 -04:00
|
|
|
bin_path() / (name + ".dll"), dir);
|
2020-04-29 22:10:55 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void openssl::copy_pdbs_to(const fs::path& dir)
|
|
|
|
|
{
|
|
|
|
|
for (auto&& name : output_names())
|
|
|
|
|
{
|
2020-05-04 05:38:23 -04:00
|
|
|
op::copy_file_to_dir_if_better(cx(),
|
2020-05-07 15:59:29 -04:00
|
|
|
bin_path() / (name + ".pdb"), dir);
|
2020-04-29 22:10:55 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fs::path openssl::include_path()
|
|
|
|
|
{
|
|
|
|
|
return openssl::source_path() / "include";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
url openssl::source_url()
|
|
|
|
|
{
|
|
|
|
|
return
|
|
|
|
|
"https://www.openssl.org/source/"
|
2020-05-07 11:08:33 -04:00
|
|
|
"openssl-" + version() + ".tar.gz";
|
2020-04-29 22:10:55 -04:00
|
|
|
}
|
|
|
|
|
|
2020-05-07 13:55:40 -04:00
|
|
|
url openssl::prebuilt_url()
|
|
|
|
|
{
|
|
|
|
|
return make_prebuilt_url("openssl-prebuilt-" + version() + ".7z");
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-29 22:10:55 -04:00
|
|
|
std::vector<std::string> openssl::output_names()
|
|
|
|
|
{
|
|
|
|
|
return
|
|
|
|
|
{
|
2020-05-17 19:21:26 -04:00
|
|
|
"libcrypto-" + version_no_patch_underscores() + "-x64",
|
|
|
|
|
"libssl-" + version_no_patch_underscores() + "-x64"
|
2020-04-29 22:10:55 -04:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-17 19:21:26 -04:00
|
|
|
openssl::version_info openssl::parsed_version()
|
2020-04-29 22:10:55 -04:00
|
|
|
{
|
2020-05-17 19:21:26 -04:00
|
|
|
// 1.2.3d
|
2020-04-29 22:10:55 -04:00
|
|
|
// everything but 1 is optional
|
2020-05-17 19:21:26 -04:00
|
|
|
std::regex re(
|
|
|
|
|
"(\\d+)" // 1
|
|
|
|
|
"(?:"
|
|
|
|
|
"\\.(\\d+)" // .2
|
|
|
|
|
"(?:"
|
|
|
|
|
"\\.(\\d+)([a-zA-Z]+)?" // .3d
|
|
|
|
|
")?"
|
|
|
|
|
")?");
|
|
|
|
|
|
2020-04-29 22:10:55 -04:00
|
|
|
std::smatch m;
|
|
|
|
|
|
2020-05-17 14:14:29 -04:00
|
|
|
const auto s = version();
|
|
|
|
|
|
|
|
|
|
if (!std::regex_match(s, m, re))
|
|
|
|
|
bail_out("bad openssl version '{}'", s);
|
2020-04-29 22:10:55 -04:00
|
|
|
|
2020-05-17 19:21:26 -04:00
|
|
|
return {m[1], m[2], m[3]};
|
2020-04-29 22:10:55 -04:00
|
|
|
}
|
|
|
|
|
|
2020-05-17 19:21:26 -04:00
|
|
|
std::string openssl::version_no_patch_underscores()
|
2020-04-29 22:10:55 -04:00
|
|
|
{
|
2020-05-17 19:21:26 -04:00
|
|
|
auto v = parsed_version();
|
2020-04-29 22:10:55 -04:00
|
|
|
|
2020-05-17 19:21:26 -04:00
|
|
|
std::string s = v.major;
|
2020-04-29 22:10:55 -04:00
|
|
|
|
2020-05-17 19:21:26 -04:00
|
|
|
if (v.minor != "")
|
|
|
|
|
s += "_" + v.minor;
|
2020-04-29 22:10:55 -04:00
|
|
|
|
|
|
|
|
return s;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace
|