File: rev-deps.sh

package info (click to toggle)
ppxlib 0.15.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 1,284 kB
  • sloc: ml: 17,184; sh: 149; makefile: 36; python: 36
file content (154 lines) | stat: -rwxr-xr-x 2,897 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/bin/bash
set -euo pipefail


pull () {
  case $1 in
    janestreet|js)
      JS_GREP_ARG=""
      ;;
    *)
      JS_GREP_ARG="-v"
      ;;
  esac

  # Get a first list of revdeps candidate
  REVDEPS=$(opam list -s --depends-on ppxlib.0.13.0 --coinstallable-with ocaml.4.10.0)

  TRUE_REVDEPS=""
  for d in $REVDEPS
  do
    ALL_VERS=$(opam show --field=all-versions $d)
    LATEST_VER=${ALL_VERS##* }
    deps=$(opam show --field=depends: $d.$LATEST_VER)
    # Filter out packages that come from Janestreet mono repo and
    # packages whose latest version isn't a rev dep anymore
    if (opam show --field=maintainer: $d.$LATEST_VER | grep $JS_GREP_ARG "janestreet" > /dev/null) &&
      (echo "$deps" | grep "ppxlib" > /dev/null) &&
      (echo "$deps" | grep "dune" > /dev/null)
    then
      TRUE_REVDEPS="$TRUE_REVDEPS $d.$LATEST_VER"
    fi
  done

  if [ -z "$TRUE_REVDEPS" ]
  then
    echo "No revdeps found for ppxlib"
    exit 1
  fi

  mkdir -p dunireverse
  cd dunireverse

  for d in $TRUE_REVDEPS
  do
    echo "$d" >> .deps
  done

  cat .deps

  for d in $TRUE_REVDEPS
  do
    basename=${d%%.*}
    ver=${d#*.}
    tmp=$(opam show --field=dev-repo: $d)
    tmp=${tmp%\"}
    tmp=${tmp#\"}
    DEV_REPO=${tmp#git+}
    git clone $DEV_REPO $basename
    case $1 in
      janestreet|js)
        # To checkout to the latest released version
        cd $basename
        git checkout $ver || git checkout v$ver
        cd ..
        ;;
      *)
        :
        ;;
    esac
  done
  cd ..
}

install_deps_opam () {
  cd dunireverse
  for dir in */
  do
    basename=${dir%/}
    echo "Installing $basename dependencies"
    opam install --deps-only $basename/$basename.opam -y || opam install --deps-only $basename/opam -y
  done
}

install_deps_duniverse () {
  # Generate a dummy opam file
  echo 'opam-version: "2.0"' > dunireverse.opam
  echo "depends: [" >> dunireverse.opam
  echo "  \"ocaml\" {=\"4.10.0\"}" >> dunireverse.opam
  cat dunireverse/.deps | while read line
  do
    basename=${line%%.*}
    ver=${line#*.}
    echo "  \"$basename\" {=\"$ver\"}" >> dunireverse.opam
  done
  echo "]" >> dunireverse.opam
  duniverse init
  duniverse opam-install || true
  duniverse pull --no-cache

  cat dunireverse/.deps | while read line
  do
    rm -r duniverse/$line
  done
}

install_deps () {
  case $1 in
    duniverse)
      install_deps_duniverse
      ;;
    opam|*)
      install_deps_opam
      ;;
  esac
}

build () {
  PACKAGES="ppxlib"
  cd dunireverse
  for dir in */
  do
    basename=${dir%/}
    PACKAGES="$PACKAGES,$basename"
  done
  cd ..
  dune build -p $PACKAGES
}

if [ $# -ne 2 ]
then
  SND_ARG=""
else
  SND_ARG="$2"
fi

case $1 in
  "")
    pull
    install_deps
    build
    ;;
  pull)
    pull "$SND_ARG"
    ;;
  install-deps)
    install_deps "$SND_ARG"
    ;;
  build)
    build
    ;;
  *)
    echo "invalid subcommand $1"
    exit 1
esac