[llvm] 73cda4d - [llvm-rc] Fix handling of the /X option to match its documentation and rc.exe
Martin Storsjö via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 19 23:25:13 PDT 2021
Author: Martin Storsjö
Date: 2021-04-20T09:22:43+03:00
New Revision: 73cda4d1835021aa02cb421bc7e75a8087b0b213
URL: https://github.com/llvm/llvm-project/commit/73cda4d1835021aa02cb421bc7e75a8087b0b213
DIFF: https://github.com/llvm/llvm-project/commit/73cda4d1835021aa02cb421bc7e75a8087b0b213.diff
LOG: [llvm-rc] Fix handling of the /X option to match its documentation and rc.exe
This matches how it's documented in the option listing.
Differential Revision: https://reviews.llvm.org/D100754
Added:
Modified:
llvm/test/tools/llvm-rc/include-paths.test
llvm/tools/llvm-rc/ResourceFileWriter.cpp
llvm/tools/llvm-rc/ResourceFileWriter.h
llvm/tools/llvm-rc/llvm-rc.cpp
Removed:
################################################################################
diff --git a/llvm/test/tools/llvm-rc/include-paths.test b/llvm/test/tools/llvm-rc/include-paths.test
index 6acc967af9432..0097ae88e1dba 100644
--- a/llvm/test/tools/llvm-rc/include-paths.test
+++ b/llvm/test/tools/llvm-rc/include-paths.test
@@ -13,6 +13,16 @@
; RUN: llvm-rc /FO %t.nested-include.res /I %p/Inputs/nested -- %p/Inputs/deep-include.rc
; RUN: llvm-readobj %t.nested-include.res | FileCheck --check-prefix=FOUND %s
+; The include dir can be specified via the INCLUDE env var too.
+; RUN: rm -f %t.nested-include.res
+; RUN: env INCLUDE=%p/Inputs/nested llvm-rc /FO %t.nested-include.res -- %p/Inputs/deep-include.rc
+; RUN: llvm-readobj %t.nested-include.res | FileCheck --check-prefix=FOUND %s
+
+; Specifying the /X option should make it ignore the INCLUDE variable.
+; RUN: rm -f %t.nested-include.res
+; RUN: not env INCLUDE=%p/Inputs/nested llvm-rc /X /FO %t.nested-include.res -- %p/Inputs/deep-include.rc 2>&1 \
+; RUN: | FileCheck --check-prefix=MISSING %s
+
; Otherwise, it should not find the bitmap.
; RUN: rm -f %t.nested-include.res
; RUN: not llvm-rc /FO %t.nested-include.res -- %p/Inputs/deep-include.rc 2>&1 \
diff --git a/llvm/tools/llvm-rc/ResourceFileWriter.cpp b/llvm/tools/llvm-rc/ResourceFileWriter.cpp
index 2856fa8fe08a8..0c922698f57da 100644
--- a/llvm/tools/llvm-rc/ResourceFileWriter.cpp
+++ b/llvm/tools/llvm-rc/ResourceFileWriter.cpp
@@ -1553,10 +1553,11 @@ ResourceFileWriter::loadFile(StringRef File) const {
Path, /*IsText=*/false, /*RequiresNullTerminator=*/false));
}
- if (auto Result =
- llvm::sys::Process::FindInEnvPath("INCLUDE", File, Params.NoInclude))
- return errorOrToExpected(MemoryBuffer::getFile(
- *Result, /*IsText=*/false, /*RequiresNullTerminator=*/false));
+ if (!Params.NoInclude) {
+ if (auto Result = llvm::sys::Process::FindInEnvPath("INCLUDE", File))
+ return errorOrToExpected(MemoryBuffer::getFile(
+ *Result, /*IsText=*/false, /*RequiresNullTerminator=*/false));
+ }
return make_error<StringError>("error : file not found : " + Twine(File),
inconvertibleErrorCode());
diff --git a/llvm/tools/llvm-rc/ResourceFileWriter.h b/llvm/tools/llvm-rc/ResourceFileWriter.h
index d545a7a9cab15..0f3d5937259f8 100644
--- a/llvm/tools/llvm-rc/ResourceFileWriter.h
+++ b/llvm/tools/llvm-rc/ResourceFileWriter.h
@@ -35,7 +35,7 @@ enum CodePage {
struct WriterParams {
std::vector<std::string> Include; // Additional folders to search for files.
- std::vector<std::string> NoInclude; // Folders to exclude from file search.
+ bool NoInclude; // Ignore the INCLUDE variable.
StringRef InputFilePath; // The full path of the input file.
int CodePage = CpAcp; // The codepage for interpreting characters.
};
diff --git a/llvm/tools/llvm-rc/llvm-rc.cpp b/llvm/tools/llvm-rc/llvm-rc.cpp
index e9027a21d46b8..2007ef903c7d7 100644
--- a/llvm/tools/llvm-rc/llvm-rc.cpp
+++ b/llvm/tools/llvm-rc/llvm-rc.cpp
@@ -142,7 +142,7 @@ int main(int Argc, const char **Argv) {
llvm::sys::fs::make_absolute(InputFile);
Params.InputFilePath = InputFile;
Params.Include = InputArgs.getAllArgValues(OPT_includepath);
- Params.NoInclude = InputArgs.getAllArgValues(OPT_noinclude);
+ Params.NoInclude = InputArgs.hasArg(OPT_noinclude);
if (InputArgs.hasArg(OPT_codepage)) {
if (InputArgs.getLastArgValue(OPT_codepage)
More information about the llvm-commits
mailing list