dirsearch.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // dirsearch.h -- directory searching for gold -*- C++ -*-
  2. // Copyright (C) 2006-2015 Free Software Foundation, Inc.
  3. // Written by Ian Lance Taylor <iant@google.com>.
  4. // This file is part of gold.
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation; either version 3 of the License, or
  8. // (at your option) any later version.
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program; if not, write to the Free Software
  15. // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  16. // MA 02110-1301, USA.
  17. #ifndef GOLD_DIRSEARCH_H
  18. #define GOLD_DIRSEARCH_H
  19. #include <string>
  20. #include <list>
  21. #include "options.h"
  22. #include "token.h"
  23. namespace gold
  24. {
  25. class General_options;
  26. class Workqueue;
  27. // A simple interface to manage directories to be searched for
  28. // libraries.
  29. class Dirsearch
  30. {
  31. public:
  32. Dirsearch()
  33. : directories_(NULL), token_(true)
  34. { }
  35. // Set the list of directories to search.
  36. void
  37. initialize(Workqueue*, const General_options::Dir_list*);
  38. // Search for a file, giving one or two names to search for (the
  39. // second one may be empty). Return a full path name for the file,
  40. // or the empty string if it could not be found. This may only be
  41. // called if the token is not blocked. Set *IS_IN_SYSROOT if the
  42. // file was found in a directory which is in the sysroot. *PINDEX
  43. // should be set to zero the first time this is called; it will be
  44. // updated with the index of the directory where the file is found,
  45. // and that value plus one may be used to find the next file with
  46. // the same name(s).
  47. std::string
  48. find(const std::vector<std::string>& names, bool* is_in_sysroot,
  49. int* pindex, std::string *found_name) const;
  50. // Return the blocker token which controls access.
  51. Task_token*
  52. token()
  53. { return &this->token_; }
  54. // Search for a file in a directory list. This is a low-level function and
  55. // therefore can be used before options and parameters are set.
  56. static std::string
  57. find_file_in_dir_list(const std::string& name,
  58. const General_options::Dir_list& directories,
  59. const std::string& extra_search_dir);
  60. private:
  61. // We can not copy this class.
  62. Dirsearch(const Dirsearch&);
  63. Dirsearch& operator=(const Dirsearch&);
  64. // Directories to search.
  65. const General_options::Dir_list* directories_;
  66. // Blocker token to control access from tasks.
  67. Task_token token_;
  68. };
  69. } // End namespace gold.
  70. #endif // !defined(GOLD_DIRSEARCH_H)