Skip to content

Commit 9469813

Browse files
committed
Rename clang-tools binaries for Windows (#13)
* Rename clang-tools binaries for Windows * Update test * Update function variables * Add .gitpod.yml * Update install * Fix if condition
1 parent 4b49644 commit 9469813

File tree

5 files changed

+43
-17
lines changed

5 files changed

+43
-17
lines changed

.github/workflows/python-test.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,18 @@ jobs:
6060
- name: Install clang-tools of pull_request event
6161
if: github.event_name == 'pull_request'
6262
run: pip install git+https://github.com/cpp-linter/clang-tools-pip.git@${{ github.head_ref }}
63-
- name: Installation testing
63+
- name: Install clang-tools
6464
run: |
6565
clang-tools --install ${{ matrix.version }}
6666
which clang-format-${{ matrix.version }}
67-
clang-format-${{ matrix.version }} --version
6867
which clang-tidy-${{ matrix.version }}
68+
- name: Check clang-tools on Windows
69+
if: matrix.os == 'windows-latest'
70+
run: |
71+
clang-format-${{ matrix.version }}.exe --version
72+
clang-tidy-${{ matrix.version }}.exe --version
73+
- name: Check clang-tools on Unix
74+
if: matrix.os == 'ubuntu-latest' || matrix.os == 'macos-latest'
75+
run: |
76+
clang-format-${{ matrix.version }} --version
6977
clang-tidy-${{ matrix.version }} --version

.gitpod.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# This configuration file was automatically generated by Gitpod.
2+
# Please adjust to your needs (see https://www.gitpod.io/docs/config-gitpod-file)
3+
# and commit this file to your remote git repository to share the goodness with others.
4+
5+
tasks:
6+
- init: pip install -e .

clang_tools/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from clang_tools.util import check_install_os
2+
3+
4+
install_os = check_install_os()

clang_tools/install.py

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import sys
66
from posixpath import basename
77

8+
from clang_tools import install_os
89
from clang_tools.util import check_install_os
910
from clang_tools.util import download_file
1011

@@ -36,7 +37,6 @@ def clang_tidy_exist(version) -> bool:
3637

3738

3839
def clang_tools_binary_url(tool, version) -> string:
39-
install_os = check_install_os()
4040
base_url = "https://github.com/muttleyxd/clang-tools-static-binaries/releases/download/master-208096c1"
4141
if install_os == "windows":
4242
download_url = f"{base_url}/{tool}-{version}_{install_os}-amd64.exe".replace(" ", "")
@@ -48,22 +48,30 @@ def clang_tools_binary_url(tool, version) -> string:
4848
def install_clang_format(version, directory) -> None:
4949
if clang_format_exist(version):
5050
return
51-
clang_format_binary_url = clang_tools_binary_url("clang-format", version)
52-
clang_format_binary = basename(clang_format_binary_url)
53-
download_file(clang_format_binary_url, clang_format_binary)
54-
move_and_chmod_binary(clang_format_binary, f"clang-format-{version}", directory)
51+
clang_format_bin_url = clang_tools_binary_url("clang-format", version)
52+
clang_format_bin = basename(clang_format_bin_url)
53+
download_file(clang_format_bin_url, clang_format_bin)
54+
if install_os == "windows":
55+
new_clang_format_bin = f"clang-format-{version}.exe"
56+
else:
57+
new_clang_format_bin = f"clang-format-{version}"
58+
move_and_chmod_bin(clang_format_bin, new_clang_format_bin, directory)
5559

5660

5761
def install_clang_tidy(version, directory) -> None:
5862
if clang_tidy_exist(version):
5963
return
60-
clang_tidy_binary_url = clang_tools_binary_url("clang-tidy", version)
61-
clang_tidy_binary = basename(clang_tidy_binary_url)
62-
download_file(clang_tidy_binary_url, clang_tidy_binary)
63-
move_and_chmod_binary(clang_tidy_binary, f"clang-tidy-{version}", directory)
64+
clang_tidy_bin_url = clang_tools_binary_url("clang-tidy", version)
65+
clang_tidy_bin = basename(clang_tidy_bin_url)
66+
download_file(clang_tidy_bin_url, clang_tidy_bin)
67+
if install_os == "windows":
68+
new_clang_tidy_bin = f"clang-tidy-{version}.exe"
69+
else:
70+
new_clang_tidy_bin = f"clang-tidy-{version}"
71+
move_and_chmod_bin(clang_tidy_bin, new_clang_tidy_bin, directory)
6472

6573

66-
def move_and_chmod_binary(old_file_name, new_file_name, directory) -> None:
74+
def move_and_chmod_bin(old_bin_name, new_bin_name, directory) -> None:
6775
"""Move download clang-tools binary and move to bin dir with right permission."""
6876
if directory:
6977
install_dir = directory
@@ -76,12 +84,12 @@ def move_and_chmod_binary(old_file_name, new_file_name, directory) -> None:
7684
try:
7785
if not os.path.isdir(install_dir):
7886
os.makedirs(install_dir)
79-
shutil.move(old_file_name, f"{install_dir}/{new_file_name}")
80-
os.chmod(os.path.join(install_dir, new_file_name), 0o755)
87+
shutil.move(old_bin_name, f"{install_dir}/{new_bin_name}")
88+
os.chmod(os.path.join(install_dir, new_bin_name), 0o755)
8189
except PermissionError:
8290
raise SystemExit(
83-
f"Don't have permission to install {new_file_name} to {install_dir}. \
84-
Try to run with the appropriate permissions."
91+
f"""Don't have permission to install {new_bin_name} to {install_dir}.
92+
Try to run with the appropriate permissions."""
8593
)
8694

8795

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
setup(
88
name="clang_tools",
9-
version="0.2.2",
9+
version="0.2.3",
1010
description="Install clang-tools (clang-format, clang-tidy) with pip",
1111
long_description=long_description,
1212
long_description_content_type="text/markdown",

0 commit comments

Comments
 (0)