Skip to content

Commit

Permalink
[opengl] Unify windows path to posix format in python. (#3470)
Browse files Browse the repository at this point in the history
Tested on the windows opengl backend manually.
  • Loading branch information
ailzhang committed Nov 12, 2021
1 parent 78d2ecb commit acd685e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 20 deletions.
2 changes: 2 additions & 0 deletions python/taichi/aot/module.py
@@ -1,6 +1,7 @@
import shutil
import warnings
from contextlib import contextmanager
from pathlib import Path, PurePosixPath

from taichi.core import ti_core as _ti_core
from taichi.lang import impl, kernel_impl
Expand Down Expand Up @@ -193,4 +194,5 @@ def save(self, filepath, filename):
filepath (str): path to a folder to store aot files.
filename (str): filename prefix for stored aot files.
"""
filepath = str(PurePosixPath(Path(filepath).resolve()))
self._aot_builder.dump(filepath, filename)
11 changes: 2 additions & 9 deletions taichi/backends/opengl/aot_module_builder_impl.cpp
Expand Up @@ -21,15 +21,8 @@ namespace {
void write_glsl_file(const std::string &output_dir,
const std::string &filename,
CompiledKernel &k) {
// Hack to assemble readable windows/unix path.
// Ideally we could use std::filesystem but it's not available on MacOS 10.14.
#if defined(TI_PLATFORM_WINDOWS)
const std::string path_delim = "\\";
#else
const std::string path_delim = "/";
#endif
const std::string glsl_path = fmt::format(
"{}{}{}_{}.glsl", output_dir, path_delim, filename, k.kernel_name);
const std::string glsl_path =
fmt::format("{}/{}_{}.glsl", output_dir, filename, k.kernel_name);
std::ofstream fs{glsl_path};
fs << k.kernel_src;
k.kernel_src = glsl_path;
Expand Down
13 changes: 2 additions & 11 deletions tests/python/test_aot.py
Expand Up @@ -8,11 +8,6 @@
import taichi as ti


def _escape_path_for_win(json_str):
return json_str.replace(os.sep,
r'\\') if ti.get_os_name() == 'win' else json_str


@ti.test(arch=ti.cc)
def test_record():
with tempfile.TemporaryDirectory() as tmpdir:
Expand Down Expand Up @@ -62,9 +57,7 @@ def foo(n: ti.template()):
m.save(tmpdir, filename)
with open(os.path.join(tmpdir,
f'{filename}_metadata.json')) as json_file:
json_str = ''.join(json_file.readlines())
json_str = _escape_path_for_win(json_str)
json.loads(json_str)
json.load(json_file)


@ti.test(arch=ti.opengl)
Expand Down Expand Up @@ -175,6 +168,4 @@ def init():
m.save(tmpdir, filename)
with open(os.path.join(tmpdir,
f'{filename}_metadata.json')) as json_file:
json_str = ''.join(json_file.readlines())
json_str = _escape_path_for_win(json_str)
json.loads(json_str)
json.load(json_file)

0 comments on commit acd685e

Please sign in to comment.