Skip to content
This repository was archived by the owner on Oct 1, 2024. It is now read-only.

Fix arduinoPath resolution on MacOS #1227

Merged
merged 4 commits into from
Apr 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/arduino/arduinoSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export class ArduinoSettings implements IArduinoSettings {

public get defaultExamplePath(): string {
if (os.platform() === "darwin") {
return path.join(util.resolveMacArduinoAppPath(this._arduinoPath), "/Contents/Java/examples");
return path.join(util.resolveMacArduinoAppPath(this._arduinoPath, this._useArduinoCli), "/Contents/Java/examples");
} else {
return path.join(this._arduinoPath, "examples");
}
Expand All @@ -116,15 +116,15 @@ export class ArduinoSettings implements IArduinoSettings {

public get defaultPackagePath(): string {
if (os.platform() === "darwin") {
return path.join(util.resolveMacArduinoAppPath(this._arduinoPath), "/Contents/Java/hardware");
return path.join(util.resolveMacArduinoAppPath(this._arduinoPath, this._useArduinoCli), "/Contents/Java/hardware");
} else { // linux and win32.
return path.join(this._arduinoPath, "hardware");
}
}

public get defaultLibPath(): string {
if (os.platform() === "darwin") {
return path.join(util.resolveMacArduinoAppPath(this._arduinoPath), "/Contents/Java/libraries");
return path.join(util.resolveMacArduinoAppPath(this._arduinoPath, this._useArduinoCli), "/Contents/Java/libraries");
} else { // linux and win32
return path.join(this._arduinoPath, "libraries");
}
Expand All @@ -133,7 +133,7 @@ export class ArduinoSettings implements IArduinoSettings {
public get commandPath(): string {
const platform = os.platform();
if (platform === "darwin") {
return path.join(util.resolveMacArduinoAppPath(this._arduinoPath), path.normalize(this._commandPath));
return path.join(util.resolveMacArduinoAppPath(this._arduinoPath, this._useArduinoCli), path.normalize(this._commandPath));
} else {
return path.join(this._arduinoPath, path.normalize(this._commandPath));
}
Expand Down
79 changes: 39 additions & 40 deletions src/common/sys/darwin.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,39 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

import * as childProcess from "child_process";
import * as path from "path";
import { directoryExistsSync, fileExistsSync, resolveMacArduinoAppPath } from "../util";

export function resolveArduinoPath(): string {
let result;

const defaultCommonPaths = [path.join(process.env.HOME, "Applications"), "/Applications"];
for (const scanPath of defaultCommonPaths) {
if (directoryExistsSync(path.join(scanPath, "Arduino.app"))) {
result = scanPath;
break;
}
}
return result || "";
}

export function validateArduinoPath(arduinoPath: string, useArduinoCli = false): boolean {
return fileExistsSync(path.join(resolveMacArduinoAppPath(arduinoPath), useArduinoCli ? "arduino-cli" : "/Contents/MacOS/Arduino"));

}

export function findFile(fileName: string, cwd: string): string {
let pathString;
try {
pathString = childProcess.execSync(`find ${cwd} -name ${fileName} -type f`, { encoding: "utf8" }).split("\n");

if (pathString && pathString[0] && fileExistsSync(pathString[0].trim())) {
pathString = path.normalize(pathString[0].trim());
} else {
pathString = null;
}
} catch (ex) {
// Ignore the errors.
}
return pathString;
}
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

import * as childProcess from "child_process";
import * as path from "path";
import { directoryExistsSync, fileExistsSync, resolveMacArduinoAppPath } from "../util";

export function resolveArduinoPath(): string {
let result;

const defaultCommonPaths = [path.join(process.env.HOME, "Applications"), "/Applications"];
for (const scanPath of defaultCommonPaths) {
if (directoryExistsSync(path.join(scanPath, "Arduino.app"))) {
result = scanPath;
break;
}
}
return result || "";
}

export function validateArduinoPath(arduinoPath: string, useArduinoCli = false): boolean {
return fileExistsSync(path.join(resolveMacArduinoAppPath(arduinoPath, useArduinoCli), useArduinoCli ? "arduino-cli" : "/Contents/MacOS/Arduino"));
}

export function findFile(fileName: string, cwd: string): string {
let pathString;
try {
pathString = childProcess.execSync(`find ${cwd} -name ${fileName} -type f`, { encoding: "utf8" }).split("\n");

if (pathString && pathString[0] && fileExistsSync(pathString[0].trim())) {
pathString = path.normalize(pathString[0].trim());
} else {
pathString = null;
}
} catch (ex) {
// Ignore the errors.
}
return pathString;
}
4 changes: 2 additions & 2 deletions src/common/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,8 +426,8 @@ export function convertToHex(number, width = 0) {
* in case you named Arduino with a version number
* @argument {string} arduinoPath
*/
export function resolveMacArduinoAppPath(arduinoPath: string): string {
if (/Arduino.*\.app/.test(arduinoPath)) {
export function resolveMacArduinoAppPath(arduinoPath: string, useArduinoCli = false): string {
if (useArduinoCli || /Arduino.*\.app/.test(arduinoPath)) {
return arduinoPath;
} else {
return path.join(arduinoPath, "Arduino.app");
Expand Down