Skip to content

Commit

Permalink
Merge pull request #662 from Saij/fix/brew_not_in_path
Browse files Browse the repository at this point in the history
Fixed the error "arch: brew not found in PATH" while installing driver
  • Loading branch information
cavearr authored Nov 19, 2022
2 parents aaa6568 + 0677b55 commit e76d876
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 67 deletions.
99 changes: 65 additions & 34 deletions app/scripts/services/drivers.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,35 @@ angular.module('icestudio')
function disableDarwinDriversSerial() {
disableDarwinDrivers();
}
function returnBrewPath(){
const result = require('child_process').execSync('uname -a').toString().trim().toLowerCase();
return (result.indexOf('arm64')>0) ? 'arch -arm64 brew' : 'brew';
function returnBrewPath() {
const fs = require('fs');

const possibleBrewPaths = [
'/usr/local/bin/brew',
'/opt/homebrew/bin/brew'
];

let brewPath = 'brew';
try {
for (let checkPath of possibleBrewPaths) {
if (fs.existsSync(checkPath)) {
brewPath = checkPath;
break;
}
}

if (typeof common.DEBUGMODE !== 'undefined' && common.DEBUGMODE === 1) {
fs.appendFileSync(common.LOGFILE, 'Found homebrew in path: ' + brewPath + "\n");
}
} catch (error) {
if (typeof common.DEBUGMODE !== 'undefined' && common.DEBUGMODE === 1) {
fs.appendFileSync(common.LOGFILE, 'Error detecting brew path:' + "\n");
fs.appendFileSync(common.LOGFILE, error + "\n");
}
}

const arch = nodeChildProcess.execSync('uname -a').toString().trim().toLowerCase();
return (arch.indexOf('arm64') > 0) ? 'arch -arm64 ' + brewPath : brewPath;
}

function enableDarwinDrivers(brewPackages, profileSetting) {
Expand All @@ -397,46 +423,51 @@ angular.module('icestudio')
fs.appendFileSync(common.LOGFILE, 'BREW COMMANDS:::' + "\n");
fs.appendFileSync(common.LOGFILE, JSON.stringify(brewCommands));
}

nodeChildProcess.exec(brewCommands.join('; '), function (error, stdout, stderr) {
if (typeof common.DEBUGMODE !== 'undefined' &&
common.DEBUGMODE === 1) {
const fs = require('fs');
fs.appendFileSync(common.LOGFILE, 'STDERR ' + stderr + "\n");

fs.appendFileSync(common.LOGFILE, 'STDERR ' + stdout + "\n");
}
if (error) {
if ((stderr.indexOf('brew: command not found') !== -1) ||
(stderr.indexOf('brew: No such file or directory') !== -1)) {
alertify.warning(gettextCatalog.getString('{{app}} is required.', { app: '<b>Homebrew</b>' }) + '<br>' +
'<u>' + gettextCatalog.getString('Click here to install it') + '</u>', 30)
.callback = function (isClicked) {
try {
nodeChildProcess.exec(brewCommands.join('; '), function (error, stdout, stderr) {
if (typeof common.DEBUGMODE !== 'undefined' &&
common.DEBUGMODE === 1) {
const fs = require('fs');
fs.appendFileSync(common.LOGFILE, 'STDERR ' + stderr + "\n");

fs.appendFileSync(common.LOGFILE, 'STDERR ' + stdout + "\n");
}
if (error) {
if ((stderr.indexOf('brew: command not found') !== -1) ||
(stderr.indexOf('brew: No such file or directory') !== -1)) {
alertify.warning(gettextCatalog.getString('{{app}} is required.', {app: '<b>Homebrew</b>'}) + '<br>' +
'<u>' + gettextCatalog.getString('Click here to install it') + '</u>', 30)
.callback = function (isClicked) {
if (isClicked) {
gui.Shell.openExternal('https://brew.sh');
}
};
} else if (stderr.indexOf('Error: Failed to download') !== -1) {
alertify.error(gettextCatalog.getString('Internet connection required'), 30);
} else {
alertify.error(stderr, 30);
}
} else {
if (profileSetting) {
profile.set(profileSetting, true);
}
alertify.success(gettextCatalog.getString('Drivers enabled'));
}
else if (stderr.indexOf('Error: Failed to download') !== -1) {
alertify.error(gettextCatalog.getString('Internet connection required'), 30);
}
else {
alertify.error(stderr, 30);
}
utils.endBlockingTask();
});
if (typeof common.DEBUGMODE !== 'undefined' &&
common.DEBUGMODE === 1) {
const fs = require('fs');
fs.appendFileSync(common.LOGFILE, '/drivers.enableDarwinDrivers' + "\n");
}
else {
if (profileSetting) {
profile.set(profileSetting, true);
}
alertify.success(gettextCatalog.getString('Drivers enabled'));
} catch (error) {
if (typeof common.DEBUGMODE !== 'undefined' && common.DEBUGMODE === 1) {
const fs = require('fs');
fs.appendFileSync(common.LOGFILE, 'Error installing driver: ' + error + "\n");
}
alertify.error('Error installing driver: ' + "\n" + error);
utils.endBlockingTask();
});
if (typeof common.DEBUGMODE !== 'undefined' &&
common.DEBUGMODE === 1) {
const fs = require('fs');
fs.appendFileSync(common.LOGFILE, '/drivers.enableDarwinDrivers' + "\n");

}
}

Expand Down
64 changes: 32 additions & 32 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.9.2w",
"description": "Visual editor for open FPGA boards",
"contributors": [
{
{
"name": "Carlos Venegas Arrabe",
"url": "https://github.com/cavearr"
},
Expand Down Expand Up @@ -49,5 +49,8 @@
},
"darwinDependencies": {
"grunt-appdmg": "https://github.com/agoodney/grunt-appdmg.git"
},
"dependencies": {
"grunt-appdmg": "github:agoodney/grunt-appdmg"
}
}

0 comments on commit e76d876

Please sign in to comment.