diff --git a/.gitignore b/.gitignore index 9cea682..9d9e4d9 100644 --- a/.gitignore +++ b/.gitignore @@ -17,4 +17,5 @@ resources/hdlParser/parser.wasm resources/dide-viewer/view/* resources/dide-lsp/server/* resources/dide-lsp/static/* -resources/dide-netlist/static/* \ No newline at end of file +resources/dide-netlist/static/* +resources/dide-netlist/view/* \ No newline at end of file diff --git a/script/__pycache__/util.cpython-38.pyc b/script/__pycache__/util.cpython-38.pyc deleted file mode 100644 index c4e7074..0000000 Binary files a/script/__pycache__/util.cpython-38.pyc and /dev/null differ diff --git a/script/.gitignore b/scripts/.gitignore similarity index 100% rename from script/.gitignore rename to scripts/.gitignore diff --git a/script/README.md b/scripts/README.md similarity index 100% rename from script/README.md rename to scripts/README.md diff --git a/script/build.bat b/scripts/build.bat similarity index 100% rename from script/build.bat rename to scripts/build.bat diff --git a/script/command/make_package.py b/scripts/command/make_package.py similarity index 93% rename from script/command/make_package.py rename to scripts/command/make_package.py index 60dc38b..4ee3468 100644 --- a/script/command/make_package.py +++ b/scripts/command/make_package.py @@ -65,16 +65,11 @@ def modify_vsix(): # move public copy_dir('./resources/public', os.path.join(extract_folder, 'extension', 'resources', 'public')) - - # move wasm - copy_dir('./resources/netlist/resources/kernel', os.path.join(extract_folder, 'extension', 'resources', 'kernel')) - # webview - copy_dir('./resources/netlist/view', os.path.join(extract_folder, 'extension', 'resources', 'netlist', 'view')) + copy_dir('./resources/dide-netlist/view', os.path.join(extract_folder, 'extension', 'resources', 'dide-netlist', 'view')) copy_dir('./resources/dide-viewer/view', os.path.join(extract_folder, 'extension', 'resources', 'dide-viewer', 'view')) - # remake target_path = os.path.join('dist', vsix_path) zip_dir(extract_folder, target_path) diff --git a/script/command/make_title_token.py b/scripts/command/make_title_token.py similarity index 100% rename from script/command/make_title_token.py rename to scripts/command/make_title_token.py diff --git a/script/command/pull-digital-lsp.py b/scripts/command/pull-digital-lsp.py similarity index 100% rename from script/command/pull-digital-lsp.py rename to scripts/command/pull-digital-lsp.py diff --git a/script/command/translate_from_en.py b/scripts/command/translate_from_en.py similarity index 100% rename from script/command/translate_from_en.py rename to scripts/command/translate_from_en.py diff --git a/script/util.py b/scripts/util.py similarity index 100% rename from script/util.py rename to scripts/util.py diff --git a/scripts/vscode-package.py b/scripts/vscode-package.py new file mode 100644 index 0000000..4ee3468 --- /dev/null +++ b/scripts/vscode-package.py @@ -0,0 +1,107 @@ +import os +import shutil +import zipfile +from colorama import Fore, Style +from typing import List, Union +from collections import namedtuple + +Command = namedtuple(typename='Command', field_names=['name', 'cmd']) + +class CommandPipe: + def __init__(self) -> None: + self.pipes: List[Command] = [] + + def add_command(self, name: str, cmd: str): + command = Command(name, cmd) + self.pipes.append(command) + + def run(self): + for i, p in enumerate(self.pipes): + progress = int((i + 1) / len(self.pipes) * 100) + space_prefix = ' ' if progress < 100 else '' + print(Fore.GREEN, f'[{space_prefix}{progress}%]', Style.RESET_ALL, p.name) + if callable(p.cmd): + p.cmd() + elif isinstance(p.cmd, str): + os.system(p.cmd) + print('Done! :D') + + +def remove_folder(name: str): + if os.path.exists(name): + shutil.rmtree(name) + +def copy_dir(src, dist): + if os.path.exists(dist): + shutil.rmtree(dist) + shutil.copytree(src, dist) + +def copy_file(src, dist): + if os.path.exists(dist): + os.remove(dist) + dirname = os.path.dirname(dist) + if not os.path.exists(dirname): + os.makedirs(dirname) + shutil.copyfile(src, dist) + +def modify_vsix(): + vsix_filter = filter(lambda file: file.endswith('.vsix'), os.listdir('.')) + vsix_file = list(vsix_filter) + if len(vsix_file) == 0: + print(Fore.RED, 'no .vsix is detected', Style.RESET_ALL) + exit() + vsix_path = vsix_file[0] + if not os.path.exists('dist'): + os.mkdir('dist') + + dist_path = os.path.join('dist', vsix_path.replace('.vsix', '.zip')) + shutil.move(vsix_path, dist_path) + + extract_folder = os.path.join('dist', 'digital-ide-temp') + with zipfile.ZipFile(dist_path, 'r') as zip_ref: + zip_ref.extractall(extract_folder) + + os.remove(dist_path) + + # move public + copy_dir('./resources/public', os.path.join(extract_folder, 'extension', 'resources', 'public')) + + # webview + copy_dir('./resources/dide-netlist/view', os.path.join(extract_folder, 'extension', 'resources', 'dide-netlist', 'view')) + copy_dir('./resources/dide-viewer/view', os.path.join(extract_folder, 'extension', 'resources', 'dide-viewer', 'view')) + + # remake + target_path = os.path.join('dist', vsix_path) + zip_dir(extract_folder, target_path) + + + +def zip_dir(dirpath, outFullName): + zip = zipfile.ZipFile(outFullName, "w", zipfile.ZIP_DEFLATED) + for path, _, filenames in os.walk(dirpath): + fpath = path.replace(dirpath, '') + for filename in filenames: + zip.write(os.path.join(path, filename), os.path.join(fpath, filename)) + zip.close() + +def install_extension(): + vsix_filter = filter(lambda file: file.endswith('.vsix'), os.listdir('dist')) + vsix_files = list(vsix_filter) + if len(vsix_files) == 0: + print(Fore.RED, 'no .vsix is detected in dist', Style.RESET_ALL) + exit() + + vsix_path = os.path.join('dist', vsix_files[0]) + os.system('code --install-extension ' + vsix_path) + +pipe = CommandPipe() +pipe.add_command('uninstall original extension', 'code --uninstall-extension sterben.fpga-support') +pipe.add_command('compile typescript', 'tsc -p ./ --outDir out-js') +pipe.add_command('webpack', 'webpack --mode production') +pipe.add_command('make vsix installer', 'vsce package') +pipe.add_command('modify vsix installer', lambda : modify_vsix()) +pipe.add_command('remove out-js', lambda : remove_folder('out-js')) +pipe.add_command('remove out', lambda : remove_folder('out')) +pipe.add_command('install', lambda : install_extension()) + +pipe.run() \ No newline at end of file diff --git a/src/function/netlist/index.ts b/src/function/dide-netlist/index.ts similarity index 85% rename from src/function/netlist/index.ts rename to src/function/dide-netlist/index.ts index ff3b401..791a447 100644 --- a/src/function/netlist/index.ts +++ b/src/function/dide-netlist/index.ts @@ -10,6 +10,8 @@ import { defaultMacro, doFastApi } from '../../hdlParser/util'; import { HdlFile } from '../../hdlParser/core'; import { t } from '../../i18n'; import { HdlLangID } from '../../global/enum'; +import { getIconConfig } from '../../hdlFs/icons'; +import { PathSet } from '../../global/util'; type SynthMode = 'before' | 'after' | 'RTL'; @@ -28,7 +30,7 @@ class Netlist { } public async open(uri: vscode.Uri, moduleName: string) { - const prjFiles = []; + const pathset = new PathSet(); const path = hdlPath.toSlash(uri.fsPath); let moduleFile = hdlParam.getHdlFile(path); @@ -58,12 +60,13 @@ class Netlist { const hdlDependence = hdlParam.getAllDependences(path, hdlModule.name); if (hdlDependence) { // include 宏在后续会被正确处理,所以只需要处理 others 即可 - prjFiles.push(...hdlDependence.others); + hdlDependence.others.forEach(path => pathset.add(path)); } } - prjFiles.push(path); + pathset.add(path); + + const prjFiles = [...pathset.files]; - console.log('enter', moduleName); console.log(prjFiles); console.log(opeParam.prjInfo.prjPath); @@ -95,6 +98,8 @@ class Netlist { }); const exitCode = wasi.start(instance); }); + + this.create(moduleName); } private getSynthMode(): SynthMode { @@ -145,11 +150,11 @@ class Netlist { private makeWasi(target: string) { // 创建日志文件路径 - const logFilePath = hdlPath.join(opeParam.workspacePath, 'wasi_log.txt'); - hdlFile.removeFile(logFilePath); - + // const logFilePath = hdlPath.join(opeParam.workspacePath, 'wasi_log.txt'); + // hdlFile.removeFile(logFilePath); // 创建可写流,将标准输出和标准错误重定向到日志文件 - const logFd = fs.openSync(logFilePath, 'a'); + // const logFd = fs.openSync(logFilePath, 'a'); + return new WASI({ version: 'preview1', args: [ @@ -163,8 +168,10 @@ class Netlist { ['/' + this.libName]: opeParam.prjInfo.libCommonPath }, stdin: process.stdin.fd, - stdout: logFd, - stderr: logFd, + stdout: process.stdout.fd, + stderr: process.stderr.fd, + // stdout: logFd, + // stderr: logFd, env: process.env }); } @@ -180,7 +187,7 @@ class Netlist { return wasm; } - private create() { + private create(moduleName: string) { // Create panel this.panel = vscode.window.createWebviewPanel( 'Netlist', @@ -205,7 +212,21 @@ class Netlist { const previewHtml = this.getWebviewContent(); if (this.panel && previewHtml) { - this.panel.webview.html = previewHtml; + const netlistPath = hdlPath.join(opeParam.extensionPath, 'resources', 'dide-netlist', 'view'); + const netlistPayloadFolder = hdlPath.join(opeParam.prjInfo.prjPath, 'netlist'); + const targetJson = hdlPath.join(netlistPayloadFolder, moduleName + '.json'); + const skinPath= hdlPath.join(netlistPath, 'dide.skin'); + + const graph = this.panel.webview.asWebviewUri(vscode.Uri.file(targetJson)).toString(); + const skin = this.panel.webview.asWebviewUri(vscode.Uri.file(skinPath)).toString(); + this.panel.iconPath = getIconConfig('view'); + + let preprocessHtml = previewHtml + .replace('test.json', graph) + .replace('test.module', moduleName) + .replace('dide.skin', skin); + + this.panel.webview.html = preprocessHtml; } else { YosysOutput.report('preview html in is empty', { level: ReportType.Warn @@ -218,7 +239,7 @@ class Netlist { } public getWebviewContent() { - const netlistPath = hdlPath.join(opeParam.extensionPath, 'resources', 'netlist', 'view'); + const netlistPath = hdlPath.join(opeParam.extensionPath, 'resources', 'dide-netlist', 'view'); const htmlIndexPath = hdlPath.join(netlistPath, 'index.html'); const html = hdlFile.readFile(htmlIndexPath)?.replace(/( { diff --git a/src/function/dide-viewer/index.ts b/src/function/dide-viewer/index.ts index 8f0cee0..1cb46d4 100644 --- a/src/function/dide-viewer/index.ts +++ b/src/function/dide-viewer/index.ts @@ -222,7 +222,7 @@ function getViewLaunchFiles(context: vscode.ExtensionContext, uri: vscode.Uri, p return { vcd, view, wasm, vcdjs, worker, root }; } else if (entryPath.endsWith('.view')) { const buffer = fs.readFileSync(entryPath); - const recoverJson = BSON.deserialize(buffer); + const recoverJson = BSON.deserialize(new Uint8Array(buffer)); if (recoverJson.originVcdFile) { const vcdPath = recoverJson.originVcdFile; if (!fs.existsSync(vcdPath)) { diff --git a/src/function/index.ts b/src/function/index.ts index fbaa2b1..5d28282 100644 --- a/src/function/index.ts +++ b/src/function/index.ts @@ -13,7 +13,7 @@ import * as tool from './tool'; // special function import * as FSM from './fsm'; -import * as Netlist from './netlist'; +import * as Netlist from './dide-netlist'; import * as WaveView from './dide-viewer'; import { ModuleDataItem } from './treeView/tree'; import { downloadLsp } from './lsp-client';