├── Makefile ├── README.md └── opam-compiler-conf.sh /Makefile: -------------------------------------------------------------------------------- 1 | define USAGE 2 | You can already use this script directly 3 | bash /path/to/opam-compiler-conf.sh 4 | 5 | You can "install" it in your PATH to make it usable from `opam` as 6 | opam compiler-conf ... 7 | 8 | To do this, just use 9 | make BINDIR=~/.local/bin install 10 | with BINDIR set to something in your PATH. 11 | endef 12 | export USAGE 13 | 14 | BINDIR=~/.local/bin 15 | 16 | SRC=opam-compiler-conf.sh 17 | DEST=$(BINDIR)/opam-compiler-conf 18 | 19 | all: 20 | @echo "$$USAGE" 21 | 22 | install: 23 | cp $(SRC) $(DEST) 24 | chmod +x $(DEST) 25 | 26 | uninstall: 27 | rm $(DEST) 28 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | opam-compiler-conf 2 | ================== 3 | 4 | A small script to create short-lived OPAM compiler switches from experimental OCaml branches 5 | 6 | ## Warning 7 | 8 | This tool currently only works with opam 1.x, not opam 2 that is nowadays the default. Sorry about that... 9 | See https://github.com/gasche/opam-compiler-conf/issues/14#issuecomment-427040608. 10 | 11 | ## Documentation 12 | 13 | Usage: 14 | ``` 15 | bash opam-compiler-conf.sh 16 | ``` 17 | 18 | Or, after `make BINDIR=~/.local/bin install`: 19 | ``` 20 | opam compiler-conf 21 | ``` 22 | 23 | Here is the output of the 'help' command: 24 | ``` 25 | available commands: get-switch get-conf check-conf get-descr configure install switch reinstall remove|uninstall help 26 | 27 | You should run this script from the directory of an OCaml compiler 28 | source that you wish to install as an OPAM switch. It was designed for 29 | short-lived experiments with experimental branches of the compiler, so 30 | it infers the switch name from DCVS information (only git is 31 | currently supported). 32 | 33 | The workflow should be as follows, from the root directory of an 34 | OCaml source tree: 35 | 36 | opam compiler-conf configure 37 | make world.opt # or any way to build the compiler 38 | opam compiler-conf install # gives you a new switch 39 | 40 | If you already have a switch for this compiler branch installed, then 41 | you should note that 42 | 43 | opam compiler-conf reinstall 44 | 45 | will recompile the OPAM packages in this switch, while just running 46 | 47 | make install 48 | 49 | will simply overwrite the compiler's installation. This can save time 50 | when you know the compiler change will not affect package compilation 51 | in any way. 52 | 53 | 54 | The full list of commands is the following: 55 | 56 | get-switch: returns the name of the OPAM switch inferred from DCVS information 57 | 58 | get-conf: returns the OPAM configuration file inferred 59 | 60 | get-descr: returns the OPAM description file inferred 61 | 62 | configure: runs the ./configure script of the OCaml distribution 63 | (OCaml needs to be told at ./configure time where it will 64 | be installed, and we handle this for you, knowing where 65 | OPAM will expect its stuff); you can pass it arguments 66 | expected by the configure script (eg. --no-tk) 67 | 68 | install: setups the OPAM switch and install it (will run 'make install') 69 | you need to have compiled the distribution first 70 | 71 | switch: switches to this new OPAM compiler (you'll still need to setup env) 72 | 73 | reinstall: reinstall the OPAM switch (useful if you changed the compiler source) 74 | 75 | uninstall: removes the OPAM switch and its configuration 76 | 77 | check-conf: checks that the last configured switch agrees with the 78 | current DCVS state (branch). This is useful if you have 79 | played with other branches (and thus other switches) and 80 | don't remember whether you should reconfigure before 81 | recompiling. 82 | 83 | get-paths: returns inferred paths (for debugging purposes) 84 | 85 | help: this message 86 | 87 | 88 | For configuration, the script supports the following environment 89 | variables: 90 | 91 | BASE_PACKAGES: Specifies the list of base-packages that a compiler 92 | description should list. It is a space-separated list of words. 93 | 94 | Default: "base-unix base-bigarray base-threads". 95 | 96 | FORCE_BRANCH: Overrides the detection of the branch name to specify 97 | any name you want (it should be an alphanumeric word with 98 | no spaces). For example, this is useful when you are checked out of 99 | your branch but still want to reinstall the current state at the 100 | same switch. 101 | 102 | FORCE_VERSION: Overrides the compiler-version detection. 103 | 104 | OPAM: the opam command to use. 105 | 106 | Default: "opam". 107 | 108 | ``` -------------------------------------------------------------------------------- /opam-compiler-conf.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #the "opam" command to use 4 | if [ -z "$OPAM" ] 5 | then 6 | OPAM=opam 7 | fi 8 | 9 | # the path to the OPAM installation 10 | OPAMDIR=$(opam config var root) 11 | if [ -z "$OPAMDIR" ] 12 | then 13 | echo 14 | echo "Error: could not determine the opam root using 'opam config var root'." 15 | echo "This may happen if you are on an switch that does not exist or was removed," 16 | echo "for example a switch created by this script then uninstalled." 17 | echo "You should switch back to a working opam state before running this script." 18 | echo "Exiting." 19 | exit 2 20 | fi 21 | 22 | USAGE="available commands:\ 23 | {get,show}-switch {get,show}-conf {get,show}-descr {get,show}-paths\ 24 | check-conf\ 25 | configure install switch reinstall {remove,uninstall}\ 26 | trouble help" 27 | 28 | if [ -z "$BASE_PACKAGES" ] 29 | then 30 | BASE_PACKAGES="base-unix base-bigarray base-threads" 31 | fi 32 | 33 | case $1 in 34 | ""|help) 35 | echo $USAGE 36 | echo 37 | cat <= 3.12": the version here needs to 161 | # give a more-or-less valid indication of which version compatibility 162 | # you will support, and in practice it does the right thing. 163 | # 164 | # For example, the SVN trunk has its VERSION file set to 165 | # 4.01.0+dev... which, when stripped of the +dev part, reasonably 166 | # indicates a high-enough OCaml version. 167 | # 168 | # OPAM packagers make use of this fact: for example, if 4.01.0 is the 169 | # name of the current development version, they will set "< 4.01.0" as 170 | # a version constraint for packages that are known to fail on trunk. 171 | 172 | if [ ! -f VERSION ] 173 | then 174 | cat < $OPAM_COMP_PATH 301 | (output_descr_data) > $OPAM_DESCR_PATH 302 | #will run 'make install' 303 | $OPAM switch install $SWITCH 304 | } 305 | 306 | do_reinstall() { 307 | check_is_installed 308 | $OPAM switch reinstall $SWITCH 309 | } 310 | 311 | do_uninstall() { 312 | if [ "$SWITCH" = $(opam switch show) ] 313 | then 314 | echo "You are still on the switch '$SWITCH', switching to 'system' to uninstall." 315 | $OPAM switch system 316 | fi 317 | $OPAM switch remove $SWITCH 318 | # issue #8: if users get a yes/no choice and chooses no, the remove 319 | # command above will return (with no particular exit code), yet 320 | # the switch is not uninstalled; do not remove 321 | # $OPAM_COMP_PATH in this case. 322 | if [ ! -d $PREFIX ] 323 | then 324 | rm $OPAM_COMP_PATH 325 | fi 326 | } 327 | 328 | # main :: IO () ;-) 329 | case "$1" in 330 | show-switch|get-switch) 331 | echo $SWITCH 332 | ;; 333 | check-conf) 334 | check_is_configured 335 | echo "Your opam compiler switch is correctly configured." 336 | echo "You can build the compiler, then run the 'install' command." 337 | ;; 338 | show-conf|get-conf) 339 | output_comp_data 340 | ;; 341 | show-descr|get-descr) 342 | output_descr_data 343 | ;; 344 | show-paths|get-paths) 345 | echo "PREFIX=$PREFIX" 346 | echo "OPAM_COMP_DIR=$OPAM_COMP_DIR" 347 | echo "OPAM_COMP_PATH=$OPAM_COMP_PATH" 348 | echo "OPAM_DESCR_PATH=$OPAM_DESCR_PATH" 349 | ;; 350 | configure) 351 | # configure the ocaml distribution for compilation 352 | shift 353 | ./configure --prefix $PREFIX "$@" 354 | ;; 355 | install) 356 | # check that ./configure was run 357 | check_is_configured 358 | do_install 359 | ;; 360 | switch) 361 | check_is_configured 362 | check_is_installed 363 | $OPAM switch $SWITCH 364 | ;; 365 | reinstall) 366 | check_is_configured 367 | if [ ! -f "$OPAM_COMP_PATH" ] 368 | then 369 | do_install 370 | else 371 | do_reinstall 372 | fi 373 | ;; 374 | remove|uninstall) 375 | check_is_installed 376 | do_uninstall 377 | ;; 378 | trouble) 379 | troubleshooting_tips 380 | ;; 381 | *) 382 | echo $USAGE 383 | ;; 384 | esac 385 | --------------------------------------------------------------------------------