Skip to content
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
4 changes: 2 additions & 2 deletions Extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1018,10 +1018,10 @@
}
},
"scripts": {
"vscode:prepublish": "tsc -p ./ && node ./out/src/Debugger/copyScript.js",
"vscode:prepublish": "npm install && tsc -p ./ && node ./out/src/Debugger/copyScript.js",
"pretest": "tsc -p ./",
"test": "mocha -u tdd ./out/test",
"compile": "tsc -watch -p ./",
"compile": "npm run vscode:prepublish && tsc -watch -p ./",
"postinstall": "node ./node_modules/vscode/bin/install"
},
"devDependencies": {
Expand Down
89 changes: 78 additions & 11 deletions Extension/src/Debugger/copyScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,19 @@
*/

import * as fs from 'fs';
import * as os from 'os';
import * as path from 'path';
import * as child_process from 'child_process';

//Change this to true to force a dev workflow.
const EnableDevWorkflow: Boolean = false;

const DebugAdapterPath = "./debugAdapters"
const DebugAdapterBinPath = DebugAdapterPath + "/bin";

var CpptoolsExtensionRoot: string = null;
var SearchCompleted: Boolean = false;

interface RootsHashtable {
"miEngineRoot": string;
"openDebugRoot": string;
Expand All @@ -25,16 +35,46 @@ const internalBinaryRoots: RootsHashtable = {
};

const externalBinaryRoots: RootsHashtable = {
"miEngineRoot": "./node_modules/msvscode.cpptools.miengine",
"openDebugRoot": "./node_modules/msvscode.cpptools.opendebugad7",
"monoDeps": "./node_modules/msvscode.cpptools.monodeps"
"miEngineRoot": DebugAdapterBinPath,
"openDebugRoot": DebugAdapterBinPath,
"monoDeps": DebugAdapterPath
};

//Change this to true to force a dev workflow.
const EnableDevWorkflow: Boolean = false;
function findCppToolsExtensionDebugAdapterFolder(): string {
const vscodeFolderRegExp = new RegExp(/\.vscode-*[a-z]*$/);
const cpptoolsFolderRegExp = new RegExp(/ms\-vscode\.cpptools\-.*$/);

var dirPath: string = os.homedir();
if (fs.existsSync(dirPath)) {
var files = fs.readdirSync(dirPath);
for (var i = 0; i < files.length; i++) {
// Check to see if it starts with '.vscode'
if (vscodeFolderRegExp.test(files[i])) {
var extPath: string = path.join(dirPath, files[i], "extensions");
if (fs.existsSync(extPath)) {
var extFiles = fs.readdirSync(extPath);
for (var j = 0; j < extFiles.length; j++) {
if (cpptoolsFolderRegExp.test(path.join(extFiles[j]))) {
dirPath = path.join(extPath, extFiles[j]);
break;
}
}
}
}
}

const DebugAdapterPath = "./debugAdapters"
const DebugAdapterBinPath = DebugAdapterPath + "/bin";
if (dirPath == os.homedir()) {
console.error("Could not find installed C/C++ extension.");
return null;
}

return dirPath;
}
else {
console.error("Unable to determine C/C++ extension installation location.")
return null;
}
}

function enableDevWorkflow(): Boolean {
if (process.env.AGENT_ID) {
Expand All @@ -51,7 +91,22 @@ function copySourceDependencies(): void {

function getRoot(rootKey: string): string {
const internal = internalBinaryRoots[rootKey];
return internal ? internal : externalBinaryRoots[rootKey];
if (internal) {
return internal;
}

// Only search for the extension root once.
if (!CpptoolsExtensionRoot && !SearchCompleted) {
CpptoolsExtensionRoot = findCppToolsExtensionDebugAdapterFolder();
SearchCompleted = true;
}

if (CpptoolsExtensionRoot) {
return path.join(CpptoolsExtensionRoot, externalBinaryRoots[rootKey]);
}

console.error("Unable to determine internal/external location to copy from for root %s.", rootKey);
return null;
}

function copyBinaryDependencies(): void {
Expand Down Expand Up @@ -84,14 +139,26 @@ function copyMonoDependencies(): void {
}

function copy(root: string, target: string, file: string): void {
if (!root) {
console.error("Unknown root location. Copy Failed for %s.", file);
return;
}

var source = path.join(root, file);
var destination: string = path.join(target, file);

console.log('Creating directory %s', target);
makeDirectory(target);
if (!fs.existsSync(target)) {
console.log('Creating directory %s', target);
makeDirectory(target);
}

console.log('copying %s to %s', source, destination);
fs.writeFileSync(destination, fs.readFileSync(source));
if (fs.existsSync(source)) {
fs.writeFileSync(destination, fs.readFileSync(source));
}
else {
console.error('ERR: could not find file %s', source);
}
}

function copyFolder(root: string, target: string): void {
Expand Down