SystemUtils.cpp (193323) | SystemUtils.cpp (195340) |
---|---|
1//===- SystemUtils.cpp - Utilities for low-level system tasks -------------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// --- 24 unchanged lines hidden (view full) --- 33 } 34 return false; 35} 36 37/// FindExecutable - Find a named executable, giving the argv[0] of program 38/// being executed. This allows us to find another LLVM tool if it is built 39/// into the same directory, but that directory is neither the current 40/// directory, nor in the PATH. If the executable cannot be found, return an | 1//===- SystemUtils.cpp - Utilities for low-level system tasks -------------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// --- 24 unchanged lines hidden (view full) --- 33 } 34 return false; 35} 36 37/// FindExecutable - Find a named executable, giving the argv[0] of program 38/// being executed. This allows us to find another LLVM tool if it is built 39/// into the same directory, but that directory is neither the current 40/// directory, nor in the PATH. If the executable cannot be found, return an |
41/// empty string. | 41/// empty string. Return the input string if given a full path to an executable. |
42/// 43#undef FindExecutable // needed on windows :( 44sys::Path llvm::FindExecutable(const std::string &ExeName, 45 const std::string &ProgramPath) { | 42/// 43#undef FindExecutable // needed on windows :( 44sys::Path llvm::FindExecutable(const std::string &ExeName, 45 const std::string &ProgramPath) { |
46 // First check the directory that the calling program is in. We can do this 47 // if ProgramPath contains at least one / character, indicating that it is a 48 // relative path to bugpoint itself. 49 sys::Path Result ( ProgramPath ); | 46 // First check if the given name is already a valid path to an executable. 47 sys::Path Result(ExeName); 48 Result.makeAbsolute(); 49 if (Result.canExecute()) 50 return Result; 51 52 // Otherwise check the directory that the calling program is in. We can do 53 // this if ProgramPath contains at least one / character, indicating that it 54 // is a relative path to bugpoint itself. 55 Result = ProgramPath; |
50 Result.eraseComponent(); 51 if (!Result.isEmpty()) { 52 Result.appendComponent(ExeName); 53 if (Result.canExecute()) 54 return Result; 55 } 56 57 return sys::Program::FindProgramByName(ExeName); 58} | 56 Result.eraseComponent(); 57 if (!Result.isEmpty()) { 58 Result.appendComponent(ExeName); 59 if (Result.canExecute()) 60 return Result; 61 } 62 63 return sys::Program::FindProgramByName(ExeName); 64} |