diff --git a/.github/workflows/python-test.yml b/.github/workflows/python-test.yml index dddf9cf..69d518d 100644 --- a/.github/workflows/python-test.yml +++ b/.github/workflows/python-test.yml @@ -60,10 +60,18 @@ jobs: - name: Install clang-tools of pull_request event if: github.event_name == 'pull_request' run: pip install git+https://github.com/cpp-linter/clang-tools-pip.git@${{ github.head_ref }} - - name: Installation testing + - name: Install clang-tools run: | clang-tools --install ${{ matrix.version }} which clang-format-${{ matrix.version }} - clang-format-${{ matrix.version }} --version which clang-tidy-${{ matrix.version }} + - name: Check clang-tools on Windows + if: matrix.os == 'windows-latest' + run: | + clang-format-${{ matrix.version }}.exe --version + clang-tidy-${{ matrix.version }}.exe --version + - name: Check clang-tools on Unix + if: matrix.os == 'ubuntu-latest' || matrix.os == 'macos-latest' + run: | + clang-format-${{ matrix.version }} --version clang-tidy-${{ matrix.version }} --version diff --git a/.gitpod.yml b/.gitpod.yml new file mode 100644 index 0000000..df75fe2 --- /dev/null +++ b/.gitpod.yml @@ -0,0 +1,6 @@ +# This configuration file was automatically generated by Gitpod. +# Please adjust to your needs (see https://www.gitpod.io/docs/config-gitpod-file) +# and commit this file to your remote git repository to share the goodness with others. + +tasks: + - init: pip install -e . diff --git a/clang_tools/__init__.py b/clang_tools/__init__.py index e69de29..e0e51d1 100644 --- a/clang_tools/__init__.py +++ b/clang_tools/__init__.py @@ -0,0 +1,4 @@ +from clang_tools.util import check_install_os + + +install_os = check_install_os() diff --git a/clang_tools/install.py b/clang_tools/install.py index db29504..03d6c45 100644 --- a/clang_tools/install.py +++ b/clang_tools/install.py @@ -5,6 +5,7 @@ import sys from posixpath import basename +from clang_tools import install_os from clang_tools.util import check_install_os from clang_tools.util import download_file @@ -36,7 +37,6 @@ def clang_tidy_exist(version) -> bool: def clang_tools_binary_url(tool, version) -> string: - install_os = check_install_os() base_url = "https://github.com/muttleyxd/clang-tools-static-binaries/releases/download/master-208096c1" if install_os == "windows": download_url = f"{base_url}/{tool}-{version}_{install_os}-amd64.exe".replace(" ", "") @@ -48,22 +48,30 @@ def clang_tools_binary_url(tool, version) -> string: def install_clang_format(version, directory) -> None: if clang_format_exist(version): return - clang_format_binary_url = clang_tools_binary_url("clang-format", version) - clang_format_binary = basename(clang_format_binary_url) - download_file(clang_format_binary_url, clang_format_binary) - move_and_chmod_binary(clang_format_binary, f"clang-format-{version}", directory) + clang_format_bin_url = clang_tools_binary_url("clang-format", version) + clang_format_bin = basename(clang_format_bin_url) + download_file(clang_format_bin_url, clang_format_bin) + if install_os == "windows": + new_clang_format_bin = f"clang-format-{version}.exe" + else: + new_clang_format_bin = f"clang-format-{version}" + move_and_chmod_bin(clang_format_bin, new_clang_format_bin, directory) def install_clang_tidy(version, directory) -> None: if clang_tidy_exist(version): return - clang_tidy_binary_url = clang_tools_binary_url("clang-tidy", version) - clang_tidy_binary = basename(clang_tidy_binary_url) - download_file(clang_tidy_binary_url, clang_tidy_binary) - move_and_chmod_binary(clang_tidy_binary, f"clang-tidy-{version}", directory) + clang_tidy_bin_url = clang_tools_binary_url("clang-tidy", version) + clang_tidy_bin = basename(clang_tidy_bin_url) + download_file(clang_tidy_bin_url, clang_tidy_bin) + if install_os == "windows": + new_clang_tidy_bin = f"clang-tidy-{version}.exe" + else: + new_clang_tidy_bin = f"clang-tidy-{version}" + move_and_chmod_bin(clang_tidy_bin, new_clang_tidy_bin, directory) -def move_and_chmod_binary(old_file_name, new_file_name, directory) -> None: +def move_and_chmod_bin(old_bin_name, new_bin_name, directory) -> None: """Move download clang-tools binary and move to bin dir with right permission.""" if directory: install_dir = directory @@ -76,12 +84,12 @@ def move_and_chmod_binary(old_file_name, new_file_name, directory) -> None: try: if not os.path.isdir(install_dir): os.makedirs(install_dir) - shutil.move(old_file_name, f"{install_dir}/{new_file_name}") - os.chmod(os.path.join(install_dir, new_file_name), 0o755) + shutil.move(old_bin_name, f"{install_dir}/{new_bin_name}") + os.chmod(os.path.join(install_dir, new_bin_name), 0o755) except PermissionError: raise SystemExit( - f"Don't have permission to install {new_file_name} to {install_dir}. \ - Try to run with the appropriate permissions." + f"""Don't have permission to install {new_bin_name} to {install_dir}. + Try to run with the appropriate permissions.""" )