Skip to content

Commit

Permalink
Move the R build script to the devcontainer
Browse files Browse the repository at this point in the history
  • Loading branch information
programLyrique committed Jan 16, 2025
1 parent 3c7db97 commit b48e481
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 1 deletion.
4 changes: 3 additions & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,6 @@ RUN curl -fsSL -o /opt/llvm.sh https://apt.llvm.org/llvm.sh \
&& /opt/llvm.sh "$LLVM_VERSION"

# Install R
RUN make setup
COPY ./build-gnur.sh /workspace/tools/build-gnur.sh
RUN mkdir -p /workspace/external
RUN cd /workspace/external ; bash ../tools/build-gnur.sh
112 changes: 112 additions & 0 deletions .devcontainer/build-gnur.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#!/bin/bash

set -Eeuo pipefail

SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
BASE_DIR=$(cd "$SCRIPT_DIR/.." && pwd)
R_DIR=""

if [ ! -d "$BASE_DIR" ]; then
echo "Could not determine absolute dir of $0"
echo "Maybe accessed with symlink"
exit 1
fi

function usage() {
echo "$0 [-d] <R sources path>"
}

while [[ $# -gt 0 ]]; do
case $1 in
-d | --debug)
export CFLAGS="-ggdb3 -O0"
export CXXFLAGS="-ggdb3 -O0"
export CPPFLAGS="-ggdb3 -O0"
echo "Building a debug version of R"
shift
;;
-*)
echo "Unknown option $1"
exit 1
;;
*)
if [[ -z "$R_DIR" ]]; then
R_DIR="$1"
shift
else
echo "Unknown options $*"
exit 1
fi
;;
esac
done

if [[ -z "$R_DIR" ]]; then
usage
exit 1
fi

echo "Building in $R_DIR"

if [[ "$OSTYPE" == "darwin"* ]]; then
USING_OSX=1
else
USING_OSX=0
fi

if [[ ! -f ${R_DIR}/.git ]]; then
echo "-> update submodules"
git submodule update --init
fi

function build {
cd "$R_DIR"

if [[ $(git diff --shortstat 2>/dev/null | tail -n1) != "" ]]; then
echo "** warning: $R_DIR repo is dirty"
sleep 1
fi

tools/rsync-recommended

if [[ ! -f Makefile ]]; then
echo "-> configure"
if [ $USING_OSX -eq 1 ]; then
./configure --enable-R-shlib --with-internal-tzcode --with-ICU=no --with-x=no || cat config.log
else
./configure
fi
fi

if [ ! -f doc/FAQ ]; then
touch doc/FAQ
fi

if [ ! -f "$R_DIR/SVN-REVISION" ]; then
# R must either be built from a svn checkout, or from the tarball generated by make dist
# this is a workaround to build it from a git mirror
# see https://github.com/wch/r-source/wiki/Home/6d35777dcb772f86371bf221c194ca0aa7874016#building-r-from-source
echo -n 'Revision: ' >SVN-REVISION
# get the latest revision that is not a rir patch
REV=$(git log --grep "git-svn-id" -1 --format=%B | grep "^git-svn-id" | sed -E 's/^git-svn-id: https:\/\/svn.r-project.org\/R\/[^@]*@([0-9]+).*$/\1/')
# can fail on shallow checkouts, so let's put the last known there
if [ "$REV" == "" ]; then
REV='74948'
fi
echo "$REV" >>SVN-REVISION
echo -n 'Last Changed Date: ' >>SVN-REVISION
REV_DATE=$(git log --grep "git-svn-id" -1 --pretty=format:"%ad" --date=iso | cut -d' ' -f1)
# can fail on shallow checkouts, so let's put the last known there
if [ "$REV_DATE" == "" ]; then
REV_DATE='2018-07-02'
fi
echo "$REV_DATE" >>SVN-REVISION

rm -f non-tarball
fi

echo "-> make"
make -j8
}

build

0 comments on commit b48e481

Please sign in to comment.