Skip to content

Commit

Permalink
Add mock templates configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Adadov committed Dec 27, 2024
1 parent 91ce3b8 commit f281055
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 26 deletions.
25 changes: 16 additions & 9 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
// Place your settings in this file to overwrite default and user settings.
{
"files.exclude": {
"out": false // set this to true to hide the "out" folder with the compiled JS files
},
"search.exclude": {
"out": true // set this to false to include "out" folder in search results
},
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
"typescript.tsc.autoDetect": "off"
}
"files.exclude": {
"out": false // set this to true to hide the "out" folder with the compiled JS files
},
"search.exclude": {
"out": true // set this to false to include "out" folder in search results
},
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
"typescript.tsc.autoDetect": "off",
"rpmspecChangelog.mockOses": [
"fedora-40-x86_64",
"fedora-41-x86_64",
"fedora-42-x86_64",
"alma+epel-8-x86_64",
"alma+epel-9-x86_64",
]
}
51 changes: 34 additions & 17 deletions src/mockTaskProvider.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
import * as vscode from 'vscode';


interface mockBuildTaskDefinition extends vscode.TaskDefinition {

}
const logs: vscode.OutputChannel = vscode.window.createOutputChannel("Mock");

export class mockBuildTaskProvider implements vscode.TaskProvider {
static mockBuildScriptType = 'rpmbuild';
private tasks?: vscode.Task[];

// We use a CustomExecution task when state needs to be shared across runs of the task or when
// the task requires use of some VS Code API to run.
// If you don't need to share state between runs and if you don't need to execute VS Code API in your task,
// then a simple ShellExecution or ProcessExecution should be enough.
// Since our build has this shared state, the CustomExecution is used below.
private sharedState: string | undefined;
private tasks: vscode.Task[] = [];

private definition = {
type: mockBuildTaskProvider.mockBuildScriptType
};

constructor(private workspaceRoot: string) { }
constructor(private workspaceRoot: string) {
logs.appendLine("Oneline")
logs.show(true);
}

public async provideTasks(): Promise<vscode.Task[]> {
return this.getTasks();
Expand All @@ -30,26 +28,45 @@ export class mockBuildTaskProvider implements vscode.TaskProvider {
}

private getTasks(): vscode.Task[] {
const settings = vscode.workspace.getConfiguration('rpmspecChangelog');

this.tasks = [];

let base = 40;
for (let i = 0; i < 3; i++) {
const task = this.getTask((base + i) + "");
console.log(base + i);
if (task instanceof vscode.Task) {
let oses: string[] = settings.get("mockOses") ?? [];
console.log("oses", oses);
if (oses!.length > 0) {
let cmd = "";
for (let i = 0; i < oses.length; i++) {
let os = oses[i];
let task: vscode.Task = this.getTask(os + "") as vscode.Task;
this.tasks!.push(task);
cmd += `mock -r ${os} --spec ` + '${file}' + ` --sources ~/rpmbuild/SOURCES '-D disable_source_fetch %nil';`
}
const termExec = new vscode.ShellExecution(cmd);
const allTask = new vscode.Task(this.definition, vscode.TaskScope.Workspace, `run mock: all`,
mockBuildTaskProvider.mockBuildScriptType, termExec);
this.tasks!.push(allTask);
} else {
let base = 40;
for (let i = 0; i < 3; i++) {
let task = this.getTask("fedora-" + (base + i) + "-x86_64");
console.log("fedora-" + (base + i) + "-x86_64");
if (task instanceof vscode.Task) {
this.tasks!.push(task);
}
}
}

return this.tasks;
}

private getTask(fversion: string): vscode.Task|undefined {
private getTask(os: string): vscode.Task | undefined {
logs.appendLine("OS: " + os);
if (!vscode.window.activeTextEditor?.document.fileName.endsWith(".spec")) {
return undefined;
}
const termExec = new vscode.ShellExecution(`echo "vers: ${fversion}"; mock -r fedora-${fversion}-x86_64 --spec ` + '${file}' + ` --sources ~/rpmbuild/SOURCES '-D disable_source_fetch %nil'`);
return new vscode.Task(this.definition, vscode.TaskScope.Workspace, `run mock fedora ${fversion}`,
const termExec = new vscode.ShellExecution(`echo "vers: ${os}"; mock -r ${os} --spec ` + '${file}' + ` --sources ~/rpmbuild/SOURCES '-D disable_source_fetch %nil'`);
return new vscode.Task(this.definition, vscode.TaskScope.Workspace, `run mock: ${os}`,
mockBuildTaskProvider.mockBuildScriptType, termExec);
}
}
Expand Down

0 comments on commit f281055

Please sign in to comment.