#!/bin/bash # nailing-cargo: wrapper to use unpublished local crates # # Copyright (C) 2019 Ian Jackson # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as # published by the Free Software Foundation, either version 3 of the # License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . set -e # example usages: # ../nailing-cargo/nailing-cargo make # ../nailing-cargo/nailing-cargo cargo build # CARGO='../nailing-cargo/nailing-cargo cargo' make # Why do we need this ? # # https://stackoverflow.com/questions/33025887/how-to-use-a-local-unpublished-crate # https://github.com/rust-lang/cargo/issues/1481 lock=${PWD%/*}/.nail.lock if [ "x$NAILING_CARGO" != "x$lock" ]; then NAILING_CARGO=$lock \ exec with-lock-ex -w "$lock" "$0" "$@" fi exec 203<../Cargo.nail f=Cargo.toml sed=' /^ *\[dependencies\]/,/^ \[/{ ' exec 204<../Cargo.nail while read <&204 what where; do if [ "x$what" = x- ]; then continue; fi if [ "x$what" = 'x#' ]; then continue; fi qwhere="${where//\//\\/}" sed+=' s/^'$what' *= *\(\".*\"\) *$/'$what' = { version = \1 }/; s/^'$what' *= *{/'$what' = { path = "..\/'"${qwhere}"'", /; /^'$what' *=/ s/version *= *\"[^"]*\"//; /^'$what' *=/ s/, *\([,}]\)/\1/; ' done sed+='} ' exec 204<../Cargo.nail while read <&204 what where; do if [ "x$what" = 'x#' ]; then continue; fi wf=../$where/$f rm -f $wf.nailing~ sed <$wf >$wf.nailing~ "$sed" done exec 204<../Cargo.nail while read <&204 what where; do if [ "x$what" = 'x#' ]; then continue; fi wf=../$where/$f if ! test -e $wf.unnailed~; then ln $wf $wf.unnailed~ fi done trap ' set +e while read <&203 what where; do if [ "x$what" = "x#" ]; then continue; fi wf=../$where/$f if test -e $wf.unnailed~; then rm -f $wf.nailed~ ln $wf $wf.nailed~ mv -f $wf.unnailed~ $wf fi done echo >&2 'Unnailed' ' EXIT exec 204<../Cargo.nail printf >&2 'Nailing' while read <&204 what where; do if [ "x$what" = 'x#' ]; then continue; fi wf=../$where/$f printf >&2 ' %s' "$what" if cmp -s $wf.nailed~ $wf.nailing~; then mv -f $wf.nailed~ $wf rm -f $wf.nailing else mv -f $wf.nailing~ $wf rm -f $wf.nailed fi done echo >&2 "$@"