@@ -103,38 +103,62 @@ defmodule Mix.Tasks.ElixirMake.Checksum do
103
103
tasks =
104
104
Task . async_stream (
105
105
urls ,
106
- fn { { _target , _nif_version } , url } -> { url , Artefact . download ( url ) } end ,
106
+ fn { { _target , _nif_version } , url } ->
107
+ checksum_algo = Artefact . checksum_algo ( )
108
+ checksum_file_url = "#{ url } .#{ Atom . to_string ( checksum_algo ) } "
109
+ artifact_checksum = Artefact . download ( checksum_file_url )
110
+
111
+ with { :ok , body } <- artifact_checksum ,
112
+ [ checksum , basename ] <- String . split ( body , " " , trim: true ) do
113
+ { :checksum , url ,
114
+ % Artefact {
115
+ basename: String . trim ( basename ) ,
116
+ checksum: checksum ,
117
+ checksum_algo: checksum_algo
118
+ } }
119
+ else
120
+ _ -> { :download , url , Artefact . download ( url ) }
121
+ end
122
+ end ,
107
123
timeout: :infinity ,
108
124
ordered: false
109
125
)
110
126
111
127
cache_dir = Artefact . cache_dir ( )
112
128
113
- Enum . flat_map ( tasks , fn { :ok , { url , download } } ->
114
- case download do
115
- { :ok , body } ->
116
- basename = basename_from_url ( url )
117
- path = Path . join ( cache_dir , basename )
118
- File . write! ( path , body )
119
- artefact = Artefact . checksum ( basename , body )
120
-
121
- Mix . shell ( ) . info (
122
- "NIF cached at #{ path } with checksum #{ artefact . checksum } (#{ artefact . checksum_algo } )"
123
- )
124
-
125
- [ artefact ]
126
-
127
- result ->
128
- if ignore_unavailable? do
129
- msg = "Skipped unavailable NIF artifact. Reason: #{ inspect ( result ) } "
130
- Mix . shell ( ) . info ( msg )
131
- else
132
- msg = "Could not finish the download of NIF artifacts. Reason: #{ inspect ( result ) } "
133
- Mix . shell ( ) . error ( msg )
134
- end
129
+ Enum . flat_map ( tasks , fn
130
+ { :ok , { :checksum , _url , artefact } } ->
131
+ Mix . shell ( ) . info (
132
+ "NIF checksum file with checksum #{ artefact . checksum } (#{ artefact . checksum_algo } )"
133
+ )
135
134
136
- [ ]
137
- end
135
+ [ artefact ]
136
+
137
+ { :ok , { :download , url , download } } ->
138
+ case download do
139
+ { :ok , body } ->
140
+ basename = basename_from_url ( url )
141
+ path = Path . join ( cache_dir , basename )
142
+ File . write! ( path , body )
143
+ artefact = Artefact . checksum ( basename , body )
144
+
145
+ Mix . shell ( ) . info (
146
+ "NIF cached at #{ path } with checksum #{ artefact . checksum } (#{ artefact . checksum_algo } )"
147
+ )
148
+
149
+ [ artefact ]
150
+
151
+ result ->
152
+ if ignore_unavailable? do
153
+ msg = "Skipped unavailable NIF artifact. Reason: #{ inspect ( result ) } "
154
+ Mix . shell ( ) . info ( msg )
155
+ else
156
+ msg = "Could not finish the download of NIF artifacts. Reason: #{ inspect ( result ) } "
157
+ Mix . shell ( ) . error ( msg )
158
+ end
159
+
160
+ [ ]
161
+ end
138
162
end )
139
163
end
140
164
0 commit comments