Skip to content

Add the possibility to have seperate manifests for different projects #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
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
20 changes: 17 additions & 3 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,25 @@
"@typescript-eslint"
],
"rules": {
"@typescript-eslint/naming-convention": "warn",
"@typescript-eslint/naming-convention": [
"warn",
{
"selector": "import",
"format": [
"camelCase",
"PascalCase"
]
}
],
"@typescript-eslint/semi": "warn",
"curly": "warn",
"eqeqeq": "warn",
"no-throw-literal": "warn",
"semi": "off"
}
}
},
"ignorePatterns": [
"out",
"dist",
"**/*.d.ts"
]
}
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v16.13.1
v20.11.0
5 changes: 3 additions & 2 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"dbaeumer.vscode-eslint"
"dbaeumer.vscode-eslint",
"ms-vscode.extension-test-runner"
]
}
}
38 changes: 23 additions & 15 deletions manifest/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,22 @@
{
"name": "ninja",
"filename": "ninja-win.zip",
"url": "https://github.com/ninja-build/ninja/releases/download/v1.10.2/ninja-win.zip",
"md5": "8dad6a63141d57aae277e68ef7658ca1"
"url": "https://github.com/ninja-build/ninja/releases/download/v1.11.1/ninja-win.zip",
"md5": "5c2f60f4a984a65602b6e6cb93eae367"
},
{
"name": "cmake",
"filename": "cmake-3.22.0-windows-x86_64.zip",
"url": "https://github.com/Kitware/CMake/releases/download/v3.22.0/cmake-3.22.0-windows-x86_64.zip",
"md5": "1a273903dcb295455b69af7c9c10efa2",
"suffix": "cmake-3.22.0-windows-x86_64\\bin\\"
"url": "https://github.com/Kitware/CMake/releases/download/v3.28.3/cmake-3.28.3-windows-x86_64.zip",
"md5": "f60735981d24d6f6d327fec6ac57d371",
"suffix": "cmake-3.28.3-windows-x86_64\\bin\\"
},
{
"name": "toolchain",
"filename": "zephyr-sdk-0.15.1_windows-x86_64_minimal.zip",
"url": "https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.15.1/zephyr-sdk-0.15.1_windows-x86_64_minimal.zip",
"md5": "4c73427373995d1ac53412383a2f6610",
"suffix": "zephyr-sdk-0.15.1\\arm-zephyr-eabi\\bin\\",
"filename": "zephyr-sdk-0.16.5_windows-x86_64_minimal.7z",
"url": "https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.16.5/zephyr-sdk-0.16.5_windows-x86_64_minimal.7z",
"md5": "37d76b698e5ddc47b01c9faa3d781f94",
"suffix": "zephyr-sdk-0.16.5\\arm-zephyr-eabi\\bin\\",
"env": [
{
"name": "ZEPHYR_TOOLCHAIN_VARIANT",
Expand All @@ -44,20 +44,28 @@
},
{
"name": "ZEPHYR_SDK_INSTALL_DIR",
"suffix": "zephyr-sdk-0.15.1",
"suffix": "zephyr-sdk-0.16.5",
"usepath": true,
"append": false
}
]
},
{
"name": "toolchain",
"filename": "toolchain_windows-x86_64_arm-zephyr-eabi.zip",
"url": "https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.15.1/toolchain_windows-x86_64_arm-zephyr-eabi.zip",
"md5": "1786d58c03f3e380d683b1e5ded45131",
"suffix": "zephyr-sdk-0.15.1\\arm-zephyr-eabi\\bin\\",
"filename": "toolchain_windows-x86_64_arm-zephyr-eabi.7z",
"url": "https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.16.5/toolchain_windows-x86_64_arm-zephyr-eabi.7z",
"md5": "94ee641b3f8edb8e5ae4fa60783e43ab",
"suffix": "zephyr-sdk-0.16.5\\arm-zephyr-eabi\\bin\\",
"clear_target": false,
"copy_to_subfolder": "zephyr-sdk-0.15.1"
"copy_to_subfolder": "zephyr-sdk-0.16.5"
},
{
"name": "toolchain",
"filename": "xpack-openocd-0.12.0-2-win32-x64.zip",
"url": "https://github.com/xpack-dev-tools/openocd-xpack/releases/download/v0.12.0-2/xpack-openocd-0.12.0-2-win32-x64.zip",
"md5": "db724ce414f8cb0e310a92add00be6a9",
"suffix": "xpack-openocd-0.12.0-2\\bin\\",
"clear_target": false
}
]
}
Expand Down
34 changes: 18 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
"name": "zephyr-tools",
"displayName": "Circuit Dojo Zephyr SDK Tools",
"description": "Used for building your Zephyr projects.",
"version": "0.1.33",
"version": "0.2.0",
"license": "Apache-2.0",
"publisher": "circuitdojo",
"icon": "img/bulb.png",
"engines": {
"vscode": "^1.52.0",
"vscode": "^1.86.0",
"node": ">=16"
},
"repository": {
Expand Down Expand Up @@ -114,23 +114,25 @@
"test": "node ./out/test/runTest.js"
},
"devDependencies": {
"@types/fs-extra": "^8.0.1",
"@types/glob": "^7.1.3",
"@types/mocha": "^8.0.4",
"@types/node": "^12.11.7",
"@types/vscode": "^1.52.0",
"@typescript-eslint/eslint-plugin": "^4.9.0",
"@typescript-eslint/parser": "^4.9.0",
"eslint": "^7.15.0",
"glob": "^7.1.6",
"mocha": "^8.1.3",
"typescript": "^4.1.2",
"vscode-test": "^1.4.1"
"@types/fs-extra": "^11.0.4",
"@types/mocha": "^10.0.6",
"@types/node": "20.11.16",
"@types/node-7z": "^2.1.8",
"@types/vscode": "^1.86.0",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",
"eslint": "^8.56.0",
"glob": "^10.3.10",
"mocha": "^10.2.0",
"typescript": "^5.3.3",
"vscode-test": "^1.6.1"
},
"dependencies": {
"fs-extra": "^10.0.0",
"fs-extra": "^11.2.0",
"node-stream-zip": "^1.15.0",
"typed-rest-client": "^1.8.6"
"typed-rest-client": "^1.8.11",
"node-7z": "^3.0.0",
"7zip-bin": "^5.2.0"
},
"extensionPack": [
"ms-vscode.cpptools",
Expand Down
45 changes: 31 additions & 14 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import * as os from 'os';
import * as fs from 'fs-extra';
import * as path from 'path';
import * as unzip from 'node-stream-zip';
import sevenBin from '7zip-bin';
import { extractFull } from 'node-7z';

import { TaskManager } from './taskmanager';
import { FileDownload } from './download';
Expand Down Expand Up @@ -56,9 +58,6 @@ type Manifest = {
linux: ManifestEntry[];
};

// Manifest data
const manifest: Manifest = require("../manifest/manifest.json");

// Platform
let platform: NodeJS.Platform = os.platform();

Expand Down Expand Up @@ -90,6 +89,9 @@ let baudlist = [
// Important directories
let toolsdir = path.join(os.homedir(), toolsfoldername);

// Manifest data
let manifest: Manifest = require(helper.find_file("manifest.json"));

// Project specific configuration
export interface ProjectConfig {
board?: string;
Expand Down Expand Up @@ -134,13 +136,15 @@ export async function activate(context: vscode.ExtensionContext) {
}

// Create new
context.subscriptions.push(vscode.commands.registerCommand('zephyr-tools.create-project', async (dest: vscode.Uri | undefined) => { await commands.create_new(context, config, dest) }));
context.subscriptions.push(vscode.commands.registerCommand('zephyr-tools.create-project', async (dest: vscode.Uri | undefined) => { await commands.create_new(context, config, dest); }));

// The command has been defined in the package.json file
// Now provide the implementation of the command with registerCommand
// The commandId parameter must match the command field in package.json
context.subscriptions.push(vscode.commands.registerCommand('zephyr-tools.setup', async () => {

manifest = require(helper.find_file("manifest.json"));

// Reset "zephyr.env"
context.globalState.update("zephyr.task", undefined);
context.globalState.update("zephyr.env", undefined);
Expand Down Expand Up @@ -169,13 +173,15 @@ export async function activate(context: vscode.ExtensionContext) {
output.clear();
output.show();

helper.create_dir_if_not_exist(toolsdir);

// check if directory in $HOME exists
let exists = await fs.pathExists(toolsdir);
if (!exists) {
console.log("toolsdir not found");
// Otherwise create home directory
await fs.mkdirp(toolsdir);
}
//let exists = await fs.pathExists(toolsdir);
//if (!exists) {
// console.log("toolsdir not found");
// // Otherwise create home directory
// await fs.mkdirp(toolsdir);
//}

// Promisified exec
let exec = util.promisify(cp.exec);
Expand Down Expand Up @@ -248,8 +254,19 @@ export async function activate(context: vscode.ExtensionContext) {
await zip.extract(null, copytopath);
await zip.close();

} else if (download.url.includes("7z")) {

// Unzip and copy
output.appendLine(`[SETUP] 7z extract ${filepath} to ${copytopath}`);

const pathTo7zip = sevenBin.path7za;
const seven = extractFull(filepath, copytopath, {
$bin: pathTo7zip
});

} else if (download.url.includes("tar")) {

helper.create_dir_if_not_exist(copytopath);
// Then untar
const cmd = `tar -xvf "${filepath}" -C "${copytopath}"`;
output.appendLine(cmd);
Expand Down Expand Up @@ -549,7 +566,7 @@ export async function activate(context: vscode.ExtensionContext) {
let dest = await helper.get_dest(_dest);

// See if config is set first
if (config.isSetup && dest != null) {
if (config.isSetup && dest !== null) {
initRepo(config, context, dest);
} else {
vscode.window.showErrorMessage('Run `Zephyr Tools: Setup` command first.');
Expand Down Expand Up @@ -1097,7 +1114,7 @@ export async function initRepo(config: GlobalConfig, context: vscode.ExtensionCo
let branch = await vscode.window.showInputBox(branchInputOptions);

// TODO: determine choices for west.yml
let manifest = "west.yml"
let manifest = "west.yml";

// git clone to destination
let cmd = `west init -m ${url} --mf ${manifest}`;
Expand Down Expand Up @@ -1275,7 +1292,7 @@ async function load(config: GlobalConfig, project: ProjectConfig) {
}

// Put device into BL mode automagically
if (project.board == "circuitdojo_feather_nrf9160_ns") {
if (project.board === "circuitdojo_feather_nrf9160_ns") {
let cmd = `zephyr-tools -b`;
let exec = new vscode.ShellExecution(cmd, options);

Expand Down Expand Up @@ -1596,7 +1613,7 @@ async function changeBoard(config: GlobalConfig, context: vscode.ExtensionContex
let files = await vscode.workspace.fs.readDirectory(rootPath);
for (const [index, [file, type]] of files.entries()) {

if (type == vscode.FileType.Directory) {
if (type === vscode.FileType.Directory) {
// Get boards
let boardsDir = vscode.Uri.joinPath(rootPath, `${file}/boards`);

Expand Down
40 changes: 39 additions & 1 deletion src/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as os from 'os';
import * as fs from 'fs-extra';
import * as path from 'path';
import * as unzip from 'node-stream-zip';
import { fileURLToPath } from 'url';

export async function get_dest(_dest: vscode.Uri | undefined): Promise<vscode.Uri | null> {

Expand Down Expand Up @@ -35,4 +36,41 @@ export async function get_dest(_dest: vscode.Uri | undefined): Promise<vscode.Ur
}

return dest;
}
}

function checkFileExistsSync(filepath: string) {
let flag = true;
try {
fs.accessSync(filepath, fs.constants.F_OK);
} catch (e) {
flag = false;
}
return flag;
}

export function create_dir_if_not_exist(directory: string): void {
// check if directory in $HOME exists
let exists = fs.pathExistsSync(directory);
if (!exists) {
console.log('${directory} not found -> created');
// Otherwise create home directory
fs.mkdirpSync(directory);
}
}

export function find_file(file: string): string {
let sources = ["../manifest", path.join(os.homedir(), ".zephyrtools")];

if (vscode.workspace.workspaceFolders) {
sources.push(path.join(vscode.workspace.workspaceFolders[0].uri.fsPath, "app"));
}

for (let index = sources.length; index > 0; index--) {
let fullpath = path.join(sources[index - 1], file);
if (checkFileExistsSync(fullpath)) {
return fullpath;
}
}

return path.join(sources[0], file);
}
10 changes: 6 additions & 4 deletions src/test/suite/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import * as path from 'path';
import * as Mocha from 'mocha';
import Mocha from 'mocha';
import * as glob from 'glob';


export function run(): Promise<void> {
// Create the mocha test
const mocha = new Mocha({
Expand All @@ -12,13 +13,13 @@ export function run(): Promise<void> {
const testsRoot = path.resolve(__dirname, '..');

return new Promise((c, e) => {
glob('**/**.test.js', { cwd: testsRoot }, (err, files) => {
glob.glob('**/**.test.js', { cwd: testsRoot }).catch(err => {
if (err) {
return e(err);
}

}).then(files => {
// Add files to the test suite
files.forEach(f => mocha.addFile(path.resolve(testsRoot, f)));
files?.forEach(f => mocha.addFile(path.resolve(testsRoot, f)));

try {
// Run the mocha test
Expand All @@ -36,3 +37,4 @@ export function run(): Promise<void> {
});
});
}

Loading