Skip to content

Commit

Permalink
Avoid creating circular symlinks in launch scripts (bazelbuild#34) (b…
Browse files Browse the repository at this point in the history
…azelbuild#35)

The launcher script for csharp_binary and csharp_nunit_test rules
creates symlinks (ln -s -f) at the top level of runfiles for its
.exe and other files which normally live in subdirectories.

However, when the .exe was already at the top level, it would be
overwritten with a circular symlink. To fix this we check whether
the symlink is needed before creating it.
  • Loading branch information
iainmerrick authored and zaphar committed Nov 3, 2016
1 parent 343ecc8 commit 9f24777
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions dotnet/csharp.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,15 @@ if [[ -e "$0.runfiles" ]]; then
cd $0.runfiles/{workspace}
fi
# Create top-level symlinks for lib files.
# TODO(jeremy): This is a gross and fragile hack.
# We should be able to do better than this.
for l in {libs}; do
ln -s -f $l $(basename $l)
if [[ ! -e $(basename $l) ]]; then
# Note: -f required because the symlink may exist
# even though its current target does not exist.
ln -s -f $l $(basename $l)
fi
done
{mono_exe} {nunit_exe} {libs} "$@"
Expand All @@ -134,11 +139,18 @@ if [[ -e "$0.runfiles" ]]; then
cd $0.runfiles/{workspace}
fi
# Create top-level symlinks for .exe and lib files.
# TODO(jeremy): This is a gross and fragile hack.
# We should be able to do better than this.
ln -s -f {exe} $(basename {exe})
if [[ ! -e $(basename {exe}) ]]; then
# Note: -f required because the symlink may exist
# even though its current target does not exist.
ln -s -f {exe} $(basename {exe})
fi
for l in {libs}; do
ln -s -f $l $(basename {workspace}/$l)
if [[ ! -e $(basename {workspace}/$l) ]]; then
ln -s -f $l $(basename {workspace}/$l)
fi
done
{mono_exe} $(basename {exe}) "$@"
Expand Down

0 comments on commit 9f24777

Please sign in to comment.