diff options
| author | Thomas Fussell <thomas.fussell@gmail.com> | 2017-03-17 00:33:06 -0400 |
|---|---|---|
| committer | Thomas Fussell <thomas.fussell@gmail.com> | 2017-03-17 00:33:06 -0400 |
| commit | d821b0a28a7223d0b49745c53a3ff032fcb001c8 (patch) | |
| tree | 12e13d5ff298a4e4b4f946ceb90b49cbfbe2d2c9 /toolsrc/src | |
| parent | 4921636f6bc92e041a410870ce564615c85a6cfb (diff) | |
| parent | 01b1e39c6a006adba7b9cf2af758be679d0b7eb9 (diff) | |
| download | vcpkg-d821b0a28a7223d0b49745c53a3ff032fcb001c8.tar.gz vcpkg-d821b0a28a7223d0b49745c53a3ff032fcb001c8.zip | |
Merge branch 'master' of https://github.com/Microsoft/vcpkg
Diffstat (limited to 'toolsrc/src')
37 files changed, 160 insertions, 133 deletions
diff --git a/toolsrc/src/BinaryParagraph.cpp b/toolsrc/src/BinaryParagraph.cpp index 8605cd276..be3931ba9 100644 --- a/toolsrc/src/BinaryParagraph.cpp +++ b/toolsrc/src/BinaryParagraph.cpp @@ -31,14 +31,14 @@ namespace vcpkg const std::string architecture = details::remove_required_field(&fields, BinaryParagraphRequiredField::ARCHITECTURE); const triplet target_triplet = triplet::from_canonical_name(architecture); - this->spec = package_spec::from_name_and_triplet(name, target_triplet).get_or_throw(); + this->spec = package_spec::from_name_and_triplet(name, target_triplet).get_or_throw(VCPKG_LINE_INFO); this->version = details::remove_required_field(&fields, BinaryParagraphRequiredField::VERSION); this->description = details::remove_optional_field(&fields, BinaryParagraphOptionalField::DESCRIPTION); this->maintainer = details::remove_optional_field(&fields, BinaryParagraphOptionalField::MAINTAINER); std::string multi_arch = details::remove_required_field(&fields, BinaryParagraphRequiredField::MULTI_ARCH); - Checks::check_exit(multi_arch == "same", "Multi-Arch must be 'same' but was %s", multi_arch); + Checks::check_exit(VCPKG_LINE_INFO, multi_arch == "same", "Multi-Arch must be 'same' but was %s", multi_arch); std::string deps = details::remove_optional_field(&fields, BinaryParagraphOptionalField::DEPENDS); this->depends = parse_depends(deps); @@ -46,7 +46,7 @@ namespace vcpkg BinaryParagraph::BinaryParagraph(const SourceParagraph& spgh, const triplet& target_triplet) { - this->spec = package_spec::from_name_and_triplet(spgh.name, target_triplet).get_or_throw(); + this->spec = package_spec::from_name_and_triplet(spgh.name, target_triplet).get_or_throw(VCPKG_LINE_INFO); this->version = spgh.version; this->description = spgh.description; this->maintainer = spgh.maintainer; diff --git a/toolsrc/src/LineInfo.cpp b/toolsrc/src/LineInfo.cpp new file mode 100644 index 000000000..fa26355e4 --- /dev/null +++ b/toolsrc/src/LineInfo.cpp @@ -0,0 +1,11 @@ +#include "pch.h" +#include "LineInfo.h" +#include "vcpkg_Strings.h" + +namespace vcpkg +{ + std::string LineInfo::toString() const + { + return Strings::format("%s(%d)", this->file_name, this->line_number); + } +} diff --git a/toolsrc/src/MachineType.cpp b/toolsrc/src/MachineType.cpp index 81012234d..97d0a0280 100644 --- a/toolsrc/src/MachineType.cpp +++ b/toolsrc/src/MachineType.cpp @@ -36,7 +36,7 @@ namespace vcpkg case MachineType::WCEMIPSV2: return t; default: - Checks::exit_with_message("Unknown machine type code 0x%x", value); + Checks::exit_with_message(VCPKG_LINE_INFO, "Unknown machine type code 0x%x", value); } } } diff --git a/toolsrc/src/Paragraphs.cpp b/toolsrc/src/Paragraphs.cpp index cb90ed1ec..f1505698c 100644 --- a/toolsrc/src/Paragraphs.cpp +++ b/toolsrc/src/Paragraphs.cpp @@ -99,7 +99,7 @@ namespace vcpkg::Paragraphs auto begin_fieldname = cur; while (is_alphanum(ch) || ch == '-') next(ch); - Checks::check_exit(ch == ':', "Expected ':'"); + Checks::check_exit(VCPKG_LINE_INFO, ch == ':', "Expected ':'"); fieldname = std::string(begin_fieldname, cur); // skip ': ' @@ -117,7 +117,7 @@ namespace vcpkg::Paragraphs get_fieldname(ch, fieldname); auto it = fields.find(fieldname); - Checks::check_exit(it == fields.end(), "Duplicate field"); + Checks::check_exit(VCPKG_LINE_INFO, it == fields.end(), "Duplicate field"); get_fieldvalue(ch, fieldvalue); @@ -158,7 +158,7 @@ namespace vcpkg::Paragraphs return parse_paragraphs(*spgh); } - Checks::exit_with_message("Error while reading %s: %s", control_path.generic_string(), contents.error_code().message()); + Checks::exit_with_message(VCPKG_LINE_INFO, "Error while reading %s: %s", control_path.generic_string(), contents.error_code().message()); } std::vector<std::unordered_map<std::string, std::string>> parse_paragraphs(const std::string& str) @@ -171,7 +171,7 @@ namespace vcpkg::Paragraphs try { auto pghs = get_paragraphs(path / "CONTROL"); - Checks::check_exit(pghs.size() == 1, "Invalid control file at %s\\CONTROL", path.string()); + Checks::check_exit(VCPKG_LINE_INFO, pghs.size() == 1, "Invalid control file at %s\\CONTROL", path.string()); return SourceParagraph(pghs[0]); } catch (std::runtime_error const&) {} @@ -192,7 +192,7 @@ namespace vcpkg::Paragraphs pghs = parse_paragraphs(*control_contents); } catch (std::runtime_error) {} - Checks::check_exit(pghs.size() == 1, "Invalid control file at %s", path.string()); + Checks::check_exit(VCPKG_LINE_INFO, pghs.size() == 1, "Invalid control file at %s", path.string()); return BinaryParagraph(pghs[0]); } return control_contents_maybe.error_code(); diff --git a/toolsrc/src/PostBuildLint.cpp b/toolsrc/src/PostBuildLint.cpp index 8abf71bb3..00a6eabe6 100644 --- a/toolsrc/src/PostBuildLint.cpp +++ b/toolsrc/src/PostBuildLint.cpp @@ -98,12 +98,12 @@ namespace vcpkg::PostBuildLint return lint_status::SUCCESS; } - static lint_status check_folder_lib_cmake(const fs::path& package_dir) + static lint_status check_folder_lib_cmake(const fs::path& package_dir, const package_spec& spec) { const fs::path lib_cmake = package_dir / "lib" / "cmake"; if (fs::exists(lib_cmake)) { - System::println(System::color::warning, "The /lib/cmake folder should be moved to just /cmake"); + System::println(System::color::warning, "The /lib/cmake folder should be moved to /share/%s/cmake.", spec.name()); return lint_status::ERROR_DETECTED; } @@ -227,7 +227,7 @@ namespace vcpkg::PostBuildLint { const std::wstring cmd_line = Strings::wformat(LR"("%s" /exports "%s")", dumpbin_exe.native(), dll.native()); System::exit_code_and_output ec_data = System::cmd_execute_and_capture_output(cmd_line); - Checks::check_exit(ec_data.exit_code == 0, "Running command:\n %s\n failed", Strings::utf16_to_utf8(cmd_line)); + Checks::check_exit(VCPKG_LINE_INFO, ec_data.exit_code == 0, "Running command:\n %s\n failed", Strings::utf16_to_utf8(cmd_line)); if (ec_data.output.find("ordinal hint RVA name") == std::string::npos) { @@ -258,7 +258,7 @@ namespace vcpkg::PostBuildLint { const std::wstring cmd_line = Strings::wformat(LR"("%s" /headers "%s")", dumpbin_exe.native(), dll.native()); System::exit_code_and_output ec_data = System::cmd_execute_and_capture_output(cmd_line); - Checks::check_exit(ec_data.exit_code == 0, "Running command:\n %s\n failed", Strings::utf16_to_utf8(cmd_line)); + Checks::check_exit(VCPKG_LINE_INFO, ec_data.exit_code == 0, "Running command:\n %s\n failed", Strings::utf16_to_utf8(cmd_line)); if (ec_data.output.find("App Container") == std::string::npos) { @@ -318,7 +318,7 @@ namespace vcpkg::PostBuildLint for (const fs::path& file : files) { - Checks::check_exit(file.extension() == ".dll", "The file extension was not .dll: %s", file.generic_string()); + Checks::check_exit(VCPKG_LINE_INFO, file.extension() == ".dll", "The file extension was not .dll: %s", file.generic_string()); COFFFileReader::dll_info info = COFFFileReader::read_dll(file); const std::string actual_architecture = get_actual_architecture(info.machine_type); @@ -343,9 +343,9 @@ namespace vcpkg::PostBuildLint for (const fs::path& file : files) { - Checks::check_exit(file.extension() == ".lib", "The file extension was not .lib: %s", file.generic_string()); + Checks::check_exit(VCPKG_LINE_INFO, file.extension() == ".lib", "The file extension was not .lib: %s", file.generic_string()); COFFFileReader::lib_info info = COFFFileReader::read_lib(file); - Checks::check_exit(info.machine_types.size() == 1, "Found more than 1 architecture in file %s", file.generic_string()); + Checks::check_exit(VCPKG_LINE_INFO, info.machine_types.size() == 1, "Found more than 1 architecture in file %s", file.generic_string()); const std::string actual_architecture = get_actual_architecture(info.machine_types.at(0)); if (expected_architecture != actual_architecture) @@ -496,7 +496,7 @@ namespace vcpkg::PostBuildLint { const std::wstring cmd_line = Strings::wformat(LR"("%s" /directives "%s")", dumpbin_exe.native(), lib.native()); System::exit_code_and_output ec_data = System::cmd_execute_and_capture_output(cmd_line); - Checks::check_exit(ec_data.exit_code == 0, "Running command:\n %s\n failed", Strings::utf16_to_utf8(cmd_line)); + Checks::check_exit(VCPKG_LINE_INFO, ec_data.exit_code == 0, "Running command:\n %s\n failed", Strings::utf16_to_utf8(cmd_line)); for (const BuildType::type& bad_build_type : bad_build_types) { @@ -543,7 +543,7 @@ namespace vcpkg::PostBuildLint { const std::wstring cmd_line = Strings::wformat(LR"("%s" /dependents "%s")", dumpbin_exe.native(), dll.native()); System::exit_code_and_output ec_data = System::cmd_execute_and_capture_output(cmd_line); - Checks::check_exit(ec_data.exit_code == 0, "Running command:\n %s\n failed", Strings::utf16_to_utf8(cmd_line)); + Checks::check_exit(VCPKG_LINE_INFO, ec_data.exit_code == 0, "Running command:\n %s\n failed", Strings::utf16_to_utf8(cmd_line)); for (const OutdatedDynamicCrt& outdated_crt : outdated_crts) { @@ -630,7 +630,7 @@ namespace vcpkg::PostBuildLint error_count += check_for_files_in_include_directory(package_dir); error_count += check_for_files_in_debug_include_directory(package_dir); error_count += check_for_files_in_debug_share_directory(package_dir); - error_count += check_folder_lib_cmake(package_dir); + error_count += check_folder_lib_cmake(package_dir, spec); error_count += check_for_misplaced_cmake_files(package_dir, spec); error_count += check_folder_debug_lib_cmake(package_dir); error_count += check_for_dlls_in_lib_dirs(package_dir); @@ -693,7 +693,7 @@ namespace vcpkg::PostBuildLint } case LinkageType::backing_enum_t::NULLVALUE: default: - Checks::unreachable(); + Checks::unreachable(VCPKG_LINE_INFO); } error_count += check_no_empty_folders(package_dir); diff --git a/toolsrc/src/PostBuildLint_BuildInfo.cpp b/toolsrc/src/PostBuildLint_BuildInfo.cpp index 0d1d480b8..5b475322a 100644 --- a/toolsrc/src/PostBuildLint_BuildInfo.cpp +++ b/toolsrc/src/PostBuildLint_BuildInfo.cpp @@ -19,17 +19,17 @@ namespace vcpkg::PostBuildLint BuildInfo build_info; const std::string crt_linkage_as_string = details::remove_required_field(&pgh, BuildInfoRequiredField::CRT_LINKAGE); build_info.crt_linkage = LinkageType::value_of(crt_linkage_as_string); - Checks::check_exit(build_info.crt_linkage != LinkageType::NULLVALUE, "Invalid crt linkage type: [%s]", crt_linkage_as_string); + Checks::check_exit(VCPKG_LINE_INFO, build_info.crt_linkage != LinkageType::NULLVALUE, "Invalid crt linkage type: [%s]", crt_linkage_as_string); const std::string library_linkage_as_string = details::remove_required_field(&pgh, BuildInfoRequiredField::LIBRARY_LINKAGE); build_info.library_linkage = LinkageType::value_of(library_linkage_as_string); - Checks::check_exit(build_info.library_linkage != LinkageType::NULLVALUE, "Invalid library linkage type: [%s]", library_linkage_as_string); + Checks::check_exit(VCPKG_LINE_INFO, build_info.library_linkage != LinkageType::NULLVALUE, "Invalid library linkage type: [%s]", library_linkage_as_string); // The remaining entries are policies for (const std::unordered_map<std::string, std::string>::value_type& p : pgh) { const BuildPolicies::type policy = BuildPolicies::parse(p.first); - Checks::check_exit(policy != BuildPolicies::NULLVALUE, "Unknown policy found: %s", p.first); + Checks::check_exit(VCPKG_LINE_INFO, policy != BuildPolicies::NULLVALUE, "Unknown policy found: %s", p.first); const opt_bool_t status = opt_bool::parse(p.second); build_info.policies.emplace(policy, status); } @@ -40,7 +40,7 @@ namespace vcpkg::PostBuildLint BuildInfo read_build_info(const fs::path& filepath) { const std::vector<std::unordered_map<std::string, std::string>> pghs = Paragraphs::get_paragraphs(filepath); - Checks::check_exit(pghs.size() == 1, "Invalid BUILD_INFO file for package"); + Checks::check_exit(VCPKG_LINE_INFO, pghs.size() == 1, "Invalid BUILD_INFO file for package"); return BuildInfo::create(pghs[0]); } diff --git a/toolsrc/src/PostBuildLint_BuildPolicies.cpp b/toolsrc/src/PostBuildLint_BuildPolicies.cpp index f070a2a42..b7ebf5380 100644 --- a/toolsrc/src/PostBuildLint_BuildPolicies.cpp +++ b/toolsrc/src/PostBuildLint_BuildPolicies.cpp @@ -1,6 +1,7 @@ #include "pch.h" #include "PostBuildLint_BuildPolicies.h" #include "vcpkg_Enums.h" +#include "vcpkg_Checks.h" namespace vcpkg::PostBuildLint::BuildPolicies { @@ -23,7 +24,7 @@ namespace vcpkg::PostBuildLint::BuildPolicies case NULLVALUE: return NULLVALUE_STRING; default: - Enums::unreachable(ENUM_NAME); + Checks::unreachable(VCPKG_LINE_INFO); } } @@ -42,9 +43,9 @@ namespace vcpkg::PostBuildLint::BuildPolicies case ONLY_RELEASE_CRT: return CMAKE_VARIABLE_ONLY_RELEASE_CRT; case NULLVALUE: - Enums::nullvalue_used(ENUM_NAME); + Enums::nullvalue_used(VCPKG_LINE_INFO, ENUM_NAME); default: - Enums::unreachable(ENUM_NAME); + Checks::unreachable(VCPKG_LINE_INFO); } } diff --git a/toolsrc/src/PostBuildLint_BuildType.cpp b/toolsrc/src/PostBuildLint_BuildType.cpp index f2fb292d7..593d976f2 100644 --- a/toolsrc/src/PostBuildLint_BuildType.cpp +++ b/toolsrc/src/PostBuildLint_BuildType.cpp @@ -1,6 +1,6 @@ #include "pch.h" #include "PostBuildLint_BuildType.h" -#include "vcpkg_Enums.h" +#include "vcpkg_Checks.h" namespace vcpkg::PostBuildLint::BuildType { @@ -26,7 +26,7 @@ namespace vcpkg::PostBuildLint::BuildType return RELEASE_DYNAMIC; } - Enums::unreachable(ENUM_NAME); + Checks::unreachable(VCPKG_LINE_INFO); } const ConfigurationType::type& type::config() const @@ -57,7 +57,7 @@ namespace vcpkg::PostBuildLint::BuildType case BuildType::RELEASE_DYNAMIC: return REGEX_RELEASE_DYNAMIC; default: - Enums::unreachable(ENUM_NAME); + Checks::unreachable(VCPKG_LINE_INFO); } } @@ -79,7 +79,7 @@ namespace vcpkg::PostBuildLint::BuildType case BuildType::RELEASE_DYNAMIC: return NAME_RELEASE_DYNAMIC; default: - Enums::unreachable(ENUM_NAME); + Checks::unreachable(VCPKG_LINE_INFO); } } } diff --git a/toolsrc/src/PostBuildLint_ConfigurationType.cpp b/toolsrc/src/PostBuildLint_ConfigurationType.cpp index 990b10a37..cca6eb63a 100644 --- a/toolsrc/src/PostBuildLint_ConfigurationType.cpp +++ b/toolsrc/src/PostBuildLint_ConfigurationType.cpp @@ -1,6 +1,7 @@ #include "pch.h" #include "PostBuildLint_ConfigurationType.h" #include "vcpkg_Enums.h" +#include "package_spec.h" namespace vcpkg::PostBuildLint::ConfigurationType { @@ -20,7 +21,7 @@ namespace vcpkg::PostBuildLint::ConfigurationType case ConfigurationType::NULLVALUE: return NULLVALUE_STRING; default: - Enums::unreachable(ENUM_NAME); + Checks::unreachable(VCPKG_LINE_INFO); } } } diff --git a/toolsrc/src/PostBuildLint_LinkageType.cpp b/toolsrc/src/PostBuildLint_LinkageType.cpp index 6d2c2c935..c6cb9ed58 100644 --- a/toolsrc/src/PostBuildLint_LinkageType.cpp +++ b/toolsrc/src/PostBuildLint_LinkageType.cpp @@ -1,6 +1,7 @@ #include "pch.h" #include "PostBuildLint_LinkageType.h" #include "vcpkg_Enums.h" +#include "vcpkg_Checks.h" namespace vcpkg::PostBuildLint::LinkageType { @@ -20,7 +21,7 @@ namespace vcpkg::PostBuildLint::LinkageType case LinkageType::NULLVALUE: return NULLVALUE_STRING; default: - Enums::unreachable(ENUM_NAME); + Checks::unreachable(VCPKG_LINE_INFO); } } diff --git a/toolsrc/src/StatusParagraphs.cpp b/toolsrc/src/StatusParagraphs.cpp index 9a440fbb8..cd932fd72 100644 --- a/toolsrc/src/StatusParagraphs.cpp +++ b/toolsrc/src/StatusParagraphs.cpp @@ -42,7 +42,7 @@ namespace vcpkg StatusParagraphs::iterator StatusParagraphs::insert(std::unique_ptr<StatusParagraph> pgh) { - Checks::check_exit(pgh != nullptr, "Inserted null paragraph"); + Checks::check_exit(VCPKG_LINE_INFO, pgh != nullptr, "Inserted null paragraph"); const package_spec& spec = pgh->package.spec; auto ptr = find(spec.name(), spec.target_triplet()); if (ptr == end()) diff --git a/toolsrc/src/coff_file_reader.cpp b/toolsrc/src/coff_file_reader.cpp index f48f912c1..922d8c420 100644 --- a/toolsrc/src/coff_file_reader.cpp +++ b/toolsrc/src/coff_file_reader.cpp @@ -30,9 +30,9 @@ namespace vcpkg::COFFFileReader return data; } - static void verify_equal_strings(const char* expected, const char* actual, int size, const char* label) + static void verify_equal_strings(const LineInfo& line_info, const char* expected, const char* actual, int size, const char* label) { - Checks::check_exit(memcmp(expected, actual, size) == 0, "Incorrect string (%s) found. Expected: (%s) but found (%s)", label, expected, actual); + Checks::check_exit(line_info, memcmp(expected, actual, size) == 0, "Incorrect string (%s) found. Expected: (%s) but found (%s)", label, expected, actual); } static void read_and_verify_PE_signature(fstream& fs) @@ -48,7 +48,7 @@ namespace vcpkg::COFFFileReader fs.seekg(offset_to_PE_signature); char signature[PE_SIGNATURE_SIZE]; fs.read(signature, PE_SIGNATURE_SIZE); - verify_equal_strings(PE_SIGNATURE, signature, PE_SIGNATURE_SIZE, "PE_SIGNATURE"); + verify_equal_strings(VCPKG_LINE_INFO, PE_SIGNATURE, signature, PE_SIGNATURE_SIZE, "PE_SIGNATURE"); fs.seekg(offset_to_PE_signature + PE_SIGNATURE_SIZE, ios_base::beg); } @@ -104,7 +104,7 @@ namespace vcpkg::COFFFileReader if (ret.data[0] != '\0') // Due to freeglut. github issue #223 { const std::string header_end = ret.data.substr(HEADER_END_OFFSET, HEADER_END_SIZE); - verify_equal_strings(HEADER_END, header_end.c_str(), HEADER_END_SIZE, "LIB HEADER_END"); + verify_equal_strings(VCPKG_LINE_INFO, HEADER_END, header_end.c_str(), HEADER_END_SIZE, "LIB HEADER_END"); } return ret; @@ -186,11 +186,11 @@ namespace vcpkg::COFFFileReader const std::string sig1_as_string = ret.data.substr(SIG1_OFFSET, SIG1_SIZE); const uint16_t sig1 = reinterpret_bytes<uint16_t>(sig1_as_string.c_str()); - Checks::check_exit(sig1 == SIG1, "Sig1 was incorrect. Expected %s but got %s", SIG1, sig1); + Checks::check_exit(VCPKG_LINE_INFO, sig1 == SIG1, "Sig1 was incorrect. Expected %s but got %s", SIG1, sig1); const std::string sig2_as_string = ret.data.substr(SIG2_OFFSET, SIG2_SIZE); const uint16_t sig2 = reinterpret_bytes<uint16_t>(sig2_as_string.c_str()); - Checks::check_exit(sig2 == SIG2, "Sig2 was incorrect. Expected %s but got %s", SIG2, sig2); + Checks::check_exit(VCPKG_LINE_INFO, sig2 == SIG2, "Sig2 was incorrect. Expected %s but got %s", SIG2, sig2); return ret; } @@ -218,13 +218,13 @@ namespace vcpkg::COFFFileReader char file_start[FILE_START_SIZE]; fs.read(file_start, FILE_START_SIZE); - verify_equal_strings(FILE_START, file_start, FILE_START_SIZE, "LIB FILE_START"); + verify_equal_strings(VCPKG_LINE_INFO, FILE_START, file_start, FILE_START_SIZE, "LIB FILE_START"); } dll_info read_dll(const fs::path& path) { std::fstream fs(path, std::ios::in | std::ios::binary | std::ios::ate); - Checks::check_exit(fs.is_open(), "Could not open file %s for reading", path.generic_string()); + Checks::check_exit(VCPKG_LINE_INFO, fs.is_open(), "Could not open file %s for reading", path.generic_string()); read_and_verify_PE_signature(fs); coff_file_header header = coff_file_header::read(fs); @@ -261,7 +261,7 @@ namespace vcpkg::COFFFileReader lib_info read_lib(const fs::path& path) { std::fstream fs(path, std::ios::in | std::ios::binary | std::ios::ate); - Checks::check_exit(fs.is_open(), "Could not open file %s for reading", path.generic_string()); + Checks::check_exit(VCPKG_LINE_INFO, fs.is_open(), "Could not open file %s for reading", path.generic_string()); read_and_verify_archive_file_signature(fs); @@ -270,12 +270,12 @@ namespace vcpkg::COFFFileReader // First Linker Member const archive_member_header first_linker_member_header = archive_member_header::read(fs); - Checks::check_exit(first_linker_member_header.name().substr(0, 2) == "/ ", "Could not find proper first linker member"); + Checks::check_exit(VCPKG_LINE_INFO, first_linker_member_header.name().substr(0, 2) == "/ ", "Could not find proper first linker member"); marker.advance_by(archive_member_header::HEADER_SIZE + first_linker_member_header.member_size()); marker.seek_to_marker(fs); const archive_member_header second_linker_member_header = archive_member_header::read(fs); - Checks::check_exit(second_linker_member_header.name().substr(0, 2) == "/ ", "Could not find proper second linker member"); + Checks::check_exit(VCPKG_LINE_INFO, second_linker_member_header.name().substr(0, 2) == "/ ", "Could not find proper second linker member"); // The first 4 bytes contains the number of archive members const uint32_t archive_member_count = read_value_from_stream<uint32_t>(fs); const offsets_array offsets = offsets_array::read(fs, archive_member_count); diff --git a/toolsrc/src/commands_build.cpp b/toolsrc/src/commands_build.cpp index a47083cbd..5ad39ae63 100644 --- a/toolsrc/src/commands_build.cpp +++ b/toolsrc/src/commands_build.cpp @@ -28,12 +28,12 @@ namespace vcpkg::Commands::Build BuildResult build_package(const SourceParagraph& source_paragraph, const package_spec& spec, const vcpkg_paths& paths, const fs::path& port_dir, const StatusParagraphs& status_db) { - Checks::check_exit(spec.name() == source_paragraph.name, "inconsistent arguments to build_package()"); + Checks::check_exit(VCPKG_LINE_INFO, spec.name() == source_paragraph.name, "inconsistent arguments to build_package()"); const triplet& target_triplet = spec.target_triplet(); - for (auto&& dep : source_paragraph.depends) + for (auto&& dep : filter_dependencies(source_paragraph.depends, target_triplet)) { - if (status_db.find_installed(dep.name, target_triplet) == status_db.end()) + if (status_db.find_installed(dep, target_triplet) == status_db.end()) { return BuildResult::CASCADED_DUE_TO_MISSING_DEPENDENCIES; } @@ -101,7 +101,7 @@ namespace vcpkg::Commands::Build case BuildResult::BUILD_FAILED: return BUILD_FAILED_STRING; case BuildResult::POST_BUILD_CHECKS_FAILED: return POST_BUILD_CHECKS_FAILED_STRING; case BuildResult::CASCADED_DUE_TO_MISSING_DEPENDENCIES: return CASCADED_DUE_TO_MISSING_DEPENDENCIES_STRING; - default: Checks::unreachable(); + default: Checks::unreachable(VCPKG_LINE_INFO); } } @@ -134,7 +134,7 @@ namespace vcpkg::Commands::Build } const expected<SourceParagraph> maybe_spgh = Paragraphs::try_load_port(port_dir); - Checks::check_exit(!maybe_spgh.error_code(), "Could not find package named %s: %s", spec, maybe_spgh.error_code().message()); + Checks::check_exit(VCPKG_LINE_INFO, !maybe_spgh.error_code(), "Could not find package named %s: %s", spec, maybe_spgh.error_code().message()); const SourceParagraph& spgh = *maybe_spgh.get(); StatusParagraphs status_db = database_load_check(paths); @@ -149,7 +149,7 @@ namespace vcpkg::Commands::Build }), unmet_dependencies.end()); - Checks::check_exit(!unmet_dependencies.empty()); + Checks::check_exit(VCPKG_LINE_INFO, !unmet_dependencies.empty()); System::println(System::color::error, "The build command requires all dependencies to be already installed."); System::println("The following dependencies are missing:"); System::println(""); diff --git a/toolsrc/src/commands_ci.cpp b/toolsrc/src/commands_ci.cpp index 315308a62..45ef2db28 100644 --- a/toolsrc/src/commands_ci.cpp +++ b/toolsrc/src/commands_ci.cpp @@ -20,7 +20,7 @@ namespace vcpkg::Commands::CI std::vector<package_spec> specs; for (const SourceParagraph& p : ports) { - specs.push_back(package_spec::from_name_and_triplet(p.name, target_triplet).get_or_throw()); + specs.push_back(package_spec::from_name_and_triplet(p.name, target_triplet).get_or_throw(VCPKG_LINE_INFO)); } return specs; @@ -37,7 +37,7 @@ namespace vcpkg::Commands::CI StatusParagraphs status_db = database_load_check(paths); const std::vector<package_spec_with_install_plan> install_plan = Dependencies::create_install_plan(paths, specs, status_db); - Checks::check_exit(!install_plan.empty(), "Install plan cannot be empty"); + Checks::check_exit(VCPKG_LINE_INFO, !install_plan.empty(), "Install plan cannot be empty"); std::vector<BuildResult> results; std::vector<std::chrono::milliseconds::rep> timing; @@ -70,7 +70,7 @@ namespace vcpkg::Commands::CI System::println(System::color::error, Build::create_error_message(result, action.spec)); continue; } - const BinaryParagraph bpgh = Paragraphs::try_load_cached_package(paths, action.spec).get_or_throw(); + const BinaryParagraph bpgh = Paragraphs::try_load_cached_package(paths, action.spec).get_or_throw(VCPKG_LINE_INFO); Install::install_package(paths, bpgh, &status_db); System::println(System::color::success, "Package %s is installed", action.spec); } @@ -81,7 +81,7 @@ namespace vcpkg::Commands::CI System::println(System::color::success, "Package %s is installed from cache", action.spec); } else - Checks::unreachable(); + Checks::unreachable(VCPKG_LINE_INFO); } catch (const std::exception& e) { diff --git a/toolsrc/src/commands_create.cpp b/toolsrc/src/commands_create.cpp index b74693ed5..2c3e02877 100644 --- a/toolsrc/src/commands_create.cpp +++ b/toolsrc/src/commands_create.cpp @@ -29,9 +29,9 @@ namespace vcpkg::Commands::Create if (args.command_arguments.size() >= 3) { const std::string& zip_file_name = args.command_arguments.at(2); - Checks::check_exit(!Files::has_invalid_chars_for_filesystem(zip_file_name), - R"(Filename cannot contain invalid chars %s, but was %s)", - Files::FILESYSTEM_INVALID_CHARACTERS, zip_file_name); + Checks::check_exit(VCPKG_LINE_INFO, !Files::has_invalid_chars_for_filesystem(zip_file_name), + R"(Filename cannot contain invalid chars %s, but was %s)", + Files::FILESYSTEM_INVALID_CHARACTERS, zip_file_name); cmake_args.push_back({ L"FILENAME", zip_file_name }); } diff --git a/toolsrc/src/commands_edit.cpp b/toolsrc/src/commands_edit.cpp index ce0557e09..1252790af 100644 --- a/toolsrc/src/commands_edit.cpp +++ b/toolsrc/src/commands_edit.cpp @@ -14,7 +14,7 @@ namespace vcpkg::Commands::Edit const std::string port_name = args.command_arguments.at(0); const fs::path portpath = paths.ports / port_name; - Checks::check_exit(fs::is_directory(portpath), R"(Could not find port named "%s")", port_name); + Checks::check_exit(VCPKG_LINE_INFO, fs::is_directory(portpath), R"(Could not find port named "%s")", port_name); // Find the user's selected editor std::wstring env_EDITOR; @@ -56,13 +56,19 @@ namespace vcpkg::Commands::Edit env_EDITOR = p.native(); break; } + auto p_insiders = fs::path(*code_installpath) / "Code - Insiders.exe"; + if (fs::exists(p_insiders)) + { + env_EDITOR = p_insiders.native(); + break; + } } } } if (env_EDITOR.empty()) { - Checks::exit_with_message("Visual Studio Code was not found and the environment variable EDITOR is not set"); + Checks::exit_with_message(VCPKG_LINE_INFO, "Visual Studio Code was not found and the environment variable EDITOR is not set"); } std::wstring cmdLine = Strings::wformat(LR"("%s" "%s" "%s" -n)", env_EDITOR, portpath.native(), (portpath / "portfile.cmake").native()); diff --git a/toolsrc/src/commands_hash.cpp b/toolsrc/src/commands_hash.cpp index 805da4153..2e55a4bb6 100644 --- a/toolsrc/src/commands_hash.cpp +++ b/toolsrc/src/commands_hash.cpp @@ -9,15 +9,15 @@ namespace vcpkg::Commands::Hash auto cmd_line = Strings::wformat(LR"(CertUtil.exe -hashfile "%s" %s)", path.c_str(), hashType.c_str()); auto ec_data = System::cmd_execute_and_capture_output(cmd_line); - Checks::check_exit(ec_data.exit_code == 0, "Running command:\n %s\n failed", Strings::utf16_to_utf8(cmd_line)); + Checks::check_exit(VCPKG_LINE_INFO, ec_data.exit_code == 0, "Running command:\n %s\n failed", Strings::utf16_to_utf8(cmd_line)); std::string const& output = ec_data.output; auto start = output.find_first_of("\r\n"); - Checks::check_exit(start != std::string::npos, "Unexpected output format from command: %s", Strings::utf16_to_utf8(cmd_line)); + Checks::check_exit(VCPKG_LINE_INFO, start != std::string::npos, "Unexpected output format from command: %s", Strings::utf16_to_utf8(cmd_line)); auto end = output.find_first_of("\r\n", start + 1); - Checks::check_exit(end != std::string::npos, "Unexpected output format from command: %s", Strings::utf16_to_utf8(cmd_line)); + Checks::check_exit(VCPKG_LINE_INFO, end != std::string::npos, "Unexpected output format from command: %s", Strings::utf16_to_utf8(cmd_line)); auto hash = output.substr(start, end - start); hash.erase(std::remove_if(hash.begin(), hash.end(), isspace), hash.end()); diff --git a/toolsrc/src/commands_import.cpp b/toolsrc/src/commands_import.cpp index 11924b4b2..a74b9e662 100644 --- a/toolsrc/src/commands_import.cpp +++ b/toolsrc/src/commands_import.cpp @@ -14,7 +14,7 @@ namespace vcpkg::Commands::Import static Binaries find_binaries_in_dir(const fs::path& path) { - Files::check_is_directory(path); + Files::check_is_directory(VCPKG_LINE_INFO, path); Binaries binaries; binaries.dlls = Files::recursive_find_files_with_extension_in_dir(path, ".dll"); @@ -35,9 +35,9 @@ namespace vcpkg::Commands::Import static void place_library_files_in(const fs::path& include_directory, const fs::path& project_directory, const fs::path& destination_path) { - Files::check_is_directory(include_directory); - Files::check_is_directory(project_directory); - Files::check_is_directory(destination_path); + Files::check_is_directory(VCPKG_LINE_INFO, include_directory); + Files::check_is_directory(VCPKG_LINE_INFO, project_directory); + Files::check_is_directory(VCPKG_LINE_INFO, destination_path); Binaries debug_binaries = find_binaries_in_dir(project_directory / "Debug"); Binaries release_binaries = find_binaries_in_dir(project_directory / "Release"); @@ -73,7 +73,7 @@ namespace vcpkg::Commands::Import const fs::path project_directory(args.command_arguments[2]); auto pghs = Paragraphs::get_paragraphs(control_file_path); - Checks::check_exit(pghs.size() == 1, "Invalid control file %s for package", control_file_path.generic_string()); + Checks::check_exit(VCPKG_LINE_INFO, pghs.size() == 1, "Invalid control file %s for package", control_file_path.generic_string()); StatusParagraph spgh; spgh.package = BinaryParagraph(pghs[0]); diff --git a/toolsrc/src/commands_install.cpp b/toolsrc/src/commands_install.cpp index bb3df943c..b7a8eafac 100644 --- a/toolsrc/src/commands_install.cpp +++ b/toolsrc/src/commands_install.cpp @@ -170,7 +170,7 @@ namespace vcpkg::Commands::Install { if (status_db->find_installed(dep, spgh.package.spec.target_triplet()) == status_db->end()) { - Checks::unreachable(); + Checks::unreachable(VCPKG_LINE_INFO); } } write_update(paths, spgh); @@ -193,7 +193,7 @@ namespace vcpkg::Commands::Install StatusParagraphs status_db = database_load_check(paths); std::vector<package_spec_with_install_plan> install_plan = Dependencies::create_install_plan(paths, specs, status_db); - Checks::check_exit(!install_plan.empty(), "Install plan cannot be empty"); + Checks::check_exit(VCPKG_LINE_INFO, !install_plan.empty(), "Install plan cannot be empty"); std::string specs_string = install_plan[0].spec.toString(); for (size_t i = 1; i < install_plan.size(); ++i) @@ -223,7 +223,7 @@ namespace vcpkg::Commands::Install System::println(Build::create_user_troubleshooting_message(action.spec)); exit(EXIT_FAILURE); } - const BinaryParagraph bpgh = Paragraphs::try_load_cached_package(paths, action.spec).get_or_throw(); + const BinaryParagraph bpgh = Paragraphs::try_load_cached_package(paths, action.spec).get_or_throw(VCPKG_LINE_INFO); install_package(paths, bpgh, &status_db); System::println(System::color::success, "Package %s is installed", action.spec); } @@ -233,7 +233,7 @@ namespace vcpkg::Commands::Install System::println(System::color::success, "Package %s is installed", action.spec); } else - Checks::unreachable(); + Checks::unreachable(VCPKG_LINE_INFO); } catch (const std::exception& e) { diff --git a/toolsrc/src/commands_integrate.cpp b/toolsrc/src/commands_integrate.cpp index f98b9f77c..7011f8d1d 100644 --- a/toolsrc/src/commands_integrate.cpp +++ b/toolsrc/src/commands_integrate.cpp @@ -156,7 +156,7 @@ namespace vcpkg::Commands::Integrate System::println(System::color::warning, "Warning: Previous integration file was not removed"); exit(EXIT_FAILURE); default: - Checks::unreachable(); + Checks::unreachable(VCPKG_LINE_INFO); } } } @@ -195,10 +195,10 @@ namespace vcpkg::Commands::Integrate System::println(System::color::warning, "Warning: integration was not applied"); exit(EXIT_FAILURE); default: - Checks::unreachable(); + Checks::unreachable(VCPKG_LINE_INFO); } - Checks::check_exit(fs::exists(system_wide_targets_file), "Error: failed to copy targets file to %s", system_wide_targets_file.string()); + Checks::check_exit(VCPKG_LINE_INFO, fs::exists(system_wide_targets_file), "Error: failed to copy targets file to %s", system_wide_targets_file.string()); } const fs::path appdata_src_path = tmp_dir / "vcpkg.user.targets"; @@ -272,7 +272,7 @@ namespace vcpkg::Commands::Integrate const int exit_code = System::cmd_execute_clean(cmd_line); const fs::path nuget_package = buildsystems_dir / Strings::format("%s.%s.nupkg", nuget_id, nupkg_version); - Checks::check_exit(exit_code == 0 && fs::exists(nuget_package), "Error: NuGet package creation failed"); + Checks::check_exit(VCPKG_LINE_INFO, exit_code == 0 && fs::exists(nuget_package), "Error: NuGet package creation failed"); System::println(System::color::success, "Created nupkg: %s", nuget_package.string()); System::println(R"( diff --git a/toolsrc/src/commands_portsdiff.cpp b/toolsrc/src/commands_portsdiff.cpp index 4d5a589f6..b1a166ed1 100644 --- a/toolsrc/src/commands_portsdiff.cpp +++ b/toolsrc/src/commands_portsdiff.cpp @@ -57,9 +57,9 @@ namespace vcpkg::Commands::PortsDiff { static const std::string VALID_COMMIT_OUTPUT = "commit\n"; - const std::wstring cmd = Strings::wformat(LR"("%s" cat-file -t %s 2>NUL)", git_exe.native(), git_commit_id); + const std::wstring cmd = Strings::wformat(LR"("%s" cat-file -t %s)", git_exe.native(), git_commit_id); const System::exit_code_and_output output = System::cmd_execute_and_capture_output(cmd); - Checks::check_exit(output.output == VALID_COMMIT_OUTPUT, "Invalid commit id %s", Strings::utf16_to_utf8(git_commit_id)); + Checks::check_exit(VCPKG_LINE_INFO, output.output == VALID_COMMIT_OUTPUT, "Invalid commit id %s", Strings::utf16_to_utf8(git_commit_id)); } void perform_and_exit(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths) diff --git a/toolsrc/src/commands_remove.cpp b/toolsrc/src/commands_remove.cpp index 1b7b7923a..7e4228496 100644 --- a/toolsrc/src/commands_remove.cpp +++ b/toolsrc/src/commands_remove.cpp @@ -129,7 +129,7 @@ namespace vcpkg::Commands::Remove continue; } - Checks::unreachable(); + Checks::unreachable(VCPKG_LINE_INFO); } if (!not_installed.empty()) @@ -158,7 +158,7 @@ namespace vcpkg::Commands::Remove return " " + p->spec.toString(); } - Checks::unreachable(); + Checks::unreachable(VCPKG_LINE_INFO); })); } } @@ -175,7 +175,7 @@ namespace vcpkg::Commands::Remove auto status_db = database_load_check(paths); const std::vector<package_spec_with_remove_plan> remove_plan = Dependencies::create_remove_plan(specs, status_db); - Checks::check_exit(!remove_plan.empty(), "Remove plan cannot be empty"); + Checks::check_exit(VCPKG_LINE_INFO, !remove_plan.empty(), "Remove plan cannot be empty"); print_plan(remove_plan); @@ -208,7 +208,7 @@ namespace vcpkg::Commands::Remove break; case remove_plan_type::UNKNOWN: default: - Checks::unreachable(); + Checks::unreachable(VCPKG_LINE_INFO); } if (alsoRemoveFolderFromPackages) diff --git a/toolsrc/src/commands_search.cpp b/toolsrc/src/commands_search.cpp index 8bac858f1..463257fc9 100644 --- a/toolsrc/src/commands_search.cpp +++ b/toolsrc/src/commands_search.cpp @@ -88,7 +88,7 @@ namespace vcpkg::Commands::Search } } - System::println("\nIf your library is not listed, please open an issue at:\n" + System::println("\nIf your library is not listed, please open an issue at and/or consider making a pull request:\n" " https://github.com/Microsoft/vcpkg/issues"); exit(EXIT_SUCCESS); diff --git a/toolsrc/src/opt_bool.cpp b/toolsrc/src/opt_bool.cpp index 324936fb4..b4642f273 100644 --- a/toolsrc/src/opt_bool.cpp +++ b/toolsrc/src/opt_bool.cpp @@ -24,6 +24,6 @@ namespace vcpkg::opt_bool return opt_bool_t::DISABLED; } - Checks::exit_with_message("Could not convert string [%s] to opt_bool", s); + Checks::exit_with_message(VCPKG_LINE_INFO, "Could not convert string [%s] to opt_bool", s); } } diff --git a/toolsrc/src/package_spec_parse_result.cpp b/toolsrc/src/package_spec_parse_result.cpp index 892232c2e..fc92cf2ff 100644 --- a/toolsrc/src/package_spec_parse_result.cpp +++ b/toolsrc/src/package_spec_parse_result.cpp @@ -20,7 +20,7 @@ namespace vcpkg case package_spec_parse_result::INVALID_CHARACTERS: return "Contains invalid characters. Only alphanumeric lowercase ASCII characters and dashes are allowed"; default: - Checks::unreachable(); + Checks::unreachable(VCPKG_LINE_INFO); } } diff --git a/toolsrc/src/triplet.cpp b/toolsrc/src/triplet.cpp index d91e0e68f..173656f7b 100644 --- a/toolsrc/src/triplet.cpp +++ b/toolsrc/src/triplet.cpp @@ -40,7 +40,7 @@ namespace vcpkg { const std::string s(Strings::ascii_to_lowercase(triplet_as_string)); auto it = std::find(s.cbegin(), s.cend(), '-'); - Checks::check_exit(it != s.cend(), "Invalid triplet: %s", triplet_as_string); + Checks::check_exit(VCPKG_LINE_INFO, it != s.cend(), "Invalid triplet: %s", triplet_as_string); triplet t; t.m_canonical_name = s; diff --git a/toolsrc/src/vcpkg.cpp b/toolsrc/src/vcpkg.cpp index e94d2538b..6c81d54f9 100644 --- a/toolsrc/src/vcpkg.cpp +++ b/toolsrc/src/vcpkg.cpp @@ -1,7 +1,6 @@ #define WIN32_LEAN_AND_MEAN #include <Windows.h> -#include <iostream> #include <fstream> #include <memory> #include <cassert> @@ -14,11 +13,10 @@ #include "Paragraphs.h" #include "vcpkg_Strings.h" #include "vcpkg_Chrono.h" +#include "vcpkglib.h" using namespace vcpkg; -bool g_debugging = false; - void invalid_command(const std::string& cmd) { System::println(System::color::error, "invalid command: %s", cmd); @@ -58,13 +56,13 @@ static void inner(const vcpkg_cmd_arguments& args) } } - Checks::check_exit(!vcpkg_root_dir.empty(), "Error: Could not detect vcpkg-root."); + Checks::check_exit(VCPKG_LINE_INFO, !vcpkg_root_dir.empty(), "Error: Could not detect vcpkg-root."); const expected<vcpkg_paths> expected_paths = vcpkg_paths::create(vcpkg_root_dir); - Checks::check_exit(!expected_paths.error_code(), "Error: Invalid vcpkg root directory %s: %s", vcpkg_root_dir.string(), expected_paths.error_code().message()); - const vcpkg_paths paths = expected_paths.get_or_throw(); + Checks::check_exit(VCPKG_LINE_INFO, !expected_paths.error_code(), "Error: Invalid vcpkg root directory %s: %s", vcpkg_root_dir.string(), expected_paths.error_code().message()); + const vcpkg_paths paths = expected_paths.get_or_throw(VCPKG_LINE_INFO); int exit_code = _wchdir(paths.root.c_str()); - Checks::check_exit(exit_code == 0, "Changing the working dir failed"); + Checks::check_exit(VCPKG_LINE_INFO, exit_code == 0, "Changing the working dir failed"); if (auto command_function = Commands::find(args.command, Commands::get_available_commands_type_b())) { @@ -113,7 +111,7 @@ static void loadConfig() try { - std::string config_contents = Files::read_contents(localappdata / "vcpkg" / "config").get_or_throw(); + std::string config_contents = Files::read_contents(localappdata / "vcpkg" / "config").get_or_throw(VCPKG_LINE_INFO); std::unordered_map<std::string, std::string> keys; auto pghs = Paragraphs::parse_paragraphs(config_contents); @@ -128,7 +126,7 @@ static void loadConfig() auto user_id = keys["User-Id"]; auto user_time = keys["User-Since"]; - Checks::check_throw(!user_id.empty() && !user_time.empty(), ""); // Use as goto to the catch statement + Checks::check_throw(VCPKG_LINE_INFO, !user_id.empty() && !user_time.empty(), ""); // Use as goto to the catch statement SetUserInformation(user_id, user_time); return; @@ -156,7 +154,7 @@ static void loadConfig() static std::string trim_path_from_command_line(const std::string& full_command_line) { - Checks::check_exit(full_command_line.size() > 0, "Internal failure - cannot have empty command line"); + Checks::check_exit(VCPKG_LINE_INFO, full_command_line.size() > 0, "Internal failure - cannot have empty command line"); if (full_command_line[0] == '"') { diff --git a/toolsrc/src/vcpkg_Checks.cpp b/toolsrc/src/vcpkg_Checks.cpp index 02d3480a2..81e7d3825 100644 --- a/toolsrc/src/vcpkg_Checks.cpp +++ b/toolsrc/src/vcpkg_Checks.cpp @@ -1,12 +1,22 @@ #include "pch.h" #include "vcpkg_Checks.h" #include "vcpkg_System.h" +#include "vcpkglib.h" namespace vcpkg::Checks { - __declspec(noreturn) void unreachable() + static void print_line_info_if_debug(const LineInfo& line_info) + { + if (g_debugging) + { + System::println(System::color::error, line_info.toString()); + } + } + + __declspec(noreturn) void unreachable(const LineInfo& line_info) { System::println(System::color::error, "Error: Unreachable code was reached"); + System::println(System::color::error, line_info.toString()); // Always print line_info here #ifndef NDEBUG std::abort(); #else @@ -14,38 +24,40 @@ namespace vcpkg::Checks #endif } - __declspec(noreturn) void exit_with_message(const char* errorMessage) + __declspec(noreturn) void exit_with_message(const LineInfo& line_info, const char* errorMessage) { System::println(System::color::error, errorMessage); + print_line_info_if_debug(line_info); exit(EXIT_FAILURE); } - __declspec(noreturn) void throw_with_message(const char* errorMessage) + __declspec(noreturn) void throw_with_message(const LineInfo& line_info, const char* errorMessage) { + print_line_info_if_debug(line_info); throw std::runtime_error(errorMessage); } - void check_throw(bool expression, const char* errorMessage) + void check_throw(const LineInfo& line_info, bool expression, const char* errorMessage) { if (!expression) { - throw_with_message(errorMessage); + throw_with_message(line_info, errorMessage); } } - void check_exit(bool expression) + void check_exit(const LineInfo& line_info, bool expression) { if (!expression) { - exit(EXIT_FAILURE); + exit_with_message(line_info, ""); } } - void check_exit(bool expression, const char* errorMessage) + void check_exit(const LineInfo& line_info, bool expression, const char* errorMessage) { if (!expression) { - exit_with_message(errorMessage); + exit_with_message(line_info, errorMessage); } } } diff --git a/toolsrc/src/vcpkg_Dependencies.cpp b/toolsrc/src/vcpkg_Dependencies.cpp index e8bf10617..b96cf282c 100644 --- a/toolsrc/src/vcpkg_Dependencies.cpp +++ b/toolsrc/src/vcpkg_Dependencies.cpp @@ -56,7 +56,7 @@ namespace vcpkg::Dependencies { for (const std::string& dep_as_string : dependencies_as_string) { - const package_spec current_dep = package_spec::from_name_and_triplet(dep_as_string, spec.target_triplet()).get_or_throw(); + const package_spec current_dep = package_spec::from_name_and_triplet(dep_as_string, spec.target_triplet()).get_or_throw(VCPKG_LINE_INFO); graph.add_edge(spec, current_dep); if (was_examined.find(current_dep) == was_examined.end()) { @@ -82,7 +82,7 @@ namespace vcpkg::Dependencies expected<SourceParagraph> maybe_spgh = Paragraphs::try_load_port(paths.port_dir(spec)); SourceParagraph* spgh = maybe_spgh.get(); - Checks::check_exit(spgh != nullptr, "Cannot find package %s", spec.name()); + Checks::check_exit(VCPKG_LINE_INFO, spgh != nullptr, "Cannot find package %s", spec.name()); process_dependencies(filter_dependencies(spgh->depends, spec.target_triplet())); was_examined.emplace(spec, install_plan_action{install_plan_type::BUILD_AND_INSTALL, nullptr, std::make_unique<SourceParagraph>(std::move(*spgh))}); } diff --git a/toolsrc/src/vcpkg_Enums.cpp b/toolsrc/src/vcpkg_Enums.cpp index 5e698659d..b5a487a37 100644 --- a/toolsrc/src/vcpkg_Enums.cpp +++ b/toolsrc/src/vcpkg_Enums.cpp @@ -9,13 +9,8 @@ namespace vcpkg::Enums return Strings::format("%s_NULLVALUE", enum_name); } - void nullvalue_used(const std::string& enum_name) + __declspec(noreturn) void nullvalue_used(const LineInfo& line_info, const std::string& enum_name) { - Checks::exit_with_message("NULLVALUE of enum %s was used", enum_name); - } - - void unreachable(const std::string& enum_name) - { - Checks::exit_with_message("Unreachable code for enum, %s", enum_name); + Checks::exit_with_message(VCPKG_LINE_INFO, "NULLVALUE of enum %s was used", enum_name); } } diff --git a/toolsrc/src/vcpkg_Environment.cpp b/toolsrc/src/vcpkg_Environment.cpp index 8aaaba8a8..f0c157b6e 100644 --- a/toolsrc/src/vcpkg_Environment.cpp +++ b/toolsrc/src/vcpkg_Environment.cpp @@ -12,7 +12,7 @@ namespace vcpkg::Environment const fs::path script = paths.scripts / "findVisualStudioInstallationInstances.ps1"; const std::wstring cmd = System::create_powershell_script_cmd(script); System::exit_code_and_output ec_data = System::cmd_execute_and_capture_output(cmd); - Checks::check_exit(ec_data.exit_code == 0, "Could not run script to detect VS 2017 instances"); + Checks::check_exit(VCPKG_LINE_INFO, ec_data.exit_code == 0, "Could not run script to detect VS 2017 instances"); return Strings::split(ec_data.output, "\n"); } @@ -141,7 +141,7 @@ namespace vcpkg::Environment static fs::path find_ProgramFiles() { const optional<std::wstring> program_files = System::get_environmental_variable(L"PROGRAMFILES"); - Checks::check_exit(program_files.get() != nullptr, "Could not detect the PROGRAMFILES environmental variable"); + Checks::check_exit(VCPKG_LINE_INFO, program_files.get() != nullptr, "Could not detect the PROGRAMFILES environmental variable"); return *program_files; } diff --git a/toolsrc/src/vcpkg_Files.cpp b/toolsrc/src/vcpkg_Files.cpp index 57d4c665c..95b99691c 100644 --- a/toolsrc/src/vcpkg_Files.cpp +++ b/toolsrc/src/vcpkg_Files.cpp @@ -6,9 +6,9 @@ namespace vcpkg::Files { static const std::regex FILESYSTEM_INVALID_CHARACTERS_REGEX = std::regex(R"([\/:*?"<>|])"); - void check_is_directory(const fs::path& dirpath) + void check_is_directory(const LineInfo& line_info, const fs::path& dirpath) { - Checks::check_exit(fs::is_directory(dirpath), "The path %s is not a directory", dirpath.string()); + Checks::check_exit(VCPKG_LINE_INFO, fs::is_directory(dirpath), "The path %s is not a directory", dirpath.string()); } bool has_invalid_chars_for_filesystem(const std::string& s) diff --git a/toolsrc/src/vcpkg_System.cpp b/toolsrc/src/vcpkg_System.cpp index 472f8450f..a4e78d90a 100644 --- a/toolsrc/src/vcpkg_System.cpp +++ b/toolsrc/src/vcpkg_System.cpp @@ -103,7 +103,7 @@ namespace vcpkg::System // Flush stdout before launching external process fflush(stdout); - const std::wstring& actual_cmd_line = Strings::wformat(LR"###("%s")###", cmd_line); + const std::wstring& actual_cmd_line = Strings::wformat(LR"###("%s 2>&1")###", cmd_line); std::string output; char buf[1024]; @@ -132,7 +132,7 @@ namespace vcpkg::System std::wstring create_powershell_script_cmd(const fs::path& script_path, const std::wstring& args) { // TODO: switch out ExecutionPolicy Bypass with "Remove Mark Of The Web" code and restore RemoteSigned - return Strings::wformat(LR"(powershell -ExecutionPolicy Bypass -Command "& {& '%s' %s}")", script_path.native(), args); + return Strings::wformat(LR"(powershell -NoProfile -ExecutionPolicy Bypass -Command "& {& '%s' %s}")", script_path.native(), args); } void print(const char* message) @@ -172,9 +172,9 @@ namespace vcpkg::System return nullptr; auto ret = std::make_unique<std::wstring>(sz, L'\0'); - Checks::check_exit(MAXDWORD >= ret->size()); + Checks::check_exit(VCPKG_LINE_INFO, MAXDWORD >= ret->size()); auto sz2 = GetEnvironmentVariableW(varname, ret->data(), static_cast<DWORD>(ret->size())); - Checks::check_exit(sz2 + 1 == sz); + Checks::check_exit(VCPKG_LINE_INFO, sz2 + 1 == sz); ret->pop_back(); return ret; } diff --git a/toolsrc/src/vcpkg_metrics_uploader.cpp b/toolsrc/src/vcpkg_metrics_uploader.cpp index 82dcd4b03..9f040286b 100644 --- a/toolsrc/src/vcpkg_metrics_uploader.cpp +++ b/toolsrc/src/vcpkg_metrics_uploader.cpp @@ -12,6 +12,6 @@ int WINAPI WinMain(_In_ HINSTANCE, _In_opt_ HINSTANCE, _In_ LPSTR, _In_ int) szArgList = CommandLineToArgvW(GetCommandLineW(), &argCount); - Checks::check_exit(argCount == 2, "Requires exactly one argument, the path to the payload file"); - Upload(Files::read_contents(szArgList[1]).get_or_throw()); + Checks::check_exit(VCPKG_LINE_INFO, argCount == 2, "Requires exactly one argument, the path to the payload file"); + Upload(Files::read_contents(szArgList[1]).get_or_throw(VCPKG_LINE_INFO)); } diff --git a/toolsrc/src/vcpkg_paths.cpp b/toolsrc/src/vcpkg_paths.cpp index fa6fca370..f339be47a 100644 --- a/toolsrc/src/vcpkg_paths.cpp +++ b/toolsrc/src/vcpkg_paths.cpp @@ -12,7 +12,7 @@ namespace vcpkg { static const std::regex re(R"###((\d+)\.(\d+)\.(\d+))###"); - auto rc = System::cmd_execute_and_capture_output(Strings::wformat(LR"(%s 2>&1)", version_cmd)); + auto rc = System::cmd_execute_and_capture_output(Strings::wformat(LR"(%s)", version_cmd)); if (rc.exit_code != 0) { return false; @@ -81,9 +81,9 @@ namespace vcpkg exit(rc.exit_code); } - const fs::path actual_downloaded_path = rc.output; - Checks::check_exit(expected_downloaded_path == actual_downloaded_path, "Expected dependency downloaded path to be %s, but was %s", - expected_downloaded_path.generic_string(), actual_downloaded_path.generic_string()); + const fs::path actual_downloaded_path = Strings::trimmed(rc.output); + Checks::check_exit(VCPKG_LINE_INFO, expected_downloaded_path == actual_downloaded_path, "Expected dependency downloaded path to be %s, but was %s", + expected_downloaded_path.generic_string(), actual_downloaded_path.generic_string()); return actual_downloaded_path; } diff --git a/toolsrc/src/vcpkglib.cpp b/toolsrc/src/vcpkglib.cpp index 7ea33da0a..932502d2d 100644 --- a/toolsrc/src/vcpkglib.cpp +++ b/toolsrc/src/vcpkglib.cpp @@ -7,6 +7,8 @@ namespace vcpkg { + bool g_debugging = false; + static StatusParagraphs load_current_database(const fs::path& vcpkg_dir_status_file, const fs::path& vcpkg_dir_status_file_old) { if (!fs::exists(vcpkg_dir_status_file)) @@ -20,7 +22,7 @@ namespace vcpkg fs::rename(vcpkg_dir_status_file_old, vcpkg_dir_status_file); } - auto text = Files::read_contents(vcpkg_dir_status_file).get_or_throw(); + auto text = Files::read_contents(vcpkg_dir_status_file).get_or_throw(VCPKG_LINE_INFO); auto pghs = Paragraphs::parse_paragraphs(text); std::vector<std::unique_ptr<StatusParagraph>> status_pghs; @@ -63,7 +65,7 @@ namespace vcpkg if (b->path().filename() == "incomplete") continue; - auto text = Files::read_contents(b->path()).get_or_throw(); + auto text = Files::read_contents(b->path()).get_or_throw(VCPKG_LINE_INFO); auto pghs = Paragraphs::parse_paragraphs(text); for (auto&& p : pghs) { @@ -183,7 +185,7 @@ namespace vcpkg } const fs::path listfile_path = paths.listfile_path(pgh->package); - std::vector<std::string> installed_files_of_current_pgh = Files::read_all_lines(listfile_path).get_or_throw(); + std::vector<std::string> installed_files_of_current_pgh = Files::read_all_lines(listfile_path).get_or_throw(VCPKG_LINE_INFO); Strings::trim_all_and_remove_whitespace_strings(&installed_files_of_current_pgh); upgrade_to_slash_terminated_sorted_format(&installed_files_of_current_pgh, listfile_path); diff --git a/toolsrc/src/vcpkglib_helpers.cpp b/toolsrc/src/vcpkglib_helpers.cpp index 6b96c25cb..1730be374 100644 --- a/toolsrc/src/vcpkglib_helpers.cpp +++ b/toolsrc/src/vcpkglib_helpers.cpp @@ -31,14 +31,14 @@ namespace vcpkg::details std::string required_field(const std::unordered_map<std::string, std::string>& fields, const std::string& fieldname) { auto it = fields.find(fieldname); - Checks::check_exit(it != fields.end(), "Required field not present: %s", fieldname); + Checks::check_exit(VCPKG_LINE_INFO, it != fields.end(), "Required field not present: %s", fieldname); return it->second; } std::string remove_required_field(std::unordered_map<std::string, std::string>* fields, const std::string& fieldname) { auto it = fields->find(fieldname); - Checks::check_exit(it != fields->end(), "Required field not present: %s", fieldname); + Checks::check_exit(VCPKG_LINE_INFO, it != fields->end(), "Required field not present: %s", fieldname); const std::string value = std::move(it->second); fields->erase(it); |
