Skip to content

Commit 85bd896

Browse files
committed
run cmake-format
1 parent a5b0738 commit 85bd896

File tree

2 files changed

+36
-34
lines changed

2 files changed

+36
-34
lines changed

cmake/CPM.cmake

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -202,30 +202,26 @@ function(cpm_package_name_from_git_uri URI RESULT)
202202
endif()
203203
endfunction()
204204

205-
206-
# Find the shortest hash that can be used
207-
# eg, if origin_hash is cccb77ae9609d2768ed80dd42cec54f77b1f1455
208-
# the following files will be checked, until one is found that
209-
# is either empty (allowing us to assign origin_hash), or whose contents matches
210-
# ${origin_hash}
205+
# Find the shortest hash that can be used eg, if origin_hash is
206+
# cccb77ae9609d2768ed80dd42cec54f77b1f1455 the following files will be checked, until one is found
207+
# that is either empty (allowing us to assign origin_hash), or whose contents matches ${origin_hash}
208+
#
209+
# * .../cccb.hash
210+
# * .../cccb77ae.hash
211+
# * .../cccb77ae9609.hash
212+
# * .../cccb77ae9609d276.hash
213+
# * etc
211214
#
212-
# - .../cccb.hash
213-
# - .../cccb77ae.hash
214-
# - .../cccb77ae9609.hash
215-
# - .../cccb77ae9609d276.hash
216-
# etc
217-
# We will be able to use a shorter path with very high probability, but in the
218-
# (rare) event that the first couple characters collide, we will check
219-
# longer and longer substrings.
215+
# We will be able to use a shorter path with very high probability, but in the (rare) event that the
216+
# first couple characters collide, we will check longer and longer substrings.
220217
function(cpm_get_shortest_hash source_cache_dir origin_hash short_hash_output_var)
221218
foreach(len RANGE 4 40 4)
222219
string(SUBSTRING "${origin_hash}" 0 ${len} short_hash)
223220
set(hash_lock ${source_cache_dir}/${short_hash}.lock)
224221
set(hash_fp ${source_cache_dir}/${short_hash}.hash)
225-
# Take a lock, so we don't have a race condition with another instance
226-
# of cmake. We will release this lock when we can, however, if there
227-
# is an error, we want to ensure it gets released on it's own on exit
228-
# from the function.
222+
# Take a lock, so we don't have a race condition with another instance of cmake. We will release
223+
# this lock when we can, however, if there is an error, we want to ensure it gets released on
224+
# it's own on exit from the function.
229225
file(LOCK ${hash_lock} GUARD FUNCTION)
230226

231227
# Load the contents of .../${short_hash}.hash
@@ -244,10 +240,12 @@ function(cpm_get_shortest_hash source_cache_dir origin_hash short_hash_output_va
244240
file(LOCK ${hash_lock} RELEASE)
245241
endif()
246242
endforeach()
247-
set(${short_hash_output_var} "${short_hash}" PARENT_SCOPE)
243+
set(${short_hash_output_var}
244+
"${short_hash}"
245+
PARENT_SCOPE
246+
)
248247
endfunction()
249248

250-
251249
# Try to infer package name and version from a url
252250
function(cpm_package_name_and_ver_from_url url outName outVer)
253251
if(url MATCHES "[/\\?]([a-zA-Z0-9_\\.-]+)\\.(tar|tar\\.gz|tar\\.bz2|zip|ZIP)(\\?|/|$)")
@@ -845,17 +843,17 @@ function(CPMAddPackage)
845843
elseif(CPM_USE_NAMED_CACHE_DIRECTORIES)
846844
string(SHA1 origin_hash "${origin_parameters};NEW_CACHE_STRUCTURE_TAG")
847845
cpm_get_shortest_hash(
848-
"${CPM_SOURCE_CACHE}/${lower_case_name}" # source cache directory
849-
"${origin_hash}" # Input hash
850-
origin_hash # Computed hash
846+
"${CPM_SOURCE_CACHE}/${lower_case_name}" # source cache directory
847+
"${origin_hash}" # Input hash
848+
origin_hash # Computed hash
851849
)
852850
set(download_directory ${CPM_SOURCE_CACHE}/${lower_case_name}/${origin_hash}/${CPM_ARGS_NAME})
853851
else()
854852
string(SHA1 origin_hash "${origin_parameters}")
855853
cpm_get_shortest_hash(
856-
"${CPM_SOURCE_CACHE}/${lower_case_name}" # source cache directory
857-
"${origin_hash}" # Input hash
858-
origin_hash # Computed hash
854+
"${CPM_SOURCE_CACHE}/${lower_case_name}" # source cache directory
855+
"${origin_hash}" # Input hash
856+
origin_hash # Computed hash
859857
)
860858
set(download_directory ${CPM_SOURCE_CACHE}/${lower_case_name}/${origin_hash})
861859
endif()

test/unit/get_shortest_hash.cmake

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ include(${CPM_PATH}/CPM.cmake)
44
include(${CPM_PATH}/testing.cmake)
55

66
# Random suffix
7-
string(RANDOM LENGTH 6 ALPHABET "0123456789abcdef" tmpdir_suffix)
7+
string(
8+
RANDOM
9+
LENGTH 6
10+
ALPHABET "0123456789abcdef" tmpdir_suffix
11+
)
812

913
# Seconds since epoch
1014
string(TIMESTAMP tmpdir_base "%s" UTC)
@@ -25,13 +29,13 @@ assert_not_exists(${tmp}/cccb77ae9609.hash)
2529
assert_not_exists(${tmp}/cccb77ae9608.hash)
2630
assert_not_exists(${tmp}/cccb77be.hash)
2731

28-
# 2. The directory is empty, so it should get a 4-character hash
32+
# 1. The directory is empty, so it should get a 4-character hash
2933
cpm_get_shortest_hash(${tmp} "cccb77ae9609d2768ed80dd42cec54f77b1f1455" hash)
3034
assert_equal(${hash} "cccb")
3135
assert_contents_equal(${tmp}/cccb.hash cccb77ae9609d2768ed80dd42cec54f77b1f1455)
3236

33-
# 3. Calling the function with a new hash that differs subtly should result
34-
# in more characters being used, enough to uniquely identify the hash
37+
# 1. Calling the function with a new hash that differs subtly should result in more characters being
38+
# used, enough to uniquely identify the hash
3539

3640
cpm_get_shortest_hash(${tmp} "cccb77ae9609d2768ed80dd42cec54f77b1f1456" hash)
3741
assert_equal(${hash} "cccb77ae")
@@ -49,15 +53,15 @@ cpm_get_shortest_hash(${tmp} "cccb77be9609d2768ed80dd42cec54f77b1f1456" hash)
4953
assert_equal(${hash} "cccb77be")
5054
assert_contents_equal(${tmp}/cccb77be.hash cccb77be9609d2768ed80dd42cec54f77b1f1456)
5155

52-
# 4. The old file should still exist, and have the same content
56+
# 1. The old file should still exist, and have the same content
5357
assert_contents_equal(${tmp}/cccb.hash cccb77ae9609d2768ed80dd42cec54f77b1f1455)
5458
assert_contents_equal(${tmp}/cccb77ae.hash cccb77ae9609d2768ed80dd42cec54f77b1f1456)
5559
assert_contents_equal(${tmp}/cccb77ae9609.hash cccb77ae9609d2768ed80dd42cec54f77b1f1457)
5660
assert_contents_equal(${tmp}/cccb77ae9608.hash cccb77ae9608d2768ed80dd42cec54f77b1f1455)
5761
assert_contents_equal(${tmp}/cccb77be.hash cccb77be9609d2768ed80dd42cec54f77b1f1456)
5862

59-
# 5. Confirm idempotence: calling any of these function should produce the same hash
60-
# as before (hash lookups work correctly once the .hash files are created)
63+
# 1. Confirm idempotence: calling any of these function should produce the same hash as before (hash
64+
# lookups work correctly once the .hash files are created)
6165

6266
cpm_get_shortest_hash(${tmp} "cccb77ae9609d2768ed80dd42cec54f77b1f1455" hash)
6367
assert_equal(${hash} "cccb")
@@ -79,6 +83,6 @@ cpm_get_shortest_hash(${tmp} "cccb77be9609d2768ed80dd42cec54f77b1f1456" hash)
7983
assert_equal(${hash} "cccb77be")
8084
assert_contents_equal(${tmp}/cccb77be.hash cccb77be9609d2768ed80dd42cec54f77b1f1456)
8185

82-
# 6. Cleanup - remove the temporary directory that we created
86+
# 1. Cleanup - remove the temporary directory that we created
8387

8488
file(REMOVE_RECURSE ${tmp})

0 commit comments

Comments
 (0)