Use std::filesystem to compute output paths in blobcat and impellerc (flutter/engine#33939)

This commit is contained in:
Jonah Williams
2022-06-09 15:48:05 -07:00
committed by GitHub
parent 7f68c203f9
commit b30f87212c
3 changed files with 26 additions and 8 deletions

View File

@@ -362,7 +362,8 @@ bool WriteAtomically(const fml::UniqueFD& base_directory,
OpenFile(file_path.c_str(), true, FilePermission::kReadWrite);
if (!temp_file.is_valid()) {
FML_DLOG(ERROR) << "Could not create temporary file.";
FML_DLOG(ERROR) << "Could not create file: " << file_path.c_str() << " "
<< GetLastError() << " " << GetLastErrorMessage();
return false;
}

View File

@@ -35,7 +35,10 @@ bool Main(const fml::CommandLine& command_line) {
auto current_directory =
fml::OpenDirectory(std::filesystem::current_path().string().c_str(),
false, fml::FilePermission::kReadWrite);
if (!fml::WriteAtomically(current_directory, output.c_str(), *blob)) {
auto output_path =
std::filesystem::absolute(std::filesystem::current_path() / output);
if (!fml::WriteAtomically(current_directory, output_path.string().c_str(),
*blob)) {
std::cerr << "Could not write shader blob to path " << output << std::endl;
return false;
}

View File

@@ -66,8 +66,10 @@ bool Main(const fml::CommandLine& command_line) {
return false;
}
auto spriv_file_name = std::filesystem::absolute(
std::filesystem::current_path() / switches.spirv_file_name);
if (!fml::WriteAtomically(*switches.working_directory,
switches.spirv_file_name.c_str(),
spriv_file_name.string().c_str(),
*compiler.GetSPIRVAssembly())) {
std::cerr << "Could not write file to " << switches.spirv_file_name
<< std::endl;
@@ -75,8 +77,10 @@ bool Main(const fml::CommandLine& command_line) {
}
if (TargetPlatformNeedsSL(options.target_platform)) {
auto sl_file_name = std::filesystem::absolute(
std::filesystem::current_path() / switches.sl_file_name);
if (!fml::WriteAtomically(*switches.working_directory,
switches.sl_file_name.c_str(),
sl_file_name.string().c_str(),
*compiler.GetSLShaderSource())) {
std::cerr << "Could not write file to " << switches.spirv_file_name
<< std::endl;
@@ -86,9 +90,11 @@ bool Main(const fml::CommandLine& command_line) {
if (TargetPlatformNeedsReflection(options.target_platform)) {
if (!switches.reflection_json_name.empty()) {
auto reflection_json_name = std::filesystem::absolute(
std::filesystem::current_path() / switches.reflection_json_name);
if (!fml::WriteAtomically(
*switches.working_directory,
switches.reflection_json_name.c_str(),
reflection_json_name.string().c_str(),
*compiler.GetReflector()->GetReflectionJSON())) {
std::cerr << "Could not write reflection json to "
<< switches.reflection_json_name << std::endl;
@@ -97,9 +103,12 @@ bool Main(const fml::CommandLine& command_line) {
}
if (!switches.reflection_header_name.empty()) {
auto reflection_header_name =
std::filesystem::absolute(std::filesystem::current_path() /
switches.reflection_header_name.c_str());
if (!fml::WriteAtomically(
*switches.working_directory,
switches.reflection_header_name.c_str(),
reflection_header_name.string().c_str(),
*compiler.GetReflector()->GetReflectionHeader())) {
std::cerr << "Could not write reflection header to "
<< switches.reflection_header_name << std::endl;
@@ -108,8 +117,11 @@ bool Main(const fml::CommandLine& command_line) {
}
if (!switches.reflection_cc_name.empty()) {
auto reflection_cc_name =
std::filesystem::absolute(std::filesystem::current_path() /
switches.reflection_cc_name.c_str());
if (!fml::WriteAtomically(*switches.working_directory,
switches.reflection_cc_name.c_str(),
reflection_cc_name.string().c_str(),
*compiler.GetReflector()->GetReflectionCC())) {
std::cerr << "Could not write reflection CC to "
<< switches.reflection_cc_name << std::endl;
@@ -132,8 +144,10 @@ bool Main(const fml::CommandLine& command_line) {
result_file = switches.spirv_file_name;
break;
}
auto depfile_path = std::filesystem::absolute(
std::filesystem::current_path() / switches.depfile_path.c_str());
if (!fml::WriteAtomically(*switches.working_directory,
switches.depfile_path.c_str(),
depfile_path.string().c_str(),
*compiler.CreateDepfileContents({result_file}))) {
std::cerr << "Could not write depfile to " << switches.depfile_path
<< std::endl;