golang.org/x/build@v0.0.0-20240506185731-218518f32b70/env/windows-arm64/azure/setupAndRunAllDotBat.sh (about)

     1  #!/bin/sh
     2  # Copyright 2023 The Go Authors. All rights reserved.
     3  # Use of this source code is governed by a BSD-style
     4  # license that can be found in the LICENSE file.
     5  
     6  #
     7  # For initial hand testing a newly created/configured test/debug VM. Set the
     8  # environment variables below before running this script:
     9  #
    10  #    ACCOUNT             account to use when ssh'ing to the VM
    11  #    VM_IP_ADDRESS       public IP address of VM
    12  #
    13  # Note that as the script runs it will invoke "ssh", which will require the
    14  # invoker to enter the VM account password several times. TODO: use -M and
    15  # -S ssh flags to avoid reauthentication.
    16  #
    17  # This script also uses "gsutil" to copy things from the go-builder GCS bucket
    18  # as part of the setup.
    19  #
    20  #-----------------------------
    21  #
    22  function checkvarpresent() {
    23    local TAG="$1"
    24    local WHICH="$2"
    25    if [ -z "$WHICH" ]; then
    26      echo "error: set env var $TAG before running this script"
    27      exit 1
    28    fi
    29  }
    30  #
    31  function copy_file_to_vm() {
    32    local FILE="$1"
    33    local TGT="$2"
    34    local SPATH="scp://${ACCOUNT}@${VM_IP_ADDRESS}/${TGT}"
    35    echo "... executing: scp $FILE $SPATH"
    36    scp $FILE $SPATH
    37    if [ $? != 0 ]; then
    38      echo "** copy failed, aborting"
    39      exit 1
    40    fi
    41  }
    42  function run_command_on_vm() {
    43    local CMD="$*"
    44    echo "... executing: ssh ${ACCOUNT}@${VM_IP_ADDRESS} $CMD"
    45    ssh ${ACCOUNT}@${VM_IP_ADDRESS} $CMD
    46    if [ $? != 0 ]; then
    47      echo "** command failed, aborting"
    48      exit 1
    49    fi
    50  }
    51  function copy_from_go_builder_data() {
    52    local FILE="$1"
    53    local TGT="$2"
    54    echo "... executing: gsutil cp gs://go-builder-data/${FILE} $TGT"
    55    gsutil cp gs://go-builder-data/${FILE} $TGT
    56    if [ $? != 0 ]; then
    57      echo "error: copy from gs://go-builder-data/${FILE} failed, aborting"
    58      exit 1
    59    fi
    60  }
    61  #
    62  checkvarpresent ACCOUNT "$ACCOUNT"
    63  checkvarpresent VM_IP_ADDDRESS "$VM_IP_ADDRESS"
    64  #
    65  # Create various directories on the VM.
    66  #
    67  TF=`mktemp /tmp/mkdirsbat.XXXXXXXXXX`
    68  cat >$TF<<EOF
    69  rmdir /s /q C:\Windows\Temp\go
    70  rmdir /s /q C:\Windows\Temp\gobootstrap
    71  mkdir C:\Windows\Temp\go
    72  mkdir C:\Windows\Temp\gobootstrap
    73  EOF
    74  echo "... creating go and gobootstrap directories on VM"
    75  SCRIPT="C:\Windows\Temp\mkdirs.bat"
    76  copy_file_to_vm $TF $SCRIPT
    77  rm -f $TF
    78  run_command_on_vm $SCRIPT
    79  echo "... dir creation on vm complete."
    80  #
    81  # Collect windows bootstrap go to use with all.bat
    82  #
    83  TF2=`mktemp /tmp/bootstrapgo.XXXXXXXXXX`
    84  echo "... copying bootstrap Go from GCS bucket to local path"
    85  copy_from_go_builder_data gobootstrap-windows-arm64-go1.17.13.tar.gz $TF2
    86  #
    87  # Copy the bootstrap Go tar file to the VM.
    88  #
    89  echo "... copying bootstrap Go to VM"
    90  BOOTGOLOC="C:\Windows\Temp\bootgo.tgz"
    91  copy_file_to_vm $TF2 $BOOTGOLOC
    92  rm -f $TF2
    93  echo "... finished copying bootstrap Go to VM"
    94  #
    95  # Unpack the bootstrap Go on the VM
    96  #
    97  echo "... unpacking bootstrap Go on VM"
    98  run_command_on_vm "C:\golang\bootstrap.exe --untar-file=${BOOTGOLOC} --untar-dest-dir=C:\Windows\Temp\gobootstrap"
    99  echo "... finished unpacking bootstrap Go on VM"
   100  #
   101  # Clone Go repo at head, dump a dummy version in it.
   102  #
   103  echo "... starting clone of Go repo"
   104  TF3=`mktemp -d /tmp/gorepo.XXXXXXXXXX`
   105  TF4=`mktemp /tmp/go.XXXXXXXXXX.tgz`
   106  mkdir $TF3/go
   107  git clone --depth=1  https://go.googlesource.com/go $TF3/go
   108  if [ $? != 0 ]; then
   109    echo "error: git clone failed (git clone --depth=1  https://go.googlesource.com/go $TF3/go)"
   110    exit 1
   111  fi
   112  echo -n devel gomote.XXXXX > $TF3/go/VERSION
   113  echo -n devel gomote.XXXXX > $TF3/go/VERSION.cache
   114  rm -rf $TF3/go/.git
   115  echo "... finished clone and setup of Go repo"
   116  #
   117  # Tar up the Go repo and copy it to the VM
   118  #
   119  echo "... tar up go repo"
   120  (cd $TF3 ; tar zcf - ./go) > $TF4
   121  echo "... copying go repo tar file to VM"
   122  GOTIPLOC="C:\Windows\Temp\gotip.tgz"
   123  copy_file_to_vm $TF4 $GOTIPLOC
   124  rm -f $TF4
   125  rm -rf $TF3
   126  #
   127  # Unpack on the VM
   128  #
   129  echo "... unpacking Go repo tar file on vm"
   130  run_command_on_vm "C:\golang\bootstrap.exe --untar-file=${GOTIPLOC} --untar-dest-dir=C:\Windows\Temp\go"
   131  #
   132  # Create command to run all.bat
   133  #
   134  TF5=`mktemp /tmp/runallbat.XXXXXXXXXX`
   135  echo "... creating bat script to run all.bat"
   136  cat >$TF5<<EOF
   137  cd C:\Windows\Temp\go\go\src
   138  set PATH=%PATH%;C:\godep\llvm-aarch64\bin
   139  set GOROOT_BOOTSTRAP=C:\Windows\Temp\gobootstrap
   140  all.bat
   141  EOF
   142  #
   143  # Copy script to VM
   144  #
   145  echo "... copying all.bat script to VM"
   146  ALLBATSCRIPT="C:\Windows\Temp\runall.bat"
   147  copy_file_to_vm $TF5 $ALLBATSCRIPT
   148  rm -f $TF5
   149  #
   150  # Execute
   151  #
   152  echo "... running all.bat invocation script"
   153  run_command_on_vm $ALLBATSCRIPT
   154  echo "done."
   155  exit 0