update.go 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /* Copyright 2019 The Bazel Authors. All rights reserved.
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License.
  11. */
  12. package language
  13. import (
  14. "github.com/bazelbuild/bazel-gazelle/config"
  15. "github.com/bazelbuild/bazel-gazelle/repo"
  16. "github.com/bazelbuild/bazel-gazelle/rule"
  17. )
  18. // RepoUpdater may be implemented by languages that support updating
  19. // repository rules that provide named libraries.
  20. //
  21. // EXPERIMENTAL: this may change or be removed.
  22. type RepoUpdater interface {
  23. UpdateRepos(args UpdateReposArgs) UpdateReposResult
  24. }
  25. // UpdateReposArgs contains arguments for RepoUpdater.UpdateRepos.
  26. // Arguments are passed in a struct value so that new fields may be added
  27. // in the future without breaking existing implementations.
  28. //
  29. // EXPERIMENTAL: this may change or be removed.
  30. type UpdateReposArgs struct {
  31. // Config is the configuration for the main workspace.
  32. Config *config.Config
  33. // Imports is a list of libraries to update. UpdateRepos should return
  34. // repository rules that provide these libraries. It may also return
  35. // repository rules providing transitive dependencies.
  36. Imports []string
  37. // Cache stores information fetched from the network and ensures that
  38. // the same request isn't made multiple times.
  39. Cache *repo.RemoteCache
  40. }
  41. // UpdateReposResult contains return values for RepoUpdater.UpdateRepos.
  42. // Results are returned through a struct so that new (optional) fields may be
  43. // added without breaking existing implementations.
  44. //
  45. // EXPERIMENTAL: this may change or be removed.
  46. type UpdateReposResult struct {
  47. // Gen is a list of repository rules that provide libraries named by
  48. // UpdateImportArgs.Imports. These will be merged with existing rules or
  49. // added to WORKSPACE. This list may be shorter or longer than the list
  50. // of imports, since a single repository may provide multiple imports,
  51. // and additional repositories may be needed for transitive dependencies.
  52. Gen []*rule.Rule
  53. // Error is any fatal error that occurred. Non-fatal errors should be logged.
  54. Error error
  55. }
  56. // RepoImporter may be implemented by languages that support importing
  57. // repository rules from another build system.
  58. //
  59. // EXPERIMENTAL: this may change or be removed.
  60. type RepoImporter interface {
  61. // CanImport returns whether a given configuration file may be imported
  62. // with this extension. Only one extension may import any given file.
  63. // ImportRepos will not be called unless this returns true.
  64. CanImport(path string) bool
  65. // ImportRepos generates a list of repository rules by reading a
  66. // configuration file from another build system.
  67. ImportRepos(args ImportReposArgs) ImportReposResult
  68. }
  69. // ImportReposArgs contains arguments for RepoImporter.ImportRepos.
  70. // Arguments are passed in a struct value so that new fields may be added
  71. // in the future without breaking existing implementations.
  72. //
  73. // EXPERIMENTAL: this may change or be removed.
  74. type ImportReposArgs struct {
  75. // Config is the configuration for the main workspace.
  76. Config *config.Config
  77. // Path is the name of the configuration file to import.
  78. Path string
  79. // Prune indicates whether repository rules that are no longer needed
  80. // should be deleted. This means the Empty list in the result should be
  81. // filled in.
  82. Prune bool
  83. // Cache stores information fetched from the network and ensures that
  84. // the same request isn't made multiple times.
  85. Cache *repo.RemoteCache
  86. }
  87. // ImportReposResult contains return values for RepoImporter.ImportRepos.
  88. // Results are returned through a struct so that new (optional) fields may
  89. // be added without breaking existing implementations.
  90. //
  91. // EXPERIMENTAL: this may change or be removed.
  92. type ImportReposResult struct {
  93. // Gen is a list of imported repository rules.
  94. Gen []*rule.Rule
  95. // Empty is a list of repository rules that may be deleted. This should only
  96. // be set if ImportReposArgs.Prune is true.
  97. Empty []*rule.Rule
  98. // Error is any fatal error that occurred. Non-fatal errors should be logged.
  99. Error error
  100. }