|
2 | 2 | import glob
|
3 | 3 | import hashlib
|
4 | 4 | import os
|
| 5 | +import platform |
5 | 6 | import re
|
6 | 7 | import subprocess
|
7 | 8 | import tarfile
|
|
13 | 14 | from setuptools.command.build_py import build_py
|
14 | 15 | from setuptools.command.develop import develop
|
15 | 16 |
|
16 |
| -P2PD_VERSION = "v0.3.16" |
| 17 | +P2PD_VERSION = "v0.3.17" |
17 | 18 |
|
18 | 19 | P2PD_SOURCE_URL = f"https://github.com/learning-at-home/go-libp2p-daemon/archive/refs/tags/{P2PD_VERSION}.tar.gz"
|
19 | 20 | P2PD_BINARY_URL = f"https://github.com/learning-at-home/go-libp2p-daemon/releases/download/{P2PD_VERSION}/"
|
20 | 21 |
|
21 | 22 | # The value is sha256 of the binary from the release page
|
22 |
| -EXECUTABLES = { |
23 |
| - "p2pd": "057ec61edbe926cf049e9532d43ea9540da55db7b2d8c816d2bbdddce23f3cdf", |
| 23 | +P2P_BINARY_HASH = { |
| 24 | + "linux": "b0dd69e80f03a6fe5546f7079242b0228e93cd88d6e58442a227ed9521a95328", |
| 25 | + "darwin": "f5cf7a86335e0264a65a6cf0fbd1033409e6f9bee65f9c4ee6c330b3cb53c3b5", |
24 | 26 | }
|
25 | 27 |
|
26 | 28 | here = os.path.abspath(os.path.dirname(__file__))
|
@@ -71,31 +73,31 @@ def build_p2p_daemon():
|
71 | 73 | with tarfile.open(dest, "r:gz") as tar:
|
72 | 74 | tar.extractall(tempdir)
|
73 | 75 |
|
74 |
| - for executable in EXECUTABLES: |
75 |
| - result = subprocess.run( |
76 |
| - ["go", "build", "-o", os.path.join(here, "hivemind", "hivemind_cli", executable)], |
77 |
| - cwd=os.path.join(tempdir, f"go-libp2p-daemon-{P2PD_VERSION.lstrip('v')}", executable), |
78 |
| - ) |
79 |
| - if result.returncode != 0: |
80 |
| - raise RuntimeError(f"Failed to build {executable}: exited with status code: {result.returncode}") |
| 76 | + result = subprocess.run( |
| 77 | + ["go", "build", "-o", os.path.join(here, "hivemind", "hivemind_cli", "p2pd")], |
| 78 | + cwd=os.path.join(tempdir, f"go-libp2p-daemon-{P2PD_VERSION.lstrip('v')}", "p2pd"), |
| 79 | + ) |
| 80 | + if result.returncode != 0: |
| 81 | + raise RuntimeError(f"Failed to build p2pd: exited with status code: {result.returncode}") |
81 | 82 |
|
82 | 83 |
|
83 | 84 | def download_p2p_daemon():
|
84 |
| - for executable, expected_hash in EXECUTABLES.items(): |
85 |
| - binary_path = os.path.join(here, "hivemind", "hivemind_cli", executable) |
| 85 | + binary_path = os.path.join(here, "hivemind", "hivemind_cli", "p2pd") |
| 86 | + os_name = platform.system().lower() |
| 87 | + expected_hash = P2P_BINARY_HASH[os_name] |
86 | 88 |
|
87 |
| - if sha256(binary_path) != expected_hash: |
88 |
| - binary_url = os.path.join(P2PD_BINARY_URL, executable) |
89 |
| - print(f"Downloading {binary_url}") |
| 89 | + if sha256(binary_path) != expected_hash: |
| 90 | + binary_url = os.path.join(P2PD_BINARY_URL, f"p2pd-{os_name}") |
| 91 | + print(f"Downloading {binary_url}") |
90 | 92 |
|
91 |
| - urllib.request.urlretrieve(binary_url, binary_path) |
92 |
| - os.chmod(binary_path, 0o777) |
| 93 | + urllib.request.urlretrieve(binary_url, binary_path) |
| 94 | + os.chmod(binary_path, 0o777) |
93 | 95 |
|
94 |
| - actual_hash = sha256(binary_path) |
95 |
| - if actual_hash != expected_hash: |
96 |
| - raise RuntimeError( |
97 |
| - f"The sha256 checksum for {executable} does not match (expected: {expected_hash}, actual: {actual_hash})" |
98 |
| - ) |
| 96 | + actual_hash = sha256(binary_path) |
| 97 | + if actual_hash != expected_hash: |
| 98 | + raise RuntimeError( |
| 99 | + f"The sha256 checksum for p2pd does not match (expected: {expected_hash}, actual: {actual_hash})" |
| 100 | + ) |
99 | 101 |
|
100 | 102 |
|
101 | 103 | class BuildPy(build_py):
|
|
0 commit comments