Skip to content

Commit

Permalink
Don't fail to package when run twice
Browse files Browse the repository at this point in the history
Guards against exit when the default nuget source is already installed, or when wix is installed but not the wix ui toolset.
  • Loading branch information
apache-hb authored and jpakkane committed Sep 28, 2024
1 parent b7ce7c2 commit 83b2968
Showing 1 changed file with 34 additions and 10 deletions.
44 changes: 34 additions & 10 deletions packaging/createmsi.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

# Elementtree does not support CDATA. So hack it.
WINVER_CHECK = 'Installed OR (VersionNT64 > 602)>'
NUGET_INDEX = 'https://api.nuget.org/v3/index.json'
WIXEXT_TOOL = 'WixToolset.UI.wixext'

def gen_guid():
'''
Expand Down Expand Up @@ -302,28 +304,50 @@ def build_package(self):
])


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():
subprocess.check_call(['dotnet',
'nuget',
'add',
'source',
'https://api.nuget.org/v3/index.json'])
# Check if nuget source is active before trying to add it
# dotnet nuget add source returns non-zero if the source already exists
if not is_nuget_source_active():
subprocess.check_call(['dotnet',
'nuget',
'add',
'source',
NUGET_INDEX])

subprocess.check_call(['dotnet',
'tool',
'install',
'--global',
'wix'])
subprocess.check_call(['wix',
'extension',
'add',
'WixToolset.UI.wixext',
])

if __name__ == '__main__':
if not os.path.exists('meson.py'):
sys.exit(print('Run me in the top level source dir.'))
if not shutil.which('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'])

p = PackageGenerator()
Expand Down

0 comments on commit 83b2968

Please sign in to comment.