Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 223a485

Browse files
authored
Handle include paths the same way as output paths (#37335)
1 parent 396be86 commit 223a485

File tree

4 files changed

+29
-29
lines changed

4 files changed

+29
-29
lines changed

impeller/compiler/impellerc_main.cc

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,9 @@ bool Main(const fml::CommandLine& command_line) {
110110

111111
auto spriv_file_name = std::filesystem::absolute(
112112
std::filesystem::current_path() / switches.spirv_file_name);
113-
if (!fml::WriteAtomically(
114-
*switches.working_directory,
115-
reinterpret_cast<const char*>(spriv_file_name.u8string().c_str()),
116-
*compiler.GetSPIRVAssembly())) {
113+
if (!fml::WriteAtomically(*switches.working_directory,
114+
Utf8FromPath(spriv_file_name).c_str(),
115+
*compiler.GetSPIRVAssembly())) {
117116
std::cerr << "Could not write file to " << switches.spirv_file_name
118117
<< std::endl;
119118
return false;
@@ -144,10 +143,9 @@ bool Main(const fml::CommandLine& command_line) {
144143
std::cerr << "Runtime stage data could not be created." << std::endl;
145144
return false;
146145
}
147-
if (!fml::WriteAtomically(*switches.working_directory, //
148-
reinterpret_cast<const char*>(
149-
sl_file_name.u8string().c_str()), //
150-
*stage_data_mapping //
146+
if (!fml::WriteAtomically(*switches.working_directory, //
147+
Utf8FromPath(sl_file_name).c_str(), //
148+
*stage_data_mapping //
151149
)) {
152150
std::cerr << "Could not write file to " << switches.sl_file_name
153151
<< std::endl;
@@ -159,10 +157,9 @@ bool Main(const fml::CommandLine& command_line) {
159157
return false;
160158
}
161159
} else {
162-
if (!fml::WriteAtomically(
163-
*switches.working_directory,
164-
reinterpret_cast<const char*>(sl_file_name.u8string().c_str()),
165-
*compiler.GetSLShaderSource())) {
160+
if (!fml::WriteAtomically(*switches.working_directory,
161+
Utf8FromPath(sl_file_name).c_str(),
162+
*compiler.GetSLShaderSource())) {
166163
std::cerr << "Could not write file to " << switches.sl_file_name
167164
<< std::endl;
168165
return false;
@@ -176,8 +173,7 @@ bool Main(const fml::CommandLine& command_line) {
176173
std::filesystem::current_path() / switches.reflection_json_name);
177174
if (!fml::WriteAtomically(
178175
*switches.working_directory,
179-
reinterpret_cast<const char*>(
180-
reflection_json_name.u8string().c_str()),
176+
Utf8FromPath(reflection_json_name).c_str(),
181177
*compiler.GetReflector()->GetReflectionJSON())) {
182178
std::cerr << "Could not write reflection json to "
183179
<< switches.reflection_json_name << std::endl;
@@ -191,8 +187,7 @@ bool Main(const fml::CommandLine& command_line) {
191187
switches.reflection_header_name.c_str());
192188
if (!fml::WriteAtomically(
193189
*switches.working_directory,
194-
reinterpret_cast<const char*>(
195-
reflection_header_name.u8string().c_str()),
190+
Utf8FromPath(reflection_header_name).c_str(),
196191
*compiler.GetReflector()->GetReflectionHeader())) {
197192
std::cerr << "Could not write reflection header to "
198193
<< switches.reflection_header_name << std::endl;
@@ -205,8 +200,7 @@ bool Main(const fml::CommandLine& command_line) {
205200
std::filesystem::absolute(std::filesystem::current_path() /
206201
switches.reflection_cc_name.c_str());
207202
if (!fml::WriteAtomically(*switches.working_directory,
208-
reinterpret_cast<const char*>(
209-
reflection_cc_name.u8string().c_str()),
203+
Utf8FromPath(reflection_cc_name).c_str(),
210204
*compiler.GetReflector()->GetReflectionCC())) {
211205
std::cerr << "Could not write reflection CC to "
212206
<< switches.reflection_cc_name << std::endl;
@@ -234,10 +228,9 @@ bool Main(const fml::CommandLine& command_line) {
234228
}
235229
auto depfile_path = std::filesystem::absolute(
236230
std::filesystem::current_path() / switches.depfile_path.c_str());
237-
if (!fml::WriteAtomically(
238-
*switches.working_directory,
239-
reinterpret_cast<const char*>(depfile_path.u8string().c_str()),
240-
*compiler.CreateDepfileContents({result_file}))) {
231+
if (!fml::WriteAtomically(*switches.working_directory,
232+
Utf8FromPath(depfile_path).c_str(),
233+
*compiler.CreateDepfileContents({result_file}))) {
241234
std::cerr << "Could not write depfile to " << switches.depfile_path
242235
<< std::endl;
243236
return false;

impeller/compiler/switches.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <map>
99

1010
#include "flutter/fml/file.h"
11+
#include "impeller/compiler/utilities.h"
1112

1213
namespace impeller {
1314
namespace compiler {
@@ -126,12 +127,11 @@ Switches::Switches(const fml::CommandLine& command_line)
126127

127128
// fml::OpenDirectoryReadOnly for Windows doesn't handle relative paths
128129
// beginning with `../` well, so we build an absolute path.
129-
auto include_dir_absolute =
130-
ToUtf8(std::filesystem::absolute(std::filesystem::current_path() /
131-
include_dir_path)
132-
.native());
130+
auto include_dir_absolute = std::filesystem::absolute(
131+
std::filesystem::current_path() / include_dir_path);
132+
133133
auto dir = std::make_shared<fml::UniqueFD>(fml::OpenDirectoryReadOnly(
134-
*working_directory, include_dir_absolute.c_str()));
134+
*working_directory, Utf8FromPath(include_dir_absolute).c_str()));
135135
if (!dir || !dir->is_valid()) {
136136
continue;
137137
}

impeller/compiler/utilities.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,13 @@
1111
namespace impeller {
1212
namespace compiler {
1313

14+
std::string Utf8FromPath(const std::filesystem::path& path) {
15+
return reinterpret_cast<const char*>(path.u8string().c_str());
16+
}
17+
1418
std::string InferShaderNameFromPath(std::string_view path) {
15-
return reinterpret_cast<const char*>(
16-
std::filesystem::path{path}.stem().u8string().c_str());
19+
auto p = std::filesystem::path{path}.stem();
20+
return Utf8FromPath(p);
1721
}
1822

1923
std::string ConvertToCamelCase(std::string_view string) {

impeller/compiler/utilities.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#pragma once
66

7+
#include <filesystem>
78
#include <string>
89
#include <string_view>
910

@@ -12,6 +13,8 @@
1213
namespace impeller {
1314
namespace compiler {
1415

16+
std::string Utf8FromPath(const std::filesystem::path& path);
17+
1518
std::string InferShaderNameFromPath(std::string_view path);
1619

1720
std::string ConvertToCamelCase(std::string_view string);

0 commit comments

Comments
 (0)