Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions .github/workflows/python-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 6 additions & 0 deletions .gitpod.yml
Original file line number Diff line number Diff line change
@@ -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 .
4 changes: 4 additions & 0 deletions clang_tools/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from clang_tools.util import check_install_os


install_os = check_install_os()
36 changes: 22 additions & 14 deletions clang_tools/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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(" ", "")
Expand All @@ -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
Expand All @@ -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."""
)


Expand Down