• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2024 Google LLC
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #include "include/core/SkString.h"
9 #include "src/sksl/SkSLModuleData.h"
10 #include "src/utils/SkOSPath.h"
11 #include "tools/SkGetExecutablePath.h"
12 
13 #include <fstream>
14 
15 namespace SkSL {
16 
GetModuleData(ModuleName,const char * filename)17 std::string GetModuleData(ModuleName /*name*/, const char* filename) {
18     std::string exePath = SkGetExecutablePath();
19     SkString exeDir = SkOSPath::Dirname(exePath.c_str());
20     SkString modulePath = SkOSPath::Join(exeDir.c_str(), filename);
21     std::ifstream in(std::string{modulePath.c_str()});
22     std::string moduleSource{std::istreambuf_iterator<char>(in), std::istreambuf_iterator<char>()};
23     if (in.rdstate()) {
24         SK_ABORT("Error reading %s\n", modulePath.c_str());
25     }
26     return moduleSource;
27 }
28 
29 }  // namespace SkSL
30