mirror of
https://github.com/microsoft/vcpkg.git
synced 2025-01-18 12:53:02 +08:00
export
: Refactoring
This commit is contained in:
parent
75e3838582
commit
0c47e6e04a
@ -76,6 +76,41 @@ namespace vcpkg::Commands::Export
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void do_nuget_export(const VcpkgPaths& paths, const fs::path& exported_dir_path)
|
||||||
|
{
|
||||||
|
Files::Filesystem& fs = paths.get_filesystem();
|
||||||
|
|
||||||
|
const std::string exported_dir_filename = exported_dir_path.filename().string();
|
||||||
|
const std::string nuget_id = "vcpkg-" + exported_dir_filename;
|
||||||
|
const std::string nupkg_version = "1.0.0";
|
||||||
|
|
||||||
|
const std::string nuspec_file_content = create_nuspec_file_contents(exported_dir_filename, nuget_id, nupkg_version);
|
||||||
|
|
||||||
|
const fs::path nuspec_file_path = paths.root / "export.nuspec";
|
||||||
|
fs.write_contents(nuspec_file_path, nuspec_file_content);
|
||||||
|
|
||||||
|
const fs::path& nuget_exe = paths.get_nuget_exe();
|
||||||
|
|
||||||
|
// -NoDefaultExcludes is needed for ".vcpkg-root"
|
||||||
|
const std::wstring cmd_line = Strings::wformat(LR"("%s" pack -OutputDirectory "%s" "%s" -NoDefaultExcludes)", nuget_exe.native(), paths.root.native(), nuspec_file_path.native());
|
||||||
|
|
||||||
|
const int exit_code = System::cmd_execute_clean(cmd_line);
|
||||||
|
Checks::check_exit(VCPKG_LINE_INFO, exit_code == 0, "Error: NuGet package creation failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
static std::string create_exported_dir_filename()
|
||||||
|
{
|
||||||
|
const tm date_time = System::get_current_date_time();
|
||||||
|
|
||||||
|
// Format is: YYYY-mm-dd_HH-MM-SS
|
||||||
|
// 19 characters + 1 null terminating character will be written for a total of 20 chars
|
||||||
|
char mbstr[20];
|
||||||
|
const size_t bytes_written = std::strftime(mbstr, sizeof(mbstr), "%Y-%m-%d_%H-%M-%S", &date_time);
|
||||||
|
Checks::check_exit(VCPKG_LINE_INFO, bytes_written == 19, "Expected 19 bytes to be written, but %u were written", bytes_written);
|
||||||
|
const std::string date_time_as_string(mbstr);
|
||||||
|
return ("exported-" + date_time_as_string);
|
||||||
|
}
|
||||||
|
|
||||||
void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths, const Triplet& default_triplet)
|
void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths, const Triplet& default_triplet)
|
||||||
{
|
{
|
||||||
static const std::string OPTION_DRY_RUN = "--dry-run";
|
static const std::string OPTION_DRY_RUN = "--dry-run";
|
||||||
@ -135,15 +170,7 @@ namespace vcpkg::Commands::Export
|
|||||||
Checks::exit_success(VCPKG_LINE_INFO);
|
Checks::exit_success(VCPKG_LINE_INFO);
|
||||||
}
|
}
|
||||||
|
|
||||||
const tm date_time = System::get_current_date_time();
|
const std::string exported_dir_filename = create_exported_dir_filename();
|
||||||
|
|
||||||
// Format is: YYYY-mm-dd_HH-MM-SS
|
|
||||||
// 19 characters + 1 null terminating character will be written for a total of 20 chars
|
|
||||||
char mbstr[20];
|
|
||||||
const size_t bytes_written = std::strftime(mbstr, sizeof(mbstr), "%Y-%m-%d_%H-%M-%S", &date_time);
|
|
||||||
Checks::check_exit(VCPKG_LINE_INFO, bytes_written == 19, "Expected 19 bytes to be written, but %u were written", bytes_written);
|
|
||||||
const std::string date_time_as_string(mbstr);
|
|
||||||
const std::string exported_dir_filename = ("exported-" + date_time_as_string);
|
|
||||||
|
|
||||||
Files::Filesystem& fs = paths.get_filesystem();
|
Files::Filesystem& fs = paths.get_filesystem();
|
||||||
const fs::path exported_dir_path = paths.root / exported_dir_filename;
|
const fs::path exported_dir_path = paths.root / exported_dir_filename;
|
||||||
@ -177,22 +204,6 @@ namespace vcpkg::Commands::Export
|
|||||||
|
|
||||||
System::println(System::Color::success, R"(Files exported at: "%s")", exported_dir_path.generic_string());
|
System::println(System::Color::success, R"(Files exported at: "%s")", exported_dir_path.generic_string());
|
||||||
|
|
||||||
const std::string nuget_id = "vcpkg-" + exported_dir_filename;
|
|
||||||
const std::string nupkg_version = "1.0.0";
|
|
||||||
|
|
||||||
const std::string nuspec_file_content = create_nuspec_file_contents(exported_dir_path.filename().string(), nuget_id, nupkg_version);
|
|
||||||
|
|
||||||
const fs::path nuspec_file_path = paths.root / "export.nuspec";
|
|
||||||
fs.write_contents(nuspec_file_path, nuspec_file_content);
|
|
||||||
|
|
||||||
const fs::path& nuget_exe = paths.get_nuget_exe();
|
|
||||||
|
|
||||||
// -NoDefaultExcludes is needed for ".vcpkg-root"
|
|
||||||
const std::wstring cmd_line = Strings::wformat(LR"("%s" pack -OutputDirectory "%s" "%s" -NoDefaultExcludes)", nuget_exe.native(), paths.root.native(), nuspec_file_path.native());
|
|
||||||
|
|
||||||
const int exit_code = System::cmd_execute_clean(cmd_line);
|
|
||||||
Checks::check_exit(VCPKG_LINE_INFO, exit_code == 0, "Error: NuGet package creation failed");
|
|
||||||
|
|
||||||
Checks::exit_success(VCPKG_LINE_INFO);
|
Checks::exit_success(VCPKG_LINE_INFO);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user