Skip to content

Commit

Permalink
fix: fix make gnubin directory on MacOS ARM
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Sep 8, 2024
1 parent 84378ae commit c5fc81d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
20 changes: 15 additions & 5 deletions packages/setup-brew/src/install.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { tmpdir } from "os"
import { dirname } from "path"
import { dirname, join } from "path"
import { type AddPathOptions, addPath } from "envosman"
import { execaSync } from "execa"
import { DownloaderHelper } from "node-downloader-helper"
Expand Down Expand Up @@ -64,23 +64,33 @@ export async function setupBrew(options: SetupBrewOptions = {}): Promise<Install
return { binDir }
}

/**
* Get the path to the bin directory of brew
* @returns {string} The path where brew binary is installed
*
* Based on the installation script from https://brew.sh
*/
export function getBrewBinDir() {
return join(getBrewDir(), "bin")
}

/**
* Get the path where brew is installed
* @returns {string} The path where brew is installed
*
* Based on the installation script from https://brew.sh
*/
export function getBrewBinDir() {
export function getBrewDir() {
if (process.platform === "darwin") {
if (process.arch === "arm64") {
return "/opt/homebrew/bin/"
return "/opt/homebrew"
} else {
return "/usr/local/bin/"
return "/usr/local"
}
}

if (process.platform === "linux") {
return "/home/linuxbrew/.linuxbrew/bin/"
return "/home/linuxbrew/.linuxbrew"
}

throw new Error("Unsupported platform for brew")
Expand Down
9 changes: 6 additions & 3 deletions src/make/make.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { join } from "path"
import { addPath } from "envosman"
import { installAptPack } from "setup-apt"
import { installBrewPack } from "setup-brew"
import { getBrewDir, installBrewPack } from "setup-brew"
import { rcOptions } from "../cli-options.js"
import { hasDnf } from "../utils/env/hasDnf.js"
import { isArch } from "../utils/env/isArch.js"
Expand All @@ -17,8 +18,10 @@ export async function setupMake(version: string, _setupDir: string, _arch: strin
}
case "darwin": {
await installBrewPack("make", version)
await addPath("/usr/local/opt/make/libexec/gnubin", rcOptions)
return { binDir: "/usr/local/opt/make/libexec/gnubin" }

const gnuBinDir = join(getBrewDir(), "opt/make/libexec/gnubin")
await addPath(gnuBinDir, rcOptions)
return { binDir: gnuBinDir }
}
case "linux": {
if (isArch()) {
Expand Down

0 comments on commit c5fc81d

Please sign in to comment.