2017-07-13 11:03:27 -04:00
|
|
|
#!/usr/bin/env python3
|
2017-02-20 04:34:42 -05:00
|
|
|
|
|
|
|
import os.path
|
2017-03-05 14:57:41 -05:00
|
|
|
import re
|
2017-02-20 04:34:42 -05:00
|
|
|
import sys
|
|
|
|
|
2017-03-05 14:57:41 -05:00
|
|
|
WINDOWS = [
|
|
|
|
# --------------------- ----------------- #
|
|
|
|
# Runtime ID Platform #
|
|
|
|
# --------------------- ----------------- #
|
2017-08-15 10:27:54 -04:00
|
|
|
( 'win-x64', 'x64' ),
|
|
|
|
( 'win-x86', 'Win32' ),
|
2017-03-05 14:57:41 -05:00
|
|
|
# --------------------- ----------------- #
|
2017-02-20 04:34:42 -05:00
|
|
|
]
|
|
|
|
|
2017-03-05 14:57:41 -05:00
|
|
|
MACOS = [
|
|
|
|
# --------------------- ----------------- #
|
|
|
|
# Runtime ID Codename #
|
|
|
|
# --------------------- ----------------- #
|
2017-08-15 10:27:54 -04:00
|
|
|
( 'osx-x64', 'sierra' ),
|
2017-03-05 14:57:41 -05:00
|
|
|
# --------------------- ----------------- #
|
|
|
|
]
|
|
|
|
|
|
|
|
LINUX = [
|
2017-07-11 19:30:23 -04:00
|
|
|
# --------------------- ----------------- #
|
|
|
|
# Runtime ID Docker Image #
|
|
|
|
# --------------------- ----------------- #
|
2017-08-13 13:06:10 -04:00
|
|
|
( 'linux-x64', 'debian:stretch' ),
|
2017-07-11 19:30:23 -04:00
|
|
|
# --------------------- ----------------- #
|
2017-03-05 14:57:41 -05:00
|
|
|
]
|
2017-02-20 04:34:42 -05:00
|
|
|
|
2017-03-05 14:57:41 -05:00
|
|
|
EXTRAS = [ 'LICENSE', 'AUTHORS', 'ChangeLog' ]
|
2017-02-20 04:34:42 -05:00
|
|
|
|
2017-03-05 14:57:41 -05:00
|
|
|
PROPSFILE = 'libsodium.props'
|
|
|
|
MAKEFILE = 'Makefile'
|
|
|
|
BUILDDIR = 'build'
|
2017-02-20 04:34:42 -05:00
|
|
|
CACHEDIR = 'cache'
|
2017-03-05 14:57:41 -05:00
|
|
|
TEMPDIR = 'temp'
|
|
|
|
|
|
|
|
PACKAGE = 'libsodium'
|
|
|
|
LIBRARY = 'libsodium'
|
|
|
|
|
|
|
|
DOCKER = 'sudo docker'
|
|
|
|
|
|
|
|
class Version:
|
|
|
|
|
2017-07-11 19:30:23 -04:00
|
|
|
def __init__(self, libsodium_version, package_version):
|
|
|
|
self.libsodium_version = libsodium_version
|
|
|
|
self.package_version = package_version
|
2017-03-05 14:57:41 -05:00
|
|
|
|
2017-07-11 19:30:23 -04:00
|
|
|
self.builddir = os.path.join(BUILDDIR, libsodium_version)
|
|
|
|
self.tempdir = os.path.join(TEMPDIR, libsodium_version)
|
|
|
|
self.projfile = os.path.join(self.builddir, '{0}.{1}.pkgproj'.format(PACKAGE, package_version))
|
2017-03-05 14:57:41 -05:00
|
|
|
self.propsfile = os.path.join(self.builddir, '{0}.props'.format(PACKAGE))
|
2017-07-11 19:30:23 -04:00
|
|
|
self.pkgfile = os.path.join(BUILDDIR, '{0}.{1}.nupkg'.format(PACKAGE, package_version))
|
2017-03-05 14:57:41 -05:00
|
|
|
|
|
|
|
class WindowsItem:
|
|
|
|
|
|
|
|
def __init__(self, version, rid, platform):
|
2017-07-11 19:30:23 -04:00
|
|
|
self.url = 'https://download.libsodium.org/libsodium/releases/libsodium-{0}-msvc.zip'.format(version.libsodium_version)
|
2017-03-05 14:57:41 -05:00
|
|
|
self.cachefile = os.path.join(CACHEDIR, re.sub(r'[^A-Za-z0-9.]', '-', self.url))
|
|
|
|
self.packfile = os.path.join(version.builddir, 'runtimes', rid, 'native', LIBRARY + '.dll')
|
|
|
|
self.itemfile = '{0}/Release/v140/dynamic/libsodium.dll'.format(platform)
|
|
|
|
self.tempdir = os.path.join(version.tempdir, rid)
|
|
|
|
self.tempfile = os.path.join(self.tempdir, os.path.normpath(self.itemfile))
|
|
|
|
|
|
|
|
def make(self, f):
|
2017-02-20 04:34:42 -05:00
|
|
|
f.write('\n')
|
2017-03-05 14:57:41 -05:00
|
|
|
f.write('{0}: {1}\n'.format(self.packfile, self.tempfile))
|
|
|
|
f.write('\t@mkdir -p $(dir $@)\n')
|
|
|
|
f.write('\tcp -f $< $@\n')
|
|
|
|
f.write('\n')
|
|
|
|
f.write('{0}: {1}\n'.format(self.tempfile, self.cachefile))
|
|
|
|
f.write('\t@mkdir -p $(dir $@)\n')
|
|
|
|
f.write('\tcd {0} && unzip -q -DD -o {1} \'{2}\'\n'.format(
|
|
|
|
self.tempdir,
|
|
|
|
os.path.relpath(self.cachefile, self.tempdir),
|
|
|
|
self.itemfile
|
|
|
|
))
|
|
|
|
|
|
|
|
class MacOSItem:
|
|
|
|
|
|
|
|
def __init__(self, version, rid, codename):
|
2017-07-11 19:30:23 -04:00
|
|
|
self.url = 'https://bintray.com/homebrew/bottles/download_file?file_path=libsodium-{0}.{1}.bottle.tar.gz'.format(version.libsodium_version, codename)
|
2017-03-05 14:57:41 -05:00
|
|
|
self.cachefile = os.path.join(CACHEDIR, re.sub(r'[^A-Za-z0-9.]', '-', self.url))
|
|
|
|
self.packfile = os.path.join(version.builddir, 'runtimes', rid, 'native', LIBRARY + '.dylib')
|
2017-07-11 19:30:23 -04:00
|
|
|
self.itemfile = 'libsodium/{0}/lib/libsodium.dylib'.format(version.libsodium_version)
|
2017-03-05 14:57:41 -05:00
|
|
|
self.tempdir = os.path.join(version.tempdir, rid)
|
|
|
|
self.tempfile = os.path.join(self.tempdir, os.path.normpath(self.itemfile))
|
|
|
|
|
|
|
|
def make(self, f):
|
|
|
|
f.write('\n')
|
|
|
|
f.write('{0}: {1}\n'.format(self.packfile, self.tempfile))
|
|
|
|
f.write('\t@mkdir -p $(dir $@)\n')
|
|
|
|
f.write('\tcp -f $< $@\n')
|
|
|
|
f.write('\n')
|
|
|
|
f.write('{0}: {1}\n'.format(self.tempfile, self.cachefile))
|
|
|
|
f.write('\t@mkdir -p $(dir $@)\n')
|
|
|
|
f.write('\tcd {0} && tar xzmf {1} \'{2}\'\n'.format(
|
|
|
|
self.tempdir,
|
|
|
|
os.path.relpath(self.cachefile, self.tempdir),
|
|
|
|
os.path.dirname(self.itemfile)
|
|
|
|
))
|
|
|
|
|
|
|
|
class LinuxItem:
|
|
|
|
|
|
|
|
def __init__(self, version, rid, docker_image):
|
2017-07-11 19:30:23 -04:00
|
|
|
self.url = 'https://download.libsodium.org/libsodium/releases/libsodium-{0}.tar.gz'.format(version.libsodium_version)
|
2017-03-05 14:57:41 -05:00
|
|
|
self.cachefile = os.path.join(CACHEDIR, re.sub(r'[^A-Za-z0-9.]', '-', self.url))
|
|
|
|
self.packfile = os.path.join(version.builddir, 'runtimes', rid, 'native', LIBRARY + '.so')
|
2017-07-11 19:30:23 -04:00
|
|
|
self.tempdir = os.path.join(version.tempdir, rid)
|
|
|
|
self.tempfile = os.path.join(self.tempdir, 'libsodium.so')
|
2017-03-05 14:57:41 -05:00
|
|
|
self.docker_image = docker_image
|
|
|
|
self.recipe = rid
|
|
|
|
|
|
|
|
def make(self, f):
|
|
|
|
recipe = self.recipe
|
|
|
|
while not os.path.exists(os.path.join('recipes', recipe)):
|
|
|
|
m = re.fullmatch(r'([^.-]+)((([.][^.-]+)*)[.][^.-]+)?([-].*)?', recipe)
|
|
|
|
if m.group(5) is None:
|
|
|
|
recipe = 'build'
|
|
|
|
break
|
|
|
|
elif m.group(2) is None:
|
|
|
|
recipe = m.group(1)
|
|
|
|
else:
|
|
|
|
recipe = m.group(1) + m.group(3) + m.group(5)
|
|
|
|
|
|
|
|
f.write('\n')
|
2017-07-11 19:30:23 -04:00
|
|
|
f.write('{0}: {1}\n'.format(self.packfile, self.tempfile))
|
|
|
|
f.write('\t@mkdir -p $(dir $@)\n')
|
|
|
|
f.write('\tcp -f $< $@\n')
|
|
|
|
f.write('\n')
|
|
|
|
f.write('{0}: {1}\n'.format(self.tempfile, self.cachefile))
|
2017-03-05 14:57:41 -05:00
|
|
|
f.write('\t@mkdir -p $(dir $@)\n')
|
|
|
|
f.write('\t{0} run --rm '.format(DOCKER) +
|
|
|
|
'-v $(abspath recipes):/io/recipes ' +
|
|
|
|
'-v $(abspath $<):/io/libsodium.tar.gz ' +
|
|
|
|
'-v $(abspath $(dir $@)):/io/output ' +
|
|
|
|
'{0} sh -x -e /io/recipes/{1}\n'.format(self.docker_image, recipe))
|
|
|
|
|
|
|
|
class ExtraItem:
|
|
|
|
|
|
|
|
def __init__(self, version, filename):
|
2017-07-11 19:30:23 -04:00
|
|
|
self.url = 'https://download.libsodium.org/libsodium/releases/libsodium-{0}.tar.gz'.format(version.libsodium_version)
|
2017-03-05 14:57:41 -05:00
|
|
|
self.cachefile = os.path.join(CACHEDIR, re.sub(r'[^A-Za-z0-9.]', '-', self.url))
|
|
|
|
self.packfile = os.path.join(version.builddir, filename)
|
2017-07-11 19:30:23 -04:00
|
|
|
self.itemfile = 'libsodium-{0}/{1}'.format(version.libsodium_version, filename)
|
|
|
|
self.tempdir = os.path.join(version.tempdir, 'extras')
|
2017-03-05 14:57:41 -05:00
|
|
|
self.tempfile = os.path.join(self.tempdir, os.path.normpath(self.itemfile))
|
|
|
|
|
|
|
|
def make(self, f):
|
|
|
|
f.write('\n')
|
|
|
|
f.write('{0}: {1}\n'.format(self.packfile, self.tempfile))
|
|
|
|
f.write('\t@mkdir -p $(dir $@)\n')
|
|
|
|
f.write('\tcp -f $< $@\n')
|
|
|
|
f.write('\n')
|
|
|
|
f.write('{0}: {1}\n'.format(self.tempfile, self.cachefile))
|
|
|
|
f.write('\t@mkdir -p $(dir $@)\n')
|
|
|
|
f.write('\tcd {0} && tar xzmf {1} \'{2}\'\n'.format(
|
|
|
|
self.tempdir,
|
|
|
|
os.path.relpath(self.cachefile, self.tempdir),
|
|
|
|
self.itemfile
|
|
|
|
))
|
2017-02-20 04:34:42 -05:00
|
|
|
|
|
|
|
def main(args):
|
2017-07-11 19:30:23 -04:00
|
|
|
m = re.fullmatch(r'((\d+\.\d+\.\d+)(\.\d+)?)(?:-(\w+(?:[_.-]\w+)*))?', args[1]) if len(args) == 2 else None
|
2017-03-05 14:57:41 -05:00
|
|
|
|
|
|
|
if m is None:
|
|
|
|
print('Usage:')
|
2017-07-11 19:30:23 -04:00
|
|
|
print(' python3 prepare.py <version>')
|
2017-03-05 14:57:41 -05:00
|
|
|
print()
|
|
|
|
print('Examples:')
|
2017-07-24 08:13:18 -04:00
|
|
|
print(' python3 prepare.py 1.0.14-preview-01')
|
|
|
|
print(' python3 prepare.py 1.0.14-preview-02')
|
|
|
|
print(' python3 prepare.py 1.0.14-preview-03')
|
|
|
|
print(' python3 prepare.py 1.0.14')
|
|
|
|
print(' python3 prepare.py 1.0.14.1-preview-01')
|
|
|
|
print(' python3 prepare.py 1.0.14.1')
|
|
|
|
print(' python3 prepare.py 1.0.14.2')
|
2017-03-05 14:57:41 -05:00
|
|
|
return 1
|
2017-02-20 04:34:42 -05:00
|
|
|
|
2017-07-11 19:30:23 -04:00
|
|
|
version = Version(m.group(2), m.group(0))
|
2017-02-20 04:34:42 -05:00
|
|
|
|
2017-03-05 14:57:41 -05:00
|
|
|
items = [ WindowsItem(version, rid, platform) for (rid, platform) in WINDOWS ] + \
|
|
|
|
[ MacOSItem(version, rid, codename) for (rid, codename) in MACOS ] + \
|
|
|
|
[ LinuxItem(version, rid, docker_image) for (rid, docker_image) in LINUX ] + \
|
|
|
|
[ ExtraItem(version, filename) for filename in EXTRAS ]
|
2017-02-20 04:34:42 -05:00
|
|
|
|
2017-03-05 14:57:41 -05:00
|
|
|
downloads = {item.cachefile: item.url for item in items}
|
2017-02-20 04:34:42 -05:00
|
|
|
|
2017-03-05 14:57:41 -05:00
|
|
|
with open(MAKEFILE, 'w') as f:
|
|
|
|
f.write('all: {0}\n'.format(version.pkgfile))
|
2017-02-20 04:34:42 -05:00
|
|
|
|
2017-03-05 14:57:41 -05:00
|
|
|
for download in sorted(downloads):
|
|
|
|
f.write('\n')
|
|
|
|
f.write('{0}:\n'.format(download))
|
|
|
|
f.write('\t@mkdir -p $(dir $@)\n')
|
|
|
|
f.write('\tcurl -f#Lo $@ \'{0}\'\n'.format(downloads[download]))
|
2017-02-20 04:34:42 -05:00
|
|
|
|
2017-03-05 14:57:41 -05:00
|
|
|
for item in items:
|
|
|
|
item.make(f)
|
|
|
|
|
|
|
|
f.write('\n')
|
|
|
|
f.write('{0}: {1}\n'.format(version.propsfile, PROPSFILE))
|
|
|
|
f.write('\t@mkdir -p $(dir $@)\n')
|
|
|
|
f.write('\tcp -f $< $@\n')
|
|
|
|
|
|
|
|
f.write('\n')
|
|
|
|
f.write('{0}: {1}\n'.format(version.projfile, version.propsfile))
|
|
|
|
f.write('\t@mkdir -p $(dir $@)\n')
|
|
|
|
f.write('\techo \'' +
|
|
|
|
'<Project Sdk="Microsoft.NET.Sdk">' +
|
|
|
|
'<Import Project="{0}" />'.format(os.path.relpath(version.propsfile, os.path.dirname(version.projfile))) +
|
|
|
|
'<PropertyGroup>' +
|
2017-07-11 19:30:23 -04:00
|
|
|
'<Version>{0}</Version>'.format(version.package_version) +
|
2017-03-05 14:57:41 -05:00
|
|
|
'</PropertyGroup>' +
|
|
|
|
'</Project>\' > $@\n')
|
|
|
|
|
|
|
|
f.write('\n')
|
|
|
|
f.write('{0}:'.format(version.pkgfile))
|
|
|
|
f.write(' \\\n\t\t{0}'.format(version.projfile))
|
|
|
|
f.write(' \\\n\t\t{0}'.format(version.propsfile))
|
|
|
|
for item in items:
|
|
|
|
f.write(' \\\n\t\t{0}'.format(item.packfile))
|
|
|
|
f.write('\n')
|
|
|
|
f.write('\t@mkdir -p $(dir $@)\n')
|
|
|
|
f.write('\t{0} run --rm '.format(DOCKER) +
|
|
|
|
'-v $(abspath recipes):/io/recipes ' +
|
|
|
|
'-v $(abspath $(dir $<)):/io/input ' +
|
|
|
|
'-v $(abspath $(dir $@)):/io/output ' +
|
2017-08-15 10:27:54 -04:00
|
|
|
'{0} sh -x -e /io/recipes/{1} {2}\n'.format('microsoft/dotnet:2.0-sdk', 'pack', os.path.relpath(version.projfile, version.builddir)))
|
2017-07-11 19:30:23 -04:00
|
|
|
|
|
|
|
f.write('\n')
|
|
|
|
f.write('test: {0}\n'.format(version.pkgfile))
|
|
|
|
f.write('\t{0} run --rm '.format(DOCKER) +
|
|
|
|
'-v $(abspath recipes):/io/recipes ' +
|
|
|
|
'-v $(abspath $(dir $<)):/io/packages ' +
|
2017-08-15 10:27:54 -04:00
|
|
|
'{0} sh -x -e /io/recipes/{1} "{2}"\n'.format('microsoft/dotnet:2.0-sdk', 'test', version.package_version))
|
2017-02-20 04:34:42 -05:00
|
|
|
|
2017-07-11 19:30:23 -04:00
|
|
|
print('prepared', MAKEFILE, 'to make', version.pkgfile, 'for libsodium', version.libsodium_version)
|
2017-03-05 14:57:41 -05:00
|
|
|
return 0
|
2017-02-20 04:34:42 -05:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2017-03-05 14:57:41 -05:00
|
|
|
sys.exit(main(sys.argv))
|