Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added update script

  • Loading branch information...
commit cc4e3c07c2ebb19dbb90c2d29c828f5fb714e605 1 parent 9c03c27
Andrei Alexandrescu authored

Showing 1 changed file with 182 additions and 0 deletions. Show diff stats Hide diff stats

  1. 182  update.sh
182  update.sh
... ...
@@ -0,0 +1,182 @@
  1
+#!/bin/zsh
  2
+
  3
+# Run this script to install or update your dmd toolchain from
  4
+# github.
  5
+#
  6
+# First run, create a working directory, e.g. /path/to/d/. Then run
  7
+# this script from that directory (the location of the script itself
  8
+# doesn't matter). It will create the following subdirectories:
  9
+# /path/to/d/dmd, /path/to/d/druntime, /path/to/d/phobos,
  10
+# /path/to/d/d-programming-language.org, /path/to/d/tools, and
  11
+# /path/to/d/installer. Then it will fetch all corresponding projects
  12
+# from github and build them fresh.
  13
+#
  14
+# On an ongoing basis, to update your toolchain from github go again
  15
+# to the same directory (in our example /path/to/d) and run the script
  16
+# again. The script will detect that directories exist and will do an
  17
+# update.
  18
+#
  19
+
  20
+setopt err_exit
  21
+
  22
+local projects
  23
+typeset -a projects
  24
+projects=(dmd druntime phobos d-programming-language.org tools installer)
  25
+# Working directory
  26
+local wd=$(pwd)
  27
+# List of projects to install vs. update. Their disjoint union is
  28
+# $projects.
  29
+local toInstall toUpdate
  30
+typeset -a toInstall toUpdate
  31
+# Mess to go here
  32
+local tempdir=$(mktemp -d /tmp/dmd-update.XXX)
  33
+
  34
+#
  35
+# Take care of the command line arguments
  36
+#
  37
+function handleCmdLine() {
  38
+    local arg
  39
+    for arg in $*; do
  40
+        case $arg in
  41
+    	    (--tag=*)
  42
+            tag="`echo $arg | sed 's/[-a-zA-Z0-9]*=//'`"
  43
+            ;;
  44
+            (*)
  45
+            echo "Error: $arg not recognized." >&2exit 1
  46
+            ;;
  47
+        esac
  48
+    done
  49
+
  50
+    if [[ ! -z $tag ]]; then
  51
+        wd+="/$tag"
  52
+        mkdir -p "$wd"
  53
+    fi
  54
+}
  55
+
  56
+#
  57
+# Confirm correct choices
  58
+#
  59
+function confirmChoices() {
  60
+    function joinWithWorkingDir() {
  61
+        for i in $*; do
  62
+            echo "$wd/$i"
  63
+        done
  64
+    }
  65
+
  66
+    for project in $projects; do
  67
+        if [ -e "$wd/$project" ]; then
  68
+            toUpdate=($toUpdate "$project")
  69
+        else
  70
+            toInstall=($toInstall "$project")
  71
+        fi
  72
+    done
  73
+    if [[ ! -z $toInstall ]]; then
  74
+        echo "*** The following projects will be INSTALLED:"
  75
+        joinWithWorkingDir ${toInstall}
  76
+    fi
  77
+    if [[ ! -z $toUpdate ]]; then
  78
+        echo "*** The following projects will be UPDATED:"
  79
+        joinWithWorkingDir ${toUpdate}
  80
+    fi
  81
+
  82
+    echo "Is this what you want?"
  83
+    local yn
  84
+    while true; do
  85
+        read yn
  86
+        case $yn in
  87
+            [Yy]* ) break;;
  88
+            [Nn]* ) exit;;
  89
+            * ) echo "Please answer y or n.";;
  90
+        esac
  91
+    done
  92
+}
  93
+
  94
+#
  95
+# Install from scratch
  96
+#
  97
+
  98
+function installAnew() {
  99
+    local projects
  100
+    projects=($*)
  101
+    for project in $projects; do
  102
+        (
  103
+            cd $wd &&
  104
+            git clone --quiet git@github.com:D-Programming-Language/$project.git &&
  105
+            touch $tempdir/$project
  106
+        ) &
  107
+    done
  108
+    wait
  109
+
  110
+    for project in $projects; do
  111
+        if [ ! -f $tempdir/$project ]; then
  112
+            echo "Getting $project failed." >&2
  113
+            rm -rf $tempdir
  114
+            exit 1
  115
+        fi
  116
+        if [[ ! -z $tag &&
  117
+                    ($project = dmd || $project = druntime || $project = phobos ||
  118
+                        $project = d-programming-language.org) ]]; then
  119
+	        ( cd $wd/$project && git checkout v$tag )
  120
+        fi
  121
+    done
  122
+}
  123
+
  124
+#
  125
+# Freshen existing stuff
  126
+#
  127
+
  128
+function update() {
  129
+    echo "Updating projects in $wd..."
  130
+
  131
+    function update_project() {
  132
+        local project=$1
  133
+        if ! ( cd "$wd/$project" && \
  134
+            git checkout master && \
  135
+            git pull origin master && \
  136
+            git pull origin master --tags && \
  137
+            git fetch && \
  138
+            git fetch --tags) 2>$tempdir/$project.log
  139
+        then
  140
+            echo "Failure updating $wd/$project." >>$tempdir/errors
  141
+            exit 1
  142
+        fi
  143
+    }
  144
+
  145
+    for project in $toUpdate; do
  146
+        update_project $project &
  147
+    done
  148
+    wait
  149
+
  150
+    if [ -f $tempdir/errors ]; then
  151
+        cat $tempdir/*.log >&2
  152
+        exit 1
  153
+    fi
  154
+}
  155
+
  156
+function makeWorld() {
  157
+# First make dmd
  158
+    ( cd "$wd/dmd/src" && make -f posix.mak clean  && make -f posix.mak -j 8 )
  159
+
  160
+# Update the running dmd version
  161
+    echo "Copying "$wd/dmd/src/dmd" over $(which dmd)"
  162
+    sudo cp "$wd/dmd/src/dmd" $(which dmd)
  163
+
  164
+# Then make druntime
  165
+    ( cd "$wd/druntime" && make -f posix.mak -j 8 DMD="$wd/dmd/src/dmd" )
  166
+
  167
+# Then make phobos
  168
+    ( cd "$wd/phobos" && make -f posix.mak -j 8 DMD="$wd/dmd/src/dmd" )
  169
+
  170
+# Then make website
  171
+    ( cd "$wd/d-programming-language.org" &&
  172
+        make -f posix.mak clean DMD="$wd/dmd/src/dmd" &&
  173
+        make -f posix.mak html -j 8 DMD="$wd/dmd/src/dmd"
  174
+    )
  175
+}
  176
+
  177
+# main
  178
+handleCmdLine
  179
+confirmChoices
  180
+installAnew $toInstall
  181
+update $toUpdate
  182
+makeWorld

0 notes on commit cc4e3c0

rofl0r

First, install zsh

Please sign in to comment.
Something went wrong with that request. Please try again.