6 #include "flutter/fml/paths.h"
7 #include "flutter/fml/process.h"
17 auto test_name = flutter::testing::GetCurrentTestName();
18 std::replace(test_name.begin(), test_name.end(),
'/',
'_');
19 std::replace(test_name.begin(), test_name.end(),
'.',
'_');
20 std::stringstream dir_name;
21 dir_name << test_name <<
"_" << std::to_string(fml::GetCurrentProcId());
22 return fml::paths::JoinPaths(
23 {flutter::testing::GetFixturesPath(), dir_name.str()});
27 intermediates_directory_ =
28 fml::OpenDirectory(intermediates_path_.c_str(),
30 fml::FilePermission::kReadWrite);
31 FML_CHECK(intermediates_directory_.is_valid());
35 intermediates_directory_.reset();
37 std::filesystem::remove_all(std::filesystem::path(intermediates_path_));
41 std::stringstream stream;
42 stream << fixture_name <<
".h";
47 std::stringstream stream;
48 stream << fixture_name <<
".cc";
53 std::stringstream stream;
54 stream << fixture_name <<
".json";
59 std::stringstream stream;
60 stream << fixture_name <<
".spv";
66 std::stringstream stream;
72 const char* fixture_name)
const {
74 auto fd = fml::OpenFileReadOnly(intermediates_directory_, filename.c_str());
75 return fml::FileMapping::CreateReadOnly(fd);
79 const char* fixture_name,
81 auto filename =
SLFileName(fixture_name, platform);
82 auto fd = fml::OpenFileReadOnly(intermediates_directory_, filename.c_str());
83 return fml::FileMapping::CreateReadOnly(fd);
89 const char* entry_point_name)
const {
90 std::shared_ptr<fml::Mapping> fixture =
91 flutter::testing::OpenFixtureAsMapping(fixture_name);
92 if (!fixture || !fixture->GetMapping()) {
93 VALIDATION_LOG <<
"Could not find shader in fixtures: " << fixture_name;
101 flutter::testing::OpenFixturesDirectory());
110 Compiler compiler(fixture, source_options, reflector_options);
117 if (!spirv_assembly) {
122 if (!fml::WriteAtomically(intermediates_directory_,
135 if (!fml::WriteAtomically(intermediates_directory_,
146 <<
"No reflector was found for target platform SL compiler.";
150 auto reflection_json = reflector->GetReflectionJSON();
151 auto reflection_header = reflector->GetReflectionHeader();
152 auto reflection_source = reflector->GetReflectionCC();
154 if (!reflection_json) {
159 if (!reflection_header) {
164 if (!reflection_source) {
169 if (!fml::WriteAtomically(intermediates_directory_,
171 *reflection_header)) {
172 VALIDATION_LOG <<
"Could not write reflection header intermediates.";
176 if (!fml::WriteAtomically(intermediates_directory_,
178 *reflection_source)) {
183 if (!fml::WriteAtomically(intermediates_directory_,
186 VALIDATION_LOG <<
"Could not write reflection json intermediates.";
std::shared_ptr< fml::Mapping > GetSPIRVAssembly() const
const Reflector * GetReflector() const
std::shared_ptr< fml::Mapping > GetSLShaderSource() const
std::string GetErrorMessages() const
bool CanCompileAndReflect(const char *fixture_name, SourceType source_type=SourceType::kUnknown, SourceLanguage source_language=SourceLanguage::kGLSL, const char *entry_point_name="main") const
std::unique_ptr< fml::FileMapping > GetReflectionJson(const char *fixture_name) const
std::unique_ptr< fml::FileMapping > GetShaderFile(const char *fixture_name, TargetPlatform platform) const
static std::string ReflectionCCName(const char *fixture_name)
static std::string ReflectionJSONName(const char *fixture_name)
static std::string GetIntermediatesPath()
static std::string ReflectionHeaderName(const char *fixture_name)
static std::string SLFileName(const char *fixture_name, TargetPlatform platform)
static std::string SPIRVFileName(const char *fixture_name)
std::string TargetPlatformSLExtension(TargetPlatform platform)
SourceType SourceTypeFromFileName(const std::string &file_name)
std::string EntryPointFunctionNameFromSourceName(const std::string &file_name, SourceType type, SourceLanguage source_language, const std::string &entry_point_name)
bool TargetPlatformNeedsReflection(TargetPlatform platform)
std::string header_file_name
SourceLanguage source_language
std::string entry_point_name
TargetPlatform target_platform
std::shared_ptr< fml::UniqueFD > working_directory