Avoid wasted work. Inspired by Peter Collingbourne's similar change for libArchive. (
https://reviews.llvm.org/D26696)
Details
Diff Detail
Event Timeline
Test case?
I'd note that this isn't so much about wasted work as it is about correctness -- it is legal (although probably not a good idea) for a filename to contain a backslash on *nix.
And for --reproduce in particular I can easily imagine wanting to preserve unintentional uses of backslash in filenames, e.g. when porting a Windows based build system to *nix.
lib/Core/Reproduce.cpp | ||
---|---|---|
55 | Move the ifdef inside the function so that we only need one. |
I don't really care about silly filename containing \ as part of it, but because that's semantically correct, so I'm fine with this.
Not directly related to this patch, but I found that gnuwin32's cpio behaves very weirdly with filenames containing / as path separators. It mostly works, but it prints out error messages. I guess some part of gnuwin32's cpio doesn't handle / as path separators.
test/ELF/reproduce-backslash.s | ||
---|---|---|
5 ↗ | (On Diff #78224) | And I want to avoid "rm -rf" in general because one mistake can really be disastrous (not only one person but everybody who checks out a buggy test file and run it). |
test/ELF/reproduce-backslash.s | ||
---|---|---|
5 ↗ | (On Diff #78224) | What's the alternative? The directory might be non-empty, so rmdir doesn't work. We can remove the rm comment altogether, but the risk is leaving random test output around. |
test/ELF/reproduce-backslash.s | ||
---|---|---|
5 ↗ | (On Diff #78224) | I mean, in this case is possible (as I did in the new patch), but in general I doubt we can avoid calling rm -rf. |
LGTM
test/ELF/reproduce-backslash.s | ||
---|---|---|
5 ↗ | (On Diff #78224) | There might be a case in which we really need to run "rm -rf", but before writing that command, I'll do whatever I can do to avoid it. That's what I mean. |
I'm a bit late because I forgot to submit the comments.
You're missing a Windows test which shows you're replacing the path components.
Probably with REQUIRES: system-windows, x86, cpio
P.S: Sorry for the old, "not visible" comments. I can't get phabricator to delete them.
lib/Core/Reproduce.cpp | ||
---|---|---|
55 | You can even do if (LLVM_ON_WIN32) and get rid of the ifdefs. | |
lld/trunk/lib/Core/Reproduce.cpp | ||
56 ↗ | (On Diff #78236) | Nit: How about if (LLVM_ON_WIN32)? |
lld/trunk/test/ELF/reproduce-backslash.s | ||
1 ↗ | (On Diff #78236) | Can shell be replaced by UNSUPPORTED: system-windows, or are you relying on having a "proper shell" and I'm missing something? |
test/ELF/reproduce-backslash.s | ||
7 ↗ | (On Diff #78144) | This probably won't work on Windows, though. |
lld/trunk/lib/Core/Reproduce.cpp | ||
---|---|---|
56 ↗ | (On Diff #78236) | Is that a common practice? I believe for #define'd macros, we usually use #ifdef. |
lld/trunk/test/ELF/reproduce-backslash.s | ||
1 ↗ | (On Diff #78236) | shell is used to imply "not on Windows", though it is indeed confusing. Windows has shells (command prompt and explorer), of course, so we probably should define "unix", "posix" or something like that to identify Unix. |
There are reproduce-windows.s and reproduce-windows-2.s , no?
lld/trunk/lib/Core/Reproduce.cpp | ||
---|---|---|
56 ↗ | (On Diff #78236) | Probably, but we should change also in the Archiver at that point. |
lld/trunk/test/ELF/reproduce-backslash.s | ||
1 ↗ | (On Diff #78236) | I've seen this used in general to constrain tests to be ran only on Windows (at least in lld). |
i.e.
[davide@cupiditate ELF]$ grep -R 'UNSUPPORTED' * [davide@cupiditate ELF]$ grep -R 'REQUIRES: shell' * invalid-dynamic-list.test:# REQUIRES: shell invalid-linkerscript.test:# REQUIRES: shell linkerscript/linkerscript.s:# REQUIRES: shell linkerscript/linkerscript2.s:# REQUIRES: shell reproduce-error.s:# REQUIRES: shell reproduce.s:# REQUIRES: shell
lld/trunk/lib/Core/Reproduce.cpp | ||
---|---|---|
56 ↗ | (On Diff #78236) | Just checked, and noticed we're inconsistent here. [davide@cupiditate lib]$ grep -R 'if LLVM_ON_WIN32' * | wc -l 8 [davide@cupiditate lib]$ grep -R 'ifdef LLVM_ON_WIN32' * | wc -l 29 So, Filipe, you prefer the other spelling? If so, I can change, but I'd rather change it everywhere. |
lld/trunk/lib/Core/Reproduce.cpp | ||
---|---|---|
56 ↗ | (On Diff #78236) | I was thinking that Filipe suggested use C's if instead of C preprocessor's #ifdef (which I don't agree). |
lld/trunk/lib/Core/Reproduce.cpp | ||
---|---|---|
56 ↗ | (On Diff #78236) | I'd prefer the if (LLVM_ON_WIN32) variant, as it doesn't allow for code that doesn't compile. But if the regular contributors have objections, I don't mind it too much. |
56 ↗ | (On Diff #78236) | ruiu: It's very common in the sanitizers, and it ends up being cleaner and safer. |
lld/trunk/test/ELF/reproduce-backslash.s | ||
1 ↗ | (On Diff #78236) | Indeed: shell is not used very well on llvm. I think it would be nice to get this test right (especially since it might be run under Windows with a "shell"), but I don't think we should refactor all tests right now. (And if this test ends up using shell to mean "Windows", it's not the worst thing.) Refactoring the features should probably be discussed in llvm-dev first, since we'll need to nail down the semantics correctly for the several cases we need (and make it consistent, which is the biggest problem). |
lld/trunk/lib/Core/Reproduce.cpp | ||
---|---|---|
56 ↗ | (On Diff #78236) | Since Rui doesn't seem to agree, I'll withdraw this comment. |
lld/trunk/lib/Core/Reproduce.cpp | ||
---|---|---|
56 ↗ | (On Diff #78236) | At LLVM top directory: $ git grep '#if.*LLVM_ON_WIN32'|wc -l $ git grep 'if (LLVM_ON_WIN32)' | wc -l Is this common? |
lld/trunk/lib/Core/Reproduce.cpp | ||
---|---|---|
56 ↗ | (On Diff #78236) | Are you suggesting #if LLVM_ON_WIN32 instead of #ifdef LLVM_ON_WIN32 ? Or, static void convertToUnixPathSeparator(SmallString<128> &Path) { if (LLVM_ON_WIN32) std::replace(Path.begin(), Path.end(), '\\', '/'); } ? |
lld/trunk/lib/Core/Reproduce.cpp | ||
---|---|---|
56 ↗ | (On Diff #78236) | It's probably a sanitizer thing, then. |
Move the ifdef inside the function so that we only need one.