mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 06:45:37 +08:00
build: Use argparse for CLI arguments in build script
This commit is contained in:
8
.github/workflows/build.yml
vendored
8
.github/workflows/build.yml
vendored
@@ -156,7 +156,7 @@ jobs:
|
|||||||
- name: Build swift (with symbols)
|
- name: Build swift (with symbols)
|
||||||
if: ${{ env.do_symbols == 'true' }}
|
if: ${{ env.do_symbols == 'true' }}
|
||||||
run: |
|
run: |
|
||||||
python3 -u scripts/build.py -w 64 -t gcc -c "-DVATSIM_KEY_JSON=$vatsim_key_file" --upload
|
python3 -u scripts/build.py -w 64 -t gcc -c "-DVATSIM_KEY_JSON=$vatsim_key_file" --upload-symbols
|
||||||
- name: Upload installer
|
- name: Upload installer
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
@@ -254,7 +254,7 @@ jobs:
|
|||||||
- name: Build swift (with symbols)
|
- name: Build swift (with symbols)
|
||||||
if: ${{ env.do_symbols == 'true' }}
|
if: ${{ env.do_symbols == 'true' }}
|
||||||
run: |
|
run: |
|
||||||
python -u scripts/build.py -w 64 -t msvc -c "-DVATSIM_KEY_JSON=$env:vatsim_key_file" --upload
|
python -u scripts/build.py -w 64 -t msvc -c "-DVATSIM_KEY_JSON=$env:vatsim_key_file" --upload-symbols
|
||||||
- name: Upload installer
|
- name: Upload installer
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
@@ -352,7 +352,7 @@ jobs:
|
|||||||
- name: Build swift (with symbols)
|
- name: Build swift (with symbols)
|
||||||
if: ${{ env.do_symbols == 'true' }}
|
if: ${{ env.do_symbols == 'true' }}
|
||||||
run: |
|
run: |
|
||||||
python -u scripts/build.py -w 32 -t msvc -c "-DVATSIM_KEY_JSON=$env:vatsim_key_file" --upload
|
python -u scripts/build.py -w 32 -t msvc -c "-DVATSIM_KEY_JSON=$env:vatsim_key_file" --upload-symbols
|
||||||
- name: Upload installer
|
- name: Upload installer
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
@@ -440,7 +440,7 @@ jobs:
|
|||||||
- name: Build swift (with symbols)
|
- name: Build swift (with symbols)
|
||||||
if: ${{ env.do_symbols == 'true' }}
|
if: ${{ env.do_symbols == 'true' }}
|
||||||
run: |
|
run: |
|
||||||
python3 -u scripts/build.py -w 64 -t clang -c "-DVATSIM_KEY_JSON=$vatsim_key_file" --upload
|
python3 -u scripts/build.py -w 64 -t clang -c "-DVATSIM_KEY_JSON=$vatsim_key_file" --upload-symbols
|
||||||
- name: Upload installer
|
- name: Upload installer
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
|
|||||||
@@ -3,13 +3,13 @@
|
|||||||
# SPDX-FileCopyrightText: Copyright (C) 2017 swift Project Community / Contributors
|
# SPDX-FileCopyrightText: Copyright (C) 2017 swift Project Community / Contributors
|
||||||
# SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
|
# SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
|
||||||
|
|
||||||
import getopt
|
import argparse
|
||||||
import os
|
import os
|
||||||
import os.path as path
|
import os.path as path
|
||||||
import platform
|
import platform
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
|
||||||
import datastore
|
import datastore
|
||||||
import tarfile
|
import tarfile
|
||||||
from lib.util import get_vs_env
|
from lib.util import get_vs_env
|
||||||
@@ -122,10 +122,10 @@ class Builder:
|
|||||||
os_map = {'Linux': 'linux', 'Darwin': 'macos', 'Windows': 'windows'}
|
os_map = {'Linux': 'linux', 'Darwin': 'macos', 'Windows': 'windows'}
|
||||||
extension_map = {'Linux': 'run', 'Darwin': 'dmg', 'Windows': 'exe'}
|
extension_map = {'Linux': 'run', 'Darwin': 'dmg', 'Windows': 'exe'}
|
||||||
version_segments = self.version.split('.')
|
version_segments = self.version.split('.')
|
||||||
lastSegment = version_segments.pop()
|
last_segment = version_segments.pop()
|
||||||
version_without_timestamp = '.'.join(version_segments)
|
version_without_timestamp = '.'.join(version_segments)
|
||||||
installer_name_old = '-'.join(['swiftinstaller', os_map[platform.system()], self.word_size, version_without_timestamp])
|
installer_name_old = '-'.join(['swiftinstaller', os_map[platform.system()], self.word_size, version_without_timestamp])
|
||||||
installer_name_new = '.'.join([installer_name_old, lastSegment])
|
installer_name_new = '.'.join([installer_name_old, last_segment])
|
||||||
installer_name_old = installer_name_old + '.' + extension_map[platform.system()]
|
installer_name_old = installer_name_old + '.' + extension_map[platform.system()]
|
||||||
installer_name_new = installer_name_new + '.' + extension_map[platform.system()]
|
installer_name_new = installer_name_new + '.' + extension_map[platform.system()]
|
||||||
build_path = os.path.abspath(path.join(self._get_swift_build_path(), installer_name_old))
|
build_path = os.path.abspath(path.join(self._get_swift_build_path(), installer_name_old))
|
||||||
@@ -390,48 +390,8 @@ class MacOSBuilder(Builder):
|
|||||||
Builder.__init__(self, word_size)
|
Builder.__init__(self, word_size)
|
||||||
|
|
||||||
|
|
||||||
def print_help():
|
|
||||||
supported_compilers = {'Linux': ['gcc'],
|
|
||||||
'Darwin': ['clang'],
|
|
||||||
'Windows': ['msvc']
|
|
||||||
}
|
|
||||||
compiler_help = '|'.join(supported_compilers[platform.system()])
|
|
||||||
print('build.py -w <32|64> -t <' + compiler_help + '> [-c <extra CMake argument>]')
|
|
||||||
|
|
||||||
|
|
||||||
# Entry point if called as a standalone program
|
# Entry point if called as a standalone program
|
||||||
def main(argv):
|
def main():
|
||||||
word_size = ''
|
|
||||||
tool_chain = ''
|
|
||||||
upload_symbols = False
|
|
||||||
cmake_args = []
|
|
||||||
|
|
||||||
try:
|
|
||||||
opts, args = getopt.getopt(argv, 'hw:t:uc', ['wordsize=', 'toolchain=', 'upload', 'cmake-arg='])
|
|
||||||
except getopt.GetoptError:
|
|
||||||
print_help()
|
|
||||||
sys.exit(2)
|
|
||||||
|
|
||||||
if len(opts) == 0:
|
|
||||||
print_help()
|
|
||||||
sys.exit(2)
|
|
||||||
|
|
||||||
for opt, arg in opts:
|
|
||||||
if opt == '-h':
|
|
||||||
print_help()
|
|
||||||
sys.exit()
|
|
||||||
elif opt in ('-w', '--wordsize'):
|
|
||||||
word_size = arg
|
|
||||||
elif opt in ('-t', '--toolchain'):
|
|
||||||
tool_chain = arg
|
|
||||||
elif opt in ('-u', '--upload'):
|
|
||||||
upload_symbols = True
|
|
||||||
elif opt in ('-c', '--cmake-arg'):
|
|
||||||
cmake_args += [arg]
|
|
||||||
|
|
||||||
if word_size not in ['32', '64']:
|
|
||||||
print('Unsupported word size. Choose 32 or 64')
|
|
||||||
sys.exit(2)
|
|
||||||
|
|
||||||
builders = {'Linux': {
|
builders = {'Linux': {
|
||||||
'gcc': LinuxBuilder},
|
'gcc': LinuxBuilder},
|
||||||
@@ -442,23 +402,31 @@ def main(argv):
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if tool_chain not in builders[platform.system()]:
|
supported_wordsizes = ['32', '64'] if platform.system() == 'Windows' else ['64']
|
||||||
print('Unknown or unsupported tool chain!')
|
|
||||||
sys.exit(2)
|
|
||||||
|
|
||||||
builder = builders[platform.system()][tool_chain](word_size)
|
supported_toolchains = list(builders[platform.system()].keys())
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser(prog="swift build helper")
|
||||||
|
parser.add_argument("-w", "--wordsize", choices=supported_wordsizes, required=True, help='Wordsize for the build')
|
||||||
|
parser.add_argument("-t", "--toolchain", choices=supported_toolchains, required=True, help='Toolchain for the build')
|
||||||
|
parser.add_argument("-u", "--upload-symbols", action='store_true', help='Upload the symbols')
|
||||||
|
parser.add_argument("-c", "--cmake-args", action='extend', nargs="+", type=str, help='Arguments to pass to CMake')
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
builder = builders[platform.system()][args.toolchain](args.wordsize)
|
||||||
|
|
||||||
builder.prepare()
|
builder.prepare()
|
||||||
builder.build(cmake_args)
|
builder.build(args.cmake_args)
|
||||||
builder.bundle_csl2xsb()
|
builder.bundle_csl2xsb()
|
||||||
builder.checks()
|
builder.checks()
|
||||||
builder.install()
|
builder.install()
|
||||||
builder.publish()
|
builder.publish()
|
||||||
if word_size == '64':
|
if args.wordsize == '64':
|
||||||
builder.package_xswiftbus()
|
builder.package_xswiftbus()
|
||||||
builder.symbols(upload_symbols)
|
builder.symbols(args.upload_symbols)
|
||||||
|
|
||||||
|
|
||||||
# run main if run directly
|
# run main if run directly
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main(sys.argv[1:])
|
main()
|
||||||
|
|||||||
Reference in New Issue
Block a user