Skip to content

Commit 78e0eb5

Browse files
mathstufgartung
authored andcommitted
WIP: binary_distribution: pseudocode for GPG-signed binaries
1 parent 01f3887 commit 78e0eb5

1 file changed

Lines changed: 59 additions & 31 deletions

File tree

lib/spack/spack/binary_distribution.py

Lines changed: 59 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import os
44
import platform
5+
import tarfile
56
import yaml
67

78
import llnl.util.tty as tty
@@ -109,56 +110,70 @@ def tarball_directory_name(spec):
109110
spec.name)
110111

111112

112-
def tarball_name(spec):
113+
def tarball_name(spec, ext):
113114
"""
114115
Return the name of the tarfile according to the convention
115116
<os>-<architecture>-<package>-<dag_hash>.tar.gz
116117
"""
117-
return "%s-%s-%s-%s.tar.gz" % (get_full_system_from_platform(),
118-
spec.name,
119-
spec.version,
120-
spec.dag_hash())
118+
return "%s-%s-%s-%s%s" % (get_full_system_from_platform(),
119+
spec.name,
120+
spec.version,
121+
spec.dag_hash(),
122+
ext)
121123

122124

123-
def tarball_path_name(spec):
125+
def tarball_path_name(spec, ext):
124126
"""
125127
Return the full path+name for a given spec according to the convention
126128
<tarball_directory_name>/<tarball_name>
127129
"""
128130
return os.path.join(tarball_directory_name(spec),
129-
tarball_name(spec))
131+
tarball_name(spec, ext))
130132

131133

132-
def build_tarball(spec, outdir, force=False):
134+
def build_tarball(spec, outdir, force=False, key=None):
133135
"""
134136
Build a tarball from given spec and put it into the directory structure
135137
used at the mirror (following <tarball_directory_name>).
136138
"""
137139
tarfile_dir = os.path.join(outdir, tarball_directory_name(spec))
138-
tarfile = os.path.join(outdir, tarball_path_name(spec))
139-
if os.path.exists(tarfile):
140-
if force:
141-
os.remove(tarfile)
142-
else:
143-
tty.warn("file exists, use -f to force overwrite: %s" % tarfile)
144-
return
140+
tarfile_path = os.path.join(outdir, tarball_path_name(spec, '.tar.gz'))
141+
if force:
142+
os.remove(tarfile)
143+
else:
144+
tty.warn("file exists, use -f to force overwrite: %s" % tarfile)
145+
return
145146
if not os.path.exists(tarfile_dir):
146147
mkdirp(tarfile_dir)
147148

148-
tar = which('tar', required=True)
149149
dirname = os.path.dirname(spec.prefix)
150150
basename = os.path.basename(spec.prefix)
151-
152-
# handle meta-data
153-
cp = which("cp", required=True)
154151
spec_file = os.path.join(spec.prefix, ".spack", "spec.yaml")
155-
target_spec_file = tarfile + ".yaml"
156-
cp(spec_file, target_spec_file)
157152

158153
# create info for later relocation and create tar
159-
write_buildinfo_file(spec)
160-
tar("--directory=%s" % dirname, "-czf", tarfile, basename)
161-
tty.msg(tarfile)
154+
with tarfile.open(tarfile_path, 'w:gz') as tar:
155+
write_buildinfo_file(spec)
156+
157+
tar.add(basename)
158+
159+
spec_info = tar.gettarinfo(spec_file, arcname='.spack/spec.yaml')
160+
tar.addfile(spec_info)
161+
162+
# Sign the packages.
163+
#spack gpg sign [--key key] tarfile_path
164+
#spack gpg sign [--key key] spec_file
165+
166+
spackfile_path = os.path.join(outdir, tarball_path_name(spec, '.spack'))
167+
with tarfile.open(spackfile_path, 'w') as tar:
168+
tar.add(tarfile_path)
169+
#tar.add(tarfile_path + '.asc')
170+
171+
spec_info = tar.gettarinfo(spec_file, arcname='spec.yaml')
172+
tar.addfile(spec_info)
173+
174+
#tar.add(spec_file + '.asc')
175+
176+
tty.msg(tarfile_path)
162177

163178

164179
def download_tarball(package):
@@ -170,7 +185,7 @@ def download_tarball(package):
170185
if len(mirrors) == 0:
171186
tty.die("Please add a spack mirror to allow " +
172187
"download of pre-compiled packages.")
173-
tarball = tarball_path_name(package.spec)
188+
tarball = tarball_path_name(package.spec, '.spack')
174189
for key in mirrors:
175190
url = mirrors[key] + "/" + tarball
176191
# print url
@@ -189,13 +204,26 @@ def extract_tarball(package):
189204
extract binary tarball for given package into install area
190205
"""
191206
tarball = tarball_name(package.spec)
192-
tar = which("tar")
193207
local_tarball = package.stage.path + "/" + tarball
194-
mkdirp('%s' % package.prefix)
195-
tar("--strip-components=1",
196-
"-C%s" % package.prefix,
197-
"-xf",
198-
local_tarball)
208+
mkdirp(package.prefix)
209+
tarfile_name = tarball_path_name(spec, '.tar.gz')
210+
tarfile_path = os.path.join(package.prefix, tarfile_name)
211+
with tarfile.open(local_tarball, 'r') as tar:
212+
tar.extract('spec.yaml', package.prefix)
213+
tar.extract('spec.yaml.asc', package.prefix)
214+
215+
# spack gpg verify os.path.join(package.prefix, 'spec.yaml')
216+
217+
tar.extract(tarfile_name, package.prefix)
218+
tar.extract(tarfile_name + '.asc', package.prefix)
219+
220+
# spack gpg verify tarfile_path
221+
222+
with tarfile.open(tarfile_path, 'r') as tar:
223+
tar.extractall(path=package.prefix)
224+
225+
#os.remove(tarfile_path)
226+
#os.remove(tarfile_path + '.asc')
199227

200228

201229
def relocate_package(package):

0 commit comments

Comments
 (0)