Skip to content

Commit

Permalink
Revert "Change node.processChild.exec to .execFile"
Browse files Browse the repository at this point in the history
This reverts commit b703c26.
  • Loading branch information
radurentea committed Mar 4, 2024
1 parent b703c26 commit 84fcba5
Show file tree
Hide file tree
Showing 16 changed files with 62 additions and 157 deletions.
13 changes: 2 additions & 11 deletions src/PlatformInformation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,8 @@ export class PlatformInformation {
}

public static GetUnixArchitecture(): Promise<string> {
const command = "uname";
const args = ["-m"];
return utils
.execChildProcess(command, args, utils.extensionContext.extensionPath)
.execChildProcess("uname -m", utils.extensionContext.extensionPath)
.then((architecture) => {
if (architecture) {
return architecture.trim();
Expand All @@ -92,16 +90,9 @@ export class PlatformInformation {
}

private static GetWindowsArchitecture(): Promise<string> {
const command = "wmic";
const args = [
"os",
"get",
"osarchitecture"
];
return utils
.execChildProcess(
command,
args,
"wmic os get osarchitecture",
utils.extensionContext.extensionPath
)
.then((architecture) => {
Expand Down
9 changes: 3 additions & 6 deletions src/common/abstractCloning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,14 +246,12 @@ export class AbstractCloning {
"esp-components",
];
await execChildProcess(
this.gitBinPath,
["submodule", "init"],
`${this.gitBinPath} submodule init`,
repoPath,
OutputChannel.init()
);
const gitModules = await execChildProcess(
this.gitBinPath,
["config", "-f", ".gitmodules", "--list"],
`${this.gitBinPath} config -f .gitmodules --list`,
repoPath,
OutputChannel.init()
);
Expand Down Expand Up @@ -299,8 +297,7 @@ export class AbstractCloning {
}

await execChildProcess(
this.gitBinPath,
["config", `submodule.${subPath}.url`, subUrl],
`${this.gitBinPath} config submodule.${subPath}.url ${subUrl}`,
repoPath,
OutputChannel.init()
);
Expand Down
6 changes: 2 additions & 4 deletions src/espBom/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,15 @@ export async function installEspSBOM(workspace: Uri) {
const modifiedEnv = appendIdfAndToolsToPath(workspace);
try {
const showResult = await execChildProcess(
pythonBinPath,
["-m", "pip", "show", "esp-idf-sbom"],
`"${pythonBinPath}" -m pip show esp-idf-sbom`,
workspace.fsPath,
OutputChannel.init(),
{ env: modifiedEnv }
);
OutputChannel.appendLine(showResult);
} catch (error) {
const installResult = await execChildProcess(
pythonBinPath,
["-m", "pip", "install", "esp-idf-sbom"],
`"${pythonBinPath}" -m pip install esp-idf-sbom`,
workspace.fsPath,
OutputChannel.init(),
{ env: modifiedEnv }
Expand Down
3 changes: 1 addition & 2 deletions src/espIdf/nvs/partitionTable/panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,7 @@ export class NVSPartitionTable {
}
OutputChannel.appendLine(`${pythonBinPath} ${partToolArgs.join(" ")}`);
const result = await execChildProcess(
pythonBinPath,
partToolArgs,
`${pythonBinPath} ${partToolArgs.join(" ")}`,
dirPath
);
OutputChannel.appendLine(result);
Expand Down
17 changes: 2 additions & 15 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -665,15 +665,8 @@ export async function activate(context: vscode.ExtensionContext) {
cancelToken: vscode.CancellationToken
) => {
try {
const args = [
flashScriptPath,
"-p",
port,
"erase_flash"
];
const result = await utils.execChildProcess(
pythonBinPath,
args,
`${pythonBinPath} ${flashScriptPath} -p ${port} erase_flash`,
process.cwd(),
OutputChannel.init(),
null,
Expand Down Expand Up @@ -3265,14 +3258,8 @@ export async function activate(context: vscode.ExtensionContext) {
"idf.buildPath",
workspaceRoot
) as string;
const args = [
ninjaSummaryScript,
"-C",
buildDir
];
const summaryResult = await utils.execChildProcess(
pythonBinPath,
args,
`${pythonBinPath} ${ninjaSummaryScript} -C ${buildDir}`,
workspaceRoot.fsPath,
OutputChannel.init()
);
Expand Down
3 changes: 1 addition & 2 deletions src/flash/dfu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ function deviceLabel(selectedDevice: string) {
export async function getDfuList(workspaceUri: vscode.Uri) {
const modifiedEnv = appendIdfAndToolsToPath(workspaceUri);
return await execChildProcess(
"dfu-util",
["--list"],
"dfu-util --list",
process.cwd(),
OutputChannel.init(),
{
Expand Down
11 changes: 3 additions & 8 deletions src/idfToolsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,18 +221,13 @@ export class IdfToolsManager {
) {
modifiedEnv[pathNameInEnv] = modifiedPath;
}
if (pkg.version_cmd.length === 0) {
const versionCmd = pkg.version_cmd.join(" ");
if (versionCmd === "") {
return "No command version";
}
const command = pkg.version_cmd[0];
const args = pkg.version_cmd.slice(1);
try {
const args = [

]
const binVersionResponse = await utils.execChildProcess(
command,
args,
versionCmd,
process.cwd(),
logToChannel ? this.toolsManagerChannel : undefined,
{
Expand Down
94 changes: 24 additions & 70 deletions src/pythonManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,8 @@ export async function installEspIdfToolFromIdf(
return reject(new Error("Process cancelled by user"));
}
try {
const args = [
idfToolsPyPath,
"install",
toolName
];
const processResult = await utils.execChildProcess(
pythonBinPath,
args,
`"${pythonBinPath}" ${idfToolsPyPath} install ${toolName}`,
idfToolsPath,
channel,
{ cwd: idfToolsPath, env: modifiedEnv },
Expand Down Expand Up @@ -107,8 +101,7 @@ export async function installPythonEnvFromIdfTools(
const pyEnvPath = await getPythonEnvPath(espDir, idfToolsDir, pythonBinPath);

await execProcessWithLog(
pythonBinPath,
[idfToolsPyPath,"install-python-env"],
`"${pythonBinPath}" "${idfToolsPyPath}" install-python-env`,
idfToolsDir,
pyTracker,
channel,
Expand Down Expand Up @@ -161,19 +154,19 @@ export async function installExtensionPyReqs(
`espidf.constraints.v${espIdfVersion}.txt`
);
const constrainsFileExists = await pathExists(constrainsFile);
let constraintArg = [];
let constraintArg = "";
if (constrainsFileExists) {
constraintArg = ["--constraint", constrainsFile];
constraintArg = `--constraint "${constrainsFile}" `;
} else {
const extensionConstraintsFile = join(
utils.extensionContext.extensionPath,
"espidf.constraints.txt"
`espidf.constraints.txt`
);
const extensionConstraintsFileExists = await pathExists(
extensionConstraintsFile
);
if (extensionConstraintsFileExists) {
constraintArg = ["--constraint", extensionConstraintsFile];
constraintArg = `--constraint "${extensionConstraintsFile}" `;
}
}
const installDAPyPkgsMsg = `Installing ESP-IDF Debug Adapter python packages in ${virtualEnvPython} ...\n`;
Expand All @@ -184,19 +177,8 @@ export async function installExtensionPyReqs(
if (channel) {
channel.appendLine(installDAPyPkgsMsg + "\n");
}
const args = [
"-m",
"pip",
"install",
"--upgrade",
...constraintArg,
"--no-warn-script-location",
"-r",
debugAdapterRequirements
];
await execProcessWithLog(
virtualEnvPython,
args,
`"${virtualEnvPython}" -m pip install --upgrade ${constraintArg}--no-warn-script-location -r "${debugAdapterRequirements}"`,
idfToolsDir,
pyTracker,
channel,
Expand Down Expand Up @@ -242,18 +224,8 @@ export async function installEspMatterPyReqs(
if (channel) {
channel.appendLine(installMatterPyPkgsMsg + "\n");
}
const args = [
"-m",
"pip",
"install",
"--upgrade",
"--no-warn-script-location",
"-r",
matterRequirements
];
await execProcessWithLog(
virtualEnvPython,
args,
`"${virtualEnvPython}" -m pip install --upgrade --no-warn-script-location -r "${matterRequirements}"`,
idfToolsDir,
pyTracker,
channel,
Expand All @@ -264,7 +236,6 @@ export async function installEspMatterPyReqs(
}
export async function execProcessWithLog(
cmd: string,
args: string[],
workDir: string,
pyTracker?: PyReqLog,
channel?: OutputChannel,
Expand All @@ -273,7 +244,6 @@ export async function execProcessWithLog(
) {
const processResult = await utils.execChildProcess(
cmd,
args,
workDir,
channel,
opts,
Expand All @@ -293,15 +263,9 @@ export async function getPythonEnvPath(
idfToolsDir: string,
pythonBin: string
) {
const pythonCode = `import sys; print('{}.{}'.format(sys.version_info.major, sys.version_info.minor))`;
const args = [
"-c",
pythonCode
];
const pythonVersion = (
await utils.execChildProcess(
pythonBin,
args,
`"${pythonBin}" -c "import sys; print('{}.{}'.format(sys.version_info.major, sys.version_info.minor))"`,
espIdfDir
)
).replace(/(\n|\r|\r\n)/gm, "");
Expand All @@ -320,8 +284,7 @@ export async function getPythonEnvPath(
export async function checkPythonExists(pythonBin: string, workingDir: string) {
try {
const versionResult = await utils.execChildProcess(
pythonBin,
["--version"],
`"${pythonBin}" --version`,
workingDir
);
if (versionResult) {
Expand All @@ -348,14 +311,8 @@ export async function checkPythonExists(pythonBin: string, workingDir: string) {

export async function checkPipExists(pyBinPath: string, workingDir: string) {
try {
const args = [
"-m",
"pip",
"--version"
];
const pipResult = await utils.execChildProcess(
pyBinPath,
args,
`"${pyBinPath}" -m pip --version`,
workingDir
);
if (pipResult) {
Expand Down Expand Up @@ -384,35 +341,32 @@ export async function getPythonBinList(workingDir: string) {

export async function getUnixPythonList(workingDir: string) {
try {
const pythonVersionsRaw = await utils.execChildProcess("which", ["-a", "python"], workingDir);
const pythonVersions = pythonVersionsRaw.trim() ? pythonVersionsRaw.trim().split("\n") : [];

const python3VersionsRaw = await utils.execChildProcess("which", ["-a", "python3"], workingDir);
const python3Versions = python3VersionsRaw.trim() ? python3VersionsRaw.trim().split("\n") : [];

const combinedVersionsArray = [...pythonVersions, ...python3Versions];
const uniquePathsSet = new Set(combinedVersionsArray.filter(path => path.length > 0));
const uniquePathsArray = Array.from(uniquePathsSet);

return uniquePathsArray;
const pyVersionsStr = await utils.execChildProcess(
"which -a python; which -a python3",
workingDir
);
if (pyVersionsStr) {
const resultList = pyVersionsStr.trim().split("\n");
const uniquePathsSet = new Set(resultList);
const uniquePathsArray = Array.from(uniquePathsSet);
return uniquePathsArray;
}
} catch (error) {
Logger.errorNotify("Error looking for python in system", error);
return ["Not found"];
}
}


export async function checkIfNotVirtualEnv(
pythonBinPath: string,
workDir: string
) {
try {
const isVirtualEnv = await utils.execChildProcess(
pythonBinPath,
["-c", "import sys; print(sys.prefix == sys.base_prefix)"],
const isVirtualEnvBuffer = await utils.execChildProcess(
`"${pythonBinPath}" -c "import sys; print('{}'.format(sys.prefix == sys.base_prefix))"`,
workDir
);
return isVirtualEnv.trim() === "True";
return isVirtualEnvBuffer.toString().indexOf("True") !== -1 ? true : false;
} catch (error) {
Logger.errorNotify("Error checking Python is virtualenv", error);
return false;
Expand Down
3 changes: 1 addition & 2 deletions src/support/checkEspIdfRequirements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ export async function checkRequirements(
);
modifiedEnv.IDF_PATH = reportedResult.configurationSettings.espIdfPath;
const requirementsResult = await execChildProcess(
reportedResult.configurationSettings.pythonBinPath,
[checkPythonDepsScript, "-r", requirementsPath],
`${reportedResult.configurationSettings.pythonBinPath} ${checkPythonDepsScript} -r "${requirementsPath}"`,
context.extensionPath,
{ env: modifiedEnv, cwd: context.extensionPath }
);
Expand Down
6 changes: 2 additions & 4 deletions src/support/configurationAccess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,13 @@ export async function getConfigurationAccess(
}
if (process.platform !== "win32") {
const cmakePathInEnv = await execChildProcess(
"which",
["cmake"],
`which cmake`,
context.extensionPath
);
reportedResult.configurationAccess.cmakeInEnv =
cmakePathInEnv && cmakePathInEnv.indexOf("not found") === -1;
const ninjaPathInEnv = await execChildProcess(
"which",
["ninja"],
`which ninja`,
context.extensionPath
);
reportedResult.configurationAccess.ninjaInEnv =
Expand Down
Loading

0 comments on commit 84fcba5

Please sign in to comment.