diff --git a/Dockerfile b/Dockerfile new file mode 120000 index 0000000000000000000000000000000000000000..abe155c4c2be70311ea45dcd2fcbb9643e679edc --- /dev/null +++ b/Dockerfile @@ -0,0 +1 @@ +./docker/Dockerfile \ No newline at end of file diff --git a/docker/Dockerfile b/docker/Dockerfile index ec119890895dc7d2bf6e5a2b6fc20cf9afa98552..21b042d15738b09dfa274e6ca80f31207a9996c1 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -11,20 +11,43 @@ WORKDIR /home/user # Path has to be in local context, i.e. not within a parent repository ARG GCC_PATH +# Argument to control the number of thread used to build GCC +ARG NPROC "$(nproc)" ADD --chown=user ${GCC_PATH} /home/user/gcc_src -ADD --chown=user ../ /home/user/plugin_ct +ADD --chown=user ./ /home/user/plugin_ct # Configuring and building gcc RUN mkdir gcc_build && \ cd ./gcc_build && \ ../gcc_src/configure --enable-plugin --disable-multilib --enable-checking --enable-analyzer --program-suffix=_modified --prefix=/home/user/.local && \ - make -j$(nproc) && \ - make install && \ - cd ../plugin_ct && \ - mkdir build && \ + make -j${NPROC} && \ + make install + +WORKDIR /home/user +USER root + +# Updating alternatives for gcc and g++ +RUN mv /usr/bin/gcc /usr/bin/gcc_system && \ + mv /usr/bin/g++ /usr/bin/g++_system && \ + update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc_system 0 && \ + update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++_system 0 && \ + update-alternatives --install /usr/bin/gcc gcc /home/user/.local/bin/gcc_modified 1 && \ + update-alternatives --install /usr/bin/g++ g++ /home/user/.local/bin/g++_modified 1 && \ + update-alternatives --set gcc /home/user/.local/bin/gcc_modified && \ + update-alternatives --set g++ /home/user/.local/bin/g++_modified + + +WORKDIR /home/user/plugin_ct +USER user + +# Configuring and building the plugin +RUN mkdir build && \ cd build && \ - cmake -DGCC_VERSION=13.0.1_custom ../ && \ - ../scripts/copy_analyzer_header.sh custom /home/user/gcc_src && \ + cmake -DGCC_VERSION=13.0.1_custom -G Ninja ../ && \ + bash ../scripts/copy_analyzer_header.sh custom /home/user/gcc_src/gcc && \ ninja -v && \ - install ./libctplug.so /home/user \ No newline at end of file + install ./libctplug.so /home/user + +WORKDIR /home/user +ENTRYPOINT /bin/bash diff --git a/docker/build_docker.sh b/docker/build_docker.sh index 63be22f097e92065194db52ea9d99c62ff873fed..1b52ef23fe627577495413b213a8602ae62709b0 100644 --- a/docker/build_docker.sh +++ b/docker/build_docker.sh @@ -3,19 +3,29 @@ set -x usage() { - echo -e "USAGE\n:$0 /path/to/gcc/sources" + echo -e "USAGE:\n$0 /path/to/gcc/sources [nproc]" } -if [ $# -ne 1 ] +if [ $# -lt 1 ] then - usage $0 - exit 1 + usage $0 + exit 1 fi if [ ! -d $1 ] then - echo -e "The path $1 is not a directory" - exit 1 + echo -e "The path $1 is not a directory" + exit 1 fi -docker build -t ct-tools/ctplug --build-arg="GCC_PATH=$1" . \ No newline at end of file +if [ $2 ] +then + NPROC="--build-arg=NPROC=$2" +else + NPROC="" +fi + +# Add the git clone of GCC repository here when published +# Have a look at git submodules to avoid cloning the repo in a "dirty" way + +sudo docker build -t ct-tools/ctplug --build-arg="GCC_PATH=$1" $NPROC . diff --git a/scripts/copy_analyzer_header.sh b/scripts/copy_analyzer_header.sh index 5751e81573a48ed96a41b693976154e29dc5eacb..6541de3ffa0cca1854fa080827bbbfeee0fe9df0 100644 --- a/scripts/copy_analyzer_header.sh +++ b/scripts/copy_analyzer_header.sh @@ -10,7 +10,7 @@ weird() { set -x -if [ $# -ne 1 ] +if [ $# -lt 1 ] then usage exit 1