Fix Setup.hs if c_tmpdir already exists but is invalid #537
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Changes
Setup.hs
to be more precise in the management of thecbits/tracy/{capture,profiler}/build/unix/obj
symlinks.Motivation and context
#536
Setup.hs
arranges to have the Tracy build products, which would normally end up incbits/tracy/{capture,profiler}/build/unix/obj
, be put in the Haskell build directory. This is done by placing a symlink at the location that Tracy expects, pointing into Haskell build directory (typicallydist-newstyle
). At the end of the post-build hook this symlink is again removed.However, this scheme goes wrong in the following convoluted situation:
dist-newstyle
)cabal clean
to remove the old build directoryThe check if the symlink already exists returns
False
, because a symlink that points to a non-existent path appears to "not exist", and can only be seen by explicitly checking for a symlink. Thus, because "there is no symlink yet" (or soSetup.hs
thinks), a new symlink is created, but that fails because there is already a symlink there. Thus the build crashes withcreateDirectoryLink:createSymbolicLink: already exists (File exists)
.This PR changes the logic to explicitly check for symlinks, removing it if one already exists at the intended path. If a directory is found instead, we assume that this was intentional and we do not place a symlink, hence not redirecting the Tracy build products to the Haskell build directory. If a file is found instead, we error.
This can irrevocably remove a user-placed symlink at the
obj
path, but is difficult to distinguish from some old symlink that we put there, so we do not try.How has this been tested?
Tested the five cases locally (nothing there, broken symlink there, valid symlink there, directory there, file there).
Types of changes
What types of changes does your code introduce? Put an
x
in all the boxes that apply:Checklist
Go over all the following points, and put an
x
in all the boxes that apply. If you're unsure about any of these, don't hesitate to ask. We're here to help!