diff --git a/src/vscode_plugin/src/extension.ts b/src/vscode_plugin/src/extension.ts index 216f0b5bb7d3bc303fcdd699c303e43860a7d999..16cdcf94ce9e501817e73cb88178b8a2fe8238e4 100644 --- a/src/vscode_plugin/src/extension.ts +++ b/src/vscode_plugin/src/extension.ts @@ -36,7 +36,7 @@ import { Dts2cppCtrl } from './controller/dts2cppctrl'; import { WelcomeCtrl } from './controller/welcomectrl'; import { Logger } from './common/log'; -// ��ȡ���ػ��ַ��� +// 获取本地化字符串 const SELECTED_DIR = vscode.l10n.t('You selected a directory:'); const SELECTE_DIR = vscode.l10n.t('Please select a directory.'); const NO_RES_SELECTED = vscode.l10n.t('No resource selected.'); @@ -55,6 +55,7 @@ const GEN_COMPLETE = vscode.l10n.t('Generation complete:'); const OPEN_IN_EXPLORER = vscode.l10n.t('Open in Explorer'); const PICK_MAKE = vscode.l10n.t('Use Makefile for compilation.'); const PICK_CMAKE = vscode.l10n.t('Use CMakeLists.txt for compilation.'); +const PICK_CONFIGURE = vscode.l10n.t('Use configure script for compilation.'); const TOOL_PICK_PLACEHOLDER = vscode.l10n.t('Please select the way you want to compile: '); const OH_CROSS_COMPILE_TITLE = vscode.l10n.t('OpenHarmony Cross Compile'); const COMPILATION_METHOD_LOST = vscode.l10n.t('Unable to comfirm the compilation method, compilation aborted.'); @@ -108,16 +109,22 @@ export function activate(context: vscode.ExtensionContext) { } const canCmake = fs.existsSync(thirdPartyPath.concat("/CMakeLists.txt")); const canMake = fs.existsSync(thirdPartyPath.concat("/GNUmakefile")) || fs.existsSync(thirdPartyPath.concat("/Makefile")) || fs.existsSync(thirdPartyPath.concat("/makefile")); - if (canCmake || canMake) { //�����⵽CMakeLists.txt��makefile������Լ��� - - - // ��û�в���ļ��С���װ�ļ��У��򴴽������Զ���ȡ����װĿ¼ + let canConfigure: boolean; + if (platform === "win32") { + canConfigure = false; + } else { + canConfigure = fs.existsSync(thirdPartyPath.concat("/configure")); + } + + // 如果检测到CMakeLists.txt或makefile或configure脚本,则可以继续 + if (canCmake || canMake || canConfigure) { + // 若没有插件文件夹、安装文件夹,则创建。可自动获取到安装目录 const ohCrossCompilePath = thirdPartyPath.concat("/ohCrossCompile"); if (!fs.existsSync(ohCrossCompilePath)) { fs.mkdirSync(ohCrossCompilePath); } - - // ��û�������ļ�������Ĭ�����ô��������ļ� + + // 若没有配置文件,则以默认配置创建配置文件 const configPath = ohCrossCompilePath.concat("/config.json") if (!fs.existsSync(configPath)) { const defaultConfig = { @@ -147,21 +154,34 @@ export function activate(context: vscode.ExtensionContext) { fs.writeFileSync(configPath, JSON.stringify(defaultConfig, null, 4), 'utf8'); } - // ��ȡ���뷽ʽ��make����cmake - if (configContent.settings.compileTool !== undefined && (configContent.settings.compileTool === "make" || configContent.settings.compileTool === "cmake")) { //��������ļ����Ѿ��洢���뷽ʽ������ + // 获取编译方式是make还是cmake还是configure + if (configContent.settings.compileTool !== undefined && (configContent.settings.compileTool === "make" || configContent.settings.compileTool === "cmake" || configContent.settings.compileTool === "configure")) { + //如果配置文件中已经存储编译方式,则获得 compileTool = configContent.settings.compileTool; - } else if (canCmake && canMake) { //���Զ��жϳ�make��cmake����ʹ�ã���ѯ���û������洢��� - - const toolPickItems = [ - { + } else if (canMake ? (canCmake || canConfigure) : (canCmake && canConfigure)) { + // 若有两个或两个以上的可选编译方式,则询问用户,并存储结果 + let toolPickItems: { + label: string; + description: string; + }[] = []; + if (canMake) { + toolPickItems.push({ label: "make", description: PICK_MAKE - }, - { + }); + } + if (canCmake) { + toolPickItems.push({ label: "cmake", description: PICK_CMAKE - } - ]; + }); + } + if (canConfigure) { + toolPickItems.push({ + label: "configure", + description: PICK_CONFIGURE + }); + } const toolPickOptions = { canPickMany: false, ignoreFocusOut: true, @@ -178,19 +198,27 @@ export function activate(context: vscode.ExtensionContext) { vscode.window.showInformationMessage(COMPILATION_METHOD_LOST); return; } - } else if (canCmake) { //���Զ��жϳ�ֻ����ʹ��cmake + } else if (canCmake) { + // 若自动判断出只可以使用cmake compileTool = "cmake"; configContent.settings.compileTool = "cmake"; fs.writeFileSync(configPath, JSON.stringify(configContent, null, 4), 'utf8'); - } else { //���Զ��жϳ�ֻ����ʹ��make + } else if (canMake) { + // 若自动判断出只可以使用make compileTool = "make"; configContent.settings.compileTool = "make"; fs.writeFileSync(configPath, JSON.stringify(configContent, null, 4), 'utf8'); + } else { + // 若自动判断出只可以使用configure + compileTool = "configure"; + configContent.settings.compileTool = "configure"; + fs.writeFileSync(configPath, JSON.stringify(configContent, null, 4), 'utf8'); } - // ȷ��Ҫ�����CPU�ܹ�����װ�ļ������������򴴽� - if (configContent.settings.ohArchitecture === undefined || configContent.settings.ohArchitecture.length === 0) { //�����������ļ��޷�ȷ��CPU�ܹ���������ѯ���û� + // 确认要编译的CPU架构。安装文件夹若不存在则创建 + if (configContent.settings.ohArchitecture === undefined || configContent.settings.ohArchitecture.length === 0) { + // 若根据配置文件无法确定CPU架构参数,则询问用户 const archPickItems = [ { label: "arm64-v8a", @@ -208,7 +236,8 @@ export function activate(context: vscode.ExtensionContext) { title: OH_CROSS_COMPILE_TITLE }; const archPick = await vscode.window.showQuickPick(archPickItems, archPickOptions) - if (archPick && Array.isArray(archPick) && archPick.length > 0) { //����û�ѡ�����Ϣ�������������ļ� + if (archPick && Array.isArray(archPick) && archPick.length > 0) { + // 获得用户选择的信息,并存入配置文件 for (let item of archPick) { let arch = item.label; ohArchitecture.push(arch); @@ -247,10 +276,10 @@ export function activate(context: vscode.ExtensionContext) { } - // ȷ��sdk��native���ߵ�·�� - if (configContent.settings.nativePath === undefined || configContent.settings.nativePath === "") { //ѯ���û� + // 确认sdk中native工具的路径 + if (configContent.settings.nativePath === undefined || configContent.settings.nativePath === "") { - // ȷ��sdk��Դ�DZ��ػ������� + // 询问用户。确认sdk来源是本地还是下载 const sourcePickItems = [ { label: LOCAL, @@ -270,7 +299,8 @@ export function activate(context: vscode.ExtensionContext) { const sourcePick = await vscode.window.showQuickPick(sourcePickItems, sourcePickOptions); if (sourcePick) { - if (sourcePick.label === LOCAL) { //��sdk��ԴΪ���أ���ѯ���û�native���ڵľ���·����������Ƿ�Ϸ� + // 若sdk来源为本地,则询问用户native所在的具体路径,并检查是否合法 + if (sourcePick.label === LOCAL) { const folderUri = await vscode.window.showOpenDialog({ canSelectMany: false, canSelectFolders: true, @@ -286,7 +316,7 @@ export function activate(context: vscode.ExtensionContext) { configContent.settings.nativePath = folderPath; fs.writeFileSync(configPath, JSON.stringify(configContent, null, 4), 'utf8'); - // ִ�б������� + // 执行编译命令 crossCompile(platform, undefined, configPath, thirdPartyPath, compileTool, ohArchitecture, nativePath, ohCrossCompilePath); } else { vscode.window.showInformationMessage(NATIVE_CHECK_FAILED); @@ -296,8 +326,9 @@ export function activate(context: vscode.ExtensionContext) { vscode.window.showInformationMessage(FOLDER_LOST); return; } - } else if (sourcePick.label === DOWNLOAD) { //��sdk��ԴΪ���磬��ѯ�����ذ汾������·�������ز���ѹsdk - // ��ȡ���ذ汾���Ӷ������������ + } else if (sourcePick.label === DOWNLOAD) { + // 若sdk来源为网络,则询问下载版本与下载路径,下载并解压sdk + // 获取下载版本,从而获得下载链接 const versionPickItems = [ { label: API9_LABEL, @@ -345,7 +376,7 @@ export function activate(context: vscode.ExtensionContext) { break; } - // ѯ������·�� + // 询问下载路径 const folderUri = await vscode.window.showOpenDialog({ canSelectMany: false, canSelectFolders: true, @@ -358,7 +389,7 @@ export function activate(context: vscode.ExtensionContext) { } let filePath = folderPath.concat("/ohos-sdk-windows_linux-public.tar.gz"); - // ���ز���ѹsdk�е�native + // 下载并解压sdk中的native await vscode.window.withProgress({ location: vscode.ProgressLocation.Notification, title: DOWNLOADING_TITLE, @@ -367,25 +398,28 @@ export function activate(context: vscode.ExtensionContext) { progress.report({ increment: 0, message: DOWNLOADING_START }); await downloadSdk(downloadLink, filePath, progress); vscode.window.showInformationMessage(vscode.l10n.t('SDK downloaded to: {0}', filePath)); - // vscode.window.showInformationMessage(`SDK downloaded to: ${filePath}`); - // ��ѹsdk�е�native����ƴװnativePath + // 解压sdk中的native,并拼装nativePath progress.report({ increment: 10, message: DOWNLOADING_COMPLETE }); await extractTarGz(filePath, folderPath); progress.report({ increment: 100, message: SDK_INSTALLED }); nativePath = folderPath; - if (apiVersion !== API12_LABEL) { //api12�汾·����û��ohos-sdk��9-11�汾���� + if (apiVersion !== API12_LABEL) { + // api12版本路径中没有ohos-sdk;9-11版本则有 nativePath = nativePath.concat("/ohos-sdk"); } if (platform === "win32") { - nativePath = nativePath.concat("/windows"); //windowsϵͳ�µ�nativePath·�� + // windows系统下的nativePath路径 + nativePath = nativePath.concat("/windows"); } else { - nativePath = nativePath.concat("/linux"); //linuxϵͳ�µ�nativePath·�� + // linux系统下的nativePath路径 + nativePath = nativePath.concat("/linux"); } for (const file of await fs.promises.readdir(nativePath)) { if (file.startsWith("native")) { - filePath = nativePath.concat("/" + file); //��ȡnativeѹ�������ļ�·�� + // 获取native压缩包的文件路径 + filePath = nativePath.concat("/" + file); } } Logger.getInstance().debug(filePath); @@ -396,7 +430,7 @@ export function activate(context: vscode.ExtensionContext) { configContent.settings.nativePath = nativePath; fs.writeFileSync(configPath, JSON.stringify(configContent, null, 4), 'utf8'); - // ִ�б������� + // 执行编译命令 crossCompile(platform, terminal, configPath, thirdPartyPath, compileTool, ohArchitecture, nativePath, ohCrossCompilePath); }); } else { @@ -412,19 +446,22 @@ export function activate(context: vscode.ExtensionContext) { vscode.window.showInformationMessage(SDK_SOURCE_LOST); return; } - } else { //�����ļ���nativePath�ǿգ���������ļ��л�ȡ + } else { + // 配置文件中nativePath非空,则从配置文件中获取 if (checkNative(platform, configContent.settings.nativePath)) { nativePath = configContent.settings.nativePath; - // ִ�б������� + // 执行编译命令 crossCompile(platform, undefined, configPath, thirdPartyPath, compileTool, ohArchitecture, nativePath, ohCrossCompilePath); - } else { //�������ļ��л�ȡ��nativePath�Ƿ��������ã�����ʾ + } else { + // 从配置文件中获取的nativePath非法,则重置,并提示 configContent.settings.nativePath = ""; fs.writeFileSync(configPath, JSON.stringify(configContent, null, 4), 'utf8'); vscode.window.showInformationMessage(NATIVE_CHECK_FAILED); return; } } - } else { //�û���ѡ�ļ��в���CMakeLists.ext��Makefile + } else { + // 用户所选文件夹不含CMakeLists.ext、Makefile、configure vscode.window.showErrorMessage(CMAKE_MAKE_LOST); } } @@ -451,7 +488,7 @@ export function activate(context: vscode.ExtensionContext) { // } // const serviceId = await vscode.window.showInputBox({ // placeHolder: INPUT_SERVICEID, - // value: "19000", // ����Ĭ��ֵ + // value: "19000", // 设置默认值 // validateInput: (input) => { // if (!input) { // return INPUT_NO_EMPTY; diff --git a/src/vscode_plugin/src/l10n/bundle.l10n.zh-cn.json b/src/vscode_plugin/src/l10n/bundle.l10n.zh-cn.json index 78f92867253b43343023a678f465980bfe44881e..06e2b5d2563814683a5bf9311d6a5d1741c6cb58 100644 --- a/src/vscode_plugin/src/l10n/bundle.l10n.zh-cn.json +++ b/src/vscode_plugin/src/l10n/bundle.l10n.zh-cn.json @@ -17,6 +17,7 @@ "No resource selected.": "未选择资源", "Use Makefile for compilation.": "根据 Makefile 交叉编译", "Use CMakeLists.txt for compilation.": "根据 CMakeLists.txt 交叉编译", + "Use configure script for compilation.": "根据 configure 脚本交叉编译", "Please select the way you want to compile: ": "请选择编译方式:", "OpenHarmony Cross Compile": "OpenHarmony 交叉编译", "Unable to comfirm the compilation method, compilation aborted.": "无法确认编译方式,编译过程终止", diff --git a/src/vscode_plugin/src/ohcrosscompile.ts b/src/vscode_plugin/src/ohcrosscompile.ts index 1b0d31998f2dcf770cd025626611ba9caf15d6cb..5120e720fb3dfb10ab1a9371f1b6ecb18f4df018 100644 --- a/src/vscode_plugin/src/ohcrosscompile.ts +++ b/src/vscode_plugin/src/ohcrosscompile.ts @@ -194,10 +194,13 @@ function crossCompile_win32(terminal: vscode.Terminal | undefined, thirdPartyPat }); } else if (action.compileTool === "make") { let target: string; + let ld: string; if (action.ohArchitecture === "arm64-v8a") { target = "aarch64-linux-ohos"; + ld = "ld64.lld.exe"; } else { target = "arm-linux-ohos"; + ld = "ld.lld.exe"; } commands.push({ command: `cd ${action.cwd}`, @@ -213,8 +216,11 @@ function crossCompile_win32(terminal: vscode.Terminal | undefined, thirdPartyPat command: "mingw32-make", arguments: [ `CC=\"${action.nativePath}/llvm/bin/clang.exe --target=${target}\"`, + `LD=${action.nativePath}/llvm/bin/${ld}`, `AR=${action.nativePath}/llvm/bin/llvm-ar.exe`, - `RANDLIB=${action.nativePath}/llvm/bin/llvm-ranlib.exe` + `AS=${action.nativePath}/llvm/bin/llvm-as.exe`, + `RANDLIB=${action.nativePath}/llvm/bin/llvm-ranlib.exe`, + `STRIP=${action.nativePath}/llvm/bin/llvm-strip.exe` ] }); commands.push({ @@ -321,10 +327,13 @@ function crossCompile_linux(terminal: vscode.Terminal | undefined, thirdPartyPat }); } else if (action.compileTool === "make") { let target: string; + let ld: string; if (action.ohArchitecture === "arm64-v8a") { target = "aarch64-linux-ohos"; + ld = "ld64.lld"; } else { target = "arm-linux-ohos"; + ld = "ld.lld"; } commands.push({ command: `cd ${action.cwd}`, @@ -340,8 +349,11 @@ function crossCompile_linux(terminal: vscode.Terminal | undefined, thirdPartyPat command: "make", arguments: [ `CC=\"${action.nativePath}/llvm/bin/clang --target=${target}\"`, + `LD=${action.nativePath}/llvm/bin/${ld}`, `AR=${action.nativePath}/llvm/bin/llvm-ar`, - `RANDLIB=${action.nativePath}/llvm/bin/llvm-ranlib` + `AS=${action.nativePath}/llvm/bin/llvm-as`, + `RANDLIB=${action.nativePath}/llvm/bin/llvm-ranlib`, + `STRIP=${action.nativePath}/llvm/bin/llvm-strip` ] }); commands.push({ @@ -350,6 +362,54 @@ function crossCompile_linux(terminal: vscode.Terminal | undefined, thirdPartyPat `PREFIX=${action.installPath}` ] }); + } else if (action.compileTool === "configure") { + let target: string; + let ld: string; + if (action.ohArchitecture === "arm64-v8a") { + target = "aarch64-linux-ohos"; + ld = "ld64.lld"; + } else { + target = "arm-linux-ohos"; + ld = "ld.lld"; + } + commands.push({ + command: `cd ${action.cwd}`, + arguments: [] + }); + if (ohArchitecture.length > 1) { + commands.push({ + command: "make clean", + arguments: [] + }); + } + commands.push({ + command: "./configure", + arguments: [ + `--host=${target}`, + `--prefix=${action.installPath}`, + + //针对libcoap库的编译选项 + // `--disable-documentation`, + // `--disable-dtls`, + + `CFLAGS=\"-pthread\"`, + `LDFLAGS=\"-pthread\"`, + `CC=\"${action.nativePath}/llvm/bin/clang --target=${target}\"`, + `LD=${action.nativePath}/llvm/bin/${ld}`, + `AR=${action.nativePath}/llvm/bin/llvm-ar`, + `AS=${action.nativePath}/llvm/bin/llvm-as`, + `RANDLIB=${action.nativePath}/llvm/bin/llvm-ranlib`, + `STRIP=${action.nativePath}/llvm/bin/llvm-strip` + ] + }); + commands.push({ + command: "make", + arguments: [] + }); + commands.push({ + command: "make install", + arguments: [] + }); } action.commands = commands; }