mirror of
https://github.com/Kitware/CMake.git
synced 2026-03-13 12:59:55 -05:00
Refactor: Move/rename cmProcessGetPipes() to cmGetPipes()
This commit is contained in:
@@ -264,6 +264,8 @@ set(SRCS
|
|||||||
cmGeneratorExpression.h
|
cmGeneratorExpression.h
|
||||||
cmGeneratorTarget.cxx
|
cmGeneratorTarget.cxx
|
||||||
cmGeneratorTarget.h
|
cmGeneratorTarget.h
|
||||||
|
cmGetPipes.cxx
|
||||||
|
cmGetPipes.h
|
||||||
cmGlobalCommonGenerator.cxx
|
cmGlobalCommonGenerator.cxx
|
||||||
cmGlobalCommonGenerator.h
|
cmGlobalCommonGenerator.h
|
||||||
cmGlobalGenerator.cxx
|
cmGlobalGenerator.cxx
|
||||||
|
|||||||
@@ -5,61 +5,19 @@
|
|||||||
#include "cmCTest.h"
|
#include "cmCTest.h"
|
||||||
#include "cmCTestRunTest.h"
|
#include "cmCTestRunTest.h"
|
||||||
#include "cmCTestTestHandler.h"
|
#include "cmCTestTestHandler.h"
|
||||||
|
#include "cmGetPipes.h"
|
||||||
#include "cmsys/Process.h"
|
#include "cmsys/Process.h"
|
||||||
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
# include "cm_kwiml.h"
|
# include "cm_kwiml.h"
|
||||||
#else
|
|
||||||
# include <unistd.h>
|
|
||||||
#endif
|
#endif
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#define CM_PROCESS_BUF_SIZE 65536
|
#define CM_PROCESS_BUF_SIZE 65536
|
||||||
|
|
||||||
#if defined(_WIN32) && !defined(__CYGWIN__)
|
|
||||||
# include <io.h>
|
|
||||||
|
|
||||||
static int cmProcessGetPipes(int* fds)
|
|
||||||
{
|
|
||||||
SECURITY_ATTRIBUTES attr;
|
|
||||||
HANDLE readh, writeh;
|
|
||||||
attr.nLength = sizeof(attr);
|
|
||||||
attr.lpSecurityDescriptor = nullptr;
|
|
||||||
attr.bInheritHandle = FALSE;
|
|
||||||
if (!CreatePipe(&readh, &writeh, &attr, 0))
|
|
||||||
return uv_translate_sys_error(GetLastError());
|
|
||||||
fds[0] = _open_osfhandle((intptr_t)readh, 0);
|
|
||||||
fds[1] = _open_osfhandle((intptr_t)writeh, 0);
|
|
||||||
if (fds[0] == -1 || fds[1] == -1) {
|
|
||||||
CloseHandle(readh);
|
|
||||||
CloseHandle(writeh);
|
|
||||||
return uv_translate_sys_error(GetLastError());
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
# include <errno.h>
|
|
||||||
|
|
||||||
static int cmProcessGetPipes(int* fds)
|
|
||||||
{
|
|
||||||
if (pipe(fds) == -1) {
|
|
||||||
return uv_translate_sys_error(errno);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fcntl(fds[0], F_SETFD, FD_CLOEXEC) == -1 ||
|
|
||||||
fcntl(fds[1], F_SETFD, FD_CLOEXEC) == -1) {
|
|
||||||
close(fds[0]);
|
|
||||||
close(fds[1]);
|
|
||||||
return uv_translate_sys_error(errno);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
cmProcess::cmProcess(cmCTestRunTest& runner)
|
cmProcess::cmProcess(cmCTestRunTest& runner)
|
||||||
: Runner(runner)
|
: Runner(runner)
|
||||||
, Conv(cmProcessOutput::UTF8, CM_PROCESS_BUF_SIZE)
|
, Conv(cmProcessOutput::UTF8, CM_PROCESS_BUF_SIZE)
|
||||||
@@ -120,7 +78,7 @@ bool cmProcess::StartProcess(uv_loop_t& loop, std::vector<size_t>* affinity)
|
|||||||
pipe_reader.init(loop, 0, this);
|
pipe_reader.init(loop, 0, this);
|
||||||
|
|
||||||
int fds[2] = { -1, -1 };
|
int fds[2] = { -1, -1 };
|
||||||
status = cmProcessGetPipes(fds);
|
status = cmGetPipes(fds);
|
||||||
if (status != 0) {
|
if (status != 0) {
|
||||||
cmCTestLog(this->Runner.GetCTest(), ERROR_MESSAGE,
|
cmCTestLog(this->Runner.GetCTest(), ERROR_MESSAGE,
|
||||||
"Error initializing pipe: " << uv_strerror(status)
|
"Error initializing pipe: " << uv_strerror(status)
|
||||||
|
|||||||
48
Source/cmGetPipes.cxx
Normal file
48
Source/cmGetPipes.cxx
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
||||||
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
||||||
|
#include "cmGetPipes.h"
|
||||||
|
|
||||||
|
#include "cm_uv.h"
|
||||||
|
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
|
#if defined(_WIN32) && !defined(__CYGWIN__)
|
||||||
|
# include <io.h>
|
||||||
|
|
||||||
|
int cmGetPipes(int* fds)
|
||||||
|
{
|
||||||
|
SECURITY_ATTRIBUTES attr;
|
||||||
|
HANDLE readh, writeh;
|
||||||
|
attr.nLength = sizeof(attr);
|
||||||
|
attr.lpSecurityDescriptor = nullptr;
|
||||||
|
attr.bInheritHandle = FALSE;
|
||||||
|
if (!CreatePipe(&readh, &writeh, &attr, 0))
|
||||||
|
return uv_translate_sys_error(GetLastError());
|
||||||
|
fds[0] = _open_osfhandle((intptr_t)readh, 0);
|
||||||
|
fds[1] = _open_osfhandle((intptr_t)writeh, 0);
|
||||||
|
if (fds[0] == -1 || fds[1] == -1) {
|
||||||
|
CloseHandle(readh);
|
||||||
|
CloseHandle(writeh);
|
||||||
|
return uv_translate_sys_error(GetLastError());
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
# include <errno.h>
|
||||||
|
# include <unistd.h>
|
||||||
|
|
||||||
|
int cmGetPipes(int* fds)
|
||||||
|
{
|
||||||
|
if (pipe(fds) == -1) {
|
||||||
|
return uv_translate_sys_error(errno);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fcntl(fds[0], F_SETFD, FD_CLOEXEC) == -1 ||
|
||||||
|
fcntl(fds[1], F_SETFD, FD_CLOEXEC) == -1) {
|
||||||
|
close(fds[0]);
|
||||||
|
close(fds[1]);
|
||||||
|
return uv_translate_sys_error(errno);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
8
Source/cmGetPipes.h
Normal file
8
Source/cmGetPipes.h
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
||||||
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
||||||
|
#ifndef cmGetPipes_h
|
||||||
|
#define cmGetPipes_h
|
||||||
|
|
||||||
|
int cmGetPipes(int* fds);
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user