You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

get_main_pkgs.sh 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/usr/bin/env bash
  2. # Copyright The OpenTelemetry Authors
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. set -euo pipefail
  16. top_dir='.'
  17. if [[ $# -gt 0 ]]; then
  18. top_dir="${1}"
  19. fi
  20. p=$(pwd)
  21. mod_dirs=()
  22. # Note `mapfile` does not exist in older bash versions:
  23. # https://stackoverflow.com/questions/41475261/need-alternative-to-readarray-mapfile-for-script-on-older-version-of-bash
  24. while IFS= read -r line; do
  25. mod_dirs+=("$line")
  26. done < <(find "${top_dir}" -type f -name 'go.mod' -exec dirname {} \; | sort)
  27. for mod_dir in "${mod_dirs[@]}"; do
  28. cd "${mod_dir}"
  29. while IFS= read -r line; do
  30. echo ".${line#${p}}"
  31. done < <(go list --find -f '{{.Name}}|{{.Dir}}' ./... | grep '^main|' | cut -f 2- -d '|')
  32. cd "${p}"
  33. done