This repository has been archived by the owner on Apr 19, 2023. It is now read-only.
forked from cloudflare/go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcf-copy-from-circle.py
83 lines (67 loc) · 2.23 KB
/
cf-copy-from-circle.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# Temporary file: copies Dilithium from Cloudflare's circl library into crypto.
import os
import sys
import tempfile
import subprocess
base = os.path.dirname(os.path.abspath(sys.argv[0]))
REPO = 'https://github.com/cloudflare/circl'
BRANCH = 'master'
circl = os.path.join(base, 'src/circl')
if os.path.exists(circl):
print("Removing old circl ...")
subprocess.check_call(['rm', '-r', '-f', circl])
with tempfile.TemporaryDirectory() as d:
print(f"Cloning {REPO} branch {BRANCH} ...")
subprocess.check_call(['git', 'clone', REPO, '--branch', BRANCH],
cwd=d)
print("Copying ...")
subprocess.check_call(['cp', '-r',
os.path.join(d, 'circl'),
circl,
])
print("Removing avo sourcecode (for now) ...")
# XXX figure out a way to prevent ./src/all.sh from trying to build the
# asm folders that require avo.
subprocess.check_call(['rm', '-r',
os.path.join(circl, 'simd/keccakf1600/internal/asm'),
os.path.join(circl, 'sign/dilithium/internal/common/asm'),
os.path.join(circl, 'pke/kyber/internal/common/asm'),
])
print("Removing templates (for now) ...")
# XXX figure out a way to prevent build/deps_test.go from trying to pase
# the templates.
subprocess.check_call(['rm', '-r',
os.path.join(circl, 'sign/dilithium/templates'),
os.path.join(circl, 'sign/dilithium/gen.go'),
])
#print("Removing unused packages ...")
#subprocess.check_call(['rm', '-r', '-f',
# os.path.join(circl, 'group'),
#])
print("Removing misc cruft ...")
subprocess.check_call(['rm', '-r', '-f',
os.path.join(circl, '.git'),
os.path.join(circl, 'go.mod'),
os.path.join(circl, 'go.sum'),
os.path.join(circl, '.etc'),
os.path.join(circl, 'Makefile'),
os.path.join(circl, 'codecov.yml'),
])
print("Correcting import paths ...")
def correct(fn):
with open(fn, 'rb') as f:
s = f.read()
s = s.replace(
b'github.com/cloudflare/circl',
b'circl',
).replace(
b'golang.org/x/sys/cpu',
b'internal/cpu',
)
with open(fn, 'wb') as f:
f.write(s)
for subdir, _, files in os.walk(circl):
for fn in files:
correct(os.path.join(subdir, fn))
print("Formatting ....")
subprocess.check_call(['go', 'fmt', './...'], cwd=circl)