Skip to content

Commit 6e2135a

Browse files
committed
cmake: put URL in json
1 parent 4fc8d8a commit 6e2135a

File tree

13 files changed

+69
-46
lines changed

13 files changed

+69
-46
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: ci
22

33
env:
4-
cmake_version: '3.21.3'
4+
cmake_version: '3.22.1'
55
CMAKE_BUILD_TYPE: Release
66
HOMEBREW_NO_INSTALL_CLEANUP: 1
77

MANIFEST.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
include src/cmakeutils/CMAKE_VERSION src/cmakeutils/NINJA_VERSION VERSION
1+
include src/cmakeutils/versions.json

build_cmake.cmake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ if (L LESS 5) # 3.x or 3.xx
3434
string(JSON version GET ${_j} cmake ${version})
3535
endif()
3636

37-
set(host https://github.com/Kitware/CMake/releases/download/v${version}/)
37+
string(JSON host GET ${_j} cmake source)
38+
set(host ${host}v${version}/)
3839
set(stem cmake-${version})
3940
set(name ${stem}.tar.gz)
4041

build_ninja.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ set(CMAKE_TLS_VERIFY true)
1515

1616
if(NOT version)
1717
file(READ ${CMAKE_CURRENT_LIST_DIR}/src/cmakeutils/versions.json _j)
18-
string(JSON version GET ${_j} ninja)
18+
string(JSON version GET ${_j} ninja latest)
1919
endif()
2020

21-
set(host https://github.com/ninja-build/ninja/archive/)
21+
string(JSON host GET ${_j} ninja source)
2222
set(name v${version}.zip)
2323

2424
function(checkup ninja)

install_cmake.cmake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ if (L LESS 5) # 3.x or 3.xx
3232
string(JSON version GET ${_j} cmake ${version})
3333
endif()
3434

35-
set(host https://github.com/Kitware/CMake/releases/download/v${version}/)
35+
string(JSON host GET ${_j} cmake binary)
36+
set(host ${host}v${version}/)
3637

3738

3839
function(checkup exe)

install_ninja.cmake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ set(CMAKE_TLS_VERIFY true)
1515

1616
if(NOT version)
1717
file(READ ${CMAKE_CURRENT_LIST_DIR}/src/cmakeutils/versions.json _j)
18-
string(JSON version GET ${_j} ninja)
18+
string(JSON version GET ${_j} ninja latest)
1919
endif()
2020

21-
set(host https://github.com/ninja-build/ninja/releases/download/v${version}/)
22-
21+
string(JSON host GET ${_j} ninja binary)
22+
set(host ${host}v${version}/)
2323

2424
function(checkup ninja)
2525

pyproject.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,4 @@
22
requires = ["setuptools", "wheel"]
33

44
[tool.black]
5-
line-length = 132
6-
7-
[tool.pytest.ini_options]
8-
addopts = "-ra -v"
5+
line-length = 100

src/cmakeutils/cmake_compile.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@
3434
from pathlib import Path
3535

3636

37-
from .cmake_setup import default_version, file_checksum
37+
from .cmake_setup import latest_version, file_checksum
3838

3939
url_stem = "https://github.com/Kitware/CMake/releases/download"
4040

4141

4242
def main():
4343
p = argparse.ArgumentParser()
44-
p.add_argument("version", nargs="?", default=default_version())
44+
p.add_argument("version", nargs="?", default=latest_version())
4545
p.add_argument("-prefix", help="where to install CMake")
4646
p.add_argument("-workdir", help="use existing source code path")
4747
p = p.parse_args()
@@ -69,7 +69,9 @@ def main():
6969
print("\nreopen a new terminal to use CMake", p.version)
7070
else:
7171
print(f"CMake built under {src_root}")
72-
print("To install CMake, rerun using cmake_compile -prefix option set to desired install path.")
72+
print(
73+
"To install CMake, rerun using cmake_compile -prefix option set to desired install path."
74+
)
7375

7476

7577
def job_count() -> int:

src/cmakeutils/cmake_setup.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,22 @@
2121
import zipfile
2222
import tempfile
2323

24-
HEAD = "https://github.com/Kitware/CMake/releases/download/"
2524
PLATFORMS = ("amd64", "x86_64", "x64", "i86pc")
2625

2726

28-
def default_version() -> str:
29-
jd = json.load(importlib.resources.open_text("cmakeutils", "versions.json"))["cmake"]
30-
return jd[jd["latest"]]
27+
def latest_version() -> str:
28+
cjd = json.load(importlib.resources.open_text("cmakeutils", "versions.json"))["cmake"]
29+
return cjd[cjd["latest"]]
30+
31+
32+
def get_host() -> str:
33+
return json.load(importlib.resources.open_text("cmakeutils", "versions.json"))["cmake"][
34+
"binary"
35+
]
3136

3237

3338
def url_retrieve(url: str, outfile: Path):
39+
print("downloading", url)
3440
outfile = Path(outfile).expanduser().resolve()
3541
if outfile.is_dir():
3642
raise ValueError("Please specify full filepath, including filename")
@@ -114,24 +120,26 @@ def cmake_files(cmake_version: str, odir: Path) -> tuple[Path, str]:
114120

115121
ofn = f"cmake-{cmake_version}-{tail}"
116122

117-
return odir / ofn, HEAD + f"v{cmake_version}/{ofn}"
123+
return odir / ofn, f"{cmake_version}/{ofn}"
118124

119125

120126
def download_cmake(outdir: Path, get_version: str) -> Path:
121127

128+
host = get_host()
129+
122130
outdir = Path(outdir).expanduser()
123131
outdir.mkdir(parents=True, exist_ok=True)
124-
outfile, url = cmake_files(get_version, outdir)
132+
outfile, tail = cmake_files(get_version, outdir)
125133
# %% checksum
126134
hashstem = f"cmake-{get_version}-SHA-256.txt"
127-
hashurl = HEAD + f"v{get_version}/{hashstem}"
135+
hashurl = f"{host}v{get_version}/{hashstem}"
128136
hashfile = outdir / hashstem
129137

130138
if not hashfile.is_file() or hashfile.stat().st_size == 0:
131139
url_retrieve(hashurl, hashfile)
132140

133141
if not outfile.is_file() or outfile.stat().st_size < 1e6:
134-
url_retrieve(url, outfile)
142+
url_retrieve(f"{host}v{tail}", outfile)
135143

136144
if not file_checksum(outfile, hashfile, "sha256"):
137145
raise ValueError(f"{outfile} SHA256 checksum did not match {hashfile}")
@@ -141,8 +149,12 @@ def download_cmake(outdir: Path, get_version: str) -> Path:
141149

142150
def main():
143151
p = argparse.ArgumentParser()
144-
p.add_argument("version", help="request version (default latest)", nargs="?", default=default_version())
145-
p.add_argument("-o", "--outdir", help="download archive directory", default=tempfile.gettempdir())
152+
p.add_argument(
153+
"version", help="request version (default latest)", nargs="?", default=latest_version()
154+
)
155+
p.add_argument(
156+
"-o", "--outdir", help="download archive directory", default=tempfile.gettempdir()
157+
)
146158
p.add_argument("--prefix", help="Path prefix to install CMake under", default="~")
147159
P = p.parse_args()
148160

src/cmakeutils/graph.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313

1414
def main():
1515
p = argparse.ArgumentParser(description="convert .dot graph to SVG or PNG")
16-
p.add_argument("path", help="Path to CMake gfx/ directory from cmake -B build --graphviz=gfx/block.dot")
16+
p.add_argument(
17+
"path", help="Path to CMake gfx/ directory from cmake -B build --graphviz=gfx/block.dot"
18+
)
1719
p.add_argument("format", help="output format", choices=["svg", "png"], default="svg", nargs="?")
1820
P = p.parse_args()
1921

0 commit comments

Comments
 (0)