{"action":"opened","issue":{"url":"https://api.github.com/repos/ninja-build/ninja/issues/1400","repository_url":"https://api.github.com/repos/ninja-build/ninja","labels_url":"https://api.github.com/repos/ninja-build/ninja/issues/1400/labels{/name}","comments_url":"https://api.github.com/repos/ninja-build/ninja/issues/1400/comments","events_url":"https://api.github.com/repos/ninja-build/ninja/issues/1400/events","html_url":"https://github.com/ninja-build/ninja/issues/1400","id":306256677,"number":1400,"title":"Ninja does not correctly resolve symlinks in depfiles","user":{"login":"kalekundert","id":298132,"avatar_url":"https://avatars2.githubusercontent.com/u/298132?v=4","gravatar_id":"","url":"https://api.github.com/users/kalekundert","html_url":"https://github.com/kalekundert","followers_url":"https://api.github.com/users/kalekundert/followers","following_url":"https://api.github.com/users/kalekundert/following{/other_user}","gists_url":"https://api.github.com/users/kalekundert/gists{/gist_id}","starred_url":"https://api.github.com/users/kalekundert/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kalekundert/subscriptions","organizations_url":"https://api.github.com/users/kalekundert/orgs","repos_url":"https://api.github.com/users/kalekundert/repos","events_url":"https://api.github.com/users/kalekundert/events{/privacy}","received_events_url":"https://api.github.com/users/kalekundert/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-03-18T16:47:27Z","updated_at":"2018-03-18T16:47:27Z","closed_at":null,"author_association":"NONE","body":"I've been having trouble trying to build a large project with ninja, because it keeps trying to rebuild the whole project from scratch every time.  I think I tracked this down to a symlink being resolved incorrectly in the depfile generated by `clang++` (`g++` doesn't have the same problem), but I'll try to explain the bug below:\r\n\r\nI started by running `ninja path/to/file.o` twice.  Both runs successfully compiled the file, but the second run shouldn't have needed to.  Next I ran `ninja -d explain path/to/file.o` to see why ninja thought it had to rebuild the file.  I got about 100 dirty files, all of which were stdlib headers.  Here are the first few, for example:\r\n\r\n```\r\nninja explain: output /include/c++/7/cstddef of phony edge with no inputs doesn't exist\r\nninja explain: /include/c++/7/cstddef is dirty\r\nninja explain: output /include/c++/7/x86_64-redhat-linux/bits/c++config.h of phony edge with no inputs doesn't exist\r\nninja explain: /include/c++/7/x86_64-redhat-linux/bits/c++config.h is dirty\r\nninja explain: output /include/c++/7/x86_64-redhat-linux/bits/os_defines.h of phony edge with no inputs doesn't exist\r\nninja explain: /include/c++/7/x86_64-redhat-linux/bits/os_defines.h is dirty\r\nninja explain: output /include/c++/7/x86_64-redhat-linux/bits/cpu_defines.h of phony edge with no inputs doesn't exist\r\nninja explain: /include/c++/7/x86_64-redhat-linux/bits/cpu_defines.h is dirty\r\n```\r\n\r\nNinja is correct that `/include` does not exist on my machine.  These header dependencies came from a depfile generated by `clang++`, so I ran `ninja -d keepdepfile path/to/file.o` and looked at the resulting depfile.  Here's the `cstddef` header path generated by `clang++`:\r\n\r\n```\r\n/bin/../lib/gcc/x86_64-redhat-linux/7/../../../../include/c++/7/cstddef\r\n```\r\n\r\nIf you resolve this path lexically (i.e. without checking for symlinks), as ninja seems to be doing, you end up with `/include/c++/7/cstddef`, which doesn't exist.  The problem is that on my machine, `/lib` is a symlink to `/usr/lib`.  When that's taken into account, the path generated by `clang++` is resolved to a file that does exist:\r\n\r\n```\r\n$ realpath /bin/../lib/gcc/x86_64-redhat-linux/7/../../../../include/c++/7/cstddef\r\n/usr/include/c++/7/cstddef\r\n```\r\n\r\nTLDR: It seems like ninja is resolving paths in depfiles without checking for symlinks.  This seems like a pretty easy issue, so I'll poke around and see if I can make a PR to fix this."}}
{"actor":{"display_login":"kalekundert"}}