cmSystemTools.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file LICENSE.rst or https://cmake.org/licensing for details. */
  3. #pragma once
  4. #include "cmConfigure.h" // IWYU pragma: keep
  5. #if !defined(_WIN32)
  6. # include <sys/types.h>
  7. #endif
  8. #include <cstddef>
  9. #include <functional>
  10. #include <map>
  11. #include <sstream>
  12. #include <string>
  13. #include <vector>
  14. #include <cm/optional>
  15. #include <cm/string_view>
  16. #include <cm3p/uv.h>
  17. #include "cmsys/Status.hxx" // IWYU pragma: export
  18. #include "cmsys/SystemTools.hxx" // IWYU pragma: export
  19. #include "cmDuration.h"
  20. #include "cmProcessOutput.h"
  21. struct cmMessageMetadata;
  22. /** \class cmSystemTools
  23. * \brief A collection of useful functions for CMake.
  24. *
  25. * cmSystemTools is a class that provides helper functions
  26. * for the CMake build system.
  27. */
  28. class cmSystemTools : public cmsys::SystemTools
  29. {
  30. public:
  31. using Superclass = cmsys::SystemTools;
  32. using Encoding = cmProcessOutput::Encoding;
  33. /**
  34. * Return a lower case string
  35. */
  36. static std::string LowerCase(cm::string_view);
  37. static std::string LowerCase(char const* s)
  38. {
  39. return LowerCase(cm::string_view{ s });
  40. }
  41. using cmsys::SystemTools::LowerCase;
  42. /**
  43. * Return an upper case string
  44. */
  45. static std::string UpperCase(cm::string_view);
  46. static std::string UpperCase(char const* s)
  47. {
  48. return UpperCase(cm::string_view{ s });
  49. }
  50. using cmsys::SystemTools::UpperCase;
  51. /**
  52. * Look for and replace registry values in a string
  53. */
  54. static void ExpandRegistryValues(std::string& source,
  55. KeyWOW64 view = KeyWOW64_Default);
  56. /** Map help document name to file name. */
  57. static std::string HelpFileName(cm::string_view);
  58. using MessageCallback =
  59. std::function<void(std::string const&, cmMessageMetadata const&)>;
  60. /**
  61. * Set the function used by GUIs to display error messages
  62. * Function gets passed: message as a const char*,
  63. * title as a const char*.
  64. */
  65. static void SetMessageCallback(MessageCallback f);
  66. /**
  67. * Display an error message.
  68. */
  69. static void Error(std::string const& m);
  70. /**
  71. * Display a message.
  72. */
  73. static void Message(std::string const& m, char const* title = nullptr);
  74. static void Message(std::string const& m, cmMessageMetadata const& md);
  75. using OutputCallback = std::function<void(std::string const&)>;
  76. //! Send a string to stdout
  77. static void Stdout(std::string const& s);
  78. static void SetStdoutCallback(OutputCallback f);
  79. //! Send a string to stderr
  80. static void Stderr(std::string const& s);
  81. static void SetStderrCallback(OutputCallback f);
  82. using InterruptCallback = std::function<bool()>;
  83. static void SetInterruptCallback(InterruptCallback f);
  84. static bool GetInterruptFlag();
  85. //! Return true if there was an error at any point.
  86. static bool GetErrorOccurredFlag()
  87. {
  88. return cmSystemTools::s_ErrorOccurred ||
  89. cmSystemTools::s_FatalErrorOccurred || GetInterruptFlag();
  90. }
  91. //! If this is set to true, cmake stops processing commands.
  92. static void SetFatalErrorOccurred()
  93. {
  94. cmSystemTools::s_FatalErrorOccurred = true;
  95. }
  96. static void SetErrorOccurred() { cmSystemTools::s_ErrorOccurred = true; }
  97. //! Return true if there was an error at any point.
  98. static bool GetFatalErrorOccurred()
  99. {
  100. return cmSystemTools::s_FatalErrorOccurred || GetInterruptFlag();
  101. }
  102. //! Set the error occurred flag and fatal error back to false
  103. static void ResetErrorOccurredFlag()
  104. {
  105. cmSystemTools::s_FatalErrorOccurred = false;
  106. cmSystemTools::s_ErrorOccurred = false;
  107. }
  108. //! Return true if the path is a framework
  109. static bool IsPathToFramework(std::string const& path);
  110. //! Return true if the path is a xcframework
  111. static bool IsPathToXcFramework(std::string const& path);
  112. //! Return true if the path is a macOS non-framework shared library (aka
  113. //! .dylib)
  114. static bool IsPathToMacOSSharedLibrary(std::string const& path);
  115. static bool DoesFileExistWithExtensions(
  116. std::string const& name, std::vector<std::string> const& sourceExts);
  117. /**
  118. * Check if the given file exists in one of the parent directory of the
  119. * given file or directory and if it does, return the name of the file.
  120. * Toplevel specifies the top-most directory to where it will look.
  121. */
  122. static std::string FileExistsInParentDirectories(
  123. std::string const& fname, std::string const& directory,
  124. std::string const& toplevel);
  125. static void Glob(std::string const& directory, std::string const& regexp,
  126. std::vector<std::string>& files);
  127. static void GlobDirs(std::string const& fullPath,
  128. std::vector<std::string>& files);
  129. /**
  130. * Try to find a list of files that match the "simple" globbing
  131. * expression. At this point in time the globbing expressions have
  132. * to be in form: /directory/partial_file_name*. The * character has
  133. * to be at the end of the string and it does not support ?
  134. * []... The optional argument type specifies what kind of files you
  135. * want to find. 0 means all files, -1 means directories, 1 means
  136. * files only. This method returns true if search was successful.
  137. */
  138. static bool SimpleGlob(std::string const& glob,
  139. std::vector<std::string>& files, int type = 0);
  140. enum class CopyWhen
  141. {
  142. Always,
  143. OnlyIfDifferent,
  144. };
  145. enum class CopyInputRecent
  146. {
  147. No,
  148. Yes,
  149. };
  150. enum class CopyResult
  151. {
  152. Success,
  153. Failure,
  154. };
  155. #if defined(_MSC_VER)
  156. /** Visual C++ does not define mode_t. */
  157. using mode_t = unsigned short;
  158. #endif
  159. /**
  160. * Make a new temporary directory. The path must end in "XXXXXX", and will
  161. * be modified to reflect the name of the directory created. This function
  162. * is similar to POSIX mkdtemp (and is implemented using the same where that
  163. * function is available).
  164. *
  165. * This function can make a full path even if none of the directories existed
  166. * prior to calling this function.
  167. *
  168. * Note that this function may modify \p path even if it does not succeed.
  169. */
  170. static cmsys::Status MakeTempDirectory(char* path,
  171. mode_t const* mode = nullptr);
  172. static cmsys::Status MakeTempDirectory(std::string& path,
  173. mode_t const* mode = nullptr);
  174. /** Copy a file. */
  175. static CopyResult CopySingleFile(std::string const& oldname,
  176. std::string const& newname, CopyWhen when,
  177. CopyInputRecent inputRecent,
  178. std::string* err = nullptr);
  179. enum class Replace
  180. {
  181. Yes,
  182. No,
  183. };
  184. enum class RenameResult
  185. {
  186. Success,
  187. NoReplace,
  188. Failure,
  189. };
  190. /** Rename a file or directory within a single disk volume (atomic
  191. if possible). */
  192. static bool RenameFile(std::string const& oldname,
  193. std::string const& newname);
  194. static RenameResult RenameFile(std::string const& oldname,
  195. std::string const& newname, Replace replace,
  196. std::string* err = nullptr);
  197. //! Rename a file if contents are different, delete the source otherwise
  198. static cmsys::Status MoveFileIfDifferent(std::string const& source,
  199. std::string const& destination);
  200. /**
  201. * According to the CreateProcessW documentation:
  202. *
  203. * To run a batch file, you must start the command interpreter; set
  204. * lpApplicationName to cmd.exe and set lpCommandLine to the following
  205. * arguments: /c plus the name of the batch file.
  206. *
  207. * Additionally, "cmd /c" does not always parse batch file names correctly
  208. * if they contain spaces, but using "cmd /c call" seems to work.
  209. *
  210. * The function is noop on platforms different from the pure WIN32 one.
  211. */
  212. static void MaybePrependCmdExe(std::vector<std::string>& cmdLine);
  213. /**
  214. * Run a single executable command
  215. *
  216. * Output is controlled with outputflag. If outputflag is OUTPUT_NONE, no
  217. * user-viewable output from the program being run will be generated.
  218. * OUTPUT_MERGE is the legacy behavior where stdout and stderr are merged
  219. * into stdout. OUTPUT_FORWARD copies the output to stdout/stderr as
  220. * it was received. OUTPUT_PASSTHROUGH passes through the original handles.
  221. *
  222. * If timeout is specified, the command will be terminated after
  223. * timeout expires. Timeout is specified in seconds.
  224. *
  225. * Argument retVal should be a pointer to the location where the
  226. * exit code will be stored. If the retVal is not specified and
  227. * the program exits with a code other than 0, then the this
  228. * function will return false.
  229. *
  230. * If the command has spaces in the path the caller MUST call
  231. * cmSystemTools::ConvertToRunCommandPath on the command before passing
  232. * it into this function or it will not work. The command must be correctly
  233. * escaped for this to with spaces.
  234. */
  235. enum OutputOption
  236. {
  237. OUTPUT_NONE = 0,
  238. OUTPUT_MERGE,
  239. OUTPUT_FORWARD,
  240. OUTPUT_PASSTHROUGH
  241. };
  242. static bool RunSingleCommand(std::string const& command,
  243. std::string* captureStdOut = nullptr,
  244. std::string* captureStdErr = nullptr,
  245. int* retVal = nullptr,
  246. char const* dir = nullptr,
  247. OutputOption outputflag = OUTPUT_MERGE,
  248. cmDuration timeout = cmDuration::zero());
  249. /**
  250. * In this version of RunSingleCommand, command[0] should be
  251. * the command to run, and each argument to the command should
  252. * be in command[1]...command[command.size()]
  253. */
  254. static bool RunSingleCommand(std::vector<std::string> const& command,
  255. std::string* captureStdOut = nullptr,
  256. std::string* captureStdErr = nullptr,
  257. int* retVal = nullptr,
  258. char const* dir = nullptr,
  259. OutputOption outputflag = OUTPUT_MERGE,
  260. cmDuration timeout = cmDuration::zero(),
  261. Encoding encoding = cmProcessOutput::Auto);
  262. static std::string PrintSingleCommand(std::vector<std::string> const&);
  263. /**
  264. * Parse arguments out of a single string command
  265. */
  266. static std::vector<std::string> ParseArguments(std::string const& command);
  267. /** Parse arguments out of a windows command line string. */
  268. static void ParseWindowsCommandLine(char const* command,
  269. std::vector<std::string>& args);
  270. /** Parse arguments out of a unix command line string. */
  271. static void ParseUnixCommandLine(char const* command,
  272. std::vector<std::string>& args);
  273. /** Split a command-line string into the parsed command and the unparsed
  274. arguments. Returns false on unfinished quoting or escaping. */
  275. static bool SplitProgramFromArgs(std::string const& command,
  276. std::string& program, std::string& args);
  277. /**
  278. * Handle response file in an argument list and return a new argument list
  279. * **/
  280. static std::vector<std::string> HandleResponseFile(
  281. std::vector<std::string>::const_iterator argBeg,
  282. std::vector<std::string>::const_iterator argEnd);
  283. static std::size_t CalculateCommandLineLengthLimit();
  284. static void DisableRunCommandOutput() { s_DisableRunCommandOutput = true; }
  285. static void EnableRunCommandOutput() { s_DisableRunCommandOutput = false; }
  286. static bool GetRunCommandOutput() { return s_DisableRunCommandOutput; }
  287. enum CompareOp
  288. {
  289. OP_EQUAL = 1,
  290. OP_LESS = 2,
  291. OP_GREATER = 4,
  292. OP_LESS_EQUAL = OP_LESS | OP_EQUAL,
  293. OP_GREATER_EQUAL = OP_GREATER | OP_EQUAL
  294. };
  295. /**
  296. * Compare versions
  297. */
  298. static bool VersionCompare(CompareOp op, std::string const& lhs,
  299. std::string const& rhs);
  300. static bool VersionCompare(CompareOp op, std::string const& lhs,
  301. char const rhs[]);
  302. static bool VersionCompareEqual(std::string const& lhs,
  303. std::string const& rhs);
  304. static bool VersionCompareGreater(std::string const& lhs,
  305. std::string const& rhs);
  306. static bool VersionCompareGreaterEq(std::string const& lhs,
  307. std::string const& rhs);
  308. /**
  309. * Compare two ASCII strings using natural versioning order.
  310. * Non-numerical characters are compared directly.
  311. * Numerical characters are first globbed such that, e.g.
  312. * `test000 < test01 < test0 < test1 < test10`.
  313. * Return a value less than, equal to, or greater than zero if lhs
  314. * precedes, equals, or succeeds rhs in the defined ordering.
  315. */
  316. static int strverscmp(std::string const& lhs, std::string const& rhs);
  317. /** Windows if this is true, the CreateProcess in RunCommand will
  318. * not show new console windows when running programs.
  319. */
  320. static void SetRunCommandHideConsole(bool v) { s_RunCommandHideConsole = v; }
  321. static bool GetRunCommandHideConsole() { return s_RunCommandHideConsole; }
  322. /** Call cmSystemTools::Error with the message m, plus the
  323. * result of strerror(errno)
  324. */
  325. static void ReportLastSystemError(char const* m);
  326. enum class WaitForLineResult
  327. {
  328. None,
  329. STDOUT,
  330. STDERR,
  331. Timeout,
  332. };
  333. /** a general output handler for libuv */
  334. static WaitForLineResult WaitForLine(uv_loop_t* loop, uv_stream_t* outPipe,
  335. uv_stream_t* errPipe, std::string& line,
  336. cmDuration timeout,
  337. std::vector<char>& out,
  338. std::vector<char>& err);
  339. static void SetForceUnixPaths(bool v) { s_ForceUnixPaths = v; }
  340. static bool GetForceUnixPaths() { return s_ForceUnixPaths; }
  341. // ConvertToOutputPath use s_ForceUnixPaths
  342. static std::string ConvertToOutputPath(std::string const& path);
  343. static void ConvertToOutputSlashes(std::string& path);
  344. // ConvertToRunCommandPath does not use s_ForceUnixPaths and should
  345. // be used when RunCommand is called from cmake, because the
  346. // running cmake needs paths to be in its format
  347. static std::string ConvertToRunCommandPath(std::string const& path);
  348. /**
  349. * For windows computes the long path for the given path,
  350. * For Unix, it is a noop
  351. */
  352. static void ConvertToLongPath(std::string& path);
  353. /** compute the relative path from local to remote. local must
  354. be a directory. remote can be a file or a directory.
  355. Both remote and local must be full paths. Basically, if
  356. you are in directory local and you want to access the file in remote
  357. what is the relative path to do that. For example:
  358. /a/b/c/d to /a/b/c1/d1 -> ../../c1/d1
  359. from /usr/src to /usr/src/test/blah/foo.cpp -> test/blah/foo.cpp
  360. */
  361. static std::string RelativePath(std::string const& local,
  362. std::string const& remote);
  363. /**
  364. * Convert the given remote path to a relative path with respect to
  365. * the given local path. Both paths must use forward slashes and not
  366. * already be escaped or quoted.
  367. */
  368. static std::string ForceToRelativePath(std::string const& local_path,
  369. std::string const& remote_path);
  370. /**
  371. * Express the 'in' path relative to 'top' if it does not start in '../'.
  372. */
  373. static std::string RelativeIfUnder(std::string const& top,
  374. std::string const& in);
  375. static cm::optional<std::string> GetEnvVar(std::string const& var);
  376. static std::vector<std::string> GetEnvPathNormalized(std::string const& var);
  377. static std::vector<std::string> SplitEnvPath(cm::string_view in);
  378. static std::vector<std::string> SplitEnvPathNormalized(cm::string_view in);
  379. /** Convert an input path to an absolute path with no '/..' components.
  380. Backslashes in the input path are converted to forward slashes.
  381. Relative paths are interpreted w.r.t. GetLogicalWorkingDirectory.
  382. This is similar to 'realpath', but preserves symlinks that are
  383. not erased by '../' components.
  384. On Windows and macOS, the on-disk capitalization is loaded for
  385. existing paths. */
  386. static std::string ToNormalizedPathOnDisk(std::string p);
  387. #ifndef CMAKE_BOOTSTRAP
  388. /** Remove an environment variable */
  389. static bool UnsetEnv(char const* value);
  390. /** Get the list of all environment variables */
  391. static std::vector<std::string> GetEnvironmentVariables();
  392. /** Append multiple variables to the current environment. */
  393. static void AppendEnv(std::vector<std::string> const& env);
  394. /**
  395. * Helper class to represent an environment diff directly. This is to avoid
  396. * repeated in-place environment modification (i.e. via setenv/putenv), which
  397. * could be slow.
  398. */
  399. class EnvDiff
  400. {
  401. public:
  402. /** Append multiple variables to the current environment diff */
  403. void AppendEnv(std::vector<std::string> const& env);
  404. /**
  405. * Add a single variable (or remove if no = sign) to the current
  406. * environment diff.
  407. */
  408. void PutEnv(std::string const& env);
  409. /** Remove a single variable from the current environment diff. */
  410. void UnPutEnv(std::string const& env);
  411. /**
  412. * Apply an ENVIRONMENT_MODIFICATION operation to this diff. Returns
  413. * false and issues an error on parse failure.
  414. */
  415. bool ParseOperation(std::string const& envmod);
  416. /**
  417. * Apply this diff to the actual environment, optionally writing out the
  418. * modifications to a CTest-compatible measurement stream.
  419. */
  420. void ApplyToCurrentEnv(std::ostringstream* measurement = nullptr);
  421. private:
  422. std::map<std::string, cm::optional<std::string>> diff;
  423. };
  424. /** Helper class to save and restore the environment.
  425. Instantiate this class as an automatic variable on
  426. the stack. Its constructor saves a copy of the current
  427. environment and then its destructor restores the
  428. original environment. */
  429. class SaveRestoreEnvironment
  430. {
  431. public:
  432. SaveRestoreEnvironment();
  433. ~SaveRestoreEnvironment();
  434. SaveRestoreEnvironment(SaveRestoreEnvironment const&) = delete;
  435. SaveRestoreEnvironment& operator=(SaveRestoreEnvironment const&) = delete;
  436. private:
  437. std::vector<std::string> Env;
  438. };
  439. #endif
  440. /** Setup the environment to enable VS 8 IDE output. */
  441. static void EnableVSConsoleOutput();
  442. enum cmTarAction
  443. {
  444. TarActionCreate,
  445. TarActionList,
  446. TarActionExtract,
  447. TarActionNone
  448. };
  449. /** Create tar */
  450. enum cmTarCompression
  451. {
  452. TarCompressGZip,
  453. TarCompressBZip2,
  454. TarCompressXZ,
  455. TarCompressZstd,
  456. TarCompressNone
  457. };
  458. enum class cmTarExtractTimestamps
  459. {
  460. Yes,
  461. No
  462. };
  463. static bool ListTar(std::string const& outFileName,
  464. std::vector<std::string> const& files, bool verbose);
  465. static bool CreateTar(std::string const& outFileName,
  466. std::vector<std::string> const& files,
  467. std::string const& workingDirectory,
  468. cmTarCompression compressType, bool verbose,
  469. std::string const& mtime = std::string(),
  470. std::string const& format = std::string(),
  471. int compressionLevel = 0);
  472. static bool ExtractTar(std::string const& inFileName,
  473. std::vector<std::string> const& files,
  474. cmTarExtractTimestamps extractTimestamps,
  475. bool verbose);
  476. /** Random number generation. */
  477. static unsigned int RandomSeed();
  478. static unsigned int RandomNumber();
  479. /**
  480. * Find an executable in the system PATH, with optional extra paths.
  481. * This wraps KWSys's FindProgram to add ToNormalizedPathOnDisk.
  482. */
  483. static std::string FindProgram(
  484. std::string const& name,
  485. std::vector<std::string> const& path = std::vector<std::string>());
  486. /** Find the directory containing CMake executables. */
  487. static void FindCMakeResources(char const* argv0);
  488. /** Get the CMake resource paths, after FindCMakeResources. */
  489. static std::string const& GetCTestCommand();
  490. static std::string const& GetCPackCommand();
  491. static std::string const& GetCMakeCommand();
  492. static std::string const& GetCMakeGUICommand();
  493. static std::string const& GetCMakeCursesCommand();
  494. static std::string const& GetCMClDepsCommand();
  495. static std::string const& GetCMakeRoot();
  496. static std::string const& GetHTMLDoc();
  497. /** Get the CMake config directory **/
  498. static cm::optional<std::string> GetSystemConfigDirectory();
  499. static cm::optional<std::string> GetCMakeConfigDirectory();
  500. static std::string const& GetLogicalWorkingDirectory();
  501. /** The logical working directory may contain symlinks but must not
  502. contain any '../' path components. */
  503. static cmsys::Status SetLogicalWorkingDirectory(std::string const& lwd);
  504. /** Try to guess the soname of a shared library. */
  505. static bool GuessLibrarySOName(std::string const& fullPath,
  506. std::string& soname);
  507. /** Try to guess the install name of a shared library. */
  508. static bool GuessLibraryInstallName(std::string const& fullPath,
  509. std::string& soname);
  510. /** Try to change the RPATH in an ELF binary. */
  511. static bool ChangeRPath(std::string const& file, std::string const& oldRPath,
  512. std::string const& newRPath,
  513. bool removeEnvironmentRPath,
  514. std::string* emsg = nullptr,
  515. bool* changed = nullptr);
  516. /** Try to set the RPATH in an ELF binary. */
  517. static bool SetRPath(std::string const& file, std::string const& newRPath,
  518. std::string* emsg = nullptr, bool* changed = nullptr);
  519. /** Try to remove the RPATH from an ELF binary. */
  520. static bool RemoveRPath(std::string const& file, std::string* emsg = nullptr,
  521. bool* removed = nullptr);
  522. /** Check whether the RPATH in an ELF binary contains the path
  523. given. */
  524. static bool CheckRPath(std::string const& file, std::string const& newRPath);
  525. /** Remove a directory; repeat a few times in case of locked files. */
  526. static bool RepeatedRemoveDirectory(std::string const& dir);
  527. /** Encode a string as a URL. */
  528. static std::string EncodeURL(std::string const& in,
  529. bool escapeSlashes = true);
  530. enum class DirCase
  531. {
  532. Sensitive,
  533. Insensitive,
  534. };
  535. /** Returns nullopt when `dir` is not a valid directory */
  536. static cm::optional<DirCase> GetDirCase(std::string const& dir);
  537. #ifdef _WIN32
  538. struct WindowsFileRetry
  539. {
  540. unsigned int Count;
  541. unsigned int Delay;
  542. };
  543. static WindowsFileRetry GetWindowsFileRetry();
  544. static WindowsFileRetry GetWindowsDirectoryRetry();
  545. struct WindowsVersion
  546. {
  547. unsigned int dwMajorVersion;
  548. unsigned int dwMinorVersion;
  549. unsigned int dwBuildNumber;
  550. };
  551. static WindowsVersion GetWindowsVersion();
  552. /** Attempt to get full path to COMSPEC, default "cmd.exe" */
  553. static std::string GetComspec();
  554. #endif
  555. /** Get the real path for a given path, removing all symlinks.
  556. This variant of GetRealPath also works on Windows but will
  557. resolve subst drives too. */
  558. static std::string GetRealPathResolvingWindowsSubst(
  559. std::string const& path, std::string* errorMessage = nullptr);
  560. /** Get the real path for a given path, removing all symlinks. */
  561. static std::string GetRealPath(std::string const& path,
  562. std::string* errorMessage = nullptr);
  563. /** Perform one-time initialization of libuv. */
  564. static void InitializeLibUV();
  565. /** Create a symbolic link if the platform supports it. Returns whether
  566. creation succeeded. */
  567. static cmsys::Status CreateSymlink(std::string const& origName,
  568. std::string const& newName);
  569. static cmsys::Status CreateSymlinkQuietly(std::string const& origName,
  570. std::string const& newName);
  571. /** Create a hard link if the platform supports it. Returns whether
  572. creation succeeded. */
  573. static cmsys::Status CreateLink(std::string const& origName,
  574. std::string const& newName);
  575. static cmsys::Status CreateLinkQuietly(std::string const& origName,
  576. std::string const& newName);
  577. /** Get the system name. */
  578. static cm::string_view GetSystemName();
  579. /** Get the system path separator character */
  580. static char GetSystemPathlistSeparator();
  581. private:
  582. static bool s_ForceUnixPaths;
  583. static bool s_RunCommandHideConsole;
  584. static bool s_ErrorOccurred;
  585. static bool s_FatalErrorOccurred;
  586. static bool s_DisableRunCommandOutput;
  587. };