1
1
import { promises as fs } from "node:fs" ;
2
- import * as os from "node:os" ;
3
2
import * as path from "node:path" ;
4
3
import * as process from "node:process" ;
5
4
@@ -30,6 +29,7 @@ import { getCygwinVersion } from "./win32.js";
30
29
export async function getLatestOpamRelease ( ) {
31
30
const semverRange = ALLOW_PRERELEASE_OPAM ? "*" : "<2.2.0" ;
32
31
const octokit = github . getOctokit ( GITHUB_TOKEN ) ;
32
+ const opam_platform = PLATFORM === "win32" ? "windows" : PLATFORM ;
33
33
const { data : releases } = await octokit . rest . repos . listReleases ( {
34
34
owner : "ocaml" ,
35
35
repo : "opam" ,
@@ -51,7 +51,7 @@ export async function getLatestOpamRelease() {
51
51
) ;
52
52
}
53
53
const matchedAssets = latestRelease . assets . find ( ( asset ) =>
54
- asset . browser_download_url . includes ( `${ ARCHITECTURE } -${ PLATFORM } ` ) ,
54
+ asset . browser_download_url . includes ( `${ ARCHITECTURE } -${ opam_platform } ` ) ,
55
55
) ;
56
56
if ( ! matchedAssets ) {
57
57
throw new Error (
@@ -64,15 +64,6 @@ export async function getLatestOpamRelease() {
64
64
} ;
65
65
}
66
66
67
- async function findOpam ( ) {
68
- if ( PLATFORM === "win32" ) {
69
- const opamPath = path . join ( CYGWIN_ROOT , "bin" , "opam.exe" ) ;
70
- return opamPath ;
71
- }
72
- const opamPath = await io . which ( "opam" ) ;
73
- return opamPath ;
74
- }
75
-
76
67
async function acquireOpamUnix ( ) {
77
68
const { version, browserDownloadUrl } = await getLatestOpamRelease ( ) ;
78
69
const cachedPath = toolCache . find ( "opam" , version , ARCHITECTURE ) ;
@@ -206,25 +197,25 @@ async function setupCygwin() {
206
197
}
207
198
208
199
async function acquireOpamWindows ( ) {
209
- const opamVersion = "0.0.0.2" ;
210
- const cachedPath = toolCache . find ( "opam" , opamVersion ) ;
200
+ const { version , browserDownloadUrl } = await getLatestOpamRelease ( ) ;
201
+ const cachedPath = toolCache . find ( "opam" , version , ARCHITECTURE ) ;
211
202
if ( cachedPath === "" ) {
212
- const downloadedPath = await toolCache . downloadTool (
213
- `https://github.com/fdopen/opam-repository-mingw/releases/download/${ opamVersion } /opam64.zip` ,
214
- ) ;
215
- const extractedPath = await toolCache . extractZip ( downloadedPath ) ;
216
- const cachedPath = await toolCache . cacheDir (
217
- extractedPath ,
203
+ const downloadedPath = await toolCache . downloadTool ( browserDownloadUrl ) ;
204
+ core . info ( `Acquired ${ version } from ${ browserDownloadUrl } ` ) ;
205
+ const cachedPath = await toolCache . cacheFile (
206
+ downloadedPath ,
207
+ "opam.exe" ,
218
208
"opam" ,
219
- opamVersion ,
209
+ version ,
210
+ ARCHITECTURE ,
220
211
) ;
221
- const installSh = path . join ( cachedPath , "opam64" , "install.sh" ) ;
222
- await fs . chmod ( installSh , 0o755 ) ;
223
- await exec ( "bash" , [ installSh , "--prefix" , "/usr" ] ) ;
212
+ core . info ( `Successfully cached opam to ${ cachedPath } ` ) ;
213
+ await fs . chmod ( `${ cachedPath } /opam.exe` , 0o755 ) ;
214
+ core . addPath ( cachedPath ) ;
215
+ core . info ( "Added opam to the path" ) ;
224
216
} else {
225
- const installSh = path . join ( cachedPath , "opam64" , "install.sh" ) ;
226
- await fs . chmod ( installSh , 0o755 ) ;
227
- await exec ( "bash" , [ installSh , "--prefix" , "/usr" ] ) ;
217
+ core . addPath ( cachedPath ) ;
218
+ core . info ( "Added cached opam to the path" ) ;
228
219
}
229
220
}
230
221
@@ -237,15 +228,6 @@ async function initializeOpamWindows() {
237
228
"--disable-sandboxing" ,
238
229
"--enable-shell-hook" ,
239
230
] ) ;
240
- await io . mkdirP ( CYGWIN_ROOT_WRAPPERBIN ) ;
241
- const opamCmd = path . join ( CYGWIN_ROOT_WRAPPERBIN , "opam.cmd" ) ;
242
- const data = [
243
- "@setlocal" ,
244
- "@echo off" ,
245
- "set PATH=%CYGWIN_ROOT_BIN%;%PATH%" ,
246
- "ocaml-env exec -- opam.exe %*" ,
247
- ] . join ( os . EOL ) ;
248
- await fs . writeFile ( opamCmd , data , { mode : 0o755 } ) ;
249
231
}
250
232
251
233
async function setupOpamWindows ( ) {
@@ -267,7 +249,6 @@ async function setupOpamWindows() {
267
249
await core . group ( "Initialise the opam state" , async ( ) => {
268
250
await initializeOpamWindows ( ) ;
269
251
} ) ;
270
- process . env [ "PATH" ] = originalPath . join ( path . delimiter ) ;
271
252
}
272
253
273
254
export async function setupOpam ( ) {
@@ -308,20 +289,18 @@ export async function installOcaml(ocamlCompiler: string) {
308
289
309
290
export async function pin ( fpaths : string [ ] ) {
310
291
await core . group ( "Pin local packages" , async ( ) => {
311
- const opam = await findOpam ( ) ;
312
292
for ( const fpath of fpaths ) {
313
293
const fname = path . basename ( fpath , ".opam" ) ;
314
294
const dname = path . dirname ( fpath ) ;
315
- await exec ( opam , [ "pin" , "add" , `${ fname } .dev` , "." , "--no-action" ] , {
295
+ await exec ( " opam" , [ "pin" , "add" , `${ fname } .dev` , "." , "--no-action" ] , {
316
296
cwd : dname ,
317
297
} ) ;
318
298
}
319
299
} ) ;
320
300
}
321
301
322
302
async function repositoryAdd ( name : string , address : string ) {
323
- const opam = await findOpam ( ) ;
324
- await exec ( opam , [
303
+ await exec ( "opam" , [
325
304
"repository" ,
326
305
"add" ,
327
306
name ,
@@ -369,14 +348,12 @@ export async function repositoryAddAll(repositories: [string, string][]) {
369
348
}
370
349
371
350
async function repositoryRemove ( name : string ) {
372
- const opam = await findOpam ( ) ;
373
- await exec ( opam , [ "repository" , "remove" , name , "--all-switches" ] ) ;
351
+ await exec ( "opam" , [ "repository" , "remove" , name , "--all-switches" ] ) ;
374
352
}
375
353
376
354
async function repositoryList ( ) {
377
- const opam = await findOpam ( ) ;
378
355
const repositoryList = await getExecOutput (
379
- opam ,
356
+ " opam" ,
380
357
[ "repository" , "list" , "--all-switches" , "--short" ] ,
381
358
{ ignoreReturnCode : true } ,
382
359
) ;
0 commit comments