CMake/Source/CPack/OSXScriptLauncher.cxx

122 lines
3.5 KiB
C++
Raw Normal View History

Simplify CMake per-source license notices Per-source copyright/license notice headers that spell out copyright holder names and years are hard to maintain and often out-of-date or plain wrong. Precise contributor information is already maintained automatically by the version control tool. Ultimately it is the receiver of a file who is responsible for determining its licensing status, and per-source notices are merely a convenience. Therefore it is simpler and more accurate for each source to have a generic notice of the license name and references to more detailed information on copyright holders and full license terms. Our `Copyright.txt` file now contains a list of Contributors whose names appeared source-level copyright notices. It also references version control history for more precise information. Therefore we no longer need to spell out the list of Contributors in each source file notice. Replace CMake per-source copyright/license notice headers with a short description of the license and links to `Copyright.txt` and online information available from "https://cmake.org/licensing". The online URL also handles cases of modules being copied out of our source into other projects, so we can drop our notices about replacing links with full license text. Run the `Utilities/Scripts/filter-notices.bash` script to perform the majority of the replacements mechanically. Manually fix up shebang lines and trailing newlines in a few files. Manually update the notices in a few files that the script does not handle.
2016-09-27 22:01:08 +03:00
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
#include <cmsys/FStream.hxx>
#include <cmsys/Process.h>
#include <cmsys/SystemTools.hxx>
#include <iostream>
#include <CoreFoundation/CoreFoundation.h>
2007-01-31 21:53:30 +03:00
// For the PATH_MAX constant
#include <sys/syslimits.h>
#define DebugError(x) \
ofs << x << std::endl; \
std::cout << x << std::endl
int main(int argc, char* argv[])
{
// if ( cmsys::SystemTools::FileExists(
std::string cwd = cmsys::SystemTools::GetCurrentWorkingDirectory();
cmsys::ofstream ofs("/tmp/output.txt");
CFStringRef fileName;
CFBundleRef appBundle;
CFURLRef scriptFileURL;
UInt8* path;
// get CF URL for script
if (!(appBundle = CFBundleGetMainBundle())) {
DebugError("Cannot get main bundle");
return 1;
}
2007-01-31 21:53:30 +03:00
fileName = CFSTR("RuntimeScript");
if (!(scriptFileURL =
CFBundleCopyResourceURL(appBundle, fileName, NULL, NULL))) {
DebugError("CFBundleCopyResourceURL failed");
return 1;
}
// create path string
if (!(path = new UInt8[PATH_MAX])) {
return 1;
}
// get the file system path of the url as a cstring
// in an encoding suitable for posix apis
if (CFURLGetFileSystemRepresentation(scriptFileURL, true, path, PATH_MAX) ==
false) {
2007-01-31 21:53:30 +03:00
DebugError("CFURLGetFileSystemRepresentation failed");
return 1;
}
// dispose of the CF variable
2007-01-31 21:53:30 +03:00
CFRelease(scriptFileURL);
std::string fullScriptPath = reinterpret_cast<char*>(path);
delete[] path;
if (!cmsys::SystemTools::FileExists(fullScriptPath.c_str())) {
return 1;
}
std::string scriptDirectory =
cmsys::SystemTools::GetFilenamePath(fullScriptPath);
ofs << fullScriptPath << std::endl;
std::vector<const char*> args;
args.push_back(fullScriptPath.c_str());
int cc;
for (cc = 1; cc < argc; ++cc) {
args.push_back(argv[cc]);
}
args.push_back(0);
cmsysProcess* cp = cmsysProcess_New();
cmsysProcess_SetCommand(cp, &*args.begin());
cmsysProcess_SetWorkingDirectory(cp, scriptDirectory.c_str());
cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
cmsysProcess_SetTimeout(cp, 0);
cmsysProcess_Execute(cp);
std::vector<char> tempOutput;
char* data;
int length;
while (cmsysProcess_WaitForData(cp, &data, &length, 0)) {
// Translate NULL characters in the output into valid text.
// Visual Studio 7 puts these characters in the output of its
// build process.
for (int i = 0; i < length; ++i) {
if (data[i] == '\0') {
data[i] = ' ';
}
}
std::cout.write(data, length);
}
cmsysProcess_WaitForExit(cp, 0);
bool result = true;
if (cmsysProcess_GetState(cp) == cmsysProcess_State_Exited) {
if (cmsysProcess_GetExitValue(cp) != 0) {
result = false;
}
} else if (cmsysProcess_GetState(cp) == cmsysProcess_State_Exception) {
const char* exception_str = cmsysProcess_GetExceptionString(cp);
std::cerr << exception_str << std::endl;
result = false;
} else if (cmsysProcess_GetState(cp) == cmsysProcess_State_Error) {
const char* error_str = cmsysProcess_GetErrorString(cp);
std::cerr << error_str << std::endl;
result = false;
} else if (cmsysProcess_GetState(cp) == cmsysProcess_State_Expired) {
const char* error_str = "Process terminated due to timeout\n";
std::cerr << error_str << std::endl;
result = false;
}
cmsysProcess_Delete(cp);
return 0;
}