-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #64 from joaovitorsilvestre/arrumando_a_casa
Simplifying a lot the bootstrap and testing, using docker
- Loading branch information
Showing
11 changed files
with
243 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
**/_compiled/ | ||
/bin/ | ||
/Makefile | ||
**/erl_crash.dump |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,31 @@ | ||
SHELL := /bin/bash | ||
ev=latest | ||
|
||
.SILENT: compile, bootstrap | ||
|
||
TEMP_FILES = /tmp | ||
THIS_GIT_VERSION := $(shell git tag | tail -1) | ||
|
||
INSTALATION_PATH := /opt/fython | ||
|
||
# makefile location | ||
ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST)))) | ||
# fython src folder | ||
SRC_DIR:="$(ROOT_DIR)/src" | ||
|
||
install-from-source: | ||
$(MAKE) compile-source DESTINE_PATH=$(INSTALATION_PATH) | ||
|
||
shell: | ||
erl -pa $(INSTALATION_PATH) -s 'Fython.Shell' start -noshell | ||
|
||
compile-source: | ||
echo "Bootstraping with version: " $(THIS_GIT_VERSION) | ||
echo "Destine path: " $(DESTINE_PATH) | ||
|
||
$(eval OUTPUT_ZIP_PATH := $(TEMP_FILES)/fython_$(THIS_GIT_VERSION)_compiled.tar.gz) | ||
wget https://github.com/joaovitorsilvestre/fython/releases/download/$(THIS_GIT_VERSION)/_compiled.tar.gz -O $(OUTPUT_ZIP_PATH) | ||
|
||
$(eval COMPILED_OUTPUT_PATH := $(TEMP_FILES)/fython_$(THIS_GIT_VERSION)_compiled_local) | ||
sudo mkdir -p $(COMPILED_OUTPUT_PATH) 2>/dev/null | ||
sudo tar -xf $(OUTPUT_ZIP_PATH) -C $(COMPILED_OUTPUT_PATH) | ||
|
||
$(MAKE) bootstrap PRE_COMPILER=$(COMPILED_OUTPUT_PATH) DESTINE_PATH=$(DESTINE_PATH) | ||
|
||
bootstrap: | ||
# e.g: make bootstrap PRE_COMPILER=/home/joao/fython/src/_compiled DESTINE_PATH=/home/joao/fython/src/_bootstrap | ||
|
||
$(eval ELIXIR_PATH = "/usr/lib/elixir/lib/elixir/ebin") | ||
$(eval ALL_FILES_PATH := $(shell find $(SRC_DIR) -name '*.fy')) | ||
|
||
echo "Bootstraping" | ||
echo "pre compiler: "$(PRE_COMPILER) | ||
echo "destine folder: "$(DESTINE_PATH) | ||
|
||
sudo rm -rf $(DESTINE_PATH) || 0 | ||
sudo mkdir $(DESTINE_PATH) | ||
|
||
# copy elixir modules | ||
sudo cp -r $(ELIXIR_PATH)/* $(DESTINE_PATH) | ||
|
||
# compile all the modules idependitly | ||
for FILE_PATH in $(ALL_FILES_PATH); do ./functions.sh exec_in_erl ${SRC_DIR} $${FILE_PATH} ${DESTINE_PATH} ${PRE_COMPILER}; done | ||
|
||
compress-to-release: | ||
cd $(FOLDER_PATH)/ && tar -zcvf $(ROOT_DIR)/_compiled.tar.gz * && cd - | ||
bootstrap-with-docker: | ||
@DOCKER_TAG="fython:bootstrap" | ||
docker build -f devtools/Dockerfile -t $$DOCKER_TAG --target base . | ||
|
||
.ONESHELL: | ||
compile-project: | ||
# USAGE: | ||
# > make compile-project path=/home/joao/fython/example | ||
@DOCKER_TAG="fython:compiler" | ||
docker build -f devtools/Dockerfile -t $$DOCKER_TAG --target compiler . | ||
docker run --env PROJET_FOLDER=/project -v $(path):/project $$DOCKER_TAG | ||
|
||
.ONESHELL: | ||
run-tests: | ||
@DOCKER_TAG="fython:tests" | ||
docker build -f devtools/Dockerfile -t $$DOCKER_TAG --target tests . | ||
docker run $$DOCKER_TAG | ||
|
||
|
||
.ONESHELL: | ||
shell-current-src: | ||
@DOCKER_TAG="fython:shell" | ||
docker build -f devtools/Dockerfile -t $$DOCKER_TAG --target shell . | ||
docker run -it $$DOCKER_TAG |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
FROM elixir:1.14.1 as base | ||
|
||
# Arguments you can modify | ||
ARG DESTINE_PATH="/compiled" | ||
ARG VERSION_TO_USE_AS_BOOTSTRAPER="v0.5.2" | ||
|
||
ENV DESTINE_PATH=$DESTINE_PATH | ||
ENV PATH_FYTHON_TO_USE_AS_BOOTSTRAPER="/fython_$VERSION_TO_USE_AS_BOOTSTRAPER" | ||
ENV ELIXIR_BEAMS_PATH="/usr/local/lib/elixir/lib/elixir/ebin/" | ||
ENV IEX_BEAMS_PATH="/usr/local/lib/elixir/lib/iex/ebin/" | ||
|
||
# geting older version to use for bootstrap | ||
ENV OUTPUT_ZIP_PATH="/fython_$VERSION_TO_USE_AS_BOOTSTRAPER_compiled.tar.gz" | ||
RUN wget https://github.com/joaovitorsilvestre/fython/releases/download/$VERSION_TO_USE_AS_BOOTSTRAPER/_compiled.tar.gz -O $OUTPUT_ZIP_PATH \ | ||
&& mkdir -p $PATH_FYTHON_TO_USE_AS_BOOTSTRAPER \ | ||
&& tar -xf $OUTPUT_ZIP_PATH -C $PATH_FYTHON_TO_USE_AS_BOOTSTRAPER | ||
|
||
COPY src src | ||
COPY /devtools/bootstrap.sh /bootstrap.sh | ||
COPY /devtools/fython /fython | ||
RUN chmod a+x /bootstrap.sh | ||
RUN chmod a+x /fython | ||
|
||
# Execute bootstrap | ||
RUN echo "Bootstraping using Fython $VERSION_TO_USE_AS_BOOTSTRAPER" \ | ||
&& ./bootstrap.sh compile /src $DESTINE_PATH $PATH_FYTHON_TO_USE_AS_BOOTSTRAPER $ELIXIR_BEAMS_PATH | ||
|
||
# Remove base used for bootstrap (to ensure that we are not using it anymore) | ||
RUN rm -rf $PATH_FYTHON_TO_USE_AS_BOOTSTRAPER | ||
|
||
# Check if it can recompile itself (its a good way to test while we dont have proper testing) | ||
#RUN ./bootstrap.sh compile /src /test_compiled1 $DESTINE_PATH $ELIXIR_BEAMS_PATH | ||
#RUN ./bootstrap.sh compile /src /test_compiled2 /test_compiled1 | ||
|
||
FROM base as elixir_shell | ||
# TODO | ||
# CMD erl -pa $IEX_BEAMS_PATH -noshell -user Elixir.IEx.CLI +iex | ||
|
||
FROM base as shell | ||
CMD /fython exec "Shell.start()" $DESTINE_PATH | ||
|
||
FROM base as compiler | ||
ENV PROJET_FOLDER="/project" | ||
CMD echo "Compiling project: $PROJET_FOLDER" \ | ||
&& /fython exec "Core.Code.compile_project('$PROJET_FOLDER')" $DESTINE_PATH | ||
|
||
FROM base as tests | ||
COPY tests tests | ||
|
||
CMD /fython exec "Core.Code.compile_project('/tests')" $DESTINE_PATH \ | ||
&& /fython exec "Math_tests.run_tests()" $DESTINE_PATH /tests/_compiled |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/bin/bash | ||
set -e # stop if any error | ||
|
||
compile () { | ||
# We use the _COMP sufix to avoid conflict with external variables | ||
# (variabls of the shell that is running this script) | ||
SRC_DIR_COMP=$1 | ||
DESTINE_PATH_COMP=$2 | ||
PATH_FYTHON_TO_USE_AS_BOOTSTRAPER_COMP=$3 | ||
ELIXIR_BEAMS_PATH_COMP=$4 | ||
|
||
ALL_FILES_PATH_COMP=$(find $SRC_DIR_COMP -name '*.fy') | ||
|
||
echo "Destine folder: $DESTINE_PATH_COMP" | ||
rm -rf $DESTINE_PATH_COMP | ||
mkdir $DESTINE_PATH_COMP | ||
|
||
cd $ELIXIR_BEAMS_PATH_COMP && cp -r . "$DESTINE_PATH_COMP" && cd / | ||
|
||
for FILE_PATH in $ALL_FILES_PATH_COMP; do | ||
ERL_COMMAND_CALL="application:start(compiler), application:start(elixir), 'Elixir.Code':compiler_options(#{ignore_module_conflict => true}), 'Fython.Core.Code':compile_project_file(<<"'"'$SRC_DIR_COMP'"'">>, <<"'"'${FILE_PATH}'"'">>, "'"'$DESTINE_PATH_COMP'"'"), init:stop()."; | ||
erl -pa $PATH_FYTHON_TO_USE_AS_BOOTSTRAPER_COMP -noshell -eval "$ERL_COMMAND_CALL"; | ||
done | ||
} | ||
|
||
$* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/bin/bash | ||
set -e # stop if any error | ||
|
||
exec () { | ||
FYTHON_CODE=$1 | ||
ERLANG_PATHS=${@:2} | ||
|
||
ERLANG_PATHS_FORMATED="" | ||
for ERL_PATH in $ERLANG_PATHS; do | ||
ERLANG_PATHS_FORMATED=$ERLANG_PATHS_FORMATED"-pa $ERL_PATH " | ||
done | ||
erl $ERLANG_PATHS_FORMATED -noshell -eval "'Fython.Core':eval_string(<<"'"'"<stdin>"'"'">>, <<"'"'"$FYTHON_CODE"'"'">>)." -run init stop | ||
} | ||
|
||
$* |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.