lint-deps.sh 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. #!/usr/bin/env bash
  2. # Copyright Materialize, Inc. and contributors. All rights reserved.
  3. #
  4. # Use of this software is governed by the Business Source License
  5. # included in the LICENSE file at the root of this repository.
  6. #
  7. # As of the Change Date specified in that file, in accordance with
  8. # the Business Source License, use of this software will be governed
  9. # by the Apache License, Version 2.0.
  10. #
  11. # Compare dependencies and their flags against a ground truth. This serves against accidentally enabling dependencies
  12. # or feature flags.
  13. #
  14. # Example usages:
  15. #
  16. # $ ci/test/lint-deps.sh
  17. #
  18. # To rewrite the stored files, pass the --rewrite option.
  19. #
  20. # See the [README](lint-deps/README.md) for more details.
  21. set -euo pipefail
  22. . misc/shlib/shlib.bash
  23. # Explicitly name targets to check dependencies. We support Apple and Linux on ARM64 and x86_64.
  24. targets=(
  25. aarch64-apple-darwin
  26. x86_64-apple-darwin
  27. aarch64-unknown-linux-gnu
  28. x86_64-unknown-linux-gnu
  29. )
  30. if [[ "$(uname -s)" = Darwin ]]; then
  31. tac() {
  32. tail -r
  33. }
  34. fi
  35. rewrite=false
  36. resources="$(dirname "$0")/lint-deps"
  37. if [[ "${1:-}" = --rewrite ]]; then
  38. shift
  39. rewrite=true
  40. fi
  41. function deps() {
  42. echo "# generated by $0 -- see ${resources}/README.md for details"
  43. # We iterate $crates instead of passing all to `cargo tree` because it produces no
  44. # output if there is no dependency to any of the specified packages.
  45. for crate in "${crates[@]}"; do
  46. # Gather data for the current target, reverse lines, find the dependency hierarchy to the root, reverse lines.
  47. # shellcheck disable=SC2046
  48. output=$(cargo tree \
  49. $(printf -- "-p %s " "${entrypoints[@]}") \
  50. --format ':{lib}:{f}' \
  51. --prefix depth \
  52. --edges normal,build \
  53. --locked \
  54. --target "$target" \
  55. "$@" \
  56. | tac \
  57. | awk -F: 'BEGIN {f=-1} /^([0-9]+):'"$crate"'/{print;f=$0-1} f==$1{print;f=f-1}' \
  58. | tac)
  59. # Only print crate and dependency chain if there is a dependency.
  60. if [ -n "$output" ]; then
  61. echo "$crate"
  62. echo "$output"
  63. fi
  64. done
  65. }
  66. ci_uncollapsed_heading "Linting dependencies -- if the check fails, consult ci/test/lint-deps/README.md"
  67. ################################################
  68. # Jemalloc lints
  69. ################################################
  70. # List of crates to include in the dependency lint, including an explanation why they're listed.
  71. crates=(
  72. # Checks that the default allocator is jemalloc on supported platforms, but can
  73. # be disabled using --no-default-features or explicitly enabled with --features=jemalloc
  74. tikv_jemalloc_ctl
  75. tikv_jemallocator
  76. tikv_jemalloc_sys
  77. )
  78. # The crates whose dependency graphs we want to lint.
  79. entrypoints=(
  80. mz-clusterd
  81. mz-environmentd
  82. mz-materialized
  83. )
  84. for target in "${targets[@]}"; do
  85. if $rewrite; then
  86. deps > "$resources/$target-default"
  87. deps --no-default-features > "$resources/$target-no-default-features"
  88. deps --features jemalloc > "$resources/$target-jemalloc"
  89. else
  90. try diff "$resources/$target-default" <(deps)
  91. try diff "$resources/$target-no-default-features" <(deps --no-default-features)
  92. try diff "$resources/$target-jemalloc" <(deps --features jemalloc)
  93. fi
  94. done
  95. ################################################
  96. # workspace-hack lints
  97. ################################################
  98. # List of crates to include in the dependency lint, including an explanation why they're listed.
  99. crates=(
  100. # Should not be included in anything that may end up in the cloud repo.
  101. # Eventually, we should be able to disable this everywhere with --no-default-features.
  102. workspace_hack
  103. )
  104. # The crates whose dependency graphs we want to lint.
  105. # This should include any current or potential dependencies
  106. # used by the cloud repo.
  107. entrypoints=(
  108. mz-alloc
  109. mz-aws-secrets-controller
  110. mz-aws-util
  111. mz-build-info
  112. mz-build-tools
  113. mz-cloud-provider
  114. mz-cloud-resources
  115. mz-http-util
  116. mz-license-keys
  117. mz-lowertest
  118. mz-lowertest-derive
  119. mz-npm
  120. mz-orchestrator
  121. mz-orchestrator-kubernetes
  122. mz-orchestrator-process
  123. mz-orchestrator-tracing
  124. mz-orchestratord
  125. mz-ore
  126. mz-ore-build
  127. mz-ore-proc
  128. mz-persist-types
  129. mz-pgrepr-consts
  130. mz-pgtz
  131. mz-prof
  132. mz-prof-http
  133. mz-proto
  134. mz-repr
  135. mz-secrets
  136. mz-segment
  137. mz-service
  138. mz-sql-lexer
  139. mz-sql-parser
  140. mz-tls-util
  141. mz-tracing
  142. mz-walkabout
  143. )
  144. for target in "${targets[@]}"; do
  145. if $rewrite; then
  146. deps --no-default-features > "$resources/$target-workspace-hack-no-default-features"
  147. else
  148. try diff "$resources/$target-workspace-hack-no-default-features" <(deps --no-default-features)
  149. fi
  150. done
  151. try_status_report