From 9d6208ffa456e7c56c475d597f40dab02b75328b Mon Sep 17 00:00:00 2001 From: hly1204 Date: Mon, 15 Jan 2024 19:54:10 +0800 Subject: [PATCH] make the python scripts work in msys2 environments --- README.md | 2 +- problem.py | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 57d0c37cf..35e7ca7fd 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Source code of [https://judge.yosupo.jp](https://judge.yosupo.jp). You can get t - Linux / OS X / Windows(MinGW-w64) - python3.6+ -- g++ / clang++ (Needs --std=c++14 and __int128_t) +- g++ / clang++ (Needs --std=c++17 and __int128_t) ## How to Use diff --git a/problem.py b/problem.py index 80347a003..22c4f3315 100644 --- a/problem.py +++ b/problem.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 import sys +import sysconfig import argparse import os import platform @@ -44,7 +45,11 @@ def param_to_str(key: str, value: object): def compile(src: Path, rootdir: Path, opts: [str] = []): if src.suffix == '.cpp': - cxx = getenv('CXX', 'g++') + # use clang for msys2 clang environment + if os.name == 'nt' and sysconfig.get_platform().startswith('mingw') and sysconfig.get_platform().endswith('clang'): + cxx = getenv('CXX', 'clang++') + else: + cxx = getenv('CXX', 'g++') cxxflags_default = '-O2 -std=c++17 -Wall -Wextra -Werror -Wno-unused-result' if platform.system() == 'Darwin': cxxflags_default += ' -Wl,-stack_size,{}'.format(hex(STACK_SIZE)) @@ -81,7 +86,8 @@ def execcmd(src: Path, arg: List[str] = []) -> List[str]: return cmd elif src.suffix == '.in': inpath = src.with_name(casename(src, int(arg[0])) + '.in') - if platform.system() == 'Windows': + # see https://www.msys2.org/docs/python/ for using msys2 + if platform.system() == 'Windows' and not (os.name == 'nt' and sysconfig.get_platform().startswith("mingw")): # Windows' built-in command cmd = ['cmd', '/C', 'type', str(inpath)] else: