Skip to content

Commit 1a6f8c6

Browse files
committed
Merge pull request #2584 from ipfs/fix/build-process
add a dist_get script for getting bins from dist.ipfs.io
2 parents 2c8fdab + db5d730 commit 1a6f8c6

File tree

4 files changed

+171
-11
lines changed

4 files changed

+171
-11
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ env:
1414
- TEST_NO_FUSE=1 TEST_VERBOSE=1 TEST_SUITE=test_sharness_expensive
1515

1616
install:
17-
- make toolkit_upgrade
1817
- make install
1918

2019
script:

Makefile

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ else
99
go_test=go test
1010
endif
1111

12+
13+
gx_bin=bin/gx-v0.7.0
14+
gx-go_bin=bin/gx-go-v1.2.0
15+
16+
# use things in our bin before any other system binaries
17+
export PATH := bin:$(PATH)
1218
export IPFS_API ?= v04x.ipfs.io
1319

1420
all: help
@@ -21,21 +27,25 @@ toolkit_upgrade: gx_upgrade gxgo_upgrade
2127
go_check:
2228
@bin/check_go_version $(IPFS_MIN_GO_VERSION)
2329

24-
gx_upgrade:
25-
go get -u github.com/whyrusleeping/gx
30+
bin/gx-v%:
31+
@echo "installing gx $(@:bin/gx-%=%)"
32+
@bin/dist_get gx $@ $(@:bin/gx-%=%)
33+
rm -f bin/gx
34+
ln -s $(@:bin/%=%) bin/gx
2635

27-
gxgo_upgrade:
28-
go get -u github.com/whyrusleeping/gx-go
36+
bin/gx-go-v%:
37+
@echo "installing gx-go $(@:bin/gx-go-%=%)"
38+
@bin/dist_get gx-go $@ $(@:bin/gx-go-%=%)
39+
rm -f bin/gx-go
40+
ln -s $(@:bin/%=%) bin/gx-go
41+
42+
gx_check: ${gx_bin} ${gx-go_bin}
2943

3044
path_check:
3145
@bin/check_go_path $(realpath $(shell pwd)) $(realpath $(GOPATH)/src/github.com/ipfs/go-ipfs)
3246

33-
gx_check:
34-
@bin/check_gx_program "gx" $(IPFS_MIN_GX_VERSION) 'Upgrade or install gx using your package manager or run `make gx_upgrade`'
35-
@bin/check_gx_program "gx-go" $(IPFS_MIN_GX_GO_VERSION) 'Upgrade or install gx-go using your package manager or run `make gxgo_upgrade`'
36-
3747
deps: go_check gx_check path_check
38-
gx --verbose install --global
48+
${gx_bin} --verbose install --global
3949

4050
# saves/vendors third-party dependencies to Godeps/_workspace
4151
# -r flag rewrites import paths to use the vendored path
@@ -58,7 +68,7 @@ clean:
5868
uninstall:
5969
make -C cmd/ipfs uninstall
6070

61-
PHONY += all help godep toolkit_upgrade gx_upgrade gxgo_upgrade gx_check
71+
PHONY += all help godep toolkit_upgrade gx_check
6272
PHONY += go_check deps vendor install build nofuse clean uninstall
6373

6474
##############################################################

bin/dist_get

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
#!/bin/sh
2+
3+
die() {
4+
echo "$@" >&2
5+
exit 1
6+
}
7+
8+
have_binary() {
9+
type "$1" > /dev/null 2> /dev/null
10+
}
11+
12+
check_writeable() {
13+
printf "" > "$1" && rm "$1"
14+
}
15+
16+
download() {
17+
dl_url="$1"
18+
dl_output="$2"
19+
20+
test "$#" -eq "2" || die "download requires exactly two arguments, was given $@"
21+
22+
if ! check_writeable "$dl_output"; then
23+
die "download error: cannot write to $dl_output"
24+
fi
25+
26+
if have_binary wget; then
27+
printf '==> Using wget to download "%s" to "%s"\n' "$dl_url" "$dl_output"
28+
wget "$dl_url" -O "$dl_output" || return
29+
elif have_binary curl; then
30+
printf '==> Using curl to download "%s" to "%s"\n' "$dl_url" "$dl_output"
31+
curl --silent "$dl_url" > "$dl_output" || return
32+
elif have_binary fetch; then
33+
printf '==> Using fetch to download "%s" to "%s"\n' "$dl_url" "$dl_output"
34+
fetch "$dl_url" -o "$dl_output" || return
35+
else
36+
die "no binary found to download $dl_url. exiting."
37+
fi
38+
echo "==> download complete!"
39+
}
40+
41+
unarchive() {
42+
ua_archivetype="$1"
43+
ua_infile="$2"
44+
ua_outfile="$3"
45+
ua_distname="$4"
46+
47+
if ! check_writeable "$ua_outfile"; then
48+
die "unarchive error: cannot write to $ua_outfile"
49+
fi
50+
51+
case "$ua_archivetype" in
52+
tar.gz)
53+
if have_binary tar; then
54+
echo "==> using 'tar' to extract binary from archive"
55+
cat "$ua_infile" | tar -O -z -x "$ua_distname/$ua_distname" > "$ua_outfile"
56+
else
57+
die "no binary on system for extracting tar files"
58+
fi
59+
;;
60+
zip)
61+
if have_binary unzip; then
62+
echo "==> using 'unzip' to extract binary from archive"
63+
unzip -p "$ua_infile" "$ua_distname/$ua_distname" > "$ua_outfile"
64+
else
65+
die "no installed method for extracting .zip archives"
66+
fi
67+
;;
68+
*)
69+
die "unrecognized archive type '$ua_archivetype'"
70+
esac
71+
72+
chmod +x "$ua_outfile"
73+
}
74+
75+
get_go_vars() {
76+
if [ ! -z "$GOOS" ] && [ ! -z "$GOARCH" ]; then
77+
printf "%s-%s" "$GOOS" "$GOARCH"
78+
fi
79+
80+
if have_binary go; then
81+
printf "%s-%s" "$(go env GOOS)" "$(go env GOARCH)"
82+
else
83+
die "no way of determining system GOOS and GOARCH\nPlease manually set GOOS and GOARCH then retry."
84+
fi
85+
}
86+
87+
mkurl() {
88+
m_name="$1"
89+
m_vers="$2"
90+
m_archive="$3"
91+
m_govars=$(get_go_vars) || die "could not get go env vars"
92+
93+
echo "http://dist.ipfs.io/$m_name/$m_vers/${m_name}_${m_vers}_$m_govars.$m_archive"
94+
}
95+
96+
distname="$1"
97+
outpath="$2"
98+
version="$3"
99+
100+
if [ -z "$distname" ] || [ -z "$outpath" ] || [ -z "$version" ]; then
101+
die "usage: dist_get <distname> <outpath> <version>"
102+
fi
103+
104+
case $version in
105+
v*)
106+
# correct input
107+
;;
108+
*)
109+
echo "invalid version '$version'" >&2
110+
die "versions must begin with 'v', for example: v0.4.0"
111+
;;
112+
esac
113+
114+
# TODO: don't depend on the go tool being installed to detect this
115+
goenv=$(get_go_vars) || die "could not get go env vars"
116+
117+
case $goenv in
118+
linux-*)
119+
archive="tar.gz"
120+
;;
121+
darwin-*)
122+
archive="tar.gz"
123+
;;
124+
windows-*)
125+
archive="zip"
126+
;;
127+
freebsd-*)
128+
archive="tar.gz"
129+
;;
130+
*)
131+
echo "unrecognized system environment: $goenv" >&2
132+
die "currently only linux, darwin, windows and freebsd are supported by this script"
133+
esac
134+
135+
136+
mkdir -p bin/tmp
137+
138+
url=$(mkurl "$distname" "$version" "$archive")
139+
tmpfi="bin/tmp/$distname.$archive"
140+
141+
download "$url" "$tmpfi"
142+
if [ $? -ne 0 ]; then
143+
die "failed to download $url to $tmpfi"
144+
fi
145+
146+
unarchive "$archive" "$tmpfi" "$outpath" "$distname"
147+
if [ $? -ne 0 ]; then
148+
die "failed to extract archive $tmpfi"
149+
fi

test/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ GOSLEEP_SRC = ./dependencies/go-sleep
99

1010
GX_RELATIVE_PATH = ../../../../gx/ipfs
1111

12+
export PATH := ../bin:${PATH}
13+
1214
# User might want to override those on the command line
1315
GOFLAGS =
1416

0 commit comments

Comments
 (0)