summaryrefslogtreecommitdiffstats
path: root/Source/cmExecuteProcessCommand.cxx
diff options
context:
space:
mode:
authorKyle Edwards <kyle.edwards@kitware.com>2023-10-16 14:42:52 (GMT)
committerKyle Edwards <kyle.edwards@kitware.com>2023-10-16 16:23:41 (GMT)
commit35f031e3b2ed09d3c2a935e61ea621b9a6941af6 (patch)
tree31cc6c0c663d92e3ee742f71c26a64212d1f9b7a /Source/cmExecuteProcessCommand.cxx
parent85fc81c61da699e7f63386d4578cc7b387040488 (diff)
downloadCMake-35f031e3b2ed09d3c2a935e61ea621b9a6941af6.zip
CMake-35f031e3b2ed09d3c2a935e61ea621b9a6941af6.tar.gz
CMake-35f031e3b2ed09d3c2a935e61ea621b9a6941af6.tar.bz2
execute_process(): Restore opening files relative to WORKING_DIRECTORY
Prior to 5420639a, execute_process() would open INPUT_FILE, OUTPUT_FILE, and ERROR_FILE relative to the WORKING_DIRECTORY argument if it was provided. Restore this behavior for backwards compatibility. Fixes: #25338
Diffstat (limited to 'Source/cmExecuteProcessCommand.cxx')
-rw-r--r--Source/cmExecuteProcessCommand.cxx62
1 files changed, 44 insertions, 18 deletions
diff --git a/Source/cmExecuteProcessCommand.cxx b/Source/cmExecuteProcessCommand.cxx
index 9b5f2b4..e764545 100644
--- a/Source/cmExecuteProcessCommand.cxx
+++ b/Source/cmExecuteProcessCommand.cxx
@@ -112,9 +112,27 @@ bool cmExecuteProcessCommand(std::vector<std::string> const& args,
return false;
}
- if (!status.GetMakefile().CanIWriteThisFile(arguments.OutputFile)) {
- status.SetError("attempted to output into a file: " +
- arguments.OutputFile + " into a source directory.");
+ std::string inputFilename = arguments.InputFile;
+ std::string outputFilename = arguments.OutputFile;
+ std::string errorFilename = arguments.ErrorFile;
+ if (!arguments.WorkingDirectory.empty()) {
+ if (!inputFilename.empty()) {
+ inputFilename = cmSystemTools::CollapseFullPath(
+ inputFilename, arguments.WorkingDirectory);
+ }
+ if (!outputFilename.empty()) {
+ outputFilename = cmSystemTools::CollapseFullPath(
+ outputFilename, arguments.WorkingDirectory);
+ }
+ if (!errorFilename.empty()) {
+ errorFilename = cmSystemTools::CollapseFullPath(
+ errorFilename, arguments.WorkingDirectory);
+ }
+ }
+
+ if (!status.GetMakefile().CanIWriteThisFile(outputFilename)) {
+ status.SetError("attempted to output into a file: " + outputFilename +
+ " into a source directory.");
cmSystemTools::SetFatalErrorOccurred();
return false;
}
@@ -162,20 +180,24 @@ bool cmExecuteProcessCommand(std::vector<std::string> const& args,
// Check the output variables.
std::unique_ptr<FILE, int (*)(FILE*)> inputFile(nullptr, fclose);
- if (!arguments.InputFile.empty()) {
- inputFile.reset(cmsys::SystemTools::Fopen(arguments.InputFile, "rb"));
- builder.SetExternalStream(cmUVProcessChainBuilder::Stream_INPUT,
- cm_fileno(inputFile.get()));
+ if (!inputFilename.empty()) {
+ inputFile.reset(cmsys::SystemTools::Fopen(inputFilename, "rb"));
+ if (inputFile) {
+ builder.SetExternalStream(cmUVProcessChainBuilder::Stream_INPUT,
+ cm_fileno(inputFile.get()));
+ }
} else {
builder.SetExternalStream(cmUVProcessChainBuilder::Stream_INPUT,
cm_fileno(stdin));
}
std::unique_ptr<FILE, int (*)(FILE*)> outputFile(nullptr, fclose);
- if (!arguments.OutputFile.empty()) {
- outputFile.reset(cmsys::SystemTools::Fopen(arguments.OutputFile, "wb"));
- builder.SetExternalStream(cmUVProcessChainBuilder::Stream_OUTPUT,
- cm_fileno(outputFile.get()));
+ if (!outputFilename.empty()) {
+ outputFile.reset(cmsys::SystemTools::Fopen(outputFilename, "wb"));
+ if (outputFile) {
+ builder.SetExternalStream(cmUVProcessChainBuilder::Stream_OUTPUT,
+ cm_fileno(outputFile.get()));
+ }
} else {
if (arguments.OutputVariable == arguments.ErrorVariable &&
!arguments.ErrorVariable.empty()) {
@@ -186,14 +208,18 @@ bool cmExecuteProcessCommand(std::vector<std::string> const& args,
}
std::unique_ptr<FILE, int (*)(FILE*)> errorFile(nullptr, fclose);
- if (!arguments.ErrorFile.empty()) {
- if (arguments.ErrorFile == arguments.OutputFile) {
- builder.SetExternalStream(cmUVProcessChainBuilder::Stream_ERROR,
- cm_fileno(outputFile.get()));
+ if (!errorFilename.empty()) {
+ if (errorFilename == outputFilename) {
+ if (outputFile) {
+ builder.SetExternalStream(cmUVProcessChainBuilder::Stream_ERROR,
+ cm_fileno(outputFile.get()));
+ }
} else {
- errorFile.reset(cmsys::SystemTools::Fopen(arguments.ErrorFile, "wb"));
- builder.SetExternalStream(cmUVProcessChainBuilder::Stream_ERROR,
- cm_fileno(errorFile.get()));
+ errorFile.reset(cmsys::SystemTools::Fopen(errorFilename, "wb"));
+ if (errorFile) {
+ builder.SetExternalStream(cmUVProcessChainBuilder::Stream_ERROR,
+ cm_fileno(errorFile.get()));
+ }
}
} else if (arguments.ErrorVariable.empty() ||
(!arguments.ErrorVariable.empty() &&