Don't fail to package when run twice

Guards against exit when the default nuget source is already installed, or when wix is installed but not the wix ui toolset.
This commit is contained in:
Elliot 2024-09-22 12:51:31 -04:00 committed by Jussi Pakkanen
parent b7ce7c2d39
commit 83b2968118
1 changed files with 34 additions and 10 deletions

View File

@ -20,6 +20,8 @@ from mesonbuild import coredata
# Elementtree does not support CDATA. So hack it. # Elementtree does not support CDATA. So hack it.
WINVER_CHECK = 'Installed OR (VersionNT64 > 602)>' WINVER_CHECK = 'Installed OR (VersionNT64 > 602)>'
NUGET_INDEX = 'https://api.nuget.org/v3/index.json'
WIXEXT_TOOL = 'WixToolset.UI.wixext'
def gen_guid(): def gen_guid():
''' '''
@ -302,28 +304,50 @@ class PackageGenerator:
]) ])
def is_nuget_source_active():
'''
Check if nuget source is active
'''
result = subprocess.run(['dotnet', 'nuget', 'list', 'source', '--format', 'Short'], stdout=subprocess.PIPE)
return f'E {NUGET_INDEX}' in result.stdout.decode('utf-8')
def is_wixext_installed():
'''
Check if wix extension is installed
'''
result = subprocess.run(['wix', 'extension', 'list'], stdout=subprocess.PIPE)
return WIXEXT_TOOL in result.stdout.decode('utf-8')
def install_wix(): def install_wix():
subprocess.check_call(['dotnet', # Check if nuget source is active before trying to add it
'nuget', # dotnet nuget add source returns non-zero if the source already exists
'add', if not is_nuget_source_active():
'source', subprocess.check_call(['dotnet',
'https://api.nuget.org/v3/index.json']) 'nuget',
'add',
'source',
NUGET_INDEX])
subprocess.check_call(['dotnet', subprocess.check_call(['dotnet',
'tool', 'tool',
'install', 'install',
'--global', '--global',
'wix']) 'wix'])
subprocess.check_call(['wix',
'extension',
'add',
'WixToolset.UI.wixext',
])
if __name__ == '__main__': if __name__ == '__main__':
if not os.path.exists('meson.py'): if not os.path.exists('meson.py'):
sys.exit(print('Run me in the top level source dir.')) sys.exit(print('Run me in the top level source dir.'))
if not shutil.which('wix'): if not shutil.which('wix'):
install_wix() install_wix()
# Install wixext if not installed
if not is_wixext_installed():
subprocess.check_call(['wix',
'extension',
'add',
WIXEXT_TOOL,
])
subprocess.check_call(['pip', 'install', '--upgrade', 'pyinstaller']) subprocess.check_call(['pip', 'install', '--upgrade', 'pyinstaller'])
p = PackageGenerator() p = PackageGenerator()