[llvm-rc] Run clang to preprocess input files

Allow opting out from preprocessing with a command line argument.

Update tests to pass -no-preprocess to make it not try to use clang
(which isn't a build level dependency of llvm-rc), but add a test that
does preprocessing under clang/test/Preprocessor.

Update a few options to allow them both joined (as -DFOO) and separate
(-D BR), as rc.exe allows both forms of them.

With the verbose flag set, this prints the preprocessing command
used (which differs from what rc.exe does).

Tests under llvm/test/tools/llvm-rc only test constructing the
preprocessor commands, while tests under clang/test/Preprocessor test
actually running the preprocessor.

Differential Revision: https://reviews.llvm.org/D100755
This commit is contained in:
Martin Storsjö 2021-04-14 16:24:30 +03:00
parent ee34ca34c6
commit 64bc44f5dd
30 changed files with 253 additions and 111 deletions

View File

@ -120,6 +120,7 @@ if( NOT CLANG_BUILT_STANDALONE )
llvm-objcopy llvm-objcopy
llvm-objdump llvm-objdump
llvm-profdata llvm-profdata
llvm-rc
llvm-readelf llvm-readelf
llvm-readobj llvm-readobj
llvm-strip llvm-strip

View File

@ -0,0 +1,7 @@
#ifndef RC_INVOKED
#error RC_INVOKED not defined
#endif
#ifndef _WIN32
#error _WIN32 not defined
#endif
#define MY_ID 42

View File

@ -0,0 +1,8 @@
// RUN: llvm-rc -i%p/Inputs -Fo%t.res %s
// RUN: llvm-readobj %t.res | FileCheck %s
// CHECK: Resource type (int): RCDATA (ID 10)
// CHECK: Resource name (int): 42
#include "llvm-rc.h"
MY_ID RCDATA {
"a long string of data"
}

View File

@ -26,7 +26,7 @@ config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell)
# suffixes: A list of file extensions to treat as test files. # suffixes: A list of file extensions to treat as test files.
config.suffixes = ['.c', '.cpp', '.i', '.cppm', '.m', '.mm', '.cu', '.hip', config.suffixes = ['.c', '.cpp', '.i', '.cppm', '.m', '.mm', '.cu', '.hip',
'.ll', '.cl', '.clcpp', '.s', '.S', '.modulemap', '.test', '.rs', '.ifs'] '.ll', '.cl', '.clcpp', '.s', '.S', '.modulemap', '.test', '.rs', '.ifs', '.rc']
# excludes: A list of directories to exclude from the testsuite. The 'Inputs' # excludes: A list of directories to exclude from the testsuite. The 'Inputs'
# subdirectories contain auxiliary inputs for various tests in their parent # subdirectories contain auxiliary inputs for various tests in their parent

View File

@ -1,7 +1,7 @@
; RUN: touch %t.manifest ; RUN: touch %t.manifest
; RUN: echo "1 24 \"%t.manifest\"" > %t.rc ; RUN: echo "1 24 \"%t.manifest\"" > %t.rc
; RUN: llvm-rc -- %t.rc ; RUN: llvm-rc -no-preprocess -- %t.rc
;; On Windows, try stripping out the drive name from the absolute path, ;; On Windows, try stripping out the drive name from the absolute path,
;; and make sure the path still is found. ;; and make sure the path still is found.
; RUN: cat %t.rc | sed 's/"[a-zA-Z]:/"/' > %t2.rc ; RUN: cat %t.rc | sed 's/"[a-zA-Z]:/"/' > %t2.rc
; RUN: llvm-rc -- %t2.rc ; RUN: llvm-rc -no-preprocess -- %t2.rc

View File

@ -1,4 +1,4 @@
; RUN: llvm-rc /C 65001 /FO %t.utf8.res -- %p/Inputs/utf8.rc ; RUN: llvm-rc -no-preprocess /C 65001 /FO %t.utf8.res -- %p/Inputs/utf8.rc
; RUN: llvm-readobj %t.utf8.res | FileCheck %s --check-prefix=UTF8 ; RUN: llvm-readobj %t.utf8.res | FileCheck %s --check-prefix=UTF8
; UTF8: Resource type (int): STRINGTABLE (ID 6) ; UTF8: Resource type (int): STRINGTABLE (ID 6)
@ -18,11 +18,11 @@
; UTF8-NEXT: 0040: 00000000 |....| ; UTF8-NEXT: 0040: 00000000 |....|
; UTF8-NEXT: ) ; UTF8-NEXT: )
; RUN: not llvm-rc /C 65001 /FO %t.utf8-escape-narrow.res -- %p/Inputs/utf8-escape-narrow.rc 2>&1 | FileCheck %s --check-prefix UTF8_ESCAPE ; RUN: not llvm-rc -no-preprocess /C 65001 /FO %t.utf8-escape-narrow.res -- %p/Inputs/utf8-escape-narrow.rc 2>&1 | FileCheck %s --check-prefix UTF8_ESCAPE
; UTF8_ESCAPE: llvm-rc: Error in STRINGTABLE statement (ID 1): ; UTF8_ESCAPE: llvm-rc: Error in STRINGTABLE statement (ID 1):
; UTF8_ESCAPE-NEXT: Unable to interpret single byte (195) as UTF-8 ; UTF8_ESCAPE-NEXT: Unable to interpret single byte (195) as UTF-8
; RUN: llvm-rc /C 1252 /FO %t.cp1252.res -- %p/Inputs/cp1252.rc ; RUN: llvm-rc -no-preprocess /C 1252 /FO %t.cp1252.res -- %p/Inputs/cp1252.rc
; RUN: llvm-readobj %t.cp1252.res | FileCheck %s --check-prefix=CP1252 ; RUN: llvm-readobj %t.cp1252.res | FileCheck %s --check-prefix=CP1252
; CP1252: Resource type (int): STRINGTABLE (ID 6) ; CP1252: Resource type (int): STRINGTABLE (ID 6)

View File

@ -1,4 +1,4 @@
; RUN: llvm-rc /FO %t -- %p/Inputs/cpp-output.rc ; RUN: llvm-rc -no-preprocess /FO %t -- %p/Inputs/cpp-output.rc
; RUN: llvm-readobj %t | FileCheck %s ; RUN: llvm-readobj %t | FileCheck %s
; CHECK: Resource type (int): STRINGTABLE (ID 6) ; CHECK: Resource type (int): STRINGTABLE (ID 6)

View File

@ -1,4 +1,4 @@
; RUN: llvm-rc /dry-run /FO %t -- %p/Inputs/empty.rc 2>&1 | FileCheck %s --allow-empty --check-prefix=FO ; RUN: llvm-rc -no-preprocess /dry-run /FO %t -- %p/Inputs/empty.rc 2>&1 | FileCheck %s --allow-empty --check-prefix=FO
; RUN: llvm-rc /dry-run /FO%t -- %p/Inputs/empty.rc 2>&1 | FileCheck %s --allow-empty --check-prefix=FO ; RUN: llvm-rc -no-preprocess /dry-run /FO%t -- %p/Inputs/empty.rc 2>&1 | FileCheck %s --allow-empty --check-prefix=FO
; FO-NOT: Exactly one input file should be provided. ; FO-NOT: Exactly one input file should be provided.

View File

@ -15,6 +15,7 @@
; CHECK-NEXT: /I <value> Add an include path. ; CHECK-NEXT: /I <value> Add an include path.
; CHECK-NEXT: /LN <value> Set the default language name. ; CHECK-NEXT: /LN <value> Set the default language name.
; CHECK-NEXT: /L <value> Set the default language identifier. ; CHECK-NEXT: /L <value> Set the default language identifier.
; CHECK-NEXT: /no-preprocess Don't try to preprocess the input file.
; CHECK-NEXT: /N Null-terminate all strings in the string table. ; CHECK-NEXT: /N Null-terminate all strings in the string table.
; CHECK-NEXT: /U <value> Undefine a symbol for the C preprocessor. ; CHECK-NEXT: /U <value> Undefine a symbol for the C preprocessor.
; CHECK-NEXT: /V Be verbose. ; CHECK-NEXT: /V Be verbose.

View File

@ -1,31 +1,31 @@
; Should find the bitmap if it is in the same folder as the rc file. ; Should find the bitmap if it is in the same folder as the rc file.
; RUN: rm -f %t.include.res ; RUN: rm -f %t.include.res
; RUN: llvm-rc /FO %t.include.res -- %p/Inputs/include.rc ; RUN: llvm-rc -no-preprocess /FO %t.include.res -- %p/Inputs/include.rc
; RUN: llvm-readobj %t.include.res | FileCheck --check-prefix=FOUND %s ; RUN: llvm-readobj %t.include.res | FileCheck --check-prefix=FOUND %s
; Try including files without quotes. ; Try including files without quotes.
; RUN: rm -f %t.noquotes.res ; RUN: rm -f %t.noquotes.res
; RUN: llvm-rc /FO %t.noquotes.res -- %p/Inputs/include-noquotes.rc ; RUN: llvm-rc -no-preprocess /FO %t.noquotes.res -- %p/Inputs/include-noquotes.rc
; RUN: llvm-readobj %t.noquotes.res | FileCheck --check-prefix=FOUND %s ; RUN: llvm-readobj %t.noquotes.res | FileCheck --check-prefix=FOUND %s
; Should find the bitmap if the folder is explicitly specified. ; Should find the bitmap if the folder is explicitly specified.
; RUN: rm -f %t.nested-include.res ; RUN: rm -f %t.nested-include.res
; RUN: llvm-rc /FO %t.nested-include.res /I %p/Inputs/nested -- %p/Inputs/deep-include.rc ; RUN: llvm-rc -no-preprocess /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 ; RUN: llvm-readobj %t.nested-include.res | FileCheck --check-prefix=FOUND %s
; The include dir can be specified via the INCLUDE env var too. ; The include dir can be specified via the INCLUDE env var too.
; RUN: rm -f %t.nested-include.res ; 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: env INCLUDE=%p/Inputs/nested llvm-rc -no-preprocess /FO %t.nested-include.res -- %p/Inputs/deep-include.rc
; RUN: llvm-readobj %t.nested-include.res | FileCheck --check-prefix=FOUND %s ; RUN: llvm-readobj %t.nested-include.res | FileCheck --check-prefix=FOUND %s
; Specifying the /X option should make it ignore the INCLUDE variable. ; Specifying the /X option should make it ignore the INCLUDE variable.
; RUN: rm -f %t.nested-include.res ; 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: not env INCLUDE=%p/Inputs/nested llvm-rc -no-preprocess /X /FO %t.nested-include.res -- %p/Inputs/deep-include.rc 2>&1 \
; RUN: | FileCheck --check-prefix=MISSING %s ; RUN: | FileCheck --check-prefix=MISSING %s
; Otherwise, it should not find the bitmap. ; Otherwise, it should not find the bitmap.
; RUN: rm -f %t.nested-include.res ; RUN: rm -f %t.nested-include.res
; RUN: not llvm-rc /FO %t.nested-include.res -- %p/Inputs/deep-include.rc 2>&1 \ ; RUN: not llvm-rc -no-preprocess /FO %t.nested-include.res -- %p/Inputs/deep-include.rc 2>&1 \
; RUN: | FileCheck --check-prefix=MISSING %s ; RUN: | FileCheck --check-prefix=MISSING %s
; Should find the bitmap if the process's current working directory ; Should find the bitmap if the process's current working directory
@ -34,7 +34,7 @@
; failure of other tests if run first. ; failure of other tests if run first.
; RUN: rm -f %t.nested-include.res ; RUN: rm -f %t.nested-include.res
; RUN: cd %p/Inputs/nested ; RUN: cd %p/Inputs/nested
; RUN: llvm-rc /FO %t.nested-include.res -- %p/Inputs/include.rc ; RUN: llvm-rc -no-preprocess /FO %t.nested-include.res -- %p/Inputs/include.rc
; RUN: llvm-readobj %t.nested-include.res | FileCheck --check-prefix=FOUND %s ; RUN: llvm-readobj %t.nested-include.res | FileCheck --check-prefix=FOUND %s
FOUND: Resource type (int): BITMAP (ID 2) FOUND: Resource type (int): BITMAP (ID 2)

View File

@ -1,6 +1,6 @@
; RUN: llvm-rc /l 40A /FO %t.res -- %p/Inputs/language.rc ; RUN: llvm-rc -no-preprocess /l 40A /FO %t.res -- %p/Inputs/language.rc
; RUN: llvm-readobj %t.res | FileCheck %s ; RUN: llvm-readobj %t.res | FileCheck %s
; RUN: llvm-rc /l40A /FO %t.res -- %p/Inputs/language.rc ; RUN: llvm-rc -no-preprocess /l40A /FO %t.res -- %p/Inputs/language.rc
; RUN: llvm-readobj %t.res | FileCheck %s ; RUN: llvm-readobj %t.res | FileCheck %s
; CHECK: Resource name (int): 1 ; CHECK: Resource name (int): 1

View File

@ -1,4 +1,4 @@
; RUN: llvm-rc /FO %t -- %p/Inputs/memoryflags-stringtable.rc ; RUN: llvm-rc -no-preprocess /FO %t -- %p/Inputs/memoryflags-stringtable.rc
; RUN: llvm-readobj %t | FileCheck %s ; RUN: llvm-readobj %t | FileCheck %s
; CHECK: Resource type (int): STRINGTABLE (ID 6) ; CHECK: Resource type (int): STRINGTABLE (ID 6)

View File

@ -1,4 +1,4 @@
; RUN: llvm-rc /FO %t -- %p/Inputs/memoryflags.rc ; RUN: llvm-rc -no-preprocess /FO %t -- %p/Inputs/memoryflags.rc
; RUN: llvm-readobj %t | FileCheck %s ; RUN: llvm-readobj %t | FileCheck %s
; CHECK: Resource type (int): CURSOR (ID 1) ; CHECK: Resource type (int): CURSOR (ID 1)

View File

@ -1,4 +1,4 @@
; RUN: llvm-rc /FO %t -- %p/Inputs/not-expr.rc ; RUN: llvm-rc -no-preprocess /FO %t -- %p/Inputs/not-expr.rc
; RUN: llvm-readobj %t | FileCheck %s --check-prefix=NOTEXPR ; RUN: llvm-readobj %t | FileCheck %s --check-prefix=NOTEXPR
; NOTEXPR: Resource type (int): DIALOG (ID 5) ; NOTEXPR: Resource type (int): DIALOG (ID 5)

View File

@ -1,4 +1,4 @@
; RUN: llvm-rc /dry-run /V -- %p/Inputs/parser-expr.rc | FileCheck %s ; RUN: llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-expr.rc | FileCheck %s
; CHECK: Language: 5, Sublanguage: 1 ; CHECK: Language: 5, Sublanguage: 1
; CHECK-NEXT: Language: 3, Sublanguage: 2 ; CHECK-NEXT: Language: 3, Sublanguage: 2
@ -17,36 +17,36 @@
; CHECK-NEXT: Language: 5, Sublanguage: 7 ; CHECK-NEXT: Language: 5, Sublanguage: 7
; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-expr-bad-binary-1.rc 2>&1 | FileCheck %s --check-prefix BINARY1 ; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-expr-bad-binary-1.rc 2>&1 | FileCheck %s --check-prefix BINARY1
; BINARY1: llvm-rc: Error parsing file: expected '-', '~', integer or '(', got & ; BINARY1: llvm-rc: Error parsing file: expected '-', '~', integer or '(', got &
; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-expr-bad-binary-2.rc 2>&1 | FileCheck %s --check-prefix BINARY2 ; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-expr-bad-binary-2.rc 2>&1 | FileCheck %s --check-prefix BINARY2
; BINARY2: llvm-rc: Error parsing file: expected '-', '~', integer or '(', got | ; BINARY2: llvm-rc: Error parsing file: expected '-', '~', integer or '(', got |
; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-expr-bad-binary-3.rc 2>&1 | FileCheck %s --check-prefix BINARY3 ; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-expr-bad-binary-3.rc 2>&1 | FileCheck %s --check-prefix BINARY3
; BINARY3: llvm-rc: Error parsing file: expected '-', '~', integer or '(', got + ; BINARY3: llvm-rc: Error parsing file: expected '-', '~', integer or '(', got +
; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-expr-bad-unary.rc 2>&1 | FileCheck %s --check-prefix UNARY ; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-expr-bad-unary.rc 2>&1 | FileCheck %s --check-prefix UNARY
; UNARY: llvm-rc: Error parsing file: expected ',', got ~ ; UNARY: llvm-rc: Error parsing file: expected ',', got ~
; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-expr-unbalanced-1.rc 2>&1 | FileCheck %s --check-prefix UNBALANCED1 ; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-expr-unbalanced-1.rc 2>&1 | FileCheck %s --check-prefix UNBALANCED1
; UNBALANCED1: llvm-rc: Error parsing file: expected ')', got , ; UNBALANCED1: llvm-rc: Error parsing file: expected ')', got ,
; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-expr-unbalanced-2.rc 2>&1 | FileCheck %s --check-prefix UNBALANCED2 ; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-expr-unbalanced-2.rc 2>&1 | FileCheck %s --check-prefix UNBALANCED2
; UNBALANCED2: llvm-rc: Error parsing file: expected ',', got ) ; UNBALANCED2: llvm-rc: Error parsing file: expected ',', got )
; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-expr-unbalanced-3.rc 2>&1 | FileCheck %s --check-prefix UNBALANCED3 ; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-expr-unbalanced-3.rc 2>&1 | FileCheck %s --check-prefix UNBALANCED3
; UNBALANCED3: llvm-rc: Error parsing file: expected ',', got ) ; UNBALANCED3: llvm-rc: Error parsing file: expected ',', got )

View File

@ -1,4 +1,4 @@
; RUN: llvm-rc /dry-run /V -- %p/Inputs/parser-correct-everything.rc | FileCheck %s --check-prefix PGOOD ; RUN: llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-correct-everything.rc | FileCheck %s --check-prefix PGOOD
; PGOOD: Icon (meh): "hello.bmp" ; PGOOD: Icon (meh): "hello.bmp"
; PGOOD-NEXT: Icon (Icon): "Icon" ; PGOOD-NEXT: Icon (Icon): "Icon"
@ -100,156 +100,156 @@
; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-stringtable-no-string.rc 2>&1 | FileCheck %s --check-prefix PSTRINGTABLE1 ; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-stringtable-no-string.rc 2>&1 | FileCheck %s --check-prefix PSTRINGTABLE1
; PSTRINGTABLE1: llvm-rc: Error parsing file: expected string, got } ; PSTRINGTABLE1: llvm-rc: Error parsing file: expected string, got }
; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-stringtable-weird-option.rc 2>&1 | FileCheck %s --check-prefix PSTRINGTABLE2 ; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-stringtable-weird-option.rc 2>&1 | FileCheck %s --check-prefix PSTRINGTABLE2
; PSTRINGTABLE2: llvm-rc: Error parsing file: expected optional statement type, BEGIN or '{', got NONSENSETYPE ; PSTRINGTABLE2: llvm-rc: Error parsing file: expected optional statement type, BEGIN or '{', got NONSENSETYPE
; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-eof.rc 2>&1 | FileCheck %s --check-prefix PEOF ; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-eof.rc 2>&1 | FileCheck %s --check-prefix PEOF
; PEOF: llvm-rc: Error parsing file: expected '-', '~', integer or '(', got <EOF> ; PEOF: llvm-rc: Error parsing file: expected '-', '~', integer or '(', got <EOF>
; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-no-characteristics-arg.rc 2>&1 | FileCheck %s --check-prefix PCHARACTERISTICS1 ; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-no-characteristics-arg.rc 2>&1 | FileCheck %s --check-prefix PCHARACTERISTICS1
; PCHARACTERISTICS1: llvm-rc: Error parsing file: expected '-', '~', integer or '(', got BEGIN ; PCHARACTERISTICS1: llvm-rc: Error parsing file: expected '-', '~', integer or '(', got BEGIN
; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-nonsense-token.rc 2>&1 | FileCheck %s --check-prefix PNONSENSE1 ; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-nonsense-token.rc 2>&1 | FileCheck %s --check-prefix PNONSENSE1
; PNONSENSE1: llvm-rc: Error parsing file: expected int or identifier, got & ; PNONSENSE1: llvm-rc: Error parsing file: expected int or identifier, got &
; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-nonsense-type.rc 2>&1 | FileCheck %s --check-prefix PNONSENSE2 ; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-nonsense-type.rc 2>&1 | FileCheck %s --check-prefix PNONSENSE2
; PNONSENSE2: llvm-rc: Error parsing file: expected filename, '{' or BEGIN, got <EOF> ; PNONSENSE2: llvm-rc: Error parsing file: expected filename, '{' or BEGIN, got <EOF>
; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-nonsense-type-eof.rc 2>&1 | FileCheck %s --check-prefix PNONSENSE3 ; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-nonsense-type-eof.rc 2>&1 | FileCheck %s --check-prefix PNONSENSE3
; PNONSENSE3: llvm-rc: Error parsing file: expected int or identifier, got <EOF> ; PNONSENSE3: llvm-rc: Error parsing file: expected int or identifier, got <EOF>
; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-language-no-comma.rc 2>&1 | FileCheck %s --check-prefix PLANGUAGE1 ; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-language-no-comma.rc 2>&1 | FileCheck %s --check-prefix PLANGUAGE1
; PLANGUAGE1: llvm-rc: Error parsing file: expected ',', got 7 ; PLANGUAGE1: llvm-rc: Error parsing file: expected ',', got 7
; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-language-too-many-commas.rc 2>&1 | FileCheck %s --check-prefix PLANGUAGE2 ; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-language-too-many-commas.rc 2>&1 | FileCheck %s --check-prefix PLANGUAGE2
; PLANGUAGE2: llvm-rc: Error parsing file: expected '-', '~', integer or '(', got , ; PLANGUAGE2: llvm-rc: Error parsing file: expected '-', '~', integer or '(', got ,
; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-html-extra-comma.rc 2>&1 | FileCheck %s --check-prefix PHTML2 ; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-html-extra-comma.rc 2>&1 | FileCheck %s --check-prefix PHTML2
; PHTML2: llvm-rc: Error parsing file: expected string, got , ; PHTML2: llvm-rc: Error parsing file: expected string, got ,
; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-accelerators-bad-flag.rc 2>&1 | FileCheck %s --check-prefix PACCELERATORS1 ; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-accelerators-bad-flag.rc 2>&1 | FileCheck %s --check-prefix PACCELERATORS1
; PACCELERATORS1: llvm-rc: Error parsing file: expected ASCII/VIRTKEY/NOINVERT/ALT/SHIFT/CONTROL, got HELLO ; PACCELERATORS1: llvm-rc: Error parsing file: expected ASCII/VIRTKEY/NOINVERT/ALT/SHIFT/CONTROL, got HELLO
; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-accelerators-bad-int-or-string.rc 2>&1 | FileCheck %s --check-prefix PACCELERATORS2 ; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-accelerators-bad-int-or-string.rc 2>&1 | FileCheck %s --check-prefix PACCELERATORS2
; PACCELERATORS2: llvm-rc: Error parsing file: expected int or string, got NotIntOrString ; PACCELERATORS2: llvm-rc: Error parsing file: expected int or string, got NotIntOrString
; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-accelerators-no-comma.rc 2>&1 | FileCheck %s --check-prefix PACCELERATORS3 ; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-accelerators-no-comma.rc 2>&1 | FileCheck %s --check-prefix PACCELERATORS3
; PACCELERATORS3: llvm-rc: Error parsing file: expected int or string, got CONTROL ; PACCELERATORS3: llvm-rc: Error parsing file: expected int or string, got CONTROL
; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-accelerators-no-comma-2.rc 2>&1 | FileCheck %s --check-prefix PACCELERATORS4 ; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-accelerators-no-comma-2.rc 2>&1 | FileCheck %s --check-prefix PACCELERATORS4
; PACCELERATORS4: llvm-rc: Error parsing file: expected ',', got 10 ; PACCELERATORS4: llvm-rc: Error parsing file: expected ',', got 10
; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-menu-bad-id.rc 2>&1 | FileCheck %s --check-prefix PMENU1 ; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-menu-bad-id.rc 2>&1 | FileCheck %s --check-prefix PMENU1
; PMENU1: llvm-rc: Error parsing file: expected '-', '~', integer or '(', got A ; PMENU1: llvm-rc: Error parsing file: expected '-', '~', integer or '(', got A
; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-menu-bad-flag.rc 2>&1 | FileCheck %s --check-prefix PMENU2 ; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-menu-bad-flag.rc 2>&1 | FileCheck %s --check-prefix PMENU2
; PMENU2: llvm-rc: Error parsing file: expected CHECKED/GRAYED/HELP/INACTIVE/MENUBARBREAK/MENUBREAK, got ERRONEOUS ; PMENU2: llvm-rc: Error parsing file: expected CHECKED/GRAYED/HELP/INACTIVE/MENUBARBREAK/MENUBREAK, got ERRONEOUS
; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-menu-missing-block.rc 2>&1 | FileCheck %s --check-prefix PMENU3 ; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-menu-missing-block.rc 2>&1 | FileCheck %s --check-prefix PMENU3
; PMENU3: llvm-rc: Error parsing file: expected '{', got POPUP ; PMENU3: llvm-rc: Error parsing file: expected '{', got POPUP
; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-menu-misspelled-separator.rc 2>&1 | FileCheck %s --check-prefix PMENU4 ; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-menu-misspelled-separator.rc 2>&1 | FileCheck %s --check-prefix PMENU4
; PMENU4: llvm-rc: Error parsing file: expected SEPARATOR or string, got NOTSEPARATOR ; PMENU4: llvm-rc: Error parsing file: expected SEPARATOR or string, got NOTSEPARATOR
; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-dialog-cant-give-helpid.rc 2>&1 | FileCheck %s --check-prefix PDIALOG1 ; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-dialog-cant-give-helpid.rc 2>&1 | FileCheck %s --check-prefix PDIALOG1
; PDIALOG1: llvm-rc: Error parsing file: expected identifier, got , ; PDIALOG1: llvm-rc: Error parsing file: expected identifier, got ,
; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-dialog-too-few-args.rc 2>&1 | FileCheck %s --check-prefix PDIALOG2 ; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-dialog-too-few-args.rc 2>&1 | FileCheck %s --check-prefix PDIALOG2
; PDIALOG2: llvm-rc: Error parsing file: expected ',', got } ; PDIALOG2: llvm-rc: Error parsing file: expected ',', got }
; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-dialog-too-many-args.rc 2>&1 | FileCheck %s --check-prefix PDIALOG3 ; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-dialog-too-many-args.rc 2>&1 | FileCheck %s --check-prefix PDIALOG3
; PDIALOG3: llvm-rc: Error parsing file: expected identifier, got , ; PDIALOG3: llvm-rc: Error parsing file: expected identifier, got ,
; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-dialog-unknown-type.rc 2>&1 | FileCheck %s --check-prefix PDIALOG4 ; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-dialog-unknown-type.rc 2>&1 | FileCheck %s --check-prefix PDIALOG4
; PDIALOG4: llvm-rc: Error parsing file: expected control type, END or '}', got UNKNOWN ; PDIALOG4: llvm-rc: Error parsing file: expected control type, END or '}', got UNKNOWN
; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-dialog-unnecessary-string.rc 2>&1 | FileCheck %s --check-prefix PDIALOG5 ; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-dialog-unnecessary-string.rc 2>&1 | FileCheck %s --check-prefix PDIALOG5
; PDIALOG5: llvm-rc: Error parsing file: expected '-', '~', integer or '(', got "This shouldn't be here" ; PDIALOG5: llvm-rc: Error parsing file: expected '-', '~', integer or '(', got "This shouldn't be here"
; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-dialog-simple-font.rc 2>&1 | FileCheck %s --check-prefix PDIALOG6 ; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-dialog-simple-font.rc 2>&1 | FileCheck %s --check-prefix PDIALOG6
; PDIALOG6: llvm-rc: Error parsing file: expected identifier, got , ; PDIALOG6: llvm-rc: Error parsing file: expected identifier, got ,
; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-versioninfo-wrong-fixed.rc 2>&1 | FileCheck %s --check-prefix PVERSIONINFO1 ; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-versioninfo-wrong-fixed.rc 2>&1 | FileCheck %s --check-prefix PVERSIONINFO1
; PVERSIONINFO1: llvm-rc: Error parsing file: expected fixed VERSIONINFO statement type, got WEIRDFIXED ; PVERSIONINFO1: llvm-rc: Error parsing file: expected fixed VERSIONINFO statement type, got WEIRDFIXED
; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-versioninfo-named-main-block.rc 2>&1 | FileCheck %s --check-prefix PVERSIONINFO2 ; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-versioninfo-named-main-block.rc 2>&1 | FileCheck %s --check-prefix PVERSIONINFO2
; PVERSIONINFO2: llvm-rc: Error parsing file: expected fixed VERSIONINFO statement type, got BLOCK ; PVERSIONINFO2: llvm-rc: Error parsing file: expected fixed VERSIONINFO statement type, got BLOCK
; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-versioninfo-unnamed-inner-block.rc 2>&1 | FileCheck %s --check-prefix PVERSIONINFO3 ; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-versioninfo-unnamed-inner-block.rc 2>&1 | FileCheck %s --check-prefix PVERSIONINFO3
; PVERSIONINFO3: llvm-rc: Error parsing file: expected string, got { ; PVERSIONINFO3: llvm-rc: Error parsing file: expected string, got {
; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-versioninfo-unnamed-value.rc 2>&1 | FileCheck %s --check-prefix PVERSIONINFO4 ; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-versioninfo-unnamed-value.rc 2>&1 | FileCheck %s --check-prefix PVERSIONINFO4
; PVERSIONINFO4: llvm-rc: Error parsing file: expected string, got END ; PVERSIONINFO4: llvm-rc: Error parsing file: expected string, got END
; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-versioninfo-bad-type.rc 2>&1 | FileCheck %s --check-prefix PVERSIONINFO5 ; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-versioninfo-bad-type.rc 2>&1 | FileCheck %s --check-prefix PVERSIONINFO5
; PVERSIONINFO5: llvm-rc: Error parsing file: expected BLOCK or VALUE, got INCORRECT ; PVERSIONINFO5: llvm-rc: Error parsing file: expected BLOCK or VALUE, got INCORRECT
; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-versioninfo-repeated-fixed.rc 2>&1 | FileCheck %s --check-prefix PVERSIONINFO6 ; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-versioninfo-repeated-fixed.rc 2>&1 | FileCheck %s --check-prefix PVERSIONINFO6
; PVERSIONINFO6: llvm-rc: Error parsing file: expected yet unread fixed VERSIONINFO statement type, got FILEVERSION ; PVERSIONINFO6: llvm-rc: Error parsing file: expected yet unread fixed VERSIONINFO statement type, got FILEVERSION
; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-user-invalid-contents.rc 2>&1 | FileCheck %s --check-prefix PUSER1 ; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-user-invalid-contents.rc 2>&1 | FileCheck %s --check-prefix PUSER1
; PUSER1: llvm-rc: Error parsing file: expected int or string, got InvalidToken ; PUSER1: llvm-rc: Error parsing file: expected int or string, got InvalidToken

View File

@ -0,0 +1,3 @@
; RUN: llvm-rc -### -i%p "-DFOO1=\"foo bar\"" -UFOO2 -D FOO3 -- %p/Inputs/empty.rc | FileCheck %s
; CHECK: {{^}} "clang" "--driver-mode=gcc" "-target" "{{.*}}-pc-windows-msvc-coff" "-E" "-xc" "-DRC_INVOKED" "{{.*}}empty.rc" "-o" "{{.*}}preproc-{{.*}}.rc" "-I" "{{.*}}" "-D" "FOO1=\"foo bar\"" "-U" "FOO2" "-D" "FOO3"{{$}}

View File

@ -1,4 +1,4 @@
; RUN: llvm-rc /FO %t -- %p/Inputs/tag-accelerators.rc ; RUN: llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-accelerators.rc
; RUN: llvm-readobj %t | FileCheck %s --check-prefix=ACCELERATORS ; RUN: llvm-readobj %t | FileCheck %s --check-prefix=ACCELERATORS
; ACCELERATORS: Resource type (int): ACCELERATOR (ID 9) ; ACCELERATORS: Resource type (int): ACCELERATOR (ID 9)
@ -79,79 +79,79 @@
; ACCELERATORS-NEXT: ) ; ACCELERATORS-NEXT: )
; RUN: not llvm-rc /FO %t -- %p/Inputs/tag-accelerators-bad-id.rc 2>&1 | FileCheck %s --check-prefix BADID ; RUN: not llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-accelerators-bad-id.rc 2>&1 | FileCheck %s --check-prefix BADID
; BADID: llvm-rc: Error in ACCELERATORS statement (ID 1): ; BADID: llvm-rc: Error in ACCELERATORS statement (ID 1):
; BADID-NEXT: ACCELERATORS entry ID (1234567) does not fit in 16 bits. ; BADID-NEXT: ACCELERATORS entry ID (1234567) does not fit in 16 bits.
; RUN: not llvm-rc /FO %t -- %p/Inputs/tag-accelerators-ascii-virtkey.rc 2>&1 | FileCheck %s --check-prefix ASCII1 ; RUN: not llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-accelerators-ascii-virtkey.rc 2>&1 | FileCheck %s --check-prefix ASCII1
; ASCII1: llvm-rc: Error in ACCELERATORS statement (ID 2): ; ASCII1: llvm-rc: Error in ACCELERATORS statement (ID 2):
; ASCII1-NEXT: Accelerator ID 15: Accelerator can't be both ASCII and VIRTKEY ; ASCII1-NEXT: Accelerator ID 15: Accelerator can't be both ASCII and VIRTKEY
; RUN: not llvm-rc /FO %t -- %p/Inputs/tag-accelerators-ascii-control.rc 2>&1 | FileCheck %s --check-prefix ASCII2 ; RUN: not llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-accelerators-ascii-control.rc 2>&1 | FileCheck %s --check-prefix ASCII2
; ASCII2: llvm-rc: Error in ACCELERATORS statement (ID 2): ; ASCII2: llvm-rc: Error in ACCELERATORS statement (ID 2):
; ASCII2-NEXT: Accelerator ID 15: Can only apply ALT, SHIFT or CONTROL to VIRTKEY accelerators ; ASCII2-NEXT: Accelerator ID 15: Can only apply ALT, SHIFT or CONTROL to VIRTKEY accelerators
; RUN: not llvm-rc /FO %t -- %p/Inputs/tag-accelerators-ascii-shift.rc 2>&1 | FileCheck %s --check-prefix ASCII3 ; RUN: not llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-accelerators-ascii-shift.rc 2>&1 | FileCheck %s --check-prefix ASCII3
; ASCII3: llvm-rc: Error in ACCELERATORS statement (ID 2): ; ASCII3: llvm-rc: Error in ACCELERATORS statement (ID 2):
; ASCII3-NEXT: Accelerator ID 15: Can only apply ALT, SHIFT or CONTROL to VIRTKEY accelerators ; ASCII3-NEXT: Accelerator ID 15: Can only apply ALT, SHIFT or CONTROL to VIRTKEY accelerators
; RUN: not llvm-rc /FO %t -- %p/Inputs/tag-accelerators-ascii-alt.rc 2>&1 | FileCheck %s --check-prefix ASCII4 ; RUN: not llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-accelerators-ascii-alt.rc 2>&1 | FileCheck %s --check-prefix ASCII4
; ASCII4: llvm-rc: Error in ACCELERATORS statement (ID 2): ; ASCII4: llvm-rc: Error in ACCELERATORS statement (ID 2):
; ASCII4-NEXT: Accelerator ID 15: Can only apply ALT, SHIFT or CONTROL to VIRTKEY accelerators ; ASCII4-NEXT: Accelerator ID 15: Can only apply ALT, SHIFT or CONTROL to VIRTKEY accelerators
; RUN: not llvm-rc /FO %t -- %p/Inputs/tag-accelerators-bad-key-id.rc 2>&1 | FileCheck %s --check-prefix BADKEYID ; RUN: not llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-accelerators-bad-key-id.rc 2>&1 | FileCheck %s --check-prefix BADKEYID
; BADKEYID: llvm-rc: Error in ACCELERATORS statement (ID 9): ; BADKEYID: llvm-rc: Error in ACCELERATORS statement (ID 9):
; BADKEYID-NEXT: Numeric event key ID (1234567) does not fit in 16 bits. ; BADKEYID-NEXT: Numeric event key ID (1234567) does not fit in 16 bits.
; RUN: not llvm-rc /FO %t -- %p/Inputs/tag-accelerators-too-short.rc 2>&1 | FileCheck %s --check-prefix LENGTH1 ; RUN: not llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-accelerators-too-short.rc 2>&1 | FileCheck %s --check-prefix LENGTH1
; LENGTH1: llvm-rc: Error in ACCELERATORS statement (ID 10): ; LENGTH1: llvm-rc: Error in ACCELERATORS statement (ID 10):
; LENGTH1-NEXT: Accelerator ID 12: Accelerator string events should have length 1 or 2 ; LENGTH1-NEXT: Accelerator ID 12: Accelerator string events should have length 1 or 2
; RUN: not llvm-rc /FO %t -- %p/Inputs/tag-accelerators-too-long.rc 2>&1 | FileCheck %s --check-prefix LENGTH2 ; RUN: not llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-accelerators-too-long.rc 2>&1 | FileCheck %s --check-prefix LENGTH2
; LENGTH2: llvm-rc: Error in ACCELERATORS statement (ID 12): ; LENGTH2: llvm-rc: Error in ACCELERATORS statement (ID 12):
; LENGTH2-NEXT: Accelerator ID 5: Accelerator string events should have length 1 or 2 ; LENGTH2-NEXT: Accelerator ID 5: Accelerator string events should have length 1 or 2
; RUN: not llvm-rc /FO %t -- %p/Inputs/tag-accelerators-only-caret.rc 2>&1 | FileCheck %s --check-prefix CARET1 ; RUN: not llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-accelerators-only-caret.rc 2>&1 | FileCheck %s --check-prefix CARET1
; CARET1: llvm-rc: Error in ACCELERATORS statement (ID 555): ; CARET1: llvm-rc: Error in ACCELERATORS statement (ID 555):
; CARET1-NEXT: Accelerator ID 100: No character following '^' in accelerator event ; CARET1-NEXT: Accelerator ID 100: No character following '^' in accelerator event
; RUN: not llvm-rc /FO %t -- %p/Inputs/tag-accelerators-no-caret.rc 2>&1 | FileCheck %s --check-prefix CARET2 ; RUN: not llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-accelerators-no-caret.rc 2>&1 | FileCheck %s --check-prefix CARET2
; CARET2: llvm-rc: Error in ACCELERATORS statement (ID 50): ; CARET2: llvm-rc: Error in ACCELERATORS statement (ID 50):
; CARET2-NEXT: Accelerator ID 1: Event string should be one-character, possibly preceded by '^' ; CARET2-NEXT: Accelerator ID 1: Event string should be one-character, possibly preceded by '^'
; RUN: not llvm-rc /FO %t -- %p/Inputs/tag-accelerators-long-virtkey.rc 2>&1 | FileCheck %s --check-prefix CARET3 ; RUN: not llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-accelerators-long-virtkey.rc 2>&1 | FileCheck %s --check-prefix CARET3
; CARET3: llvm-rc: Error in ACCELERATORS statement (ID 100): ; CARET3: llvm-rc: Error in ACCELERATORS statement (ID 100):
; CARET3-NEXT: Accelerator ID 10: VIRTKEY accelerator events can't be preceded by '^' ; CARET3-NEXT: Accelerator ID 10: VIRTKEY accelerator events can't be preceded by '^'
; RUN: not llvm-rc /FO %t -- %p/Inputs/tag-accelerators-control-nonalpha.rc 2>&1 | FileCheck %s --check-prefix NONALPHA1 ; RUN: not llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-accelerators-control-nonalpha.rc 2>&1 | FileCheck %s --check-prefix NONALPHA1
; NONALPHA1: llvm-rc: Error in ACCELERATORS statement (ID 100): ; NONALPHA1: llvm-rc: Error in ACCELERATORS statement (ID 100):
; NONALPHA1-NEXT: Accelerator ID 1: Control character accelerator event should be alphabetic ; NONALPHA1-NEXT: Accelerator ID 1: Control character accelerator event should be alphabetic
; RUN: not llvm-rc /FO %t -- %p/Inputs/tag-accelerators-virtual-nonalpha.rc 2>&1 | FileCheck %s --check-prefix NONALPHA2 ; RUN: not llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-accelerators-virtual-nonalpha.rc 2>&1 | FileCheck %s --check-prefix NONALPHA2
; NONALPHA2: llvm-rc: Error in ACCELERATORS statement (ID 42): ; NONALPHA2: llvm-rc: Error in ACCELERATORS statement (ID 42):
; NONALPHA2-NEXT: Accelerator ID 1: Non-alphanumeric characters cannot describe virtual keys ; NONALPHA2-NEXT: Accelerator ID 1: Non-alphanumeric characters cannot describe virtual keys

View File

@ -1,4 +1,4 @@
; RUN: llvm-rc /FO %t -- %p/Inputs/tag-dialog.rc ; RUN: llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-dialog.rc
; RUN: llvm-readobj %t | FileCheck %s --check-prefix=DIALOG ; RUN: llvm-readobj %t | FileCheck %s --check-prefix=DIALOG
; DIALOG: Resource type (int): DIALOG (ID 5) ; DIALOG: Resource type (int): DIALOG (ID 5)
@ -163,7 +163,7 @@
; DIALOG-NEXT: ) ; DIALOG-NEXT: )
; RUN: llvm-rc /FO %t -- %p/Inputs/tag-dialog-headers.rc ; RUN: llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-dialog-headers.rc
; RUN: llvm-readobj %t | FileCheck %s --check-prefix=HEADERS ; RUN: llvm-readobj %t | FileCheck %s --check-prefix=HEADERS
; HEADERS: Resource type (int): DIALOG (ID 5) ; HEADERS: Resource type (int): DIALOG (ID 5)
@ -636,73 +636,73 @@
; HEADERS-NEXT: ) ; HEADERS-NEXT: )
; RUN: not llvm-rc /FO %t -- %p/Inputs/tag-dialog-large-coord.rc 2>&1 | FileCheck %s --check-prefix COORD1 ; RUN: not llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-dialog-large-coord.rc 2>&1 | FileCheck %s --check-prefix COORD1
; COORD1: llvm-rc: Error in DIALOGEX statement (ID 1): ; COORD1: llvm-rc: Error in DIALOGEX statement (ID 1):
; COORD1-NEXT: Dialog x-coordinate (50000) does not fit in 16-bit signed integer type. ; COORD1-NEXT: Dialog x-coordinate (50000) does not fit in 16-bit signed integer type.
; RUN: not llvm-rc /FO %t -- %p/Inputs/tag-dialog-large-coord-neg.rc 2>&1 | FileCheck %s --check-prefix COORD2 ; RUN: not llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-dialog-large-coord-neg.rc 2>&1 | FileCheck %s --check-prefix COORD2
; COORD2: llvm-rc: Error in DIALOG statement (ID 1): ; COORD2: llvm-rc: Error in DIALOG statement (ID 1):
; COORD2-NEXT: Dialog y-coordinate (-40000) does not fit in 16-bit signed integer type. ; COORD2-NEXT: Dialog y-coordinate (-40000) does not fit in 16-bit signed integer type.
; RUN: not llvm-rc /FO %t -- %p/Inputs/tag-dialog-large-size.rc 2>&1 | FileCheck %s --check-prefix COORD3 ; RUN: not llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-dialog-large-size.rc 2>&1 | FileCheck %s --check-prefix COORD3
; COORD3: llvm-rc: Error in DIALOGEX statement (ID 1): ; COORD3: llvm-rc: Error in DIALOGEX statement (ID 1):
; COORD3-NEXT: Dialog height (32768) does not fit in 16-bit signed integer type. ; COORD3-NEXT: Dialog height (32768) does not fit in 16-bit signed integer type.
; RUN: not llvm-rc /FO %t -- %p/Inputs/tag-dialog-negative-size.rc 2>&1 | FileCheck %s --check-prefix COORD4 ; RUN: not llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-dialog-negative-size.rc 2>&1 | FileCheck %s --check-prefix COORD4
; COORD4: llvm-rc: Error in DIALOGEX statement (ID 1): ; COORD4: llvm-rc: Error in DIALOGEX statement (ID 1):
; COORD4-NEXT: Dialog width (-50) cannot be negative. ; COORD4-NEXT: Dialog width (-50) cannot be negative.
; RUN: not llvm-rc /FO %t -- %p/Inputs/tag-dialog-ctl-large-coord.rc 2>&1 | FileCheck %s --check-prefix CTL-COORD1 ; RUN: not llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-dialog-ctl-large-coord.rc 2>&1 | FileCheck %s --check-prefix CTL-COORD1
; CTL-COORD1: llvm-rc: Error in DIALOGEX statement (ID 1): ; CTL-COORD1: llvm-rc: Error in DIALOGEX statement (ID 1):
; CTL-COORD1-NEXT: Error in LTEXT control (ID 1): ; CTL-COORD1-NEXT: Error in LTEXT control (ID 1):
; CTL-COORD1-NEXT: Dialog control x-coordinate (44444) does not fit in 16-bit signed integer type. ; CTL-COORD1-NEXT: Dialog control x-coordinate (44444) does not fit in 16-bit signed integer type.
; RUN: not llvm-rc /FO %t -- %p/Inputs/tag-dialog-ctl-large-coord-neg.rc 2>&1 | FileCheck %s --check-prefix CTL-COORD2 ; RUN: not llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-dialog-ctl-large-coord-neg.rc 2>&1 | FileCheck %s --check-prefix CTL-COORD2
; CTL-COORD2: llvm-rc: Error in DIALOG statement (ID 1): ; CTL-COORD2: llvm-rc: Error in DIALOG statement (ID 1):
; CTL-COORD2-NEXT: Error in LTEXT control (ID 1): ; CTL-COORD2-NEXT: Error in LTEXT control (ID 1):
; CTL-COORD2-NEXT: Dialog control y-coordinate (-32769) does not fit in 16-bit signed integer type. ; CTL-COORD2-NEXT: Dialog control y-coordinate (-32769) does not fit in 16-bit signed integer type.
; RUN: not llvm-rc /FO %t -- %p/Inputs/tag-dialog-ctl-large-size.rc 2>&1 | FileCheck %s --check-prefix CTL-COORD3 ; RUN: not llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-dialog-ctl-large-size.rc 2>&1 | FileCheck %s --check-prefix CTL-COORD3
; CTL-COORD3: llvm-rc: Error in DIALOGEX statement (ID 1): ; CTL-COORD3: llvm-rc: Error in DIALOGEX statement (ID 1):
; CTL-COORD3-NEXT: Error in LTEXT control (ID 1): ; CTL-COORD3-NEXT: Error in LTEXT control (ID 1):
; CTL-COORD3-NEXT: Dialog control width (40000) does not fit in 16-bit signed integer type. ; CTL-COORD3-NEXT: Dialog control width (40000) does not fit in 16-bit signed integer type.
; RUN: not llvm-rc /FO %t -- %p/Inputs/tag-dialog-ctl-negative-size.rc 2>&1 | FileCheck %s --check-prefix CTL-COORD4 ; RUN: not llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-dialog-ctl-negative-size.rc 2>&1 | FileCheck %s --check-prefix CTL-COORD4
; CTL-COORD4: llvm-rc: Error in DIALOG statement (ID 1): ; CTL-COORD4: llvm-rc: Error in DIALOG statement (ID 1):
; CTL-COORD4-NEXT: Error in LTEXT control (ID 1): ; CTL-COORD4-NEXT: Error in LTEXT control (ID 1):
; CTL-COORD4-NEXT: Dialog control height (-700) cannot be negative. ; CTL-COORD4-NEXT: Dialog control height (-700) cannot be negative.
; RUN: not llvm-rc /FO %t -- %p/Inputs/tag-dialog-ctl-large-id.rc 2>&1 | FileCheck %s --check-prefix CTL-ID ; RUN: not llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-dialog-ctl-large-id.rc 2>&1 | FileCheck %s --check-prefix CTL-ID
; CTL-ID: llvm-rc: Error in DIALOG statement (ID 5): ; CTL-ID: llvm-rc: Error in DIALOG statement (ID 5):
; CTL-ID-NEXT: Error in RTEXT control (ID 100000): ; CTL-ID-NEXT: Error in RTEXT control (ID 100000):
; CTL-ID-NEXT: Control ID in simple DIALOG resource (100000) does not fit in 16 bits. ; CTL-ID-NEXT: Control ID in simple DIALOG resource (100000) does not fit in 16 bits.
; RUN: not llvm-rc /FO %t -- %p/Inputs/tag-dialog-ctl-large-ref-id.rc 2>&1 | FileCheck %s --check-prefix CTL-REF-ID ; RUN: not llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-dialog-ctl-large-ref-id.rc 2>&1 | FileCheck %s --check-prefix CTL-REF-ID
; CTL-REF-ID: llvm-rc: Error in DIALOGEX statement (ID 1): ; CTL-REF-ID: llvm-rc: Error in DIALOGEX statement (ID 1):
; CTL-REF-ID-NEXT: Error in CTEXT control (ID 42): ; CTL-REF-ID-NEXT: Error in CTEXT control (ID 42):
; CTL-REF-ID-NEXT: Control reference ID (65536) does not fit in 16 bits. ; CTL-REF-ID-NEXT: Control reference ID (65536) does not fit in 16 bits.
; RUN: not llvm-rc /FO %t -- %p/Inputs/tag-dialog-bad-style.rc 2>&1 | FileCheck %s --check-prefix STYLE ; RUN: not llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-dialog-bad-style.rc 2>&1 | FileCheck %s --check-prefix STYLE
; STYLE: llvm-rc: Error in DIALOG statement (ID 1): ; STYLE: llvm-rc: Error in DIALOG statement (ID 1):
; STYLE-NEXT: 16 higher bits of DIALOG resource style cannot be equal to 0xFFFF ; STYLE-NEXT: 16 higher bits of DIALOG resource style cannot be equal to 0xFFFF

View File

@ -1,4 +1,4 @@
; RUN: llvm-rc /FO %t -- %p/Inputs/tag-escape.rc ; RUN: llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-escape.rc
; RUN: llvm-readobj %t | FileCheck %s ; RUN: llvm-readobj %t | FileCheck %s
; CHECK: Resource type (int): MENU (ID 4) ; CHECK: Resource type (int): MENU (ID 4)

View File

@ -1,6 +1,6 @@
; RUN: rm -rf %t && mkdir %t && cd %t ; RUN: rm -rf %t && mkdir %t && cd %t
; RUN: cp %p/Inputs/webpage*.html . ; RUN: cp %p/Inputs/webpage*.html .
; RUN: llvm-rc /FO %t/tag-html.res -- %p/Inputs/tag-html.rc ; RUN: llvm-rc -no-preprocess /FO %t/tag-html.res -- %p/Inputs/tag-html.rc
; RUN: llvm-readobj %t/tag-html.res | FileCheck %s --check-prefix HTML ; RUN: llvm-readobj %t/tag-html.res | FileCheck %s --check-prefix HTML
; HTML: Resource type (int): HTML (ID 23) ; HTML: Resource type (int): HTML (ID 23)

View File

@ -1,7 +1,7 @@
; RUN: rm -rf %t ; RUN: rm -rf %t
; RUN: mkdir %t ; RUN: mkdir %t
; RUN: llvm-rc /FO %t/tag-icon-cursor.res -- %p/Inputs/tag-icon-cursor.rc ; RUN: llvm-rc -no-preprocess /FO %t/tag-icon-cursor.res -- %p/Inputs/tag-icon-cursor.rc
; RUN: llvm-readobj %t/tag-icon-cursor.res | FileCheck %s ; RUN: llvm-readobj %t/tag-icon-cursor.res | FileCheck %s
; CHECK: Resource type (int): CURSOR (ID 1) ; CHECK: Resource type (int): CURSOR (ID 1)
@ -320,12 +320,12 @@
; CHECK-NEXT: ) ; CHECK-NEXT: )
; RUN: not llvm-rc /FO %t/1 -- %p/Inputs/tag-icon-cursor-nonexistent.rc 2>&1 | FileCheck %s --check-prefix NOFILE ; RUN: not llvm-rc -no-preprocess /FO %t/1 -- %p/Inputs/tag-icon-cursor-nonexistent.rc 2>&1 | FileCheck %s --check-prefix NOFILE
; NOFILE: llvm-rc: Error in CURSOR statement (ID 500): ; NOFILE: llvm-rc: Error in CURSOR statement (ID 500):
; NOFILE-NEXT: file not found : this-file-does-not-exist.cur ; NOFILE-NEXT: file not found : this-file-does-not-exist.cur
; RUN: not llvm-rc /FO %t/1 -- %p/Inputs/tag-icon-cursor-nonsense.rc 2>&1 | FileCheck %s --check-prefix NONSENSE ; RUN: not llvm-rc -no-preprocess /FO %t/1 -- %p/Inputs/tag-icon-cursor-nonsense.rc 2>&1 | FileCheck %s --check-prefix NONSENSE
; NONSENSE: llvm-rc: Error in ICON statement (ID 1): ; NONSENSE: llvm-rc: Error in ICON statement (ID 1):
; NONSENSE-NEXT: Incorrect icon/cursor Reserved field; should be 0. ; NONSENSE-NEXT: Incorrect icon/cursor Reserved field; should be 0.

View File

@ -1,9 +1,9 @@
; RUN: llvm-rc /FO %t -- %p/Inputs/tag-menu.rc ; RUN: llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-menu.rc
; RUN: llvm-readobj %t | FileCheck %s --check-prefix=MENU ; RUN: llvm-readobj %t | FileCheck %s --check-prefix=MENU
; Test running llvm-rc without an explicit output file. ; Test running llvm-rc -no-preprocess without an explicit output file.
; RUN: cp %p/Inputs/tag-menu.rc %t.implicit.rc ; RUN: cp %p/Inputs/tag-menu.rc %t.implicit.rc
; RUN: llvm-rc -- %t.implicit.rc ; RUN: llvm-rc -no-preprocess -- %t.implicit.rc
; RUN: llvm-readobj %t.implicit.res | FileCheck --check-prefix=MENU %s ; RUN: llvm-readobj %t.implicit.res | FileCheck --check-prefix=MENU %s
; MENU: Resource type (int): MENU (ID 4) ; MENU: Resource type (int): MENU (ID 4)
@ -74,7 +74,7 @@
; MENU-NEXT: ) ; MENU-NEXT: )
; RUN: not llvm-rc /FO %t -- %p/Inputs/tag-menu-bad-menuitem-id.rc 2>&1 | FileCheck %s --check-prefix BADID ; RUN: not llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-menu-bad-menuitem-id.rc 2>&1 | FileCheck %s --check-prefix BADID
; BADID: llvm-rc: Error in MENU statement (ID 1): ; BADID: llvm-rc: Error in MENU statement (ID 1):
; BADID-NEXT: MENUITEM action ID (100000) does not fit in 16 bits. ; BADID-NEXT: MENUITEM action ID (100000) does not fit in 16 bits.

View File

@ -1,4 +1,4 @@
; RUN: llvm-rc /FO %t -- %p/Inputs/tag-stringtable-basic.rc ; RUN: llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-stringtable-basic.rc
; RUN: llvm-readobj %t | FileCheck %s ; RUN: llvm-readobj %t | FileCheck %s
; CHECK: Resource type (int): STRINGTABLE (ID 6) ; CHECK: Resource type (int): STRINGTABLE (ID 6)
@ -81,7 +81,7 @@
; CHECK-NEXT: ) ; CHECK-NEXT: )
; RUN: llvm-rc /N /FO %t0 -- %p/Inputs/tag-stringtable-basic.rc ; RUN: llvm-rc -no-preprocess /N /FO %t0 -- %p/Inputs/tag-stringtable-basic.rc
; RUN: llvm-readobj %t0 | FileCheck %s --check-prefix=NULL ; RUN: llvm-readobj %t0 | FileCheck %s --check-prefix=NULL
; NULL: Resource type (int): STRINGTABLE (ID 6) ; NULL: Resource type (int): STRINGTABLE (ID 6)
@ -166,5 +166,5 @@
; NULL-NEXT: ) ; NULL-NEXT: )
; RUN: not llvm-rc /FO %t -- %p/Inputs/tag-stringtable-same-ids.rc 2>&1 | FileCheck %s --check-prefix SAMEIDS ; RUN: not llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-stringtable-same-ids.rc 2>&1 | FileCheck %s --check-prefix SAMEIDS
; SAMEIDS: llvm-rc: Multiple STRINGTABLE strings located under ID 1 ; SAMEIDS: llvm-rc: Multiple STRINGTABLE strings located under ID 1

View File

@ -2,7 +2,7 @@
; RUN: mkdir %t ; RUN: mkdir %t
; RUN: cd %t ; RUN: cd %t
; RUN: cp %p/Inputs/bitmap.bmp . ; RUN: cp %p/Inputs/bitmap.bmp .
; RUN: llvm-rc /FO %t/tag-user.res -- %p/Inputs/tag-user.rc ; RUN: llvm-rc -no-preprocess /FO %t/tag-user.res -- %p/Inputs/tag-user.rc
; RUN: llvm-readobj %t/tag-user.res | FileCheck %s ; RUN: llvm-readobj %t/tag-user.res | FileCheck %s
; CHECK: Resource type (int): ID 500 ; CHECK: Resource type (int): ID 500

View File

@ -1,4 +1,4 @@
; RUN: llvm-rc /FO %t -- %p/Inputs/tag-versioninfo.rc ; RUN: llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-versioninfo.rc
; RUN: llvm-readobj %t | FileCheck %s ; RUN: llvm-readobj %t | FileCheck %s
; CHECK: Resource type (int): VERSIONINFO (ID 16) ; CHECK: Resource type (int): VERSIONINFO (ID 16)
@ -56,11 +56,11 @@
; CHECK-NEXT: ) ; CHECK-NEXT: )
; RUN: not llvm-rc /FO %t -- %p/Inputs/tag-versioninfo-mixed-ints-strings.rc 2>&1 | FileCheck %s --check-prefix STRINT ; RUN: not llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-versioninfo-mixed-ints-strings.rc 2>&1 | FileCheck %s --check-prefix STRINT
; STRINT: llvm-rc: Error in VERSIONINFO statement (ID 1): ; STRINT: llvm-rc: Error in VERSIONINFO statement (ID 1):
; STRINT-NEXT: VALUE "FileDescription" cannot contain both strings and integers ; STRINT-NEXT: VALUE "FileDescription" cannot contain both strings and integers
; RUN: not llvm-rc /FO %t -- %p/Inputs/tag-versioninfo-word-too-large.rc 2>&1 | FileCheck %s --check-prefix WORD ; RUN: not llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-versioninfo-word-too-large.rc 2>&1 | FileCheck %s --check-prefix WORD
; WORD: llvm-rc: Error in VERSIONINFO statement (ID 1): ; WORD: llvm-rc: Error in VERSIONINFO statement (ID 1):
; WORD-NEXT: VERSIONINFO integer value (65536) does not fit in 16 bits. ; WORD-NEXT: VERSIONINFO integer value (65536) does not fit in 16 bits.

View File

@ -1,4 +1,4 @@
; RUN: not llvm-rc /V /FO %t.res -- %p/Inputs/tokens.rc | FileCheck %s ; RUN: not llvm-rc -no-preprocess /V /FO %t.res -- %p/Inputs/tokens.rc | FileCheck %s
; llvm-rc fails now on this sample because it is an invalid resource file ; llvm-rc fails now on this sample because it is an invalid resource file
; script. We silence the error message and just analyze the output. ; script. We silence the error message and just analyze the output.

View File

@ -1,4 +1,4 @@
; RUN: llvm-rc /FO %t -- %p/Inputs/versioninfo-padding.rc ; RUN: llvm-rc -no-preprocess /FO %t -- %p/Inputs/versioninfo-padding.rc
; RUN: llvm-readobj %t | FileCheck %s ; RUN: llvm-readobj %t | FileCheck %s
; CHECK: Resource type (int): VERSIONINFO (ID 16) ; CHECK: Resource type (int): VERSIONINFO (ID 16)

View File

@ -17,13 +17,13 @@ class S_nodoc<string name> : Separate<["/", "-"], name>;
def fileout : JS<"FO", "Change the output file location.">; def fileout : JS<"FO", "Change the output file location.">;
def define : S<"D", "Define a symbol for the C preprocessor.">; def define : JS<"D", "Define a symbol for the C preprocessor.">;
def undef : S<"U", "Undefine a symbol for the C preprocessor.">; def undef : JS<"U", "Undefine a symbol for the C preprocessor.">;
def lang_id : JS<"L", "Set the default language identifier.">; def lang_id : JS<"L", "Set the default language identifier.">;
def lang_name : S<"LN", "Set the default language name.">; def lang_name : S<"LN", "Set the default language name.">;
def includepath : S<"I", "Add an include path.">; def includepath : JS<"I", "Add an include path.">;
def noinclude : F<"X", "Ignore 'include' variable.">; def noinclude : F<"X", "Ignore 'include' variable.">;
def add_null : F<"N", "Null-terminate all strings in the string table.">; def add_null : F<"N", "Null-terminate all strings in the string table.">;
@ -34,9 +34,16 @@ def verbose : F<"V", "Be verbose.">;
def help : F<"?", "Display this help and exit.">; def help : F<"?", "Display this help and exit.">;
def h : F<"H", "Display this help and exit.">, Alias<help>; def h : F<"H", "Display this help and exit.">, Alias<help>;
def codepage : JS<"C", "Set the codepage used for input strings.">;
// llvm-rc specific options:
def dry_run : F<"dry-run", "Don't compile the input; only try to parse it.">; def dry_run : F<"dry-run", "Don't compile the input; only try to parse it.">;
def codepage : JS<"C", "Set the codepage used for input strings.">; def no_preprocess : F<"no-preprocess", "Don't try to preprocess the input file.">;
// Print (but do not run) the commands to run for preprocessing
def _HASH_HASH_HASH : F_nodoc<"###">;
// Unused switches (at least for now). These will stay unimplemented // Unused switches (at least for now). These will stay unimplemented
// in an early stage of development and can be ignored. However, we need to // in an early stage of development and can be ignored. However, we need to

View File

@ -17,17 +17,22 @@
#include "ResourceScriptStmt.h" #include "ResourceScriptStmt.h"
#include "ResourceScriptToken.h" #include "ResourceScriptToken.h"
#include "llvm/ADT/Triple.h"
#include "llvm/Option/Arg.h" #include "llvm/Option/Arg.h"
#include "llvm/Option/ArgList.h" #include "llvm/Option/ArgList.h"
#include "llvm/Support/Error.h" #include "llvm/Support/Error.h"
#include "llvm/Support/FileSystem.h" #include "llvm/Support/FileSystem.h"
#include "llvm/Support/FileUtilities.h"
#include "llvm/Support/Host.h"
#include "llvm/Support/InitLLVM.h" #include "llvm/Support/InitLLVM.h"
#include "llvm/Support/ManagedStatic.h" #include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h" #include "llvm/Support/Path.h"
#include "llvm/Support/PrettyStackTrace.h" #include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/Process.h" #include "llvm/Support/Process.h"
#include "llvm/Support/Program.h"
#include "llvm/Support/Signals.h" #include "llvm/Support/Signals.h"
#include "llvm/Support/StringSaver.h"
#include "llvm/Support/raw_ostream.h" #include "llvm/Support/raw_ostream.h"
#include <algorithm> #include <algorithm>
@ -71,12 +76,114 @@ public:
}; };
static ExitOnError ExitOnErr; static ExitOnError ExitOnErr;
static FileRemover TempPreprocFile;
LLVM_ATTRIBUTE_NORETURN static void fatalError(const Twine &Message) { LLVM_ATTRIBUTE_NORETURN static void fatalError(const Twine &Message) {
errs() << Message << "\n"; errs() << Message << "\n";
exit(1); exit(1);
} }
std::string createTempFile(const Twine &Prefix, StringRef Suffix) {
std::error_code EC;
SmallString<128> FileName;
if ((EC = sys::fs::createTemporaryFile(Prefix, Suffix, FileName)))
fatalError("Unable to create temp file: " + EC.message());
return static_cast<std::string>(FileName);
}
ErrorOr<std::string> findClang(const char *Argv0) {
StringRef Parent = llvm::sys::path::parent_path(Argv0);
ErrorOr<std::string> Path = std::error_code();
if (!Parent.empty()) {
// First look for the tool with all potential names in the specific
// directory of Argv0, if known
for (const auto *Name : {"clang", "clang-cl"}) {
Path = sys::findProgramByName(Name, Parent);
if (Path)
return Path;
}
}
// If no parent directory known, or not found there, look everywhere in PATH
for (const auto *Name : {"clang", "clang-cl"}) {
Path = sys::findProgramByName(Name);
if (Path)
return Path;
}
return Path;
}
std::string getClangClTriple() {
Triple T(sys::getDefaultTargetTriple());
T.setOS(llvm::Triple::Win32);
T.setVendor(llvm::Triple::PC);
T.setEnvironment(llvm::Triple::MSVC);
T.setObjectFormat(llvm::Triple::COFF);
return T.str();
}
bool preprocess(StringRef Src, StringRef Dst, opt::InputArgList &InputArgs,
const char *Argv0) {
std::string Clang;
if (InputArgs.hasArg(OPT__HASH_HASH_HASH)) {
Clang = "clang";
} else {
ErrorOr<std::string> ClangOrErr = findClang(Argv0);
if (ClangOrErr) {
Clang = *ClangOrErr;
} else {
errs() << "llvm-rc: Unable to find clang, skipping preprocessing."
<< "\n";
errs() << "Pass -no-cpp to disable preprocessing. This will be an error "
"in the future."
<< "\n";
return false;
}
}
std::string PreprocTriple = getClangClTriple();
SmallVector<StringRef, 8> Args = {
Clang, "--driver-mode=gcc", "-target", PreprocTriple, "-E",
"-xc", "-DRC_INVOKED", Src, "-o", Dst};
if (InputArgs.hasArg(OPT_noinclude)) {
#ifdef _WIN32
::_putenv("INCLUDE=");
#else
::unsetenv("INCLUDE");
#endif
}
for (const auto *Arg :
InputArgs.filtered(OPT_includepath, OPT_define, OPT_undef)) {
switch (Arg->getOption().getID()) {
case OPT_includepath:
Args.push_back("-I");
break;
case OPT_define:
Args.push_back("-D");
break;
case OPT_undef:
Args.push_back("-U");
break;
}
Args.push_back(Arg->getValue());
}
if (InputArgs.hasArg(OPT__HASH_HASH_HASH) || InputArgs.hasArg(OPT_verbose)) {
for (const auto &A : Args) {
outs() << " ";
sys::printArg(outs(), A, InputArgs.hasArg(OPT__HASH_HASH_HASH));
}
outs() << "\n";
if (InputArgs.hasArg(OPT__HASH_HASH_HASH))
exit(0);
}
// The llvm Support classes don't handle reading from stdout of a child
// process; otherwise we could avoid using a temp file.
int Res = sys::ExecuteAndWait(Clang, Args);
if (Res) {
fatalError("llvm-rc: Preprocessing failed.");
}
return true;
}
} // anonymous namespace } // anonymous namespace
int main(int Argc, const char **Argv) { int main(int Argc, const char **Argv) {
@ -106,9 +213,17 @@ int main(int Argc, const char **Argv) {
fatalError("Exactly one input file should be provided."); fatalError("Exactly one input file should be provided.");
} }
std::string PreprocessedFile = InArgsInfo[0];
if (!InputArgs.hasArg(OPT_no_preprocess)) {
std::string OutFile = createTempFile("preproc", "rc");
TempPreprocFile.setFile(OutFile);
if (preprocess(InArgsInfo[0], OutFile, InputArgs, Argv[0]))
PreprocessedFile = OutFile;
}
// Read and tokenize the input file. // Read and tokenize the input file.
ErrorOr<std::unique_ptr<MemoryBuffer>> File = ErrorOr<std::unique_ptr<MemoryBuffer>> File =
MemoryBuffer::getFile(InArgsInfo[0]); MemoryBuffer::getFile(PreprocessedFile);
if (!File) { if (!File) {
fatalError("Error opening file '" + Twine(InArgsInfo[0]) + fatalError("Error opening file '" + Twine(InArgsInfo[0]) +
"': " + File.getError().message()); "': " + File.getError().message());