6 #include "flutter/fml/paths.h"
7 #include "flutter/fml/process.h"
18 auto test_name = flutter::testing::GetCurrentTestName();
19 std::replace(test_name.begin(), test_name.end(),
'/',
'_');
20 std::replace(test_name.begin(), test_name.end(),
'.',
'_');
21 std::stringstream dir_name;
22 dir_name << test_name <<
"_" << std::to_string(fml::GetCurrentProcId());
23 return fml::paths::JoinPaths(
24 {flutter::testing::GetFixturesPath(), dir_name.str()});
29 intermediates_directory_ =
30 fml::OpenDirectory(intermediates_path_.c_str(),
32 fml::FilePermission::kReadWrite);
33 FML_CHECK(intermediates_directory_.is_valid());
37 intermediates_directory_.reset();
39 std::filesystem::remove_all(std::filesystem::path(intermediates_path_));
43 std::stringstream stream;
44 stream << fixture_name <<
".h";
49 std::stringstream stream;
50 stream << fixture_name <<
".cc";
55 std::stringstream stream;
56 stream << fixture_name <<
".json";
61 std::stringstream stream;
62 stream << fixture_name <<
".spv";
68 std::stringstream stream;
74 const char* fixture_name)
const {
76 auto fd = fml::OpenFileReadOnly(intermediates_directory_, filename.c_str());
77 return fml::FileMapping::CreateReadOnly(fd);
81 const char* fixture_name,
83 auto filename =
SLFileName(fixture_name, platform);
84 auto fd = fml::OpenFileReadOnly(intermediates_directory_, filename.c_str());
85 return fml::FileMapping::CreateReadOnly(fd);
91 const char* entry_point_name) {
92 std::shared_ptr<fml::Mapping> fixture =
93 flutter::testing::OpenFixtureAsMapping(fixture_name);
94 if (!fixture || !fixture->GetMapping()) {
95 VALIDATION_LOG <<
"Could not find shader in fixtures: " << fixture_name;
103 flutter::testing::OpenFixturesDirectory());
114 std::make_unique<Compiler>(fixture, source_options, reflector_options);
115 if (!compiler_->IsValid()) {
116 VALIDATION_LOG <<
"Compilation failed: " << compiler_->GetErrorMessages();
120 auto spirv_assembly = compiler_->GetSPIRVAssembly();
121 if (!spirv_assembly) {
126 if (!fml::WriteAtomically(intermediates_directory_,
133 auto sl_source = compiler_->GetSLShaderSource();
139 if (!fml::WriteAtomically(intermediates_directory_,
146 auto reflector = compiler_->GetReflector();
148 VALIDATION_LOG <<
"No reflector was found for target platform SL compiler.";
152 auto reflection_json = reflector->GetReflectionJSON();
153 auto reflection_header = reflector->GetReflectionHeader();
154 auto reflection_source = reflector->GetReflectionCC();
156 if (!reflection_json) {
161 if (!reflection_header) {
166 if (!reflection_source) {
171 if (!fml::WriteAtomically(intermediates_directory_,
173 *reflection_header)) {
174 VALIDATION_LOG <<
"Could not write reflection header intermediates.";
178 if (!fml::WriteAtomically(intermediates_directory_,
180 *reflection_source)) {
185 if (!fml::WriteAtomically(intermediates_directory_,
188 VALIDATION_LOG <<
"Could not write reflection json intermediates.";
195 return compiler_.get();
const Compiler * GetCompiler() 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
bool CanCompileAndReflect(const char *fixture_name, SourceType source_type=SourceType::kUnknown, SourceLanguage source_language=SourceLanguage::kGLSL, const char *entry_point_name="main")
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::filesystem::path &file_name)
std::string EntryPointFunctionNameFromSourceName(const std::filesystem::path &file_name, SourceType type, SourceLanguage source_language, const std::string &entry_point_name)
TargetPlatform target_platform
std::string header_file_name
SourceLanguage source_language
std::string entry_point_name
TargetPlatform target_platform
std::shared_ptr< fml::UniqueFD > working_directory