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

fix check_go_path when it has spaces in it #5261

Merged
merged 5 commits into from
Jul 23, 2018
Merged

fix check_go_path when it has spaces in it #5261

merged 5 commits into from
Jul 23, 2018

Conversation

Stebalien
Copy link
Member

No description provided.

fixes #5260

License: MIT
Signed-off-by: Steven Allen <[email protected]>
@Stebalien
Copy link
Member Author

So, circleci doesn't have realpath... Is that really necessary?

@magik6k
Copy link
Member

magik6k commented Jul 19, 2018

So, circleci doesn't have realpath... Is that really necessary?

Doesn't pwd always return full normalized paths? (if we want to resolve symlinks we can use pwd -P)

It doesn't exist on all operating systems.

License: MIT
Signed-off-by: Steven Allen <[email protected]>
exit 0
fi
cd "$DIR"
done <<< "$GOPATH:"
Copy link
Member

Choose a reason for hiding this comment

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

CI is unhappy about this, probably want to switch to #!/usr/bin/env bash

License: MIT
Signed-off-by: Steven Allen <[email protected]>
@djdv
Copy link
Contributor

djdv commented Jul 19, 2018

This brings back an old issue #2833
Reference: http://www.mingw.org/wiki/Posix_path_conversion

make build
bin/check_go_version 1.10
GOPATH="C:\Users\Dominic Della Valle\Projects\Go" bin/check_go_path github.com/ipfs/go-ipfs
go-ipfs must be built from within your $GOPATH directory.
expected within 'C:\Users\Dominic Della Valle\Projects\Go' but got '/c/Users/Dominic Della Valle/Projects/Go/src/github.com/ipfs/go-ipfs'
make: *** [mk/golang.mk:69: check_go_path] Error 1

go env returns a Windows native path, while pwd returns a posix path, so they can't easily be compared.

@djdv
Copy link
Contributor

djdv commented Jul 19, 2018

We can have the platform do the path conversion for us and store it. I'm not sure if there's a less hacky way to handle it.

diff --git a/bin/check_go_path b/bin/check_go_path
index 4f8c0025f..9ddc8f29d 100755
--- a/bin/check_go_path
+++ b/bin/check_go_path
@@ -6,6 +6,14 @@ PKG="$1"

 DIR="$(pwd -P)"
 GOPATH="$(go env GOPATH)"
+PLATFORM=$(uname -o)
+
+#Win <-> POSIX path conversion
+if [ "$PLATFORM" = "Msys" ] || [ "$PLATFORM" = "Cygwin" ] ; then
+    pushd "$GOPATH"
+    GOPATH="$(pwd -P)"
+    popd
+fi

 while read -d ':' p; do
     if ! cd "$p/src/$PKG" 2>/dev/null; then

@Stebalien
Copy link
Member Author

@djdv That's just a bad error message. In that while loop, it cds into each gopath directory and uses pwd -P. Hoewver, I'm guessing that the cd 'C:\Users\Dominic Della Valle\Projects\Go/src/github.com/ipfs/go-ipfs' is throwing things off. Does switching path separators like that cause problems?

@Stebalien
Copy link
Member Author

@djdv does the latest change fix it on windows?

@djdv
Copy link
Contributor

djdv commented Jul 19, 2018

@Stebalien
Negative

>make build
bin/check_go_version 1.10
GOPATH="C:\Users\Dominic Della Valle\Projects\Go" bin/check_go_path github.com/ipfs/go-ipfs
bin/check_go_path: line 11: cd: C: No such file or directory
bin/check_go_path: line 11: cd: UsersDominic Della ValleProjectsGo: No such file or directory
go-ipfs must be built from within your $GOPATH directory.
expected within 'C:\Users\Dominic Della Valle\Projects\Go' but got '/c/Users/Dominic Della Valle/Projects/Go/src/github.com/ipfs/go-ipfs'
make: *** [mk/golang.mk:69: check_go_path] Error 1

I should mention the patch I supplied, does resolve the issue for me.

@djdv
Copy link
Contributor

djdv commented Jul 19, 2018

Does switching path separators like that cause problems?

It shouldn't for things like cd, both in cmd.exe and Msys's bash. They get normalized to 1 or the other depending on the shell. cmd:\, bash:/

>cd "C:/Users\Dominic Della Valle"
>cd
C:\Users\Dominic Della Valle

>pwd
/c/Users/Dominic Della Valle

@Stebalien
Copy link
Member Author

Oh. I forgot that windows uses ; as the path separator.

@Stebalien
Copy link
Member Author

Stebalien commented Jul 19, 2018

The problem with your patch is it won't work if GOPATH has multiple entries (which it technically can). Could you try again?

@djdv
Copy link
Contributor

djdv commented Jul 19, 2018

With the latest

make build
bin/check_go_version 1.10
GOPATH="C:\Users\Dominic Della Valle\Projects\Go" bin/check_go_path github.com/ipfs/go-ipfs
go-ipfs must be built from within your $GOPATH directory.
expected within 'C:\Users\Dominic Della Valle\Projects\Go' but got '/c/Users/Dominic Della Valle/Projects/Go/src/github.com/ipfs/go-ipfs'
make: *** [mk/golang.mk:69: check_go_path] Error 1

GOPATH has multiple entries

Ahh yes.

I suppose we could do translation inside the loop, for each element in GOPATH.
The cygpath tool seems appropriate for this and comes with the base system for Cygwin and Msys.
https://cygwin.com/cygwin-ug-net/cygpath.html

i.e.
cygpath "$(go env GOPATH)" would translate C:\Users\Dominic Della Valle\Projects\Go to /c/Users/Dominic Della Valle/Projects/Go which should match when we compare with the output of pwd.
So we can just call cygpath on each path during the compare.

License: MIT
Signed-off-by: Steven Allen <[email protected]>
@Stebalien
Copy link
Member Author

I suppose we could do translation inside the loop, for each element in GOPATH.

I'm doing that by by cding into the directory in question and using pwd -P.

Try again (force pull)?

@Stebalien Stebalien assigned djdv and unassigned Stebalien Jul 20, 2018
@Stebalien
Copy link
Member Author

@djdv I'm reassigning this to you as this is turning into debug by trial end error. The only requirements are:

  1. Works with GOPATHs with multiple entries.
  2. Works on windows with or without cygwin (e.g., from git bash (?)).
  3. Works on linux.

License: MIT
Signed-off-by: Dominic Della Valle <[email protected]>
@djdv
Copy link
Contributor

djdv commented Jul 20, 2018

@Stebalien
I was a bit scatterbrained yesterday, mixing up bash and make semantics.
The issue was around \ acting as an escape character in the call to read, as well as a hardcoded :.
Does the current patch seem acceptable?

@Stebalien
Copy link
Member Author

LGTM. @djdv, can you sign off? I can't sign of on my own PR.

@Stebalien Stebalien added RFM and removed status/in-progress In progress labels Jul 20, 2018
@whyrusleeping whyrusleeping merged commit 8ae5119 into master Jul 23, 2018
@whyrusleeping whyrusleeping deleted the fix/5260 branch July 23, 2018 01:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants