config.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. // Copyright 2018 Google Inc. All rights reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package paths
  15. import "runtime"
  16. type PathConfig struct {
  17. // Whether to create the symlink in the new PATH for this tool.
  18. Symlink bool
  19. // Whether to log about usages of this tool to the soong.log
  20. Log bool
  21. // Whether to exit with an error instead of invoking the underlying tool.
  22. Error bool
  23. // Whether we use a linux-specific prebuilt for this tool. On Darwin,
  24. // we'll allow the host executable instead.
  25. LinuxOnlyPrebuilt bool
  26. }
  27. // These binaries can be run from $PATH, nonhermetically. There should be as
  28. // few as possible of these, since this means that the build depends on tools
  29. // that are not shipped in the source tree and whose behavior is therefore
  30. // unpredictable.
  31. var Allowed = PathConfig{
  32. Symlink: true,
  33. Log: false,
  34. Error: false,
  35. }
  36. // This tool is specifically disallowed and calling it will result in an
  37. // "executable no found" error.
  38. var Forbidden = PathConfig{
  39. Symlink: false,
  40. Log: true,
  41. Error: true,
  42. }
  43. // This tool is allowed, but access to it will be logged.
  44. var Log = PathConfig{
  45. Symlink: true,
  46. Log: true,
  47. Error: false,
  48. }
  49. // The configuration used if the tool is not listed in the config below.
  50. // Currently this will create the symlink, but log and error when it's used. In
  51. // the future, I expect the symlink to be removed, and this will be equivalent
  52. // to Forbidden. This applies to every tool not specifically mentioned in the
  53. // configuration.
  54. var Missing = PathConfig{
  55. Symlink: true,
  56. Log: true,
  57. Error: true,
  58. }
  59. // This is used for binaries for which we have prebuilt versions, but only for
  60. // Linux. Thus, their execution from $PATH is only allowed on Mac OS.
  61. var LinuxOnlyPrebuilt = PathConfig{
  62. Symlink: false,
  63. Log: true,
  64. Error: true,
  65. LinuxOnlyPrebuilt: true,
  66. }
  67. func GetConfig(name string) PathConfig {
  68. if config, ok := Configuration[name]; ok {
  69. return config
  70. }
  71. return Missing
  72. }
  73. // This list specifies whether a particular binary from $PATH is allowed to be
  74. // run during the build. For more documentation, see path_interposer.go .
  75. var Configuration = map[string]PathConfig{
  76. "bash": Allowed,
  77. "dd": Allowed,
  78. "diff": Allowed,
  79. "dlv": Allowed,
  80. "expr": Allowed,
  81. "fuser": Allowed,
  82. "getopt": Allowed,
  83. "git": Allowed,
  84. "hexdump": Allowed,
  85. "jar": Allowed,
  86. "java": Allowed,
  87. "javap": Allowed,
  88. "lsof": Allowed,
  89. "openssl": Allowed,
  90. "pstree": Allowed,
  91. "rsync": Allowed,
  92. "sh": Allowed,
  93. "stubby": Allowed,
  94. "tr": Allowed,
  95. "unzip": Allowed,
  96. "zip": Allowed,
  97. // Host toolchain is removed. In-tree toolchain should be used instead.
  98. // GCC also can't find cc1 with this implementation.
  99. "ar": Forbidden,
  100. "as": Forbidden,
  101. "cc": Forbidden,
  102. "clang": Forbidden,
  103. "clang++": Forbidden,
  104. "gcc": Forbidden,
  105. "g++": Forbidden,
  106. "ld": Forbidden,
  107. "ld.bfd": Forbidden,
  108. "ld.gold": Forbidden,
  109. "pkg-config": Forbidden,
  110. // These are toybox tools that only work on Linux.
  111. "pgrep": LinuxOnlyPrebuilt,
  112. "pkill": LinuxOnlyPrebuilt,
  113. "ps": LinuxOnlyPrebuilt,
  114. }
  115. func init() {
  116. if runtime.GOOS == "darwin" {
  117. Configuration["sw_vers"] = Allowed
  118. Configuration["xcrun"] = Allowed
  119. // We don't have darwin prebuilts for some tools,
  120. // so allow the host versions.
  121. for name, config := range Configuration {
  122. if config.LinuxOnlyPrebuilt {
  123. Configuration[name] = Allowed
  124. }
  125. }
  126. }
  127. }