Skip to content

Commit

Permalink
set target / host triplet use selection
Browse files Browse the repository at this point in the history
  • Loading branch information
JackBoosY committed Nov 18, 2023
1 parent 44bff98 commit fc86cf1
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 32 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"icon": "images/vcpkg-logo.png",
"publisher": "JackBoosY",
"license": "MIT",
"version": "2.0.6",
"version": "2.0.7",
"engines": {
"vscode": "^1.76.0"
},
Expand Down
90 changes: 59 additions & 31 deletions src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -633,44 +633,72 @@ export class ConfigurationManager implements vscode.Disposable
vscode.window.showInformationMessage('Current triplet is: ' + this.getCurrentTriplet());
}

async setTargetTriplet()
private getAllSupportedTriplets()
{
vscode.window.showInputBox().then(async result => {
if (result?.length)
let triplets = [];
let vcpkgPath = workspace.getConfiguration('vcpkg').get<string>(this._vcpkgPathConfig);

// for official triplets
let officialTriplets = fs.readdirSync(vcpkgPath + '/triplets');
for (let i = 0; i < officialTriplets.length; i++)
{
let curr = officialTriplets[i];
if (curr.indexOf('.cmake') !== -1)
{
// the correct triplet name is "<arch>-<os>"
if (result.match(".+\-.+") !== null)
{
this.updateVcpkgSetting(this._targetTripletConfig, result);
this.logInfo('update target triplet to: ' + result);
vscode.window.showInformationMessage('Update target triplet to: ' + result);
}
else
{
vscode.window.showErrorMessage('Invalide triplet name.');
}
triplets.push({label: curr.substring(0, curr.indexOf('.cmake')), description: 'official triplet'});
}
}

// for unofficial triplets
let unofficialTriplets = fs.readdirSync(vcpkgPath + '/triplets/community');
for (let i = 0; i < unofficialTriplets.length; i++)
{
let curr = unofficialTriplets[i];
if (curr.indexOf('.cmake') !== -1)
{
triplets.push({label: curr.substring(0, curr.indexOf('.cmake')), description: 'unofficial triplet'});
}
});
}

// TODO: for custom triplets

return triplets;
}

async setTargetTriplet()
{
let triplets = this.getAllSupportedTriplets();
if (triplets.length === 0)
{
vscode.window.showErrorMessage('Please check your vcpkg path first.');
return;
}

let result = await vscode.window.showQuickPick(triplets, {canPickMany: false, placeHolder: "Choose a triplet"});
if (result !== undefined)
{
this.updateVcpkgSetting(this._targetTripletConfig, result.label);
this.logInfo('update target triplet to: ' + result.label);
vscode.window.showInformationMessage('Update target triplet to: ' + result.label);
}
}

async setHostTriplet()
{
vscode.window.showInputBox().then(async result => {
if (result?.length)
{
// the correct triplet name is "<arch>-<os>"
if (result.match(".+\-.+") !== null)
{
this.updateVcpkgSetting(this._hostTripletConfig, result);
this.logInfo('update host triplet to: ' + result);
vscode.window.showInformationMessage('Update host triplet to: ' + result);
}
else
{
vscode.window.showErrorMessage('Invalide triplet name.');
}
}
});
let triplets = this.getAllSupportedTriplets();
if (triplets.length === 0)
{
vscode.window.showErrorMessage('Please check your vcpkg path first.');
return;
}

let result = await vscode.window.showQuickPick(triplets, {canPickMany: false, placeHolder: "Choose a triplet"});
if (result !== undefined)
{
this.updateVcpkgSetting(this._targetTripletConfig, result.label);
this.logInfo('update host triplet to: ' + result.label);
vscode.window.showInformationMessage('Update host triplet to: ' + result.label);
}
}

async getCurrentTriplet()
Expand Down

0 comments on commit fc86cf1

Please sign in to comment.