cargo-post-process 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/usr/bin/env bash
  2. set -e
  3. # shellcheck source=helpers source-path=SCRIPTDIR
  4. . "${0%/*}/helpers"
  5. if [ "${BR_CARGO_MANIFEST_PATH}" ]; then
  6. printf 'Setting BR_CARGO_MANIFEST_PATH is no longer supported; use post-process options.\n' >&2
  7. exit 1
  8. fi
  9. manifest=Cargo.toml
  10. while getopts "n:o:m:" OPT; do
  11. case "${OPT}" in
  12. o) output="${OPTARG}";;
  13. n) base_name="${OPTARG}";;
  14. m) manifest="${OPTARG}";;
  15. :) error "option '%s' expects a mandatory argument\n" "${OPTARG}";;
  16. \?) error "unknown option '%s'\n" "${OPTARG}";;
  17. esac
  18. done
  19. # Already vendored tarball, nothing to do
  20. if tar tf "${output}" | grep -q "^[^/]*/VENDOR" ; then
  21. exit 0
  22. fi
  23. post_process_unpack "${base_name}" "${output}"
  24. # Do the Cargo vendoring
  25. pushd "${base_name}" > /dev/null
  26. # Create the local .cargo/config.toml with vendor info
  27. mkdir -p .cargo/
  28. mkdir -p "${CARGO_HOME}"
  29. flock "${CARGO_HOME}"/.br-lock \
  30. cargo vendor \
  31. --manifest-path "${manifest}" \
  32. --locked VENDOR \
  33. > .cargo/config.toml
  34. # "cargo vendor' outputs on stderr a message directing to add some data
  35. # to the project's .cargo/config.toml, data that it outputs on stdout.
  36. # Since we redirect stdout to .cargo/config.toml, the message on stderr
  37. # gets confusing, so instruct the user that it's been handled.
  38. printf '(note: .cargo/config.toml automatically updated by Buildroot)\n\n'
  39. popd > /dev/null
  40. post_process_repack "$(pwd)" "${base_name}" "${output}"