From e723b593cc1dda1ce5425922bd7bdcdc395bcbda Mon Sep 17 00:00:00 2001 From: Vitaly Petrov Date: Sat, 16 Mar 2019 23:17:40 +0300 Subject: [PATCH] Replace Travis/Windows to AppVeyor Replace Travis/Windows to AppVeyor: Fixes... Replace Travis/Windows to AppVeyor: Fixes... Replace Travis/Windows to AppVeyor: Fixes... Replace Travis/Windows to AppVeyor: Fixes... Replace Travis/Windows to AppVeyor: Fixes... Replace Travis/Windows to AppVeyor: Fixes... Replace Travis/Windows to AppVeyor: Fixes... Replace Travis/Windows to AppVeyor: Fixes... Replace Travis/Windows to AppVeyor: Fixes... Replace Travis/Windows to AppVeyor: Fixes... Replace Travis/Windows to AppVeyor: Fixes... Replace Travis/Windows to AppVeyor: Fixes... Replace Travis/Windows to AppVeyor: Fixes... Replace Travis/Windows to AppVeyor: Fixes... Replace Travis/Windows to AppVeyor: Fixes... Replace Travis/Windows to AppVeyor: Fixes... Replace Travis/Windows to AppVeyor: Fixes... Replace Travis/Windows to AppVeyor: Fixes... Replace Travis/Windows to AppVeyor: Fixes... Replace Travis/Windows to AppVeyor: Fixes... --- .appveyor.yml | 44 ++++++++++++++++++++++++++++++++++ .travis.yml | 32 ++++++++++++------------- CMakeLists.txt | 8 ++++++- README.md | 34 ++++++++++++++++----------- core/unixptyprocess.cpp | 52 ----------------------------------------- core/unixptyprocess.h | 2 +- 6 files changed, 88 insertions(+), 84 deletions(-) create mode 100644 .appveyor.yml diff --git a/.appveyor.yml b/.appveyor.yml new file mode 100644 index 0000000..20a6792 --- /dev/null +++ b/.appveyor.yml @@ -0,0 +1,44 @@ +image: Visual Studio 2017 +clone_depth: 10 +shallow_clone: true + +platform: + - x64 + - x86 + +configuration: +# - Debug + - Release + +environment: + matrix: +# - PLATFORM: x86 +# QT_DIR: C:\Qt\5.12.1\msvc2017 + - PLATFORM: x64 + QT_DIR: C:\Qt\5.12.1\msvc2017_64 + +matrix: + fast_finish: true + exclude: + - platform: x86 + QT_DIR: C:\Qt\5.12.1\msvc2017_64 + - platform: x64 + QT_DIR: C:\Qt\5.12.1\msvc2017 + +build_script: + - mkdir build + - cd build + - cmake.exe .. "-DCMAKE_PREFIX_PATH=%QT_DIR%" "-DCMAKE_BUILD_TYPE=%CONFIGURATION%" "-DTARGET_ARCH=%PLATFORM%" "-DCMAKE_GENERATOR_PLATFORM=%PLATFORM%" +# - dir + - cmake.exe --build . --target winpty +# - dir thirdparty + - cmake.exe --build . + - dir thirdparty\winpty\src\winpty +# - dir Win32 +# - dir Debug +# - dir +# - cmake.exe --build . --target test +# - dir + +#test_script: +# - ctest -C %CONFIGURATION% --output-on-failure diff --git a/.travis.yml b/.travis.yml index e466e6b..1091995 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,15 +22,15 @@ matrix: homebrew: packages: - qt - - name: Windows (VS2017 x64) - language: shell - os: windows - env: - - PLATFORM: x64 - - QT5_BASE_DIR: C:/Qt/5.12.0/msvc2017_64 - cache: - directories: - - travis-cache +# - name: Windows (VS2017 x64) +# language: shell +# os: windows +# env: +# - PLATFORM: x64 +# - QT5_BASE_DIR: C:/Qt/5.12.0/msvc2017_64 +# cache: +# directories: +# - travis-cache allow_failures: - os: windows @@ -45,13 +45,13 @@ before_script: - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then ls; fi - - #windows - - if [[ "$TRAVIS_OS_NAME" == "windows" ]]; then - curl -vLo ~/qt-unified-windows-x86-online.exe http://download.qt.io/official_releases/online_installers/qt-unified-windows-x86-online.exe; - if ! ~/qt-unified-windows-x86-online.exe --verbose --script thirdparty/qt-installer-windows.qs > ~/qt-installer-output.txt; then - cat ~/qt-installer-output.txt; exit 1; - fi - fi +# - #windows +# - if [[ "$TRAVIS_OS_NAME" == "windows" ]]; then +# curl -vLo ~/qt-unified-windows-x86-online.exe http://download.qt.io/official_releases/online_installers/qt-unified-windows-x86-online.exe; +# if ! ~/qt-unified-windows-x86-online.exe --verbose --script thirdparty/qt-installer-windows.qs > ~/qt-installer-output.txt; then +# cat ~/qt-installer-output.txt; exit 1; +# fi +# fi - #both - cmake --version diff --git a/CMakeLists.txt b/CMakeLists.txt index 8c3c872..a896b9c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,7 +19,13 @@ else() endif() if (MSVC) - set(TARGET_ARCH x64) #x86 / x64 + #target arch for find winpty libs + if (TARGET_ARCH STREQUAL "") + set(TARGET_ARCH x64) #x86 / x64 + endif() + if (TARGET_ARCH STREQUAL "x86_amd64") + set(TARGET_ARCH x64) + endif() set(BUILD_TYPE STATIC) #STATIC / SHARED set(WINPTY_ROOT_DIR "") #user can define his own installation of WinPty for prevent auto-downloading dependency endif() diff --git a/README.md b/README.md index 00a3622..904a302 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,21 @@ # Pty-Qt - C++ library for work with PseudoTerminals -Ubuntu 18.04: [![Build Status](https://travis-ci.com/kafeg/ptyqt.svg?token=8hsFoXZ5FooS7bytYzXZ&branch=master)](https://travis-ci.com/kafeg/ptyqt) - Pty-Qt is small library for access to console applications by pseudo-terminal interface on Mac, Linux and Windows. On Mac and Linux you can use standard PseudoTerminal API and on Windows you can use WinPty or ConPty. -## Pre-Requirements +### CI Status + +Ubuntu 18.04: [![Build Status](https://travis-ci.com/kafeg/ptyqt.svg?token=8hsFoXZ5FooS7bytYzXZ&branch=master)](https://travis-ci.com/kafeg/ptyqt) + +Windows: [![Build Status](https://ci.appveyor.com/api/projects/status/github/kafeg/ptyqt?svg=true)](https://ci.appveyor.com/api/projects/status/github/kafeg/ptyqt) + +## Pre-Requirements and build - ConPty part works only on Windows 10 >= 1903 (build > 18309) and can be built only with Windows SDK >= 10.0.18346.0 (maybe >= 17134, but not sure) - WinPty part requires winpty sdk for build and winpty.dll with winpty-agent.exe for deployment with target application. WinPty can work on Windows XP and later (depended on used build SDK: vc140 / vc140_xp). You can't link WinPty libraries inside your App, because it use cygwin for build. - UnixPty part can work on both Linux/Mac versions, because it based on standard POSIX pseudo terminals API - Еarget platforms: x86 or x64 - Required Qt >= 5.10 -## Build on Windows (Git Bash) +### Build on Windows (Git Bash) ```sh git clone https://github.com/Microsoft/vcpkg.git vcpkg cd vcpkg @@ -23,12 +27,12 @@ cd .. git clone https://github.com/kafeg/ptyqt.git ptyqt mkdir ptyqt-build cd ptyqt-build -${VCPKG_ROOT}/downloads/tools/cmake-3.12.4-windows/cmake-3.12.4-win32-x86/bin/cmake.exe ../ptyqt "-DCMAKE_TOOLCHAIN_FILE=/scripts/buildsystems/vcpkg.cmake" "-DVCPKG_TARGET_TRIPLET=x64-windows" +${VCPKG_ROOT}/downloads/tools/cmake-3.12.4-windows/cmake-3.12.4-win32-x86/bin/cmake.exe ../ptyqt "-DCMAKE_TOOLCHAIN_FILE=${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" "-DVCPKG_TARGET_TRIPLET=x64-windows" ${VCPKG_ROOT}/downloads/tools/cmake-3.12.4-windows/cmake-3.12.4-win32-x86/bin/cmake.exe --build . --target winpty ${VCPKG_ROOT}/downloads/tools/cmake-3.12.4-windows/cmake-3.12.4-win32-x86/bin/cmake.exe --build . ``` -## Build on Ubuntu +### Build on Ubuntu ```sh sudo apt-get install qtbase5-dev cmake libqt5websockets5-dev git clone https://github.com/kafeg/ptyqt.git ptyqt @@ -38,7 +42,7 @@ cmake ../ptyqt cmake --build . ``` -## Build on Mac +### Build on Mac ```sh brew install qt cmake git clone https://github.com/kafeg/ptyqt.git ptyqt @@ -133,13 +137,10 @@ int main(int argc, char *argv[]) } ``` -## Run tests -... - -## Run examples -1. xtermjs +## Examples +### XtermJS - build and run example -- install nodejs (your preffer way) +- install nodejs (your prefer way) - open console and run: ```sh cd ptyqt/examples/xtermjs @@ -149,10 +150,15 @@ http-server ./ ``` - open http://127.0.0.1:8080/ in Web browser +### QTerminal +in dev... + ## More information -This library based on: +Resources used to develop this library: - https://github.com/Microsoft/node-pty - https://github.com/Microsoft/console - https://github.com/rprichard/winpty - https://github.com/xtermjs/xterm.js - https://github.com/lxqt/qterminal + - https://devblogs.microsoft.com/commandline/windows-command-line-introducing-the-windows-pseudo-console-conpty/ + - https://devblogs.microsoft.com/commandline/windows-command-line-backgrounder/ diff --git a/core/unixptyprocess.cpp b/core/unixptyprocess.cpp index f98219a..91059bf 100644 --- a/core/unixptyprocess.cpp +++ b/core/unixptyprocess.cpp @@ -14,9 +14,6 @@ UnixPtyProcess::UnixPtyProcess() : IPtyProcess() , m_readMasterNotify(0) - , m_writeMasterNotify(0) - , m_readSlaveNotify(0) - , m_writeSlaveNotify(0) { m_shellProcess.setWorkingDirectory(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)); } @@ -48,11 +45,8 @@ bool UnixPtyProcess::startProcess(const QString &shellPath, QStringList environm m_shellPath = shellPath; m_size = QPair(cols, rows); - //m_shellProcess.startCli(shellPath, QStringList(), size, environment); - int rc = 0; - //open master m_shellProcess.m_handleMaster = ::posix_openpt(O_RDWR | O_NOCTTY); if (m_shellProcess.m_handleMaster <= 0) { @@ -61,7 +55,6 @@ bool UnixPtyProcess::startProcess(const QString &shellPath, QStringList environm return false; } - //get name of slave m_shellProcess.m_handleSlaveName = ptsname(m_shellProcess.m_handleMaster); if ( m_shellProcess.m_handleSlaveName.isEmpty()) { @@ -70,7 +63,6 @@ bool UnixPtyProcess::startProcess(const QString &shellPath, QStringList environm return false; } - //change permission of slave rc = grantpt(m_shellProcess.m_handleMaster); if (rc != 0) { @@ -79,7 +71,6 @@ bool UnixPtyProcess::startProcess(const QString &shellPath, QStringList environm return false; } - //unlock slave rc = unlockpt(m_shellProcess.m_handleMaster); if (rc != 0) { @@ -88,7 +79,6 @@ bool UnixPtyProcess::startProcess(const QString &shellPath, QStringList environm return false; } - //open slave m_shellProcess.m_handleSlave = ::open(m_shellProcess.m_handleSlaveName.toLatin1().data(), O_RDWR | O_NOCTTY); if (m_shellProcess.m_handleSlave < 0) { @@ -156,8 +146,6 @@ bool UnixPtyProcess::startProcess(const QString &shellPath, QStringList environm cfsetispeed(&ttmode, B38400); cfsetospeed(&ttmode, B38400); - - //set params to master rc = tcsetattr(m_shellProcess.m_handleMaster, TCSANOW, &ttmode); if (rc != 0) { @@ -187,30 +175,6 @@ bool UnixPtyProcess::startProcess(const QString &shellPath, QStringList environm m_shellProcess.emitReadyRead(); }); - m_writeMasterNotify = new QSocketNotifier(m_shellProcess.m_handleMaster, QSocketNotifier::Write, &m_shellProcess); - m_writeMasterNotify->setEnabled(true); - QObject::connect(m_writeMasterNotify, &QSocketNotifier::activated, [this](int socket) - { - Q_UNUSED(socket) - m_writeMasterNotify->setEnabled(false); - }); - - m_readSlaveNotify = new QSocketNotifier(m_shellProcess.m_handleSlave, QSocketNotifier::Read, &m_shellProcess); - m_readSlaveNotify->setEnabled(true); - QObject::connect(m_readSlaveNotify, &QSocketNotifier::activated, [](int socket) - { - Q_UNUSED(socket) - //not used... slave redirected to master - }); - - m_writeSlaveNotify = new QSocketNotifier(m_shellProcess.m_handleSlave, QSocketNotifier::Write, &m_shellProcess); - m_writeSlaveNotify->setEnabled(true); - QObject::connect(m_writeSlaveNotify, &QSocketNotifier::activated, [this](int socket) - { - Q_UNUSED(socket) - m_writeSlaveNotify->setEnabled(false); - }); - QProcessEnvironment envFormat; foreach (QString line, environment) { @@ -247,7 +211,6 @@ bool UnixPtyProcess::resize(qint16 cols, qint16 rows) bool UnixPtyProcess::kill() { - //close cli m_shellProcess.m_handleSlaveName = QString(); if (m_shellProcess.m_handleSlave >= 0) { @@ -260,18 +223,10 @@ bool UnixPtyProcess::kill() m_shellProcess.m_handleMaster = -1; } - //kill child process if (m_shellProcess.state() == QProcess::Running) { m_readMasterNotify->disconnect(); - m_writeMasterNotify->disconnect(); - m_readSlaveNotify->disconnect(); - m_writeSlaveNotify->disconnect(); - m_readMasterNotify->deleteLater(); - m_writeMasterNotify->deleteLater(); - m_readSlaveNotify->deleteLater(); - m_writeSlaveNotify->deleteLater(); m_shellProcess.terminate(); m_shellProcess.waitForFinished(1000); @@ -331,19 +286,12 @@ bool UnixPtyProcess::isAvailable() void ShellProcess::setupChildProcess() { - //for more info in book 'Advanced Programming in the UNIX Environment, 3rd Edition' - //at this point we are forked, but not executed dup2(m_handleSlave, STDIN_FILENO); dup2(m_handleSlave, STDOUT_FILENO); dup2(m_handleSlave, STDERR_FILENO); - //create session for process pid_t sid = setsid(); - - //setup slave ioctl(m_handleSlave, TIOCSCTTY, 0); - - //new group for process tcsetpgrp(m_handleSlave, sid); struct utmpx utmpxInfo; diff --git a/core/unixptyprocess.h b/core/unixptyprocess.h index 0de1bc2..d0bea7a 100644 --- a/core/unixptyprocess.h +++ b/core/unixptyprocess.h @@ -51,7 +51,7 @@ public: private: ShellProcess m_shellProcess; - QSocketNotifier *m_readMasterNotify, *m_writeMasterNotify, *m_readSlaveNotify, *m_writeSlaveNotify; //notifiers + QSocketNotifier *m_readMasterNotify; QByteArray m_shellReadBuffer; };