Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: refactored platform assignment into get_platform function #29971

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 18 additions & 15 deletions test/get_previous_releases.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,25 +249,28 @@ def build_release(tag, args) -> int:
Path('src/'+f).rename('bin/'+f)
return 0

def get_platform(host):
platforms = {
'aarch64-*-linux*': 'aarch64-linux-gnu',
'powerpc64le-*-linux-*': 'powerpc64le-linux-gnu',
'riscv64-*-linux*': 'riscv64-linux-gnu',
'x86_64-*-linux*': 'x86_64-linux-gnu',
'x86_64-apple-darwin*': 'x86_64-apple-darwin',
'aarch64-apple-darwin*': 'arm64-apple-darwin',
}

for pattern, target in platforms.items():
if fnmatch(host, pattern):
return target

print(f'Not sure which binary to download for {host}')
return None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure. Now there are two functions and more lines of code, so this is harder to read and to maintain


def check_host(args) -> int:
args.host = os.environ.get('HOST', subprocess.check_output(
'./depends/config.guess').decode())
args.host = os.environ.get('HOST', subprocess.check_output('./depends/config.guess').decode())
if args.download_binary:
platforms = {
'aarch64-*-linux*': 'aarch64-linux-gnu',
'powerpc64le-*-linux-*': 'powerpc64le-linux-gnu',
'riscv64-*-linux*': 'riscv64-linux-gnu',
'x86_64-*-linux*': 'x86_64-linux-gnu',
'x86_64-apple-darwin*': 'x86_64-apple-darwin',
'aarch64-apple-darwin*': 'arm64-apple-darwin',
}
args.platform = ''
for pattern, target in platforms.items():
if fnmatch(args.host, pattern):
args.platform = target
args.platform = get_platform(args.host)
if not args.platform:
print('Not sure which binary to download for {}'.format(args.host))
return 1
return 0

Expand Down