From f1b41a71be938b8711ee0fff0130185f512d2336 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Fri, 24 Jun 2022 16:08:08 -0400 Subject: Handling of temporary files (#2299) * #include an absolute path didn't work - because paths were taken to always be relative. * Work around windows issue with temporary file clash. * Handle the temporary file path actually creates a file. * Fix typo. * Fix typo in linux for temporary file. * Add unit test for io. Tests generateTemporary operation. --- source/compiler-core/slang-downstream-compiler.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'source/compiler-core/slang-downstream-compiler.cpp') diff --git a/source/compiler-core/slang-downstream-compiler.cpp b/source/compiler-core/slang-downstream-compiler.cpp index 5011b42a0..85726557e 100644 --- a/source/compiler-core/slang-downstream-compiler.cpp +++ b/source/compiler-core/slang-downstream-compiler.cpp @@ -428,6 +428,7 @@ SlangResult CommandLineDownstreamCompiler::compile(const CompileOptions& inOptio // Find all the files that will be produced RefPtr productFileSet(new TemporaryFileSet); + if (options.modulePath.getLength() == 0 || options.sourceContents.getLength() != 0) { String modulePath = options.modulePath; @@ -435,7 +436,15 @@ SlangResult CommandLineDownstreamCompiler::compile(const CompileOptions& inOptio // If there is no module path, generate one. if (modulePath.getLength() == 0) { - SLANG_RETURN_ON_FAIL(File::generateTemporary(UnownedStringSlice::fromLiteral("slang-generated"), modulePath)); + // Holds the temporary lock path, if a temporary path is used + String temporaryLockPath; + + // Generate a unique module path name + SLANG_RETURN_ON_FAIL(File::generateTemporary(UnownedStringSlice::fromLiteral("slang-generated"), temporaryLockPath)); + productFileSet->add(temporaryLockPath); + + modulePath = temporaryLockPath; + options.modulePath = modulePath; } @@ -511,7 +520,6 @@ SlangResult CommandLineDownstreamCompiler::compile(const CompileOptions& inOptio DownstreamDiagnostics diagnostics; SLANG_RETURN_ON_FAIL(parseOutput(exeRes, diagnostics)); - out = new CommandLineDownstreamCompileResult(diagnostics, moduleFilePath, productFileSet); return SLANG_OK; -- cgit v1.2.3