diff --git a/es2panda/aot/main.cpp b/es2panda/aot/main.cpp index 76053181fd4c38f6e426f515e0e4cdbabb33a54d..ce7cf8be198026121ad2b1606cb0e097c98835ef 100644 --- a/es2panda/aot/main.cpp +++ b/es2panda/aot/main.cpp @@ -90,14 +90,16 @@ static bool GenerateMultiProgram(const std::unordered_mapsecond; - if (!panda::pandasm::AsmEmitter::EmitPrograms(output, progs, true)) { + if (!panda::pandasm::AsmEmitter::EmitPrograms(panda::os::file::File::GetExtendedFilePath(output), progs, + true)) { std::cerr << "Failed to emit merged program, error: " << panda::pandasm::AsmEmitter::GetLastError() << std::endl; return false; } } else { for (auto &prog: programs) { - if (!panda::pandasm::AsmEmitter::Emit(prog.second, *(prog.first), nullptr, nullptr, true)) { + if (!panda::pandasm::AsmEmitter::Emit(panda::os::file::File::GetExtendedFilePath(prog.second), + *(prog.first), nullptr, nullptr, true)) { std::cout << "Failed to emit single program, error: " << panda::pandasm::AsmEmitter::GetLastError() << std::endl; return false; diff --git a/es2panda/aot/options.cpp b/es2panda/aot/options.cpp index 82645cc4f5c7c5da4c49af52c69992e487e0ce51..5f7e8219641dd1ae657b8d1a0fe346db72ea1824 100644 --- a/es2panda/aot/options.cpp +++ b/es2panda/aot/options.cpp @@ -60,7 +60,7 @@ bool Options::CollectInputFilesFromFileList(const std::string &input) { std::ifstream ifs; std::string line; - ifs.open(input.c_str()); + ifs.open(panda::os::file::File::GetExtendedFilePath(input)); if (!ifs.is_open()) { std::cerr << "Failed to open source list: " << input << std::endl; return false; diff --git a/es2panda/es2panda.cpp b/es2panda/es2panda.cpp index f593468d9c999f4bb974cf4ac8253d23a32a537d..867615913a86a54974444b39cdceb8994c9ef099 100644 --- a/es2panda/es2panda.cpp +++ b/es2panda/es2panda.cpp @@ -143,7 +143,7 @@ void Compiler::DumpAsm(const panda::pandasm::Program *prog) static bool ReadFileToBuffer(const std::string &file, std::stringstream &ss) { - std::ifstream inputStream(file, std::ios::binary); + std::ifstream inputStream(panda::os::file::File::GetExtendedFilePath(file), std::ios::binary); if (inputStream.fail()) { std::cerr << "Failed to read file to buffer: " << file << std::endl; return false; diff --git a/es2panda/util/moduleHelpers.cpp b/es2panda/util/moduleHelpers.cpp index 69174c9e67a6a62b8328f2153064e240d3f21cbd..847cbea45c466249f47f2631b63d036dc40a89ff 100644 --- a/es2panda/util/moduleHelpers.cpp +++ b/es2panda/util/moduleHelpers.cpp @@ -24,7 +24,7 @@ void ModuleHelpers::CompileNpmModuleEntryList(const std::string &entriesInfo, panda::ArenaAllocator *allocator) { std::stringstream ss; - std::ifstream inputStream(entriesInfo); + std::ifstream inputStream(panda::os::file::File::GetExtendedFilePath(entriesInfo)); if (inputStream.fail()) { std::cerr << "Failed to read file to buffer: " << entriesInfo << std::endl; return; diff --git a/es2panda/util/symbolTable.cpp b/es2panda/util/symbolTable.cpp index 2b31ca0c8b71874ce2ae7c9a28ac00601d3efdd2..75a6297a08e7ac5fe8f1bef1067efea82b354d7b 100644 --- a/es2panda/util/symbolTable.cpp +++ b/es2panda/util/symbolTable.cpp @@ -33,7 +33,8 @@ bool SymbolTable::Initialize() if (!dumpSymbolTable_.empty()) { std::fstream fs; - fs.open(dumpSymbolTable_, std::ios_base::out | std::ios_base::trunc); + fs.open(panda::os::file::File::GetExtendedFilePath(dumpSymbolTable_), + std::ios_base::out | std::ios_base::trunc); if (!fs.is_open()) { std::cerr << "Failed to create output symbol table: " << dumpSymbolTable_ << std::endl; return false; @@ -48,7 +49,7 @@ bool SymbolTable::ReadSymbolTable(const std::string &symbolTable) { std::ifstream ifs; std::string line; - ifs.open(symbolTable.c_str()); + ifs.open(panda::os::file::File::GetExtendedFilePath(symbolTable)); if (!ifs.is_open()) { std::cerr << "Failed to open symbol table: " << symbolTable << std::endl; return false; @@ -92,7 +93,8 @@ void SymbolTable::WriteSymbolTable(const std::string &content) { std::lock_guard lock(m_); std::fstream fs; - fs.open(dumpSymbolTable_, std::ios_base::app | std::ios_base::in); + fs.open(panda::os::file::File::GetExtendedFilePath(dumpSymbolTable_), + std::ios_base::app | std::ios_base::in); if (fs.is_open()) { fs << content; fs.close(); diff --git a/merge_abc/src/mergeProgram.cpp b/merge_abc/src/mergeProgram.cpp index 3b4037d4205c42086a8416ba97ad31f6f16cc45b..38f4441d425b47ec0de172305e544cf9d5cc4134 100644 --- a/merge_abc/src/mergeProgram.cpp +++ b/merge_abc/src/mergeProgram.cpp @@ -132,7 +132,7 @@ bool MergeProgram::CollectProtoFiles(std::string &input, const std::string &prot return false; } if (isList) { - std::ifstream in(inputAbs.Value()); + std::ifstream in(panda::os::file::File::GetExtendedFilePath(inputAbs.Value())); std::string line; constexpr const char CARRIAGE = '\r'; while (getline(in, line)) { diff --git a/merge_abc/src/protobufSnapshotGenerator.cpp b/merge_abc/src/protobufSnapshotGenerator.cpp index fbb9e351042477b1fd3998643769efdb83d89124..4c7fb86e046657d096b897171ee4d1a025f73511 100644 --- a/merge_abc/src/protobufSnapshotGenerator.cpp +++ b/merge_abc/src/protobufSnapshotGenerator.cpp @@ -18,27 +18,14 @@ #include "protobufSnapshotGenerator.h" namespace panda::proto { -static void GetFileStream(const std::string &path, std::ios::openmode mode, std::fstream &fs) -{ -#ifdef PANDA_TARGET_WINDOWS - if (path.length() < _MAX_PATH) { - fs = std::fstream(path, mode); - } else { - fs = std::fstream(panda::os::file::File::GetExtendedLengthStylePath(path), mode); - } -#else - fs = std::fstream(path, mode); -#endif // PANDA_TARGET_WINDOWS -} - void ProtobufSnapshotGenerator::GenerateSnapshot(const panda::pandasm::Program &program, const std::string &outputName) { protoPanda::Program protoProgram; Program::Serialize(program, protoProgram); - std::fstream output; - GetFileStream(outputName, std::ios::out | std::ios::trunc | std::ios::binary, output); + std::fstream output(panda::os::file::File::GetExtendedFilePath(outputName), + std::ios::out | std::ios::trunc | std::ios::binary); if (!output) { std::cerr << "Failed to create: " << outputName << std::endl; return; @@ -50,8 +37,7 @@ void ProtobufSnapshotGenerator::GenerateSnapshot(const panda::pandasm::Program & void ProtobufSnapshotGenerator::GenerateProgram(const std::string &inputName, panda::pandasm::Program &prog, panda::ArenaAllocator *allocator) { - std::fstream input; - GetFileStream(inputName, std::ios::in | std::ios::binary, input); + std::fstream input(panda::os::file::File::GetExtendedFilePath(inputName), std::ios::in | std::ios::binary); if (!input) { std::cerr << "Failed to open: " << inputName << std::endl; return; @@ -70,8 +56,8 @@ void ProtobufSnapshotGenerator::UpdateCacheFile( { protoPanda::CompositeProgram protoCompositeProgram; CompositeProgram::Serialize(compositeProgramMap, isDebug, protoCompositeProgram); - std::fstream output; - GetFileStream(cacheFilePath, std::ios::out | std::ios::trunc | std::ios::binary, output); + std::fstream output(panda::os::file::File::GetExtendedFilePath(cacheFilePath), + std::ios::out | std::ios::trunc | std::ios::binary); if (!output) { std::cerr << "Failed to create cache file: " << cacheFilePath << std::endl; return; @@ -83,8 +69,8 @@ void ProtobufSnapshotGenerator::UpdateCacheFile( std::map *ProtobufSnapshotGenerator::GetCacheContext( const std::string &cacheFilePath, bool isDebug, panda::ArenaAllocator *allocator) { - std::fstream input; - GetFileStream(cacheFilePath, std::ios::in | std::ios::binary, input); + std::fstream input(panda::os::file::File::GetExtendedFilePath(cacheFilePath), + std::ios::in | std::ios::binary); if (!input) { std::cout << "Cache file: " << cacheFilePath << " doesn't exist" << std::endl; return nullptr; diff --git a/ts2panda/ts2abc/ts2abc.cpp b/ts2panda/ts2abc/ts2abc.cpp index 1ea1ece3c9f22492abb8c0b724b1cf87d241f69d..0f30e58d8a9e6b842ff757dce9518b04fe8ddbe4 100644 --- a/ts2panda/ts2abc/ts2abc.cpp +++ b/ts2panda/ts2abc/ts2abc.cpp @@ -1439,6 +1439,7 @@ static bool EmitProgram(const std::string &output, int optLevel, std::string opt if (g_isOutputProto) { g_compilerOutputProto = output.substr(0, output.find_last_of(".") + 1).append(PROTO_BIN_SUFFIX); } + std::string convertedFilePath = panda::os::file::File::GetExtendedFilePath(output); #ifdef ENABLE_BYTECODE_OPT if (g_optLevel != static_cast(OptLevel::O_LEVEL0) || optLevel != static_cast(OptLevel::O_LEVEL0)) { @@ -1458,19 +1459,19 @@ static bool EmitProgram(const std::string &output, int optLevel, std::string opt panda::pandasm::AsmEmitter::PandaFileToPandaAsmMaps maps {}; panda::pandasm::AsmEmitter::PandaFileToPandaAsmMaps* mapsp = &maps; - if (!panda::pandasm::AsmEmitter::Emit(output.c_str(), prog, statp, mapsp, emitDebugInfo)) { + if (!panda::pandasm::AsmEmitter::Emit(convertedFilePath, prog, statp, mapsp, emitDebugInfo)) { std::cerr << "Failed to emit binary data: " << panda::pandasm::AsmEmitter::GetLastError() << std::endl; return false; } - panda::bytecodeopt::OptimizeBytecode(&prog, mapsp, output.c_str(), true); + panda::bytecodeopt::OptimizeBytecode(&prog, mapsp, convertedFilePath, true); if (g_compilerOutputProto.size() > 0) { panda::proto::ProtobufSnapshotGenerator::GenerateSnapshot(prog, g_compilerOutputProto); return true; } - if (!panda::pandasm::AsmEmitter::Emit(output.c_str(), prog, statp, mapsp, emitDebugInfo)) { + if (!panda::pandasm::AsmEmitter::Emit(convertedFilePath, prog, statp, mapsp, emitDebugInfo)) { std::cerr << "Failed to emit binary data: " << panda::pandasm::AsmEmitter::GetLastError() << std::endl; return false; } @@ -1482,7 +1483,7 @@ static bool EmitProgram(const std::string &output, int optLevel, std::string opt return true; } - if (!panda::pandasm::AsmEmitter::Emit(output.c_str(), prog, nullptr)) { + if (!panda::pandasm::AsmEmitter::Emit(convertedFilePath, prog, nullptr)) { std::cerr << "Failed to emit binary data: " << panda::pandasm::AsmEmitter::GetLastError() << std::endl; return false; } @@ -1631,7 +1632,7 @@ bool CompileNpmEntries(const std::string &input, const std::string &output) } std::stringstream ss; - std::ifstream inputStream(input); + std::ifstream inputStream(panda::os::file::File::GetExtendedFilePath(input)); if (inputStream.fail()) { std::cerr << "Failed to read file to buffer: " << input << std::endl; return false; @@ -1677,7 +1678,7 @@ bool HandleJsonFile(const std::string &input, std::string &data) } std::ifstream file; - file.open(fpath); + file.open(panda::os::file::File::GetExtendedFilePath(fpath)); if (file.fail()) { std::cerr << "failed to open:" << fpath << std::endl; return false;