Skip to content
This repository has been archived by the owner on Jul 17, 2019. It is now read-only.

Fix ros commands failing due to missing dylibs in macos with SIP enabled #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion src/catkin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as extension from "./extension";
import * as cp from "child_process";
import * as cp from "./child_process";
import * as vscode from "vscode";

/**
Expand Down
33 changes: 33 additions & 0 deletions src/child_process.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import * as cp from 'child_process';


function wrapCommand(command: string, env?: any) {
if (!env) {
return command;
}

const passThroughCommand = Object.keys(env)
.filter(k => k.startsWith('DYLD'))
.reduce((cmd, key) => `${cmd ? `${cmd} &&` : ''} export ${key}='${env[key]}'`, '');

return passThroughCommand ? `${passThroughCommand} && ${command}` : command;
}

/*
* HACK: Apple SIP will not allowing passing through DYLD_* environment variables to
* secured binaries like /bin/sh. This prevents certain commands like rospack list
* to fail due to missing dylib. This function will prepend export DYLD_*=value
* before command to bypass this issue.
*/
export function exec(command: string, options?: cp.ExecOptions,
callback?: (error: Error, stdout: string, stderr: string) => void) : cp.ChildProcess {
if (!options || !options.env || process.platform != 'darwin') {
return cp.exec(command, options, callback);
}

return cp.exec(wrapCommand(command, options.env), options, callback);
}

export function spawn(command: string, args?: ReadonlyArray<string>, options?: cp.SpawnOptions): cp.ChildProcess {
return cp.spawn(command, args, options);
}
2 changes: 1 addition & 1 deletion src/master.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as constants from "./constants";
import * as extension from "./extension";
import * as pfs from "./promise-fs";
import * as cp from "child_process";
import * as cp from "./child_process";
import * as _ from "underscore";
import * as vscode from "vscode";
import * as xmlrpc from "xmlrpc";
Expand Down
4 changes: 2 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as extension from "./extension";
import * as pfs from "./promise-fs";
import * as cp from "child_process";
import * as cp from "./child_process";
import * as _ from "underscore";
import * as vscode from "vscode";

Expand All @@ -26,7 +26,7 @@ export function sourceSetupFile(filename: string, env?: any): Promise<any> {
}

return env;
}, {}));
}, env));
} else {
reject(err);
}
Expand Down