Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore error of symlink #83605

Closed

Conversation

junjihashimoto
Copy link
Member

Motivation for this change

When setupCompilerEnvironmentPhase, symlink fails for existing link.
I want to ignore the error.
This pr changes ln -s to ln -sf.

OS : macos

{
  "url": "https://github.com/nixos/nixpkgs-channels.git",
  "rev": "3320a06049fc259e87a2bd98f4cd42f15f746b96",
  "date": "2020-03-26T20:57:21-04:00",
  "sha256": "1g5l186d5xh187vdcpfsz1ff8s749949c1pclvzfkylpar09ldkl",
  "fetchSubmodules": false
}

image
https://github.com/hasktorch/hasktorch/runs/541719980

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

@junjihashimoto junjihashimoto changed the title Ingnore error of synmlink Ingnore error of symlink Mar 28, 2020
@junjihashimoto junjihashimoto changed the title Ingnore error of symlink Ignore error of symlink Mar 28, 2020
@cdepillabout
Copy link
Member

This code was last changed by @infinisil in 8d4509e.

@infinisil Is it possible that there was a bug introduced in 8d4509e for when there are multiple *.dylib files that have the same name?

Is the fix that @junjihashimoto is proposing here correct?

@nh2
Copy link
Contributor

nh2 commented Mar 29, 2020

If -f is added we definitely need a (commented) explanation of what happens when multiple sources provide the same file (the last one will win), and why that makes sense.

Is it correct that there should be such conflicts in the first place?

@junjihashimoto
Copy link
Member Author

junjihashimoto commented Mar 29, 2020

@nh2
there are conf-files for each library(haskell's package) in $packageConfDir.
And dynamic-library-dirs is path of shared libraries the library uses.

For example,
Assuming we have three libraries (A, B, C),
we will have A.conf, B.conf and C.conf in $packageConfDir.
When A depends on B, and B depends on C, and C has libC.so,
we will take duplicate paths of libC.so.
But the duplicated paths are all the same, so I think we can ignore this error.

    for d in $(grep '^dynamic-library-dirs:' "$packageConfDir"/* | cut -d' ' -f2- | tr ' ' '\n' | sort -u); do
      for lib in "$d/"*.{dylib,so}; do
        ln -s "$lib" "$dynamicLinksDir"
        ln -sf "$lib" "$dynamicLinksDir"
      done
    done

@gnprice
Copy link
Contributor

gnprice commented Apr 2, 2020

Is it possible that there was a bug introduced in 8d4509e for when there are multiple *.dylib files that have the same name?

I think, from reading that commit, that the code should try to create the same set of links before and after the commit. (Outside of cases of the bug that the commit was fixing.) If so, then this has probably behaved the same way since this lib/links/ directory was introduced in #25537.

When A depends on B, and B depends on C, and C has libC.so,
we will take duplicate paths of libC.so.
But the duplicated paths are all the same, so I think we can ignore this error.

If that's what's going on, then perhaps we can have the script check that: if the link already exists, it should point to the same path we were going to create it with. Then if it doesn't, we create it just like we do now.

listDynamicLinks () {
for d in $(grep '^dynamic-library-dirs:' "$packageConfDir"/* | cut -d' ' -f2- | tr ' ' '\n' | sort -u); do
for lib in "$d/"*.{dylib,so} ; do
if [ -f "$lib" ] ; then
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we use linux, lib includes not only actual filenames but also *.dylib.
This [ -f "$lib" ] is used to delete *.dylib.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mmm, I see -- because there are no files matching somedir/*.dylib?

Hmm, but this bit of code has always been this way -- in fact it's only since February in 019e86f that it mentions .so at all, and before that it was only .dylib:

     for d in $(grep '^dynamic-library-dirs:' "$packageConfDir"/* | cut -d' ' -f2- | tr ' ' '\n' | sort -u); do
-      for lib in "$d/"*.dylib; do
+      for lib in "$d/"*.{dylib,so}; do
         ln -s "$lib" "$dynamicLinksDir"

This change should be a separate commit, in any event. Probably deserves some separate debugging and discussion, too. It sounds like an independent issue from the collision issue.

@junjihashimoto
Copy link
Member Author

@gnprice
I update this pr to to generating duplicate links.
Is it fine like this?

for d in $(grep '^dynamic-library-dirs:' "$packageConfDir"/* | cut -d' ' -f2- | tr ' ' '\n' | sort -u); do
for lib in "$d/"*.{dylib,so}; do
ln -s "$lib" "$dynamicLinksDir"
listDynamicLinks () {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a comment on this function explaining what it is doing (and why it is needed)?

Copy link
Member

@cdepillabout cdepillabout left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left one comment above.

Also, please rebase this on the haskell-updates branch.

Copy link
Contributor

@gnprice gnprice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @junjihashimoto for the revisions! Comments below.

listDynamicLinks () {
for d in $(grep '^dynamic-library-dirs:' "$packageConfDir"/* | cut -d' ' -f2- | tr ' ' '\n' | sort -u); do
for lib in "$d/"*.{dylib,so} ; do
if [ -f "$lib" ] ; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mmm, I see -- because there are no files matching somedir/*.dylib?

Hmm, but this bit of code has always been this way -- in fact it's only since February in 019e86f that it mentions .so at all, and before that it was only .dylib:

     for d in $(grep '^dynamic-library-dirs:' "$packageConfDir"/* | cut -d' ' -f2- | tr ' ' '\n' | sort -u); do
-      for lib in "$d/"*.dylib; do
+      for lib in "$d/"*.{dylib,so}; do
         ln -s "$lib" "$dynamicLinksDir"

This change should be a separate commit, in any event. Probably deserves some separate debugging and discussion, too. It sounds like an independent issue from the collision issue.

Comment on lines 388 to 403
for lib in "$d/"*.{dylib,so} ; do
if [ -f "$lib" ] ; then
echo "$lib"
fi
done
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking of something like:

  for lib in "$d/"*.{dylib,so} ; do
    local linkPath="$dynamicLinksDir/$(basename "$lib")"
    if [ -e "$linkPath" ]; then
      # link already exists! but maybe that's OK
      if [ ! -l "$linkPath" ] || [ "$(readlink "$linkPath")" != "$lib" ]; then
        echo >&2 "error: failed to create symbolic link $linkPath: file exists"
        exit 1
      fi
    else
      ln -s "$lib" "$linkPath"
    fi
  done

I.e., if the place where we want to create the link already exists, then check that it is already a link and already points exactly where we'd like to point it.

Comment on lines 396 to 398
for lib in $(listDynamicLinks | sort | uniq) ; do
ln -s "$lib" "$dynamicLinksDir"
done
Copy link
Contributor

@gnprice gnprice Apr 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style nit: I think the ln -s step can best be pushed inside the function. Then this is just a call, like:

    makeDynamicLinks

That just keeps the ln -s a little closer to the logic that drives it.

(Also, as is I think the sort | uniq shouldn't be needed, because of the sort -u that's inside the function.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your reviewing.
I will update it and check the test.

chkno and others added 12 commits April 3, 2020 14:23
The hackage-packages.nix change was generated by hackage2nix v2.15.1 from Hackage revision
commercialhaskell/all-cabal-hashes@ad4a70d.
haskellPackages.idris: Fix build (new GHC 8.8 & old megaparsec 7)
Test suite requires database. Disabling tests as is done for mysql backend.
haskellPackages.persistent-postgresql: don't check
This update was generated by hackage2nix v2.15.1 from Hackage revision
commercialhaskell/all-cabal-hashes@0123dd8.
This update was generated by hackage2nix v2.15.1 from Hackage revision
commercialhaskell/all-cabal-hashes@8c7fc4a.
This update was generated by hackage2nix v2.15.1 from Hackage revision
commercialhaskell/all-cabal-hashes@e07c49f.
This is the first step towards unbreaking the tensorflow packages.
This update was generated by hackage2nix v2.15.1 from Hackage revision
commercialhaskell/all-cabal-hashes@b4a552b.
@junjihashimoto
Copy link
Member Author

I left one comment above.

Also, please rebase this on the haskell-updates branch.

I rebase this on the haskell-updates branch, but conflicts happen.
Is it right?

@cdepillabout
Copy link
Member

@junjihashimoto

You'll need to change the base branch on this PR to be haskell-updates, not master.

@nh2
Copy link
Contributor

nh2 commented Apr 11, 2020

@junjihashimoto By the way, you do not need to make a new PR to change branches, you can click the Edit button here for that:

image

@nh2
Copy link
Contributor

nh2 commented Apr 11, 2020

For ticket subscribers, new PR is in #84985

@junjihashimoto
Copy link
Member Author

Thank you for letting me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet