@@ -91,12 +91,9 @@ struct SHA1
91
91
end
92
92
end
93
93
SHA1 (s:: Union{String,SubString{String}} ) = SHA1 (hex2bytes (s))
94
+ string (hash:: SHA1 ) = bytes2hex (hash. bytes)
94
95
95
- convert (:: Type{String} , hash:: SHA1 ) = bytes2hex (convert (Vector{UInt8}, hash))
96
- convert (:: Type{Vector{UInt8}} , hash:: SHA1 ) = hash. bytes
97
-
98
- string (hash:: SHA1 ) = String (hash)
99
- show (io:: IO , hash:: SHA1 ) = print (io, " SHA1(" , convert (String, hash), " )" )
96
+ show (io:: IO , hash:: SHA1 ) = print (io, " SHA1(" , string (hash), " )" )
100
97
isless (a:: SHA1 , b:: SHA1 ) = lexless (a. bytes, b. bytes)
101
98
hash (a:: SHA1 , h:: UInt ) = hash ((SHA1, a. bytes), h)
102
99
== (a:: SHA1 , b:: SHA1 ) = a. bytes == b. bytes
@@ -123,36 +120,28 @@ dummy_uuid(project_file::String) = isfile_casesensitive(project_file) ?
123
120
124
121
# # package path slugs: turning UUID + SHA1 into a pair of 4-byte "slugs" ##
125
122
126
- const SlugInt = UInt32 # max p = 4
127
- const chars = String ([' A' :' Z' ; ' a' :' z' ; ' 0' :' 9' ])
128
- const nchars = SlugInt (length (chars))
129
- const max_p = floor (Int, log (nchars, typemax (SlugInt) >>> 8 ))
123
+ const slug_chars = String ([' A' :' Z' ; ' a' :' z' ; ' 0' :' 9' ])
130
124
131
- function slug (x:: SlugInt , p:: Int )
132
- 1 ≤ p ≤ max_p || # otherwise previous steps are wrong
133
- error (" invalid slug size: $p (need 1 ≤ p ≤ $max_p )" )
134
- return sprint () do io
125
+ function slug (x:: UInt32 , p:: Int )
126
+ sprint (sizehint= p) do io
127
+ n = length (slug_chars)
135
128
for i = 1 : p
136
- x, d = divrem (x, nchars )
137
- write (io, chars [1 + d])
129
+ x, d = divrem (x, n )
130
+ write (io, slug_chars [1 + d])
138
131
end
139
132
end
140
133
end
141
- slug (x:: Integer , p:: Int ) = slug (SlugInt (x), p)
142
134
143
- function slug (bytes:: Vector{UInt8} , p:: Int )
144
- n = nchars^ p
145
- x = zero (SlugInt)
146
- for (i, b) in enumerate (bytes)
147
- x = (x + b* powermod (2 , 8 (i- 1 ), n)) % n
148
- end
149
- slug (x, p)
135
+ function package_slug (uuid:: UUID , p:: Int = 4 )
136
+ crc = _crc32c (uuid)
137
+ return slug (crc, p)
150
138
end
151
139
152
- slug (uuid:: UUID , p:: Int = 4 ) = slug (uuid. value % nchars^ p, p)
153
- slug (sha1:: SHA1 , p:: Int = 4 ) = slug (sha1. bytes, p)
154
-
155
- version_slug (uuid:: UUID , sha1:: SHA1 ) = joinpath (slug (uuid), slug (sha1))
140
+ function version_slug (uuid:: UUID , sha1:: SHA1 , p:: Int = 4 )
141
+ crc = _crc32c (uuid)
142
+ crc = _crc32c (sha1. bytes, crc)
143
+ return slug (crc, p)
144
+ end
156
145
157
146
# # load path expansion: turn LOAD_PATH entries into concrete paths ##
158
147
@@ -585,7 +574,7 @@ function explicit_manifest_uuid_path(manifest_file::String, pkg::PkgId)::Union{N
585
574
return entry_path (path, name)
586
575
end
587
576
hash == nothing && return nothing
588
- slug = version_slug (uuid, hash)
577
+ slug = joinpath (name, version_slug (uuid, hash) )
589
578
for depot in DEPOT_PATH
590
579
path = abspath (depot, " packages" , slug)
591
580
ispath (path) && return path
@@ -638,10 +627,13 @@ function find_source_file(path::AbstractString)
638
627
return isfile (base_path) ? base_path : nothing
639
628
end
640
629
630
+ cache_file_entry (pkg:: PkgId ) =
631
+ pkg. uuid === nothing ? " $(pkg. name) .ji" :
632
+ joinpath (pkg. name, " $(package_slug (pkg. uuid)) .ji" )
633
+
641
634
function find_all_in_cache_path (pkg:: PkgId )
642
635
paths = String[]
643
- suffix = " $(pkg. name) .ji"
644
- pkg. uuid != = nothing && (suffix = joinpath (slug (pkg. uuid), suffix))
636
+ suffix = cache_file_entry (pkg)
645
637
for prefix in LOAD_CACHE_PATH
646
638
path = joinpath (prefix, suffix)
647
639
isfile_casesensitive (path) && push! (paths, path)
@@ -1179,12 +1171,9 @@ function compilecache(pkg::PkgId)
1179
1171
path = locate_package (pkg)
1180
1172
path === nothing && throw (ArgumentError (" $name not found in path" ))
1181
1173
# decide where to put the resulting cache file
1182
- cachepath = abspath (LOAD_CACHE_PATH[1 ])
1183
- pkg. uuid != = nothing && (cachepath = joinpath (cachepath, slug (pkg. uuid)))
1184
- if ! isdir (cachepath)
1185
- mkpath (cachepath)
1186
- end
1187
- cachefile:: String = joinpath (cachepath, " $(pkg. name) .ji" )
1174
+ cachefile = abspath (LOAD_CACHE_PATH[1 ], cache_file_entry (pkg))
1175
+ cachepath = dirname (cachefile)
1176
+ isdir (cachepath) || mkpath (cachepath)
1188
1177
# build up the list of modules that we want the precompile process to preserve
1189
1178
concrete_deps = copy (_concrete_dependencies)
1190
1179
for (key, mod) in loaded_modules
0 commit comments