diff options
Diffstat (limited to 'toolsrc/src/vcpkg/build.cpp')
| -rw-r--r-- | toolsrc/src/vcpkg/build.cpp | 694 |
1 files changed, 427 insertions, 267 deletions
diff --git a/toolsrc/src/vcpkg/build.cpp b/toolsrc/src/vcpkg/build.cpp index daff7e6c8..618e4126b 100644 --- a/toolsrc/src/vcpkg/build.cpp +++ b/toolsrc/src/vcpkg/build.cpp @@ -9,6 +9,7 @@ #include <vcpkg/base/system.debug.h>
#include <vcpkg/base/system.print.h>
#include <vcpkg/base/system.process.h>
+#include <vcpkg/base/util.h>
#include <vcpkg/build.h>
#include <vcpkg/commands.h>
@@ -23,6 +24,7 @@ #include <vcpkg/vcpkglib.h>
using vcpkg::Build::BuildResult;
+using vcpkg::Dependencies::PathsPortFileProvider;
using vcpkg::Parse::ParseControlErrorInfo;
using vcpkg::Parse::ParseExpected;
@@ -31,43 +33,27 @@ namespace vcpkg::Build::Command using Dependencies::InstallPlanAction;
using Dependencies::InstallPlanType;
- static constexpr StringLiteral OPTION_CHECKS_ONLY = "--checks-only";
-
void perform_and_exit_ex(const FullPackageSpec& full_spec,
- const fs::path& port_dir,
+ const SourceControlFileLocation& scfl,
const ParsedArguments& options,
const VcpkgPaths& paths)
{
- const PackageSpec& spec = full_spec.package_spec;
- if (Util::Sets::contains(options.switches, OPTION_CHECKS_ONLY))
- {
- const auto pre_build_info = Build::PreBuildInfo::from_triplet_file(paths, spec.triplet());
- const auto build_info = Build::read_build_info(paths.get_filesystem(), paths.build_info_file_path(spec));
- const size_t error_count = PostBuildLint::perform_all_checks(spec, paths, pre_build_info, build_info);
- Checks::check_exit(VCPKG_LINE_INFO, error_count == 0);
- Checks::exit_success(VCPKG_LINE_INFO);
- }
-
- const ParseExpected<SourceControlFile> source_control_file =
- Paragraphs::try_load_port(paths.get_filesystem(), port_dir);
+ vcpkg::Util::unused(options);
- if (!source_control_file.has_value())
- {
- print_error_message(source_control_file.error());
- Checks::exit_fail(VCPKG_LINE_INFO);
- }
+ const StatusParagraphs status_db = database_load_check(paths);
+ const PackageSpec& spec = full_spec.package_spec;
+ const SourceControlFile& scf = *scfl.source_control_file;
- const auto& scf = source_control_file.value_or_exit(VCPKG_LINE_INFO);
Checks::check_exit(VCPKG_LINE_INFO,
- spec.name() == scf->core_paragraph->name,
+ spec.name() == scf.core_paragraph->name,
"The Source field inside the CONTROL file does not match the port directory: '%s' != '%s'",
- scf->core_paragraph->name,
+ scf.core_paragraph->name,
spec.name());
- const StatusParagraphs status_db = database_load_check(paths);
const Build::BuildPackageOptions build_package_options{
Build::UseHeadVersion::NO,
Build::AllowDownloads::YES,
+ Build::OnlyDownloads::NO,
Build::CleanBuildtrees::NO,
Build::CleanPackages::NO,
Build::CleanDownloads::NO,
@@ -79,8 +65,7 @@ namespace vcpkg::Build::Command std::set<std::string> features_as_set(full_spec.features.begin(), full_spec.features.end());
features_as_set.emplace("core");
- const Build::BuildPackageConfig build_config{
- *scf, spec.triplet(), fs::path{port_dir}, build_package_options, features_as_set};
+ const Build::BuildPackageConfig build_config{scfl, spec.triplet(), build_package_options, features_as_set};
const auto build_timer = Chrono::ElapsedTimer::create_started();
const auto result = Build::build_package(paths, build_config, status_db);
@@ -111,15 +96,11 @@ namespace vcpkg::Build::Command Checks::exit_success(VCPKG_LINE_INFO);
}
- static constexpr std::array<CommandSwitch, 1> BUILD_SWITCHES = {{
- {OPTION_CHECKS_ONLY, "Only run checks, do not rebuild package"},
- }};
-
const CommandStructure COMMAND_STRUCTURE = {
Help::create_example_string("build zlib:x64-windows"),
1,
1,
- {BUILD_SWITCHES, {}},
+ {{}, {}},
nullptr,
};
@@ -128,10 +109,19 @@ namespace vcpkg::Build::Command // Build only takes a single package and all dependencies must already be installed
const ParsedArguments options = args.parse_arguments(COMMAND_STRUCTURE);
std::string first_arg = args.command_arguments.at(0);
+
const FullPackageSpec spec = Input::check_and_get_full_package_spec(
std::move(first_arg), default_triplet, COMMAND_STRUCTURE.example_text);
+
Input::check_triplet(spec.package_spec.triplet(), paths);
- perform_and_exit_ex(spec, paths.port_dir(spec.package_spec), options, paths);
+
+ PathsPortFileProvider provider(paths, args.overlay_ports.get());
+ const auto port_name = spec.package_spec.name();
+ const auto* scfl = provider.get_control_file(port_name).get();
+
+ Checks::check_exit(VCPKG_LINE_INFO, scfl != nullptr, "Error: Couldn't find port '%s'", port_name);
+
+ perform_and_exit_ex(spec, *scfl, options, paths);
}
}
@@ -195,7 +185,7 @@ namespace vcpkg::Build static const std::string LIBRARY_LINKAGE = "LibraryLinkage";
}
- CStringView to_vcvarsall_target(const std::string& cmake_system_name)
+ static CStringView to_vcvarsall_target(const std::string& cmake_system_name)
{
if (cmake_system_name.empty()) return "";
if (cmake_system_name == "Windows") return "";
@@ -204,7 +194,7 @@ namespace vcpkg::Build Checks::exit_with_message(VCPKG_LINE_INFO, "Unsupported vcvarsall target %s", cmake_system_name);
}
- CStringView to_vcvarsall_toolchain(const std::string& target_architecture, const Toolset& toolset)
+ static CStringView to_vcvarsall_toolchain(const std::string& target_architecture, const Toolset& toolset)
{
auto maybe_target_arch = System::to_cpu_architecture(target_architecture);
Checks::check_exit(
@@ -228,6 +218,23 @@ namespace vcpkg::Build }));
}
+ static auto make_env_passthrough(const PreBuildInfo& pre_build_info) -> std::unordered_map<std::string, std::string>
+ {
+ std::unordered_map<std::string, std::string> env;
+
+ for (auto&& env_var : pre_build_info.passthrough_env_vars)
+ {
+ auto env_val = System::get_environment_variable(env_var);
+
+ if (env_val)
+ {
+ env[env_var] = env_val.value_or_exit(VCPKG_LINE_INFO);
+ }
+ }
+
+ return env;
+ }
+
std::string make_build_env_cmd(const PreBuildInfo& pre_build_info, const Toolset& toolset)
{
if (pre_build_info.external_toolchain_file.has_value()) return "";
@@ -268,11 +275,12 @@ namespace vcpkg::Build {
bpgh.version = *p_ver;
}
+
bcf->core_paragraph = std::move(bpgh);
return bcf;
}
- static void write_binary_control_file(const VcpkgPaths& paths, BinaryControlFile bcf)
+ static void write_binary_control_file(const VcpkgPaths& paths, const BinaryControlFile& bcf)
{
std::string start = Strings::serialize(bcf.core_paragraph);
for (auto&& feature : bcf.features)
@@ -283,23 +291,37 @@ namespace vcpkg::Build paths.get_filesystem().write_contents(binary_control_file, start, VCPKG_LINE_INFO);
}
+ static std::vector<Features> get_dependencies(const SourceControlFile& scf,
+ const std::set<std::string>& feature_list,
+ const Triplet& triplet)
+ {
+ return Util::fmap_flatten(feature_list, [&](std::string const& feature) -> std::vector<Features> {
+ if (feature == "core")
+ {
+ return filter_dependencies_to_features(scf.core_paragraph->depends, triplet);
+ }
+
+ auto maybe_feature = scf.find_feature(feature);
+ Checks::check_exit(VCPKG_LINE_INFO, maybe_feature.has_value());
+
+ return filter_dependencies_to_features(maybe_feature.get()->depends, triplet);
+ });
+ }
+
+ static std::vector<std::string> get_dependency_names(const SourceControlFile& scf,
+ const std::set<std::string>& feature_list,
+ const Triplet& triplet)
+ {
+ return Util::sort_unique_erase(
+ Util::fmap(get_dependencies(scf, feature_list, triplet), [&](const Features& feat) { return feat.name; }));
+ }
+
static std::vector<FeatureSpec> compute_required_feature_specs(const BuildPackageConfig& config,
const StatusParagraphs& status_db)
{
const Triplet& triplet = config.triplet;
- const std::vector<std::string> dep_strings =
- Util::fmap_flatten(config.feature_list, [&](std::string const& feature) -> std::vector<std::string> {
- if (feature == "core")
- {
- return filter_dependencies(config.scf.core_paragraph->depends, triplet);
- }
-
- auto maybe_feature = config.scf.find_feature(feature);
- Checks::check_exit(VCPKG_LINE_INFO, maybe_feature.has_value());
-
- return filter_dependencies(maybe_feature.get()->depends, triplet);
- });
+ const std::vector<std::string> dep_strings = get_dependency_names(config.scf, config.feature_list, triplet);
auto dep_fspecs = FeatureSpec::from_strings_and_triplet(dep_strings, triplet);
Util::sort_unique_erase(dep_fspecs);
@@ -351,22 +373,17 @@ namespace vcpkg::Build return concurrency;
}
- static ExtendedBuildResult do_build_package(const VcpkgPaths& paths,
- const PreBuildInfo& pre_build_info,
- const PackageSpec& spec,
- const std::string& abi_tag,
- const BuildPackageConfig& config)
+ static std::vector<System::CMakeVariable> get_cmake_vars(const VcpkgPaths& paths,
+ const BuildPackageConfig& config,
+ const Triplet& triplet,
+ const Toolset& toolset)
{
- auto& fs = paths.get_filesystem();
- const Triplet& triplet = spec.triplet();
-
#if !defined(_WIN32)
// TODO: remove when vcpkg.exe is in charge for acquiring tools. Change introduced in vcpkg v0.0.107.
// bootstrap should have already downloaded ninja, but making sure it is present in case it was deleted.
vcpkg::Util::unused(paths.get_tool_exe(Tools::NINJA));
#endif
- const fs::path& cmake_exe_path = paths.get_tool_exe(Tools::CMAKE);
const fs::path& git_exe_path = paths.get_tool_exe(Tools::GIT);
std::string all_features;
@@ -375,13 +392,13 @@ namespace vcpkg::Build all_features.append(feature->name + ";");
}
- const Toolset& toolset = paths.get_toolset(pre_build_info);
-
std::vector<System::CMakeVariable> variables{
{"CMD", "BUILD"},
{"PORT", config.scf.core_paragraph->name},
{"CURRENT_PORT_DIR", config.port_dir},
- {"TARGET_TRIPLET", spec.triplet().canonical_name()},
+ {"VCPKG_ROOT_PATH", paths.root},
+ {"TARGET_TRIPLET", triplet.canonical_name()},
+ {"TARGET_TRIPLET_FILE", paths.get_triplet_file_path(triplet).u8string()},
{"VCPKG_PLATFORM_TOOLSET", toolset.version.c_str()},
{"VCPKG_USE_HEAD_VERSION", Util::Enum::to_bool(config.build_package_options.use_head_version) ? "1" : "0"},
{"DOWNLOADS", paths.downloads},
@@ -392,14 +409,58 @@ namespace vcpkg::Build {"VCPKG_CONCURRENCY", std::to_string(get_concurrency())},
};
+ if (Util::Enum::to_bool(config.build_package_options.only_downloads))
+ {
+ variables.push_back({"VCPKG_DOWNLOAD_MODE", "true"});
+ }
+
if (!System::get_environment_variable("VCPKG_FORCE_SYSTEM_BINARIES").has_value())
{
variables.push_back({"GIT", git_exe_path});
}
+ const Files::Filesystem& fs = paths.get_filesystem();
+ if (fs.is_regular_file(config.port_dir / "environment-overrides.cmake"))
+ {
+ variables.emplace_back("VCPKG_ENV_OVERRIDES_FILE", config.port_dir / "environment-overrides.cmake");
+ }
+
+ std::vector<FeatureSpec> dependencies =
+ filter_dependencies_to_specs(config.scfl.source_control_file->core_paragraph->depends, triplet);
+
+ std::vector<std::string> port_toolchains;
+ for (const FeatureSpec& dependency : dependencies)
+ {
+ const fs::path port_toolchain_path = paths.installed / dependency.triplet().canonical_name() / "share" /
+ dependency.spec().name() / "port-toolchain.cmake";
+
+ if (fs.is_regular_file(port_toolchain_path))
+ {
+ System::print2(port_toolchain_path.u8string());
+ port_toolchains.emplace_back(port_toolchain_path.u8string());
+ }
+ }
+
+ if (!port_toolchains.empty())
+ {
+ variables.emplace_back("VCPKG_PORT_TOOLCHAINS", Strings::join(";", port_toolchains));
+ }
+
+ return variables;
+ }
+
+ static std::string make_build_cmd(const VcpkgPaths& paths,
+ const PreBuildInfo& pre_build_info,
+ const BuildPackageConfig& config,
+ const Triplet& triplet)
+ {
+ const Toolset& toolset = paths.get_toolset(pre_build_info);
+ const fs::path& cmake_exe_path = paths.get_tool_exe(Tools::CMAKE);
+ std::vector<System::CMakeVariable> variables = get_cmake_vars(paths, config, triplet, toolset);
+
const std::string cmd_launch_cmake = System::make_cmake_cmd(cmake_exe_path, paths.ports_cmake, variables);
- auto command = make_build_env_cmd(pre_build_info, toolset);
+ std::string command = make_build_env_cmd(pre_build_info, toolset);
if (!command.empty())
{
#ifdef _WIN32
@@ -408,10 +469,112 @@ namespace vcpkg::Build command.append(" && ");
#endif
}
+
command.append(cmd_launch_cmake);
+
+ return command;
+ }
+
+ static std::string get_triplet_abi(const VcpkgPaths& paths,
+ const PreBuildInfo& pre_build_info,
+ const Triplet& triplet)
+ {
+ static std::map<fs::path, std::string> s_hash_cache;
+
+ const fs::path triplet_file_path = paths.get_triplet_file_path(triplet);
+ const auto& fs = paths.get_filesystem();
+
+ std::string hash;
+
+ auto it_hash = s_hash_cache.find(triplet_file_path);
+ if (it_hash != s_hash_cache.end())
+ {
+ hash = it_hash->second;
+ }
+ else
+ {
+ const auto algo = Hash::Algorithm::Sha1;
+ hash = Hash::get_file_hash(VCPKG_LINE_INFO, fs, triplet_file_path, algo);
+
+ if (auto p = pre_build_info.external_toolchain_file.get())
+ {
+ hash += "-";
+ hash += Hash::get_file_hash(VCPKG_LINE_INFO, fs, *p, algo);
+ }
+ else if (pre_build_info.cmake_system_name == "Linux")
+ {
+ hash += "-";
+ hash += Hash::get_file_hash(VCPKG_LINE_INFO, fs, paths.scripts / "toolchains" / "linux.cmake", algo);
+ }
+ else if (pre_build_info.cmake_system_name == "Darwin")
+ {
+ hash += "-";
+ hash += Hash::get_file_hash(VCPKG_LINE_INFO, fs, paths.scripts / "toolchains" / "osx.cmake", algo);
+ }
+ else if (pre_build_info.cmake_system_name == "FreeBSD")
+ {
+ hash += "-";
+ hash += Hash::get_file_hash(VCPKG_LINE_INFO, fs, paths.scripts / "toolchains" / "freebsd.cmake", algo);
+ }
+ else if (pre_build_info.cmake_system_name == "Android")
+ {
+ hash += "-";
+ hash += Hash::get_file_hash(VCPKG_LINE_INFO, fs, paths.scripts / "toolchains" / "android.cmake", algo);
+ }
+
+ s_hash_cache.emplace(triplet_file_path, hash);
+ }
+
+ return hash;
+ }
+
+ static ExtendedBuildResult do_build_package(const VcpkgPaths& paths,
+ const PreBuildInfo& pre_build_info,
+ const PackageSpec& spec,
+ const std::string& abi_tag,
+ const BuildPackageConfig& config)
+ {
+ auto& fs = paths.get_filesystem();
+
+#if defined(_WIN32)
+ const fs::path& powershell_exe_path = paths.get_tool_exe("powershell-core");
+ if (!fs.exists(powershell_exe_path.parent_path() / "powershell.exe"))
+ {
+ fs.copy(powershell_exe_path, powershell_exe_path.parent_path() / "powershell.exe", fs::copy_options::none);
+ }
+#endif
+
+ const Triplet& triplet = spec.triplet();
+ const auto& triplet_file_path = paths.get_triplet_file_path(spec.triplet()).u8string();
+
+ if (!Strings::case_insensitive_ascii_starts_with(triplet_file_path, paths.triplets.u8string()))
+ {
+ System::printf("-- Loading triplet configuration from: %s\n", triplet_file_path);
+ }
+ if (!Strings::case_insensitive_ascii_starts_with(config.port_dir.u8string(), paths.ports.u8string()))
+ {
+ System::printf("-- Installing port from location: %s\n", config.port_dir.u8string());
+ }
+
const auto timer = Chrono::ElapsedTimer::create_started();
- const int return_code = System::cmd_execute_clean(command);
+ std::string command = make_build_cmd(paths, pre_build_info, config, triplet);
+ std::unordered_map<std::string, std::string> env = make_env_passthrough(pre_build_info);
+
+#if defined(_WIN32)
+ const int return_code =
+ System::cmd_execute_clean(command, env, powershell_exe_path.parent_path().u8string() + ";");
+#else
+ const int return_code = System::cmd_execute_clean(command, env);
+#endif
+ // With the exception of empty packages, builds in "Download Mode" always result in failure.
+ if (config.build_package_options.only_downloads == Build::OnlyDownloads::YES)
+ {
+ // TODO: Capture executed command output and evaluate whether the failure was intended.
+ // If an unintended error occurs then return a BuildResult::DOWNLOAD_FAILURE status.
+ return BuildResult::DOWNLOADED;
+ }
+
const auto buildtimeus = timer.microseconds();
const auto spec_string = spec.to_string();
@@ -428,9 +591,11 @@ namespace vcpkg::Build }
const BuildInfo build_info = read_build_info(fs, paths.build_info_file_path(spec));
- const size_t error_count = PostBuildLint::perform_all_checks(spec, paths, pre_build_info, build_info);
+ const size_t error_count =
+ PostBuildLint::perform_all_checks(spec, paths, pre_build_info, build_info, config.port_dir);
- auto bcf = create_binary_control_file(*config.scf.core_paragraph, triplet, build_info, abi_tag);
+ std::unique_ptr<BinaryControlFile> bcf =
+ create_binary_control_file(*config.scf.core_paragraph, triplet, build_info, abi_tag);
if (error_count != 0)
{
@@ -468,7 +633,8 @@ namespace vcpkg::Build if (fs.is_directory(file)) // Will only keep the logs
{
std::error_code ec;
- fs.remove_all(file, ec);
+ fs::path failure_point;
+ fs.remove_all(file, ec, failure_point);
}
}
}
@@ -481,15 +647,15 @@ namespace vcpkg::Build const PreBuildInfo& pre_build_info,
Span<const AbiEntry> dependency_abis)
{
- if (config.build_package_options.binary_caching == BinaryCaching::NO) return nullopt;
-
auto& fs = paths.get_filesystem();
const Triplet& triplet = config.triplet;
const std::string& name = config.scf.core_paragraph->name;
std::vector<AbiEntry> abi_tag_entries(dependency_abis.begin(), dependency_abis.end());
- abi_tag_entries.emplace_back(AbiEntry{"cmake", paths.get_tool_version(Tools::CMAKE)});
+ // Sorted here as the order of dependency_abis is the only
+ // non-deterministicly ordered set of AbiEntries
+ Util::sort(abi_tag_entries);
// If there is an unusually large number of files in the port then
// something suspicious is going on. Rather than hash all of them
@@ -497,15 +663,18 @@ namespace vcpkg::Build const int max_port_file_count = 100;
// the order of recursive_directory_iterator is undefined so save the names to sort
- std::vector<fs::path> port_files;
+ std::vector<AbiEntry> port_files;
for (auto& port_file : fs::stdfs::recursive_directory_iterator(config.port_dir))
{
- if (fs::is_regular_file(status(port_file)))
+ if (fs::is_regular_file(fs.status(VCPKG_LINE_INFO, port_file)))
{
- port_files.push_back(port_file);
+ port_files.emplace_back(
+ port_file.path().filename().u8string(),
+ vcpkg::Hash::get_file_hash(VCPKG_LINE_INFO, fs, port_file, Hash::Algorithm::Sha1));
+
if (port_files.size() > max_port_file_count)
{
- abi_tag_entries.emplace_back(AbiEntry{"no_hash_max_portfile", ""});
+ abi_tag_entries.emplace_back("no_hash_max_portfile", "");
break;
}
}
@@ -513,36 +682,39 @@ namespace vcpkg::Build if (port_files.size() <= max_port_file_count)
{
- std::sort(port_files.begin(), port_files.end());
+ Util::sort(port_files, [](const AbiEntry& l, const AbiEntry& r) {
+ return l.value < r.value || (l.value == r.value && l.key < r.key);
+ });
- int counter = 0;
- for (auto& port_file : port_files)
- {
- // When vcpkg takes a dependency on C++17 it can use fs::relative,
- // which will give a stable ordering and better names in the key entry.
- // this is not available in the filesystem TS so instead number the files for the key.
- std::string key = Strings::format("file_%03d", counter++);
- if (Debug::g_debugging)
- {
- System::print2("[DEBUG] mapping ", key, " from ", port_file.u8string(), "\n");
- }
- abi_tag_entries.emplace_back(AbiEntry{key, vcpkg::Hash::get_file_hash(fs, port_file, "SHA1")});
- }
+ std::move(port_files.begin(), port_files.end(), std::back_inserter(abi_tag_entries));
}
- abi_tag_entries.emplace_back(AbiEntry{
+ abi_tag_entries.emplace_back("cmake", paths.get_tool_version(Tools::CMAKE));
+
+#if defined(_WIN32)
+ abi_tag_entries.emplace_back("powershell", paths.get_tool_version("powershell-core"));
+#endif
+
+ abi_tag_entries.emplace_back(
"vcpkg_fixup_cmake_targets",
- vcpkg::Hash::get_file_hash(fs, paths.scripts / "cmake" / "vcpkg_fixup_cmake_targets.cmake", "SHA1")});
+ vcpkg::Hash::get_file_hash(VCPKG_LINE_INFO,
+ fs,
+ paths.scripts / "cmake" / "vcpkg_fixup_cmake_targets.cmake",
+ Hash::Algorithm::Sha1));
- abi_tag_entries.emplace_back(AbiEntry{"triplet", pre_build_info.triplet_abi_tag});
+ abi_tag_entries.emplace_back("triplet", pre_build_info.triplet_abi_tag);
+ abi_tag_entries.emplace_back("features", Strings::join(";", config.feature_list));
- const std::string features = Strings::join(";", config.feature_list);
- abi_tag_entries.emplace_back(AbiEntry{"features", features});
+ if (pre_build_info.public_abi_override)
+ {
+ abi_tag_entries.emplace_back(
+ "public_abi_override",
+ Hash::get_string_hash(pre_build_info.public_abi_override.value_or_exit(VCPKG_LINE_INFO),
+ Hash::Algorithm::Sha1));
+ }
if (config.build_package_options.use_head_version == UseHeadVersion::YES)
- abi_tag_entries.emplace_back(AbiEntry{"head", ""});
-
- Util::sort(abi_tag_entries);
+ abi_tag_entries.emplace_back("head", "");
const std::string full_abi_info =
Strings::join("", abi_tag_entries, [](const AbiEntry& p) { return p.key + " " + p.value + "\n"; });
@@ -567,24 +739,25 @@ namespace vcpkg::Build const auto abi_file_path = paths.buildtrees / name / (triplet.canonical_name() + ".vcpkg_abi_info.txt");
fs.write_contents(abi_file_path, full_abi_info, VCPKG_LINE_INFO);
- return AbiTagAndFile{Hash::get_file_hash(fs, abi_file_path, "SHA1"), abi_file_path};
+ return AbiTagAndFile{Hash::get_file_hash(VCPKG_LINE_INFO, fs, abi_file_path, Hash::Algorithm::Sha1),
+ abi_file_path};
}
System::print2(
- "Warning: binary caching disabled because abi keys are missing values:\n",
+ "Warning: abi keys are missing values:\n",
Strings::join("", abi_tag_entries_missing, [](const AbiEntry& e) { return " " + e.key + "\n"; }),
"\n");
return nullopt;
}
- static void decompress_archive(const VcpkgPaths& paths, const PackageSpec& spec, const fs::path& archive_path)
+ static int decompress_archive(const VcpkgPaths& paths, const PackageSpec& spec, const fs::path& archive_path)
{
auto& fs = paths.get_filesystem();
auto pkg_path = paths.package_dir(spec);
+ fs.remove_all(pkg_path, VCPKG_LINE_INFO);
std::error_code ec;
- fs.remove_all(pkg_path, ec);
fs.create_directories(pkg_path, ec);
auto files = fs.get_files_non_recursive(pkg_path);
Checks::check_exit(VCPKG_LINE_INFO, files.empty(), "unable to clear path: %s", pkg_path.u8string());
@@ -592,12 +765,13 @@ namespace vcpkg::Build #if defined(_WIN32)
auto&& seven_zip_exe = paths.get_tool_exe(Tools::SEVEN_ZIP);
- System::cmd_execute_clean(Strings::format(
+ int result = System::cmd_execute_clean(Strings::format(
R"("%s" x "%s" -o"%s" -y >nul)", seven_zip_exe.u8string(), archive_path.u8string(), pkg_path.u8string()));
#else
- System::cmd_execute_clean(
+ int result = System::cmd_execute_clean(
Strings::format(R"(unzip -qq "%s" "-d%s")", archive_path.u8string(), pkg_path.u8string()));
#endif
+ return result;
}
// Compress the source directory into the destination file.
@@ -641,13 +815,17 @@ namespace vcpkg::Build Util::sort_unique_erase(dep_pspecs);
// Find all features that aren't installed. This mutates required_fspecs.
- Util::erase_remove_if(required_fspecs, [&](FeatureSpec const& fspec) {
- return status_db.is_installed(fspec) || fspec.name() == name;
- });
-
- if (!required_fspecs.empty())
+ // Skip this validation when running in Download Mode.
+ if (config.build_package_options.only_downloads != Build::OnlyDownloads::YES)
{
- return {BuildResult::CASCADED_DUE_TO_MISSING_DEPENDENCIES, std::move(required_fspecs)};
+ Util::erase_remove_if(required_fspecs, [&](FeatureSpec const& fspec) {
+ return status_db.is_installed(fspec) || fspec.name() == name;
+ });
+
+ if (!required_fspecs.empty())
+ {
+ return {BuildResult::CASCADED_DUE_TO_MISSING_DEPENDENCIES, std::move(required_fspecs)};
+ }
}
const PackageSpec spec =
@@ -658,36 +836,51 @@ namespace vcpkg::Build // dep_pspecs was not destroyed
for (auto&& pspec : dep_pspecs)
{
- if (pspec == spec) continue;
+ if (pspec == spec || Util::Enum::to_bool(config.build_package_options.only_downloads))
+ {
+ continue;
+ }
const auto status_it = status_db.find_installed(pspec);
Checks::check_exit(VCPKG_LINE_INFO, status_it != status_db.end());
dependency_abis.emplace_back(
AbiEntry{status_it->get()->package.spec.name(), status_it->get()->package.abi});
}
- const auto pre_build_info = PreBuildInfo::from_triplet_file(paths, triplet);
+ const auto pre_build_info = PreBuildInfo::from_triplet_file(paths, triplet, config.scfl);
auto maybe_abi_tag_and_file = compute_abi_tag(paths, config, pre_build_info, dependency_abis);
+ if (!maybe_abi_tag_and_file)
+ {
+ return do_build_package_and_clean_buildtrees(
+ paths, pre_build_info, spec, pre_build_info.public_abi_override.value_or(AbiTagAndFile{}.tag), config);
+ }
+ std::error_code ec;
const auto abi_tag_and_file = maybe_abi_tag_and_file.get();
-
- if (config.build_package_options.binary_caching == BinaryCaching::YES && abi_tag_and_file)
+ const fs::path archives_root_dir = paths.root / "archives";
+ const std::string archive_name = abi_tag_and_file->tag + ".zip";
+ const fs::path archive_subpath = fs::u8path(abi_tag_and_file->tag.substr(0, 2)) / archive_name;
+ const fs::path archive_path = archives_root_dir / archive_subpath;
+ const fs::path archive_tombstone_path = archives_root_dir / "fail" / archive_subpath;
+ const fs::path abi_package_dir = paths.package_dir(spec) / "share" / spec.name();
+ const fs::path abi_file_in_package = paths.package_dir(spec) / "share" / spec.name() / "vcpkg_abi_info.txt";
+
+ if (config.build_package_options.binary_caching == BinaryCaching::YES)
{
- const fs::path archives_root_dir = paths.root / "archives";
- const std::string archive_name = abi_tag_and_file->tag + ".zip";
- const fs::path archive_subpath = fs::u8path(abi_tag_and_file->tag.substr(0, 2)) / archive_name;
- const fs::path archive_path = archives_root_dir / archive_subpath;
- const fs::path archive_tombstone_path = archives_root_dir / "fail" / archive_subpath;
-
if (fs.exists(archive_path))
{
System::print2("Using cached binary package: ", archive_path.u8string(), "\n");
- decompress_archive(paths, spec, archive_path);
+ int archive_result = decompress_archive(paths, spec, archive_path);
+
+ if (archive_result != 0)
+ {
+ System::print2("Failed to decompress archive package\n");
+ return BuildResult::BUILD_FAILED;
+ }
auto maybe_bcf = Paragraphs::try_load_cached_package(paths, spec);
- std::unique_ptr<BinaryControlFile> bcf =
- std::make_unique<BinaryControlFile>(std::move(maybe_bcf).value_or_exit(VCPKG_LINE_INFO));
+ auto bcf = std::make_unique<BinaryControlFile>(std::move(maybe_bcf).value_or_exit(VCPKG_LINE_INFO));
return {BuildResult::SUCCEEDED, std::move(bcf)};
}
@@ -705,71 +898,68 @@ namespace vcpkg::Build }
}
- System::print2("Could not locate cached archive: ", archive_path.u8string(), "\n");
+ System::printf("Could not locate cached archive: %s\n", archive_path.u8string());
+ }
- ExtendedBuildResult result = do_build_package_and_clean_buildtrees(
- paths, pre_build_info, spec, maybe_abi_tag_and_file.value_or(AbiTagAndFile{}).tag, config);
+ ExtendedBuildResult result = do_build_package_and_clean_buildtrees(
+ paths, pre_build_info, spec, pre_build_info.public_abi_override.value_or(abi_tag_and_file->tag), config);
- std::error_code ec;
- fs.create_directories(paths.package_dir(spec) / "share" / spec.name(), ec);
- auto abi_file_in_package = paths.package_dir(spec) / "share" / spec.name() / "vcpkg_abi_info.txt";
- fs.copy_file(abi_tag_and_file->tag_file, abi_file_in_package, fs::stdfs::copy_options::none, ec);
- Checks::check_exit(VCPKG_LINE_INFO, !ec, "Could not copy into file: %s", abi_file_in_package.u8string());
+ fs.create_directories(abi_package_dir, ec);
+ Checks::check_exit(VCPKG_LINE_INFO, !ec, "Coud not create directory %s", abi_package_dir.u8string());
+ fs.copy_file(abi_tag_and_file->tag_file, abi_file_in_package, fs::stdfs::copy_options::none, ec);
+ Checks::check_exit(VCPKG_LINE_INFO, !ec, "Could not copy into file: %s", abi_file_in_package.u8string());
- if (result.code == BuildResult::SUCCEEDED)
- {
- const auto tmp_archive_path = paths.buildtrees / spec.name() / (spec.triplet().to_string() + ".zip");
+ if (config.build_package_options.binary_caching == BinaryCaching::YES && result.code == BuildResult::SUCCEEDED)
+ {
+ const auto tmp_archive_path = paths.buildtrees / spec.name() / (spec.triplet().to_string() + ".zip");
- compress_archive(paths, spec, tmp_archive_path);
+ compress_archive(paths, spec, tmp_archive_path);
- fs.create_directories(archive_path.parent_path(), ec);
- fs.rename_or_copy(tmp_archive_path, archive_path, ".tmp", ec);
- if (ec)
- {
- System::printf(System::Color::warning,
- "Failed to store binary cache %s: %s\n",
- archive_path.u8string(),
- ec.message());
- }
- else
- System::printf("Stored binary cache: %s\n", archive_path.u8string());
+ fs.create_directories(archive_path.parent_path(), ec);
+ fs.rename_or_copy(tmp_archive_path, archive_path, ".tmp", ec);
+ if (ec)
+ {
+ System::printf(System::Color::warning,
+ "Failed to store binary cache %s: %s\n",
+ archive_path.u8string(),
+ ec.message());
}
- else if (result.code == BuildResult::BUILD_FAILED || result.code == BuildResult::POST_BUILD_CHECKS_FAILED)
+ else
+ System::printf("Stored binary cache: %s\n", archive_path.u8string());
+ }
+ else if (config.build_package_options.binary_caching == BinaryCaching::YES &&
+ (result.code == BuildResult::BUILD_FAILED || result.code == BuildResult::POST_BUILD_CHECKS_FAILED))
+ {
+ if (!fs.exists(archive_tombstone_path))
{
- if (!fs.exists(archive_tombstone_path))
- {
- // Build failed, store all failure logs in the tombstone.
- const auto tmp_log_path = paths.buildtrees / spec.name() / "tmp_failure_logs";
- const auto tmp_log_path_destination = tmp_log_path / spec.name();
- const auto tmp_failure_zip = paths.buildtrees / spec.name() / "failure_logs.zip";
- fs.create_directories(tmp_log_path_destination, ec);
+ // Build failed, store all failure logs in the tombstone.
+ const auto tmp_log_path = paths.buildtrees / spec.name() / "tmp_failure_logs";
+ const auto tmp_log_path_destination = tmp_log_path / spec.name();
+ const auto tmp_failure_zip = paths.buildtrees / spec.name() / "failure_logs.zip";
+ fs.create_directories(tmp_log_path_destination, ec);
- for (auto& log_file : fs::stdfs::directory_iterator(paths.buildtrees / spec.name()))
+ for (auto& log_file : fs::stdfs::directory_iterator(paths.buildtrees / spec.name()))
+ {
+ if (log_file.path().extension() == ".log")
{
- if (log_file.path().extension() == ".log")
- {
- fs.copy_file(log_file.path(),
- tmp_log_path_destination / log_file.path().filename(),
- fs::stdfs::copy_options::none,
- ec);
- }
+ fs.copy_file(log_file.path(),
+ tmp_log_path_destination / log_file.path().filename(),
+ fs::stdfs::copy_options::none,
+ ec);
}
+ }
- compress_directory(paths, tmp_log_path, paths.buildtrees / spec.name() / "failure_logs.zip");
+ compress_directory(paths, tmp_log_path, paths.buildtrees / spec.name() / "failure_logs.zip");
- fs.create_directories(archive_tombstone_path.parent_path(), ec);
- fs.rename_or_copy(tmp_failure_zip, archive_tombstone_path, ".tmp", ec);
+ fs.create_directories(archive_tombstone_path.parent_path(), ec);
+ fs.rename_or_copy(tmp_failure_zip, archive_tombstone_path, ".tmp", ec);
- // clean up temporary directory
- fs.remove_all(tmp_log_path, ec);
- }
+ // clean up temporary directory
+ fs.remove_all(tmp_log_path, VCPKG_LINE_INFO);
}
-
- return result;
}
- return do_build_package_and_clean_buildtrees(
- paths, pre_build_info, spec, maybe_abi_tag_and_file.value_or(AbiTagAndFile{}).tag, config);
+ return result;
}
const std::string& to_string(const BuildResult build_result)
@@ -781,6 +971,7 @@ namespace vcpkg::Build static const std::string POST_BUILD_CHECKS_FAILED_STRING = "POST_BUILD_CHECKS_FAILED";
static const std::string CASCADED_DUE_TO_MISSING_DEPENDENCIES_STRING = "CASCADED_DUE_TO_MISSING_DEPENDENCIES";
static const std::string EXCLUDED_STRING = "EXCLUDED";
+ static const std::string DOWNLOADED_STRING = "DOWNLOADED";
switch (build_result)
{
@@ -791,6 +982,7 @@ namespace vcpkg::Build case BuildResult::FILE_CONFLICTS: return FILE_CONFLICTS_STRING;
case BuildResult::CASCADED_DUE_TO_MISSING_DEPENDENCIES: return CASCADED_DUE_TO_MISSING_DEPENDENCIES_STRING;
case BuildResult::EXCLUDED: return EXCLUDED_STRING;
+ case BuildResult::DOWNLOADED: return DOWNLOADED_STRING;
default: Checks::unreachable(VCPKG_LINE_INFO);
}
}
@@ -812,7 +1004,7 @@ namespace vcpkg::Build Commands::Version::version());
}
- static BuildInfo inner_create_buildinfo(std::unordered_map<std::string, std::string> pgh)
+ static BuildInfo inner_create_buildinfo(Parse::RawParagraph pgh)
{
Parse::ParagraphParser parser(std::move(pgh));
@@ -869,25 +1061,35 @@ namespace vcpkg::Build BuildInfo read_build_info(const Files::Filesystem& fs, const fs::path& filepath)
{
- const Expected<std::unordered_map<std::string, std::string>> pghs =
- Paragraphs::get_single_paragraph(fs, filepath);
+ const Expected<Parse::RawParagraph> pghs = Paragraphs::get_single_paragraph(fs, filepath);
Checks::check_exit(VCPKG_LINE_INFO, pghs.get() != nullptr, "Invalid BUILD_INFO file for package");
return inner_create_buildinfo(*pghs.get());
}
- PreBuildInfo PreBuildInfo::from_triplet_file(const VcpkgPaths& paths, const Triplet& triplet)
+ PreBuildInfo PreBuildInfo::from_triplet_file(const VcpkgPaths& paths,
+ const Triplet& triplet,
+ Optional<const SourceControlFileLocation&> port)
{
static constexpr CStringView FLAG_GUID = "c35112b6-d1ba-415b-aa5d-81de856ef8eb";
const fs::path& cmake_exe_path = paths.get_tool_exe(Tools::CMAKE);
const fs::path ports_cmake_script_path = paths.scripts / "get_triplet_environment.cmake";
- const fs::path triplet_file_path = paths.triplets / (triplet.canonical_name() + ".cmake");
+ const fs::path triplet_file_path = paths.get_triplet_file_path(triplet);
+
+ std::vector<System::CMakeVariable> args{{"CMAKE_TRIPLET_FILE", triplet_file_path}};
+
+ if (port)
+ {
+ const SourceControlFileLocation& scfl = port.value_or_exit(VCPKG_LINE_INFO);
+
+ if (paths.get_filesystem().is_regular_file(scfl.source_location / "environment-overrides.cmake"))
+ {
+ args.emplace_back("VCPKG_ENV_OVERRIDES_FILE", scfl.source_location / "environment-overrides.cmake");
+ }
+ }
+
+ const auto cmd_launch_cmake = System::make_cmake_cmd(cmake_exe_path, ports_cmake_script_path, args);
- const auto cmd_launch_cmake = System::make_cmake_cmd(cmake_exe_path,
- ports_cmake_script_path,
- {
- {"CMAKE_TRIPLET_FILE", triplet_file_path},
- });
const auto ec_data = System::cmd_execute_and_capture_output(cmd_launch_cmake);
Checks::check_exit(VCPKG_LINE_INFO, ec_data.exit_code == 0, ec_data.output);
@@ -895,6 +1097,8 @@ namespace vcpkg::Build PreBuildInfo pre_build_info;
+ pre_build_info.port = port;
+
const auto e = lines.cend();
auto cur = std::find(lines.cbegin(), e, FLAG_GUID);
if (cur != e) ++cur;
@@ -913,105 +1117,61 @@ namespace vcpkg::Build const std::string variable_name = s.at(0);
const std::string variable_value = variable_with_no_value ? "" : s.at(1);
- if (variable_name == "VCPKG_TARGET_ARCHITECTURE")
- {
- pre_build_info.target_architecture = variable_value;
- continue;
- }
-
- if (variable_name == "VCPKG_CMAKE_SYSTEM_NAME")
- {
- pre_build_info.cmake_system_name = variable_value;
- continue;
- }
-
- if (variable_name == "VCPKG_CMAKE_SYSTEM_VERSION")
+ auto maybe_option = VCPKG_OPTIONS.find(variable_name);
+ if (maybe_option != VCPKG_OPTIONS.end())
{
- pre_build_info.cmake_system_version = variable_value;
- continue;
- }
-
- if (variable_name == "VCPKG_PLATFORM_TOOLSET")
- {
- pre_build_info.platform_toolset =
- variable_value.empty() ? nullopt : Optional<std::string>{variable_value};
- continue;
- }
-
- if (variable_name == "VCPKG_VISUAL_STUDIO_PATH")
- {
- pre_build_info.visual_studio_path =
- variable_value.empty() ? nullopt : Optional<fs::path>{variable_value};
- continue;
- }
-
- if (variable_name == "VCPKG_CHAINLOAD_TOOLCHAIN_FILE")
- {
- pre_build_info.external_toolchain_file =
- variable_value.empty() ? nullopt : Optional<std::string>{variable_value};
- continue;
+ switch (maybe_option->second)
+ {
+ case VcpkgTripletVar::TARGET_ARCHITECTURE:
+ pre_build_info.target_architecture = variable_value;
+ break;
+ case VcpkgTripletVar::CMAKE_SYSTEM_NAME: pre_build_info.cmake_system_name = variable_value; break;
+ case VcpkgTripletVar::CMAKE_SYSTEM_VERSION:
+ pre_build_info.cmake_system_version = variable_value;
+ break;
+ case VcpkgTripletVar::PLATFORM_TOOLSET:
+ pre_build_info.platform_toolset =
+ variable_value.empty() ? nullopt : Optional<std::string>{variable_value};
+ break;
+ case VcpkgTripletVar::VISUAL_STUDIO_PATH:
+ pre_build_info.visual_studio_path =
+ variable_value.empty() ? nullopt : Optional<fs::path>{variable_value};
+ break;
+ case VcpkgTripletVar::CHAINLOAD_TOOLCHAIN_FILE:
+ pre_build_info.external_toolchain_file =
+ variable_value.empty() ? nullopt : Optional<std::string>{variable_value};
+ break;
+ case VcpkgTripletVar::BUILD_TYPE:
+ if (variable_value.empty())
+ pre_build_info.build_type = nullopt;
+ else if (Strings::case_insensitive_ascii_equals(variable_value, "debug"))
+ pre_build_info.build_type = ConfigurationType::DEBUG;
+ else if (Strings::case_insensitive_ascii_equals(variable_value, "release"))
+ pre_build_info.build_type = ConfigurationType::RELEASE;
+ else
+ Checks::exit_with_message(
+ VCPKG_LINE_INFO, "Unknown setting for VCPKG_BUILD_TYPE: %s", variable_value);
+ break;
+ case VcpkgTripletVar::ENV_PASSTHROUGH:
+ pre_build_info.passthrough_env_vars = Strings::split(variable_value, ";");
+ break;
+ case VcpkgTripletVar::PUBLIC_ABI_OVERRIDE:
+ pre_build_info.public_abi_override =
+ variable_value.empty() ? nullopt : Optional<std::string>{variable_value};
+ break;
+ }
}
-
- if (variable_name == "VCPKG_BUILD_TYPE")
+ else
{
- if (variable_value.empty())
- pre_build_info.build_type = nullopt;
- else if (Strings::case_insensitive_ascii_equals(variable_value, "debug"))
- pre_build_info.build_type = ConfigurationType::DEBUG;
- else if (Strings::case_insensitive_ascii_equals(variable_value, "release"))
- pre_build_info.build_type = ConfigurationType::RELEASE;
- else
- Checks::exit_with_message(
- VCPKG_LINE_INFO, "Unknown setting for VCPKG_BUILD_TYPE: %s", variable_value);
- continue;
+ Checks::exit_with_message(VCPKG_LINE_INFO, "Unknown variable name %s", line);
}
-
- Checks::exit_with_message(VCPKG_LINE_INFO, "Unknown variable name %s", line);
}
- pre_build_info.triplet_abi_tag = [&]() {
- const auto& fs = paths.get_filesystem();
- static std::map<fs::path, std::string> s_hash_cache;
-
- auto it_hash = s_hash_cache.find(triplet_file_path);
- if (it_hash != s_hash_cache.end())
- {
- return it_hash->second;
- }
- auto hash = Hash::get_file_hash(fs, triplet_file_path, "SHA1");
-
- if (auto p = pre_build_info.external_toolchain_file.get())
- {
- hash += "-";
- hash += Hash::get_file_hash(fs, *p, "SHA1");
- }
- else if (pre_build_info.cmake_system_name == "Linux")
- {
- hash += "-";
- hash += Hash::get_file_hash(fs, paths.scripts / "toolchains" / "linux.cmake", "SHA1");
- }
- else if (pre_build_info.cmake_system_name == "Darwin")
- {
- hash += "-";
- hash += Hash::get_file_hash(fs, paths.scripts / "toolchains" / "osx.cmake", "SHA1");
- }
- else if (pre_build_info.cmake_system_name == "FreeBSD")
- {
- hash += "-";
- hash += Hash::get_file_hash(fs, paths.scripts / "toolchains" / "freebsd.cmake", "SHA1");
- }
- else if (pre_build_info.cmake_system_name == "Android")
- {
- hash += "-";
- hash += Hash::get_file_hash(fs, paths.scripts / "toolchains" / "android.cmake", "SHA1");
- }
-
- s_hash_cache.emplace(triplet_file_path, hash);
- return hash;
- }();
+ pre_build_info.triplet_abi_tag = get_triplet_abi(paths, pre_build_info, triplet);
return pre_build_info;
}
+
ExtendedBuildResult::ExtendedBuildResult(BuildResult code) : code(code) {}
ExtendedBuildResult::ExtendedBuildResult(BuildResult code, std::unique_ptr<BinaryControlFile>&& bcf)
: code(code), binary_control_file(std::move(bcf))
|
