https://gitlab.com/tezos/tezos
Raw File
Tip revision: 1a6133e4657496f3954a3ee9253f365af1b6a2a8 authored by Hantang Sun on 15 March 2024, 11:40:44 UTC
Etherlink/firehose: Tx pool stress test
Tip revision: 1a6133e
update_opam_lock.sh
#!/bin/sh

set -eu

help() {
  cat << EOT
This script updates opam/virtual/octez-deps.opam.locked.
This lock file contains the version number for all of Octez dependencies,
both direct and indirect. It does not include dev-only dependencies.

To produce this lock file, this scripts asks opam to use the commit:

  full_opam_repository_tag = $full_opam_repository_tag

from the public opam repository, to find a solution that is compatible
with opam/virtual/octez-deps.opam and opam/virtual/octez-dev-deps.opam.
Those two files are generated by the manifest
(see the documentation on profiles in manifest/manifest.mli).
Variable full_opam_repository_tag is defined in version.sh.
EOT
  exit 0
}

script_dir="$(cd "$(dirname "$0")" && echo "$(pwd -P)/")"
src_dir="$(dirname "$script_dir")"

# Needed for $full_opam_repository_tag
. scripts/version.sh

if [ "${1:-}" = "--help" ]; then
  help
fi

tmp_dir="$(mktemp -dt update_opam_lock.XXXXXXXX)"
tmp_opam_repo="$tmp_dir/repo"
tmp_opam_repo_name="update_opam_lock_tmp"
tmp_opam_switch="$tmp_dir/switch"

already_cleaned_up=no
clean_up() {
  if [ "$already_cleaned_up" = "no" ]; then
    already_cleaned_up=yes
    echo "---- Clean up."
    opam switch remove "$tmp_opam_switch" --yes || echo "Failed to remove switch."
    opam repository remove "$tmp_opam_repo_name" --all || echo "Failed to remove repository."
    rm -rf "$tmp_dir"
  fi
}

trap clean_up EXIT INT

# Ideally we would just set the opam repository URL to
# https://github.com/ocaml/opam-repository.git#$full_opam_repository_tag, but:
# - cloning the repo ourselves is actually significantly faster
#   (maybe opam does not know how to do a shallow clone);
# - this allows us to remove ocaml-system
#   (but we could also create the switch with --packages=ocaml-base-compiler.$ocaml_version);
# - this will allow us to remove other packages more easily in the future should we want to;
# - the --repositories argument of 'opam switch create' does not seem to understand
#   "url#tag", contrary to 'repository add'.
echo "---- Fetch opam repository commit: $full_opam_repository_tag"
git init "$tmp_opam_repo"
cd "$tmp_opam_repo"
git config --local protocol.version 2
git remote add origin https://github.com/ocaml/opam-repository
git fetch --depth 1 origin "$full_opam_repository_tag"
git checkout "$full_opam_repository_tag"
# Prevent opam from choosing the system-wide installed OCaml compiler.
rm -rf packages/ocaml-system
# Remove .git to be extra sure that opam will not use a different commit hash.
rm -rf .git
cd "$src_dir"

# We use --fake to tell opam not to actually compile the OCaml compiler.
# This breaks the switch but we will delete it afterwards anyway.
echo "---- Create a temporary fresh switch that uses our trimmed down repository."
unset OPAMSWITCH
opam switch create "$tmp_opam_switch" "$ocaml_version" \
  --repositories="$tmp_opam_repo_name"="$tmp_opam_repo" --no-install --fake
export OPAMSWITCH="$tmp_opam_switch"

# The default timeout (60 seconds) is often not enough.
export OPAMSOLVERTIMEOUT="${OPAMSOLVERTIMEOUT:-600}"

# Ask opam to find a solution that covers both:
# - 'octez-deps', so that we can compile Octez;
# - 'octez-dev-deps', so that the solution is compatible with tools that devs
#   may want to install.
# We use --fake to tell opam not to actually compile the packages.
echo "---- Run: 'opam install'"
opam install --yes --deps-only --fake opam/virtual/octez-deps.opam opam/virtual/octez-dev-deps.opam

# The utop package is a special case.
# The pyml package, which is an actual dependency, optionally depends on utop.
# So if utop is installed, it is added in the lock file because of pyml.
# But utop is only a dev dependency, and as such does not need to appear in the lock file.
# So we remove it before generating the lock file.
echo "---- Run: 'opam remove utop'"
opam remove --yes --fake utop

echo "---- Run: 'opam lock'"
opam lock opam/virtual/octez-deps.opam

mv octez-deps.opam.locked opam/virtual
echo "---- Updated: opam/virtual/octez-deps.opam.locked"
back to top