add versioning logic to ports
This commit is contained in:
Родитель
ddcf9de592
Коммит
6db79ca041
|
@ -1,8 +1,10 @@
|
||||||
import os, shutil
|
import os, shutil
|
||||||
|
|
||||||
|
VERSION = 1
|
||||||
|
|
||||||
def get(ports, settings, shared):
|
def get(ports, settings, shared):
|
||||||
if settings.USE_SDL == 2:
|
if settings.USE_SDL == 2:
|
||||||
ports.fetch_project('sdl2', 'https://github.com/emscripten-ports/SDL2/archive/master.zip')
|
ports.fetch_project('sdl2', 'https://github.com/emscripten-ports/SDL2/archive/master.zip', VERSION)
|
||||||
def setup_includes():
|
def setup_includes():
|
||||||
# copy includes to a location so they can be used as 'SDL2/'
|
# copy includes to a location so they can be used as 'SDL2/'
|
||||||
include_path = os.path.join(shared.Cache.get_path('ports-builds'), 'sdl2', 'include')
|
include_path = os.path.join(shared.Cache.get_path('ports-builds'), 'sdl2', 'include')
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
import os, shutil
|
import os, shutil
|
||||||
|
|
||||||
|
VERSION = 1
|
||||||
|
|
||||||
def get(ports, settings, shared):
|
def get(ports, settings, shared):
|
||||||
if settings.USE_SDL_IMAGE == 2:
|
if settings.USE_SDL_IMAGE == 2:
|
||||||
sdl_build = os.path.join(ports.get_build_dir(), 'sdl2')
|
sdl_build = os.path.join(ports.get_build_dir(), 'sdl2')
|
||||||
assert os.path.exists(sdl_build), 'You must use SDL2 to use SDL2_image'
|
assert os.path.exists(sdl_build), 'You must use SDL2 to use SDL2_image'
|
||||||
ports.fetch_project('sdl2-image', 'https://github.com/emscripten-ports/SDL2_image/archive/master.zip')
|
ports.fetch_project('sdl2-image', 'https://github.com/emscripten-ports/SDL2_image/archive/master.zip', VERSION)
|
||||||
def create():
|
def create():
|
||||||
shutil.copyfile(os.path.join(ports.get_dir(), 'sdl2-image', 'SDL2_image-master', 'SDL_image.h'), os.path.join(ports.get_build_dir(), 'sdl2', 'include', 'SDL_image.h'))
|
shutil.copyfile(os.path.join(ports.get_dir(), 'sdl2-image', 'SDL2_image-master', 'SDL_image.h'), os.path.join(ports.get_build_dir(), 'sdl2', 'include', 'SDL_image.h'))
|
||||||
shutil.copyfile(os.path.join(ports.get_dir(), 'sdl2-image', 'SDL2_image-master', 'SDL_image.h'), os.path.join(ports.get_build_dir(), 'sdl2', 'include', 'SDL2', 'SDL_image.h'))
|
shutil.copyfile(os.path.join(ports.get_dir(), 'sdl2-image', 'SDL2_image-master', 'SDL_image.h'), os.path.join(ports.get_build_dir(), 'sdl2', 'include', 'SDL2', 'SDL_image.h'))
|
||||||
|
|
|
@ -604,7 +604,7 @@ class Ports:
|
||||||
name_cache = set()
|
name_cache = set()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def fetch_project(name, url):
|
def fetch_project(name, url, expected_version):
|
||||||
fullname = os.path.join(Ports.get_dir(), name)
|
fullname = os.path.join(Ports.get_dir(), name)
|
||||||
|
|
||||||
if name not in Ports.name_cache: # only mention each port once in log
|
if name not in Ports.name_cache: # only mention each port once in log
|
||||||
|
@ -612,14 +612,19 @@ class Ports:
|
||||||
logging.debug(' (at ' + fullname + ')')
|
logging.debug(' (at ' + fullname + ')')
|
||||||
Ports.name_cache.add(name)
|
Ports.name_cache.add(name)
|
||||||
|
|
||||||
if not os.path.exists(fullname + '.zip'):
|
class State:
|
||||||
|
retrieved = False
|
||||||
|
unpacked = False
|
||||||
|
|
||||||
|
def retrieve():
|
||||||
logging.warning('retrieving port: ' + name + ' from ' + url)
|
logging.warning('retrieving port: ' + name + ' from ' + url)
|
||||||
import urllib2
|
import urllib2
|
||||||
f = urllib2.urlopen(url)
|
f = urllib2.urlopen(url)
|
||||||
data = f.read()
|
data = f.read()
|
||||||
open(fullname + '.zip', 'wb').write(data)
|
open(fullname + '.zip', 'wb').write(data)
|
||||||
|
State.retrieved = True
|
||||||
|
|
||||||
if not os.path.exists(fullname):
|
def unpack():
|
||||||
logging.warning('unpacking port: ' + name)
|
logging.warning('unpacking port: ' + name)
|
||||||
import zipfile
|
import zipfile
|
||||||
shared.safe_ensure_dirs(fullname)
|
shared.safe_ensure_dirs(fullname)
|
||||||
|
@ -630,7 +635,37 @@ class Ports:
|
||||||
z.extractall()
|
z.extractall()
|
||||||
finally:
|
finally:
|
||||||
os.chdir(cwd)
|
os.chdir(cwd)
|
||||||
|
State.unpacked = True
|
||||||
|
|
||||||
|
def check_version(expected_version):
|
||||||
|
try:
|
||||||
|
ok = False
|
||||||
|
subdir = os.listdir(fullname)[0] # each port has a singleton subdir
|
||||||
|
version = open(os.path.join(fullname, subdir, 'version.txt')).read()
|
||||||
|
version = int(version)
|
||||||
|
ok = True
|
||||||
|
finally:
|
||||||
|
if not ok: logging.error('error when checking port version for ' + name)
|
||||||
|
return version >= expected_version
|
||||||
|
|
||||||
|
# main logic
|
||||||
|
|
||||||
|
if not os.path.exists(fullname + '.zip'):
|
||||||
|
retrieve()
|
||||||
|
|
||||||
|
if not os.path.exists(fullname):
|
||||||
|
unpack()
|
||||||
|
|
||||||
|
if not check_version(expected_version):
|
||||||
|
# fetch a newer version
|
||||||
|
assert not State.retrieved, 'just retrieved port ' + name + ', but not a new enough version?'
|
||||||
|
shared.try_delete(fullname)
|
||||||
|
shared.try_delete(fullname + '.zip')
|
||||||
|
retrieve()
|
||||||
|
assert check_version(expected_version), 'just retrieved replacement port ' + name + ', but not a new enough version?'
|
||||||
|
unpack()
|
||||||
|
|
||||||
|
if State.unpacked:
|
||||||
# we unpacked a new version, clear the build in the cache
|
# we unpacked a new version, clear the build in the cache
|
||||||
shared.try_delete(os.path.join(Ports.get_build_dir(), name))
|
shared.try_delete(os.path.join(Ports.get_build_dir(), name))
|
||||||
shared.try_delete(shared.Cache.get_path(name + '.bc'))
|
shared.try_delete(shared.Cache.get_path(name + '.bc'))
|
||||||
|
|
Загрузка…
Ссылка в новой задаче