From ca13548ba0b59253955465da41cb2181d79b0699 Mon Sep 17 00:00:00 2001 From: Cyano Hao Date: Mon, 25 Sep 2023 10:15:07 +0800 Subject: [PATCH] Terminal arguments fix and cleanup (#138) * fix linux build error * Linux packaging: remove Alacritty from AppImage * limit APP_DIR trick to Windows only * implement Windows search path * fix terminal search --- RedPandaIDE/compiler/compilermanager.cpp | 2 +- RedPandaIDE/debugger.cpp | 2 +- RedPandaIDE/mainwindow.cpp | 6 ++--- RedPandaIDE/resources/terminal-unix.json | 10 -------- RedPandaIDE/resources/terminal-windows.json | 3 ++- RedPandaIDE/settings.cpp | 11 +++++++- RedPandaIDE/utils.cpp | 25 +++++++++++++++++++ packages/appimage/01-in-docker.sh | 3 --- .../appimage/dockerfile-aarch64/Dockerfile | 16 ------------ .../appimage/dockerfile-riscv64/Dockerfile | 16 ------------ .../appimage/dockerfile-x86_64/Dockerfile | 17 ------------- 11 files changed, 42 insertions(+), 69 deletions(-) diff --git a/RedPandaIDE/compiler/compilermanager.cpp b/RedPandaIDE/compiler/compilermanager.cpp index 8caab0e8..de40b2f2 100644 --- a/RedPandaIDE/compiler/compilermanager.cpp +++ b/RedPandaIDE/compiler/compilermanager.cpp @@ -325,7 +325,7 @@ void CompilerManager::run( } + splitProcessCommand(arguments); } auto [filename, args, fileOwner] = wrapCommandForTerminalEmulator( - pSettings->environment().terminalPathForExec(), + pSettings->environment().terminalPath(), pSettings->environment().terminalArgumentsPattern(), execArgs ); diff --git a/RedPandaIDE/debugger.cpp b/RedPandaIDE/debugger.cpp index d47625f7..bedfdeb2 100644 --- a/RedPandaIDE/debugger.cpp +++ b/RedPandaIDE/debugger.cpp @@ -3068,7 +3068,7 @@ void DebugTarget::run() cmd= mGDBServer; arguments = QString(" localhost:%1 \"%2\" %3").arg(mPort).arg(mInferior,mArguments); #else - cmd= pSettings->environment().terminalPathForExec(); + cmd= pSettings->environment().terminalPath(); arguments = QString(" -e \"%1\" localhost:%2 \"%3\"").arg(mGDBServer).arg(mPort).arg(mInferior); #endif QString workingDir = QFileInfo(mInferior).path(); diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index 12771831..99d89232 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -4680,7 +4680,7 @@ void MainWindow::onFilesViewOpenInTerminal() #ifdef Q_OS_WIN openShell(fileInfo.path(),"cmd.exe",getDefaultCompilerSetBinDirs()); #else - openShell(fileInfo.path(),pSettings->environment().terminalPathForExec(),getDefaultCompilerSetBinDirs()); + openShell(fileInfo.path(),pSettings->environment().terminalPath(),getDefaultCompilerSetBinDirs()); #endif } } @@ -6888,7 +6888,7 @@ void MainWindow::on_actionOpen_Terminal_triggered() #ifdef Q_OS_WIN openShell(info.path(),"cmd.exe",getBinDirsForCurrentEditor()); #else - openShell(info.path(),pSettings->environment().terminalPathForExec(),getBinDirsForCurrentEditor()); + openShell(info.path(),pSettings->environment().terminalPath(),getBinDirsForCurrentEditor()); #endif } } @@ -7225,7 +7225,7 @@ void MainWindow::on_actionProject_Open_In_Terminal_triggered() #ifdef Q_OS_WIN openShell(mProject->directory(),"cmd.exe",mProject->binDirs()); #else - openShell(mProject->directory(),pSettings->environment().terminalPathForExec(),mProject->binDirs()); + openShell(mProject->directory(),pSettings->environment().terminalPath(),mProject->binDirs()); #endif } diff --git a/RedPandaIDE/resources/terminal-unix.json b/RedPandaIDE/resources/terminal-unix.json index 72d5393d..cf0b9014 100644 --- a/RedPandaIDE/resources/terminal-unix.json +++ b/RedPandaIDE/resources/terminal-unix.json @@ -125,16 +125,6 @@ } ] }, - { - "group": "Bundled", - "terminals": [ - { - "name": "Alacritty (Bundled)", - "path": "./alacritty", - "argsPattern": "$term -e $argv" - } - ] - }, { "group": "With minor issue", "terminals": [ diff --git a/RedPandaIDE/resources/terminal-windows.json b/RedPandaIDE/resources/terminal-windows.json index 2486e2cd..e4bbe5b3 100644 --- a/RedPandaIDE/resources/terminal-windows.json +++ b/RedPandaIDE/resources/terminal-windows.json @@ -1,10 +1,11 @@ [ { "group": "Bundled", + "comment": "Use `%*APP_DIR*%` in path for application directory.", "terminals": [ { "name": "UTF-8 compatible Console Host", - "path": "%*APP_DIR*%/OpenConsole.exe", + "path": "OpenConsole.exe", "argsPattern": "$term -- $argv" } ] diff --git a/RedPandaIDE/settings.cpp b/RedPandaIDE/settings.cpp index 22e51ad1..bc42d6bc 100644 --- a/RedPandaIDE/settings.cpp +++ b/RedPandaIDE/settings.cpp @@ -3628,7 +3628,11 @@ void Settings::Environment::doLoad() // check saved terminal path mTerminalPath = stringValue("terminal_path", ""); +#ifdef Q_OS_WINDOWS + // APP_DIR trick for windows portable app + // on other platforms multiple instances share the same configuration and thus the trick may break terminal path mTerminalPath.replace("%*APP_DIR*%",pSettings->dirs().appDir()); +#endif mTerminalArgumentsPattern = stringValue("terminal_arguments_pattern", ""); checkAndSetTerminal(); @@ -3804,6 +3808,7 @@ void Settings::Environment::checkAndSetTerminal() if(fileExists(absoluteTerminalPath)) { mTerminalPath = absoluteTerminalPath; mTerminalArgumentsPattern = termItem.param; + return; } } else { for (const QString &dirPath: pathList) { @@ -3812,7 +3817,7 @@ void Settings::Environment::checkAndSetTerminal() if(fileExists(absoluteTerminalPath)) { mTerminalPath = absoluteTerminalPath; mTerminalArgumentsPattern = termItem.param; - break; + return; } } } @@ -3902,9 +3907,13 @@ void Settings::Environment::doSave() saveValue("current_folder",mCurrentFolder); saveValue("default_open_folder",mDefaultOpenFolder); QString terminalPath = mTerminalPath; +#ifdef Q_OS_WINDOWS + // APP_DIR trick for windows portable app + // on other platforms multiple instances share the same configuration and thus the trick may break terminal path if (terminalPath.startsWith(pSettings->dirs().appDir())) { terminalPath="%*APP_DIR*%"+terminalPath.mid(pSettings->dirs().appDir().length()); } +#endif saveValue("terminal_path",terminalPath); saveValue("terminal_arguments_pattern",mTerminalArgumentsPattern); diff --git a/RedPandaIDE/utils.cpp b/RedPandaIDE/utils.cpp index adc8dbde..04913f86 100644 --- a/RedPandaIDE/utils.cpp +++ b/RedPandaIDE/utils.cpp @@ -595,7 +595,32 @@ QStringList getExecutableSearchPaths() QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); QString path = env.value("PATH"); QStringList pathList = path.split(PATH_SEPARATOR); +#ifdef Q_OS_WINDOWS + /* follow Windows `CreateProcessW` search semantics. + * ref. https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-createprocessw . + */ + QStringList searchList{}; + wchar_t buffer[MAX_PATH]; + // 1. the directory from which the application loaded + searchList.push_back(QApplication::instance()->applicationDirPath()); + // 2. the current directory for the parent process + // here we add it because launching from GUI the current directory is relatively stable + searchList.push_back(QDir::currentPath()); + // 3. the 32-bit Windows system directory + if (GetSystemDirectoryW(buffer, MAX_PATH) > 0) + searchList.push_back(QString::fromWCharArray(buffer)); + if (GetWindowsDirectoryW(buffer, MAX_PATH) > 0) { + // 4. the 16-bit Windows system directory + searchList.push_back(QString::fromWCharArray(buffer) + "/System"); + // 5. the Windows directory + searchList.push_back(QString::fromWCharArray(buffer)); + } + // 6. the directories that are listed in the PATH environment variable + searchList.append(pathList); + return searchList; +#else return pathList; +#endif } QString escapeArgument(const QString &arg, [[maybe_unused]] bool isFirstArg) diff --git a/packages/appimage/01-in-docker.sh b/packages/appimage/01-in-docker.sh index 026825c5..ace08264 100755 --- a/packages/appimage/01-in-docker.sh +++ b/packages/appimage/01-in-docker.sh @@ -24,9 +24,6 @@ ln -s usr/share/icons/hicolor/scalable/apps/redpandaide.svg redpandaide.svg install -m755 /build/RedPanda-CPP/packages/appimage/AppRun.sh AppRun install -m644 /build/RedPanda-CPP/platform/linux/redpandaide.png .DirIcon -# copy dependency -cp /usr/local/bin/alacritty usr/bin - # create AppImage cd /build mksquashfs RedPandaIDE.AppDir $APPIMAGE_FILE -offset $RUNTIME_SIZE -comp zstd -root-owned -noappend -b 1M -mkfs-time 0 diff --git a/packages/appimage/dockerfile-aarch64/Dockerfile b/packages/appimage/dockerfile-aarch64/Dockerfile index 2e43bdb7..701900e8 100644 --- a/packages/appimage/dockerfile-aarch64/Dockerfile +++ b/packages/appimage/dockerfile-aarch64/Dockerfile @@ -86,19 +86,3 @@ RUN mkdir -p /build/qt5 && \ # cleanup cd / && \ rm -r /build/qt5 - -# Alacritty -RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal --default-toolchain 1.71.1 && \ - . ~/.cargo/env && \ - mkdir -p /build/alacritty && \ - cd /build/alacritty && \ - curl -L -o alacritty-${ALACRITTY_VERSION}.tar.gz "https://github.com/alacritty/alacritty/archive/refs/tags/v${ALACRITTY_VERSION}.tar.gz" && \ - tar xf alacritty-${ALACRITTY_VERSION}.tar.gz && \ - cd alacritty-${ALACRITTY_VERSION} && \ - echo -e '[profile.minsize]\ninherits="release"\ndebug=false\nstrip=true\nopt-level="s"' >>Cargo.toml && \ - cargo build --profile minsize && \ - cp target/minsize/alacritty /usr/local/bin && \ - # cleanup - cd / && \ - rm -r /build/alacritty && \ - rustup self uninstall -y diff --git a/packages/appimage/dockerfile-riscv64/Dockerfile b/packages/appimage/dockerfile-riscv64/Dockerfile index 718ce76b..4c3acbc2 100644 --- a/packages/appimage/dockerfile-riscv64/Dockerfile +++ b/packages/appimage/dockerfile-riscv64/Dockerfile @@ -68,19 +68,3 @@ RUN mkdir -p /build/qt5 && \ # cleanup cd / && \ rm -r /build/qt5 - -# Alacritty -RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal --default-toolchain 1.71.1 && \ - . ~/.cargo/env && \ - mkdir -p /build/alacritty && \ - cd /build/alacritty && \ - curl -L -o alacritty-${ALACRITTY_VERSION}.tar.gz "https://github.com/alacritty/alacritty/archive/refs/tags/v${ALACRITTY_VERSION}.tar.gz" && \ - tar xf alacritty-${ALACRITTY_VERSION}.tar.gz && \ - cd alacritty-${ALACRITTY_VERSION} && \ - /bin/echo -e '[profile.minsize]\ninherits="release"\ndebug=false\nstrip=true\nopt-level="s"' >>Cargo.toml && \ - cargo build --profile minsize && \ - cp target/minsize/alacritty /usr/local/bin && \ - # cleanup - cd / && \ - rm -r /build/alacritty && \ - rustup self uninstall -y diff --git a/packages/appimage/dockerfile-x86_64/Dockerfile b/packages/appimage/dockerfile-x86_64/Dockerfile index aa45ca83..b6f789e6 100644 --- a/packages/appimage/dockerfile-x86_64/Dockerfile +++ b/packages/appimage/dockerfile-x86_64/Dockerfile @@ -83,20 +83,3 @@ RUN mkdir -p /build/qt5 && \ # cleanup cd / && \ rm -r /build/qt5 - -# Alacritty -RUN yum install -y cargo && \ - mkdir -p /build/alacritty && \ - cd /build/alacritty && \ - curl -L -o alacritty-${ALACRITTY_VERSION}.tar.gz "https://github.com/alacritty/alacritty/archive/refs/tags/v${ALACRITTY_VERSION}.tar.gz" && \ - tar xf alacritty-${ALACRITTY_VERSION}.tar.gz && \ - cd alacritty-${ALACRITTY_VERSION} && \ - echo -e '[profile.minsize]\ninherits="release"\ndebug=false\nstrip=true\nopt-level="s"' >>Cargo.toml && \ - cargo build --profile minsize && \ - cp target/minsize/alacritty /usr/local/bin && \ - # cleanup - cd / && \ - rm -r /build/alacritty && \ - yum autoremove -y cargo && \ - yum clean all && \ - rm -r ~/.cargo