Dont change dirs when packaging

This commit is contained in:
Kovid Goyal 2019-06-28 12:00:12 +05:30
parent a50bf59a2c
commit df5a73bb35
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -16,7 +16,8 @@ import sys
import sysconfig import sysconfig
import time import time
from collections import namedtuple from collections import namedtuple
from contextlib import suppress, contextmanager from contextlib import suppress
from pathlib import Path
base = os.path.dirname(os.path.abspath(__file__)) base = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, os.path.join(base, 'glfw')) sys.path.insert(0, os.path.join(base, 'glfw'))
@ -43,16 +44,6 @@ env = None
PKGCONFIG = os.environ.get('PKGCONFIG_EXE', 'pkg-config') PKGCONFIG = os.environ.get('PKGCONFIG_EXE', 'pkg-config')
@contextmanager
def current_dir(path):
cwd = os.getcwd()
try:
os.chdir(path)
yield path
finally:
os.chdir(cwd)
def emphasis(text): def emphasis(text):
if sys.stdout.isatty(): if sys.stdout.isatty():
text = '\033[32m' + text + '\033[39m' text = '\033[32m' + text + '\033[39m'
@ -703,13 +694,13 @@ Icon=kitty
Categories=System;TerminalEmulator; Categories=System;TerminalEmulator;
''' '''
) )
with current_dir(ddir): ddir = Path(ddir)
in_src_launcher = libdir_name + '/kitty/kitty/launcher/kitty' in_src_launcher = ddir / (libdir_name + '/kitty/kitty/launcher/kitty')
launcher = 'bin/kitty' launcher = ddir / 'bin/kitty'
if os.path.exists(in_src_launcher): if os.path.exists(in_src_launcher):
os.remove(in_src_launcher) os.remove(in_src_launcher)
os.makedirs(os.path.dirname(in_src_launcher), exist_ok=True) os.makedirs(os.path.dirname(in_src_launcher), exist_ok=True)
os.symlink(os.path.relpath(launcher, os.path.dirname(in_src_launcher)), in_src_launcher) os.symlink(os.path.relpath(launcher, os.path.dirname(in_src_launcher)), in_src_launcher)
def macos_info_plist(): def macos_info_plist():
@ -782,21 +773,20 @@ def create_minimal_macos_bundle(args, where):
def create_macos_bundle_gunk(ddir): def create_macos_bundle_gunk(ddir):
with current_dir(ddir): ddir = Path(ddir)
os.mkdir('Contents') os.mkdir(ddir / 'Contents')
os.chdir('Contents') with open(ddir / 'Contents/Info.plist', 'wb') as fp:
with open('Info.plist', 'wb') as fp: fp.write(macos_info_plist())
fp.write(macos_info_plist()) os.rename(ddir / 'share', ddir / 'Contents/Resources')
os.rename('../share', 'Resources') os.rename(ddir / 'bin', ddir / 'Contents/MacOS')
os.rename('../bin', 'MacOS') os.rename(ddir / 'lib', ddir / 'Contents/Frameworks')
os.rename('../lib', 'Frameworks') os.symlink('kitty', ddir / 'Contents/MacOS/kitty-deref-symlink')
os.symlink(os.path.join('MacOS', 'kitty'), os.path.join('MacOS', 'kitty-deref-symlink')) launcher = ddir / 'Contents/MacOS/kitty'
launcher = 'MacOS/kitty' in_src_launcher = ddir / 'Contents/Frameworks/kitty/kitty/launcher/kitty'
in_src_launcher = 'Frameworks/kitty/kitty/launcher/kitty' if os.path.exists(in_src_launcher):
if os.path.exists(in_src_launcher): os.remove(in_src_launcher)
os.remove(in_src_launcher) os.makedirs(os.path.dirname(in_src_launcher), exist_ok=True)
os.makedirs(os.path.dirname(in_src_launcher), exist_ok=True) os.symlink(os.path.relpath(launcher, os.path.dirname(in_src_launcher)), in_src_launcher)
os.symlink(os.path.relpath(launcher, os.path.dirname(in_src_launcher)), in_src_launcher)
create_macos_app_icon(os.path.join(ddir, 'Contents', 'Resources')) create_macos_app_icon(os.path.join(ddir, 'Contents', 'Resources'))