From 6493421062ff714a092732b5da6977024119e132 Mon Sep 17 00:00:00 2001 From: Paul Kuruvilla Date: Tue, 13 Aug 2024 15:42:07 +0100 Subject: [PATCH 1/4] add elixir code --- .../elixir/.codecrafters/compile.sh | 11 ++++++ compiled_starters/elixir/.codecrafters/run.sh | 11 ++++++ compiled_starters/elixir/.formatter.exs | 4 +++ compiled_starters/elixir/.gitattributes | 1 + compiled_starters/elixir/.gitignore | 24 +++++++++++++ compiled_starters/elixir/README.md | 35 +++++++++++++++++++ compiled_starters/elixir/codecrafters.yml | 11 ++++++ compiled_starters/elixir/lib/main.ex | 5 +++ compiled_starters/elixir/mix.exs | 29 +++++++++++++++ compiled_starters/elixir/your_program.sh | 24 +++++++++++++ dockerfiles/elixir-1.17.Dockerfile | 16 +++++++++ .../01-oo8/code/.codecrafters/compile.sh | 11 ++++++ .../elixir/01-oo8/code/.codecrafters/run.sh | 11 ++++++ solutions/elixir/01-oo8/code/.formatter.exs | 4 +++ solutions/elixir/01-oo8/code/.gitattributes | 1 + solutions/elixir/01-oo8/code/.gitignore | 24 +++++++++++++ solutions/elixir/01-oo8/code/README.md | 35 +++++++++++++++++++ solutions/elixir/01-oo8/code/codecrafters.yml | 11 ++++++ solutions/elixir/01-oo8/code/lib/main.ex | 4 +++ solutions/elixir/01-oo8/code/mix.exs | 29 +++++++++++++++ solutions/elixir/01-oo8/code/your_program.sh | 24 +++++++++++++ solutions/elixir/01-oo8/diff/lib/main.ex.diff | 7 ++++ solutions/elixir/01-oo8/explanation.md | 16 +++++++++ .../elixir/code/.codecrafters/compile.sh | 11 ++++++ .../elixir/code/.codecrafters/run.sh | 11 ++++++ starter_templates/elixir/code/.formatter.exs | 4 +++ starter_templates/elixir/code/.gitignore | 24 +++++++++++++ starter_templates/elixir/code/lib/main.ex | 5 +++ starter_templates/elixir/code/mix.exs | 29 +++++++++++++++ starter_templates/elixir/config.yml | 3 ++ 30 files changed, 435 insertions(+) create mode 100755 compiled_starters/elixir/.codecrafters/compile.sh create mode 100755 compiled_starters/elixir/.codecrafters/run.sh create mode 100644 compiled_starters/elixir/.formatter.exs create mode 100644 compiled_starters/elixir/.gitattributes create mode 100644 compiled_starters/elixir/.gitignore create mode 100644 compiled_starters/elixir/README.md create mode 100644 compiled_starters/elixir/codecrafters.yml create mode 100644 compiled_starters/elixir/lib/main.ex create mode 100644 compiled_starters/elixir/mix.exs create mode 100755 compiled_starters/elixir/your_program.sh create mode 100644 dockerfiles/elixir-1.17.Dockerfile create mode 100755 solutions/elixir/01-oo8/code/.codecrafters/compile.sh create mode 100755 solutions/elixir/01-oo8/code/.codecrafters/run.sh create mode 100644 solutions/elixir/01-oo8/code/.formatter.exs create mode 100644 solutions/elixir/01-oo8/code/.gitattributes create mode 100644 solutions/elixir/01-oo8/code/.gitignore create mode 100644 solutions/elixir/01-oo8/code/README.md create mode 100644 solutions/elixir/01-oo8/code/codecrafters.yml create mode 100644 solutions/elixir/01-oo8/code/lib/main.ex create mode 100644 solutions/elixir/01-oo8/code/mix.exs create mode 100755 solutions/elixir/01-oo8/code/your_program.sh create mode 100644 solutions/elixir/01-oo8/diff/lib/main.ex.diff create mode 100644 solutions/elixir/01-oo8/explanation.md create mode 100755 starter_templates/elixir/code/.codecrafters/compile.sh create mode 100755 starter_templates/elixir/code/.codecrafters/run.sh create mode 100644 starter_templates/elixir/code/.formatter.exs create mode 100644 starter_templates/elixir/code/.gitignore create mode 100644 starter_templates/elixir/code/lib/main.ex create mode 100644 starter_templates/elixir/code/mix.exs create mode 100644 starter_templates/elixir/config.yml diff --git a/compiled_starters/elixir/.codecrafters/compile.sh b/compiled_starters/elixir/.codecrafters/compile.sh new file mode 100755 index 0000000..6bc2dcc --- /dev/null +++ b/compiled_starters/elixir/.codecrafters/compile.sh @@ -0,0 +1,11 @@ +#!/bin/sh +# +# This script is used to compile your program on CodeCrafters +# +# This runs before .codecrafters/run.sh +# +# Learn more: https://codecrafters.io/program-interface + +set -e # Exit on failure + +mix compile diff --git a/compiled_starters/elixir/.codecrafters/run.sh b/compiled_starters/elixir/.codecrafters/run.sh new file mode 100755 index 0000000..5651162 --- /dev/null +++ b/compiled_starters/elixir/.codecrafters/run.sh @@ -0,0 +1,11 @@ +#!/bin/sh +# +# This script is used to run your program on CodeCrafters +# +# This runs after .codecrafters/compile.sh +# +# Learn more: https://codecrafters.io/program-interface + +set -e # Exit on failure + +exec mix run --no-compile -- "$@" diff --git a/compiled_starters/elixir/.formatter.exs b/compiled_starters/elixir/.formatter.exs new file mode 100644 index 0000000..d2cda26 --- /dev/null +++ b/compiled_starters/elixir/.formatter.exs @@ -0,0 +1,4 @@ +# Used by "mix format" +[ + inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"] +] diff --git a/compiled_starters/elixir/.gitattributes b/compiled_starters/elixir/.gitattributes new file mode 100644 index 0000000..176a458 --- /dev/null +++ b/compiled_starters/elixir/.gitattributes @@ -0,0 +1 @@ +* text=auto diff --git a/compiled_starters/elixir/.gitignore b/compiled_starters/elixir/.gitignore new file mode 100644 index 0000000..39fc292 --- /dev/null +++ b/compiled_starters/elixir/.gitignore @@ -0,0 +1,24 @@ +# The directory Mix will write compiled artifacts to. +/_build/ + +# If you run "mix test --cover", coverage assets end up here. +/cover/ + +# The directory Mix downloads your dependencies sources to. +/deps/ + +# Where third-party dependencies like ExDoc output generated docs. +/doc/ + +# Ignore .fetch files in case you like to edit your project deps locally. +/.fetch + +# If the VM crashes, it generates a dump, let's ignore it too. +erl_crash.dump + +# Also ignore archive artifacts (built via "mix archive.build"). +*.ez + +# Ignore package tarball (built via "mix hex.build"). +app-*.tar + diff --git a/compiled_starters/elixir/README.md b/compiled_starters/elixir/README.md new file mode 100644 index 0000000..7c3c210 --- /dev/null +++ b/compiled_starters/elixir/README.md @@ -0,0 +1,35 @@ +![progress-banner](https://codecrafters.io/landing/images/default_progress_banners/shell.png) + +This is a starting point for Elixir solutions to the +["Build Your Own Shell" Challenge](https://app.codecrafters.io/courses/shell/overview). + +In this challenge, you'll build your own POSIX compliant shell that's capable of +interpreting shell commands, running external programs and builtin commands like +cd, pwd, echo and more. Along the way, you'll learn about shell command parsing, +REPLs, builtin commands, and more. + +**Note**: If you're viewing this repo on GitHub, head over to +[codecrafters.io](https://codecrafters.io) to try the challenge. + +# Passing the first stage + +The entry point for your `shell` implementation is in `lib/main.ex`. Study and +uncomment the relevant code, and push your changes to pass the first stage: + +```sh +git add . +git commit -m "pass 1st stage" # any msg +git push origin master +``` + +Time to move on to the next stage! + +# Stage 2 & beyond + +Note: This section is for stages 2 and beyond. + +1. Ensure you have `mix` installed locally +1. Run `./your_program.sh` to run your program, which is implemented in + `lib/main.ex`. +1. Commit your changes and run `git push origin master` to submit your solution + to CodeCrafters. Test output will be streamed to your terminal. diff --git a/compiled_starters/elixir/codecrafters.yml b/compiled_starters/elixir/codecrafters.yml new file mode 100644 index 0000000..eaed767 --- /dev/null +++ b/compiled_starters/elixir/codecrafters.yml @@ -0,0 +1,11 @@ +# Set this to true if you want debug logs. +# +# These can be VERY verbose, so we suggest turning them off +# unless you really need them. +debug: false + +# Use this to change the Elixir version used to run your code +# on Codecrafters. +# +# Available versions: elixir-1.17 +language_pack: elixir-1.17 diff --git a/compiled_starters/elixir/lib/main.ex b/compiled_starters/elixir/lib/main.ex new file mode 100644 index 0000000..39b515d --- /dev/null +++ b/compiled_starters/elixir/lib/main.ex @@ -0,0 +1,5 @@ +# Uncomment this block to pass the first stage +# IO.write("$ ") + +# Wait for user input +IO.read(:line) diff --git a/compiled_starters/elixir/mix.exs b/compiled_starters/elixir/mix.exs new file mode 100644 index 0000000..2942a03 --- /dev/null +++ b/compiled_starters/elixir/mix.exs @@ -0,0 +1,29 @@ +defmodule App.MixProject do + # NOTE: You do not need to change anything in this file. + use Mix.Project + + def project do + [ + app: :codecrafters_shell, + version: "1.0.0", + elixir: "~> 1.17", + start_permanent: Mix.env() == :prod, + deps: deps() + ] + end + + # Run "mix help compile.app" to learn about applications. + def application do + [ + extra_applications: [:logger] + ] + end + + # Run "mix help deps" to learn about dependencies. + defp deps do + [ + # {:dep_from_hexpm, "~> 0.3.0"}, + # {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"} + ] + end +end diff --git a/compiled_starters/elixir/your_program.sh b/compiled_starters/elixir/your_program.sh new file mode 100755 index 0000000..4e0640b --- /dev/null +++ b/compiled_starters/elixir/your_program.sh @@ -0,0 +1,24 @@ +#!/bin/sh +# +# Use this script to run your program LOCALLY. +# +# Note: Changing this script WILL NOT affect how CodeCrafters runs your program. +# +# Learn more: https://codecrafters.io/program-interface + +set -e # Exit early if any commands fail + +# Copied from .codecrafters/compile.sh +# +# - Edit this to change how your program compiles locally +# - Edit .codecrafters/compile.sh to change how your program compiles remotely +( + cd "$(dirname "$0")" # Ensure compile steps are run within the repository directory + mix compile +) + +# Copied from .codecrafters/run.sh +# +# - Edit this to change how your program runs locally +# - Edit .codecrafters/run.sh to change how your program runs remotely +exec mix run --no-compile -- "$@" diff --git a/dockerfiles/elixir-1.17.Dockerfile b/dockerfiles/elixir-1.17.Dockerfile new file mode 100644 index 0000000..5c0061b --- /dev/null +++ b/dockerfiles/elixir-1.17.Dockerfile @@ -0,0 +1,16 @@ +# syntax=docker/dockerfile:1.7-labs +FROM elixir:1.17.2-alpine + +# Ensures the container is re-built if dependency files change +ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="mix.exs" + +WORKDIR /app + +# .git & README.md are unique per-repository. We ignore them on first copy to prevent cache misses +COPY --exclude=.git --exclude=README.md . /app + +# Install & cache deps +RUN .codecrafters/compile.sh + +# Once the heavy steps are done, we can copy all files back +COPY . /app diff --git a/solutions/elixir/01-oo8/code/.codecrafters/compile.sh b/solutions/elixir/01-oo8/code/.codecrafters/compile.sh new file mode 100755 index 0000000..6bc2dcc --- /dev/null +++ b/solutions/elixir/01-oo8/code/.codecrafters/compile.sh @@ -0,0 +1,11 @@ +#!/bin/sh +# +# This script is used to compile your program on CodeCrafters +# +# This runs before .codecrafters/run.sh +# +# Learn more: https://codecrafters.io/program-interface + +set -e # Exit on failure + +mix compile diff --git a/solutions/elixir/01-oo8/code/.codecrafters/run.sh b/solutions/elixir/01-oo8/code/.codecrafters/run.sh new file mode 100755 index 0000000..5651162 --- /dev/null +++ b/solutions/elixir/01-oo8/code/.codecrafters/run.sh @@ -0,0 +1,11 @@ +#!/bin/sh +# +# This script is used to run your program on CodeCrafters +# +# This runs after .codecrafters/compile.sh +# +# Learn more: https://codecrafters.io/program-interface + +set -e # Exit on failure + +exec mix run --no-compile -- "$@" diff --git a/solutions/elixir/01-oo8/code/.formatter.exs b/solutions/elixir/01-oo8/code/.formatter.exs new file mode 100644 index 0000000..d2cda26 --- /dev/null +++ b/solutions/elixir/01-oo8/code/.formatter.exs @@ -0,0 +1,4 @@ +# Used by "mix format" +[ + inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"] +] diff --git a/solutions/elixir/01-oo8/code/.gitattributes b/solutions/elixir/01-oo8/code/.gitattributes new file mode 100644 index 0000000..176a458 --- /dev/null +++ b/solutions/elixir/01-oo8/code/.gitattributes @@ -0,0 +1 @@ +* text=auto diff --git a/solutions/elixir/01-oo8/code/.gitignore b/solutions/elixir/01-oo8/code/.gitignore new file mode 100644 index 0000000..39fc292 --- /dev/null +++ b/solutions/elixir/01-oo8/code/.gitignore @@ -0,0 +1,24 @@ +# The directory Mix will write compiled artifacts to. +/_build/ + +# If you run "mix test --cover", coverage assets end up here. +/cover/ + +# The directory Mix downloads your dependencies sources to. +/deps/ + +# Where third-party dependencies like ExDoc output generated docs. +/doc/ + +# Ignore .fetch files in case you like to edit your project deps locally. +/.fetch + +# If the VM crashes, it generates a dump, let's ignore it too. +erl_crash.dump + +# Also ignore archive artifacts (built via "mix archive.build"). +*.ez + +# Ignore package tarball (built via "mix hex.build"). +app-*.tar + diff --git a/solutions/elixir/01-oo8/code/README.md b/solutions/elixir/01-oo8/code/README.md new file mode 100644 index 0000000..7c3c210 --- /dev/null +++ b/solutions/elixir/01-oo8/code/README.md @@ -0,0 +1,35 @@ +![progress-banner](https://codecrafters.io/landing/images/default_progress_banners/shell.png) + +This is a starting point for Elixir solutions to the +["Build Your Own Shell" Challenge](https://app.codecrafters.io/courses/shell/overview). + +In this challenge, you'll build your own POSIX compliant shell that's capable of +interpreting shell commands, running external programs and builtin commands like +cd, pwd, echo and more. Along the way, you'll learn about shell command parsing, +REPLs, builtin commands, and more. + +**Note**: If you're viewing this repo on GitHub, head over to +[codecrafters.io](https://codecrafters.io) to try the challenge. + +# Passing the first stage + +The entry point for your `shell` implementation is in `lib/main.ex`. Study and +uncomment the relevant code, and push your changes to pass the first stage: + +```sh +git add . +git commit -m "pass 1st stage" # any msg +git push origin master +``` + +Time to move on to the next stage! + +# Stage 2 & beyond + +Note: This section is for stages 2 and beyond. + +1. Ensure you have `mix` installed locally +1. Run `./your_program.sh` to run your program, which is implemented in + `lib/main.ex`. +1. Commit your changes and run `git push origin master` to submit your solution + to CodeCrafters. Test output will be streamed to your terminal. diff --git a/solutions/elixir/01-oo8/code/codecrafters.yml b/solutions/elixir/01-oo8/code/codecrafters.yml new file mode 100644 index 0000000..eaed767 --- /dev/null +++ b/solutions/elixir/01-oo8/code/codecrafters.yml @@ -0,0 +1,11 @@ +# Set this to true if you want debug logs. +# +# These can be VERY verbose, so we suggest turning them off +# unless you really need them. +debug: false + +# Use this to change the Elixir version used to run your code +# on Codecrafters. +# +# Available versions: elixir-1.17 +language_pack: elixir-1.17 diff --git a/solutions/elixir/01-oo8/code/lib/main.ex b/solutions/elixir/01-oo8/code/lib/main.ex new file mode 100644 index 0000000..196bc13 --- /dev/null +++ b/solutions/elixir/01-oo8/code/lib/main.ex @@ -0,0 +1,4 @@ +IO.write("$ ") + +# Wait for user input +IO.read(:line) diff --git a/solutions/elixir/01-oo8/code/mix.exs b/solutions/elixir/01-oo8/code/mix.exs new file mode 100644 index 0000000..2942a03 --- /dev/null +++ b/solutions/elixir/01-oo8/code/mix.exs @@ -0,0 +1,29 @@ +defmodule App.MixProject do + # NOTE: You do not need to change anything in this file. + use Mix.Project + + def project do + [ + app: :codecrafters_shell, + version: "1.0.0", + elixir: "~> 1.17", + start_permanent: Mix.env() == :prod, + deps: deps() + ] + end + + # Run "mix help compile.app" to learn about applications. + def application do + [ + extra_applications: [:logger] + ] + end + + # Run "mix help deps" to learn about dependencies. + defp deps do + [ + # {:dep_from_hexpm, "~> 0.3.0"}, + # {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"} + ] + end +end diff --git a/solutions/elixir/01-oo8/code/your_program.sh b/solutions/elixir/01-oo8/code/your_program.sh new file mode 100755 index 0000000..4e0640b --- /dev/null +++ b/solutions/elixir/01-oo8/code/your_program.sh @@ -0,0 +1,24 @@ +#!/bin/sh +# +# Use this script to run your program LOCALLY. +# +# Note: Changing this script WILL NOT affect how CodeCrafters runs your program. +# +# Learn more: https://codecrafters.io/program-interface + +set -e # Exit early if any commands fail + +# Copied from .codecrafters/compile.sh +# +# - Edit this to change how your program compiles locally +# - Edit .codecrafters/compile.sh to change how your program compiles remotely +( + cd "$(dirname "$0")" # Ensure compile steps are run within the repository directory + mix compile +) + +# Copied from .codecrafters/run.sh +# +# - Edit this to change how your program runs locally +# - Edit .codecrafters/run.sh to change how your program runs remotely +exec mix run --no-compile -- "$@" diff --git a/solutions/elixir/01-oo8/diff/lib/main.ex.diff b/solutions/elixir/01-oo8/diff/lib/main.ex.diff new file mode 100644 index 0000000..f596b69 --- /dev/null +++ b/solutions/elixir/01-oo8/diff/lib/main.ex.diff @@ -0,0 +1,7 @@ +@@ -1,5 +1,4 @@ +-# Uncomment this block to pass the first stage +-# IO.write("$ ") ++IO.write("$ ") + + # Wait for user input + IO.read(:line) diff --git a/solutions/elixir/01-oo8/explanation.md b/solutions/elixir/01-oo8/explanation.md new file mode 100644 index 0000000..223e6a2 --- /dev/null +++ b/solutions/elixir/01-oo8/explanation.md @@ -0,0 +1,16 @@ +The entry point for your Shell implementation is in `lib/main.ex`. + +Study and uncomment the relevant code: + +```elixir +# Uncomment this block to pass the first stage +IO.write("$ ") +``` + +Push your changes to pass the first stage: + +``` +git add . +git commit -m "pass 1st stage" # any msg +git push origin master +``` diff --git a/starter_templates/elixir/code/.codecrafters/compile.sh b/starter_templates/elixir/code/.codecrafters/compile.sh new file mode 100755 index 0000000..6bc2dcc --- /dev/null +++ b/starter_templates/elixir/code/.codecrafters/compile.sh @@ -0,0 +1,11 @@ +#!/bin/sh +# +# This script is used to compile your program on CodeCrafters +# +# This runs before .codecrafters/run.sh +# +# Learn more: https://codecrafters.io/program-interface + +set -e # Exit on failure + +mix compile diff --git a/starter_templates/elixir/code/.codecrafters/run.sh b/starter_templates/elixir/code/.codecrafters/run.sh new file mode 100755 index 0000000..5651162 --- /dev/null +++ b/starter_templates/elixir/code/.codecrafters/run.sh @@ -0,0 +1,11 @@ +#!/bin/sh +# +# This script is used to run your program on CodeCrafters +# +# This runs after .codecrafters/compile.sh +# +# Learn more: https://codecrafters.io/program-interface + +set -e # Exit on failure + +exec mix run --no-compile -- "$@" diff --git a/starter_templates/elixir/code/.formatter.exs b/starter_templates/elixir/code/.formatter.exs new file mode 100644 index 0000000..d2cda26 --- /dev/null +++ b/starter_templates/elixir/code/.formatter.exs @@ -0,0 +1,4 @@ +# Used by "mix format" +[ + inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"] +] diff --git a/starter_templates/elixir/code/.gitignore b/starter_templates/elixir/code/.gitignore new file mode 100644 index 0000000..39fc292 --- /dev/null +++ b/starter_templates/elixir/code/.gitignore @@ -0,0 +1,24 @@ +# The directory Mix will write compiled artifacts to. +/_build/ + +# If you run "mix test --cover", coverage assets end up here. +/cover/ + +# The directory Mix downloads your dependencies sources to. +/deps/ + +# Where third-party dependencies like ExDoc output generated docs. +/doc/ + +# Ignore .fetch files in case you like to edit your project deps locally. +/.fetch + +# If the VM crashes, it generates a dump, let's ignore it too. +erl_crash.dump + +# Also ignore archive artifacts (built via "mix archive.build"). +*.ez + +# Ignore package tarball (built via "mix hex.build"). +app-*.tar + diff --git a/starter_templates/elixir/code/lib/main.ex b/starter_templates/elixir/code/lib/main.ex new file mode 100644 index 0000000..39b515d --- /dev/null +++ b/starter_templates/elixir/code/lib/main.ex @@ -0,0 +1,5 @@ +# Uncomment this block to pass the first stage +# IO.write("$ ") + +# Wait for user input +IO.read(:line) diff --git a/starter_templates/elixir/code/mix.exs b/starter_templates/elixir/code/mix.exs new file mode 100644 index 0000000..2942a03 --- /dev/null +++ b/starter_templates/elixir/code/mix.exs @@ -0,0 +1,29 @@ +defmodule App.MixProject do + # NOTE: You do not need to change anything in this file. + use Mix.Project + + def project do + [ + app: :codecrafters_shell, + version: "1.0.0", + elixir: "~> 1.17", + start_permanent: Mix.env() == :prod, + deps: deps() + ] + end + + # Run "mix help compile.app" to learn about applications. + def application do + [ + extra_applications: [:logger] + ] + end + + # Run "mix help deps" to learn about dependencies. + defp deps do + [ + # {:dep_from_hexpm, "~> 0.3.0"}, + # {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"} + ] + end +end diff --git a/starter_templates/elixir/config.yml b/starter_templates/elixir/config.yml new file mode 100644 index 0000000..1d5ecf8 --- /dev/null +++ b/starter_templates/elixir/config.yml @@ -0,0 +1,3 @@ +attributes: + required_executable: "mix" + user_editable_file: "lib/main.ex" From 7d226dc9ec36d456aa3dd6f275594c46764744c8 Mon Sep 17 00:00:00 2001 From: Paul Kuruvilla Date: Tue, 13 Aug 2024 16:51:00 +0100 Subject: [PATCH 2/4] wip --- compiled_starters/elixir/lib/main.ex | 12 ++++++++---- compiled_starters/elixir/mix.exs | 1 + dockerfiles/elixir-1.17.Dockerfile | 4 ++++ solutions/elixir/01-oo8/code/lib/main.ex | 10 +++++++--- solutions/elixir/01-oo8/code/mix.exs | 1 + solutions/elixir/01-oo8/diff/lib/main.ex.diff | 16 ++++++++++------ starter_templates/elixir/code/lib/main.ex | 12 ++++++++---- starter_templates/elixir/code/mix.exs | 1 + 8 files changed, 40 insertions(+), 17 deletions(-) diff --git a/compiled_starters/elixir/lib/main.ex b/compiled_starters/elixir/lib/main.ex index 39b515d..a32510a 100644 --- a/compiled_starters/elixir/lib/main.ex +++ b/compiled_starters/elixir/lib/main.ex @@ -1,5 +1,9 @@ -# Uncomment this block to pass the first stage -# IO.write("$ ") +defmodule CLI do + def main(_args) do + # Uncomment this block to pass the first stage + IO.write("$ ") -# Wait for user input -IO.read(:line) + # Wait for user input + IO.read(:line) + end +end diff --git a/compiled_starters/elixir/mix.exs b/compiled_starters/elixir/mix.exs index 2942a03..02bbc84 100644 --- a/compiled_starters/elixir/mix.exs +++ b/compiled_starters/elixir/mix.exs @@ -7,6 +7,7 @@ defmodule App.MixProject do app: :codecrafters_shell, version: "1.0.0", elixir: "~> 1.17", + escript: [main_module: CLI], start_permanent: Mix.env() == :prod, deps: deps() ] diff --git a/dockerfiles/elixir-1.17.Dockerfile b/dockerfiles/elixir-1.17.Dockerfile index 5c0061b..52c439e 100644 --- a/dockerfiles/elixir-1.17.Dockerfile +++ b/dockerfiles/elixir-1.17.Dockerfile @@ -12,5 +12,9 @@ COPY --exclude=.git --exclude=README.md . /app # Install & cache deps RUN .codecrafters/compile.sh +# If _build directory exists, move it to /app-cached +RUN mkdir -p /app-cached +RUN if [ -d "/app/_build" ]; then mv /app/_build /app-cached; fi + # Once the heavy steps are done, we can copy all files back COPY . /app diff --git a/solutions/elixir/01-oo8/code/lib/main.ex b/solutions/elixir/01-oo8/code/lib/main.ex index 196bc13..23dd27d 100644 --- a/solutions/elixir/01-oo8/code/lib/main.ex +++ b/solutions/elixir/01-oo8/code/lib/main.ex @@ -1,4 +1,8 @@ -IO.write("$ ") +defmodule CLI do + def main(_args) do + IO.write("$ ") -# Wait for user input -IO.read(:line) + # Wait for user input + IO.read(:line) + end +end diff --git a/solutions/elixir/01-oo8/code/mix.exs b/solutions/elixir/01-oo8/code/mix.exs index 2942a03..02bbc84 100644 --- a/solutions/elixir/01-oo8/code/mix.exs +++ b/solutions/elixir/01-oo8/code/mix.exs @@ -7,6 +7,7 @@ defmodule App.MixProject do app: :codecrafters_shell, version: "1.0.0", elixir: "~> 1.17", + escript: [main_module: CLI], start_permanent: Mix.env() == :prod, deps: deps() ] diff --git a/solutions/elixir/01-oo8/diff/lib/main.ex.diff b/solutions/elixir/01-oo8/diff/lib/main.ex.diff index f596b69..c630c8e 100644 --- a/solutions/elixir/01-oo8/diff/lib/main.ex.diff +++ b/solutions/elixir/01-oo8/diff/lib/main.ex.diff @@ -1,7 +1,11 @@ -@@ -1,5 +1,4 @@ --# Uncomment this block to pass the first stage --# IO.write("$ ") -+IO.write("$ ") +@@ -1,9 +1,8 @@ + defmodule CLI do + def main(_args) do +- # Uncomment this block to pass the first stage +- # IO.write("$ ") ++ IO.write("$ ") - # Wait for user input - IO.read(:line) + # Wait for user input + IO.read(:line) + end + end diff --git a/starter_templates/elixir/code/lib/main.ex b/starter_templates/elixir/code/lib/main.ex index 39b515d..572993a 100644 --- a/starter_templates/elixir/code/lib/main.ex +++ b/starter_templates/elixir/code/lib/main.ex @@ -1,5 +1,9 @@ -# Uncomment this block to pass the first stage -# IO.write("$ ") +defmodule CLI do + def main(_args) do + # Uncomment this block to pass the first stage + # IO.write("$ ") -# Wait for user input -IO.read(:line) + # Wait for user input + IO.read(:line) + end +end diff --git a/starter_templates/elixir/code/mix.exs b/starter_templates/elixir/code/mix.exs index 2942a03..02bbc84 100644 --- a/starter_templates/elixir/code/mix.exs +++ b/starter_templates/elixir/code/mix.exs @@ -7,6 +7,7 @@ defmodule App.MixProject do app: :codecrafters_shell, version: "1.0.0", elixir: "~> 1.17", + escript: [main_module: CLI], start_permanent: Mix.env() == :prod, deps: deps() ] From 640a15e9f9b5f07ec4161c6c8a13116b605f43b5 Mon Sep 17 00:00:00 2001 From: Paul Kuruvilla Date: Tue, 13 Aug 2024 18:23:45 +0100 Subject: [PATCH 3/4] update elixir --- compiled_starters/elixir/.codecrafters/compile.sh | 3 ++- compiled_starters/elixir/.codecrafters/run.sh | 2 +- compiled_starters/elixir/.gitignore | 3 +++ compiled_starters/elixir/lib/main.ex | 2 +- compiled_starters/elixir/mix.exs | 4 ++-- compiled_starters/elixir/your_program.sh | 5 +++-- solutions/elixir/01-oo8/code/.codecrafters/compile.sh | 3 ++- solutions/elixir/01-oo8/code/.codecrafters/run.sh | 2 +- solutions/elixir/01-oo8/code/.gitignore | 3 +++ solutions/elixir/01-oo8/code/mix.exs | 4 ++-- solutions/elixir/01-oo8/code/your_program.sh | 5 +++-- starter_templates/elixir/code/.codecrafters/compile.sh | 3 ++- starter_templates/elixir/code/.codecrafters/run.sh | 2 +- starter_templates/elixir/code/.gitignore | 3 +++ starter_templates/elixir/code/mix.exs | 4 ++-- 15 files changed, 31 insertions(+), 17 deletions(-) diff --git a/compiled_starters/elixir/.codecrafters/compile.sh b/compiled_starters/elixir/.codecrafters/compile.sh index 6bc2dcc..b499ff2 100755 --- a/compiled_starters/elixir/.codecrafters/compile.sh +++ b/compiled_starters/elixir/.codecrafters/compile.sh @@ -8,4 +8,5 @@ set -e # Exit on failure -mix compile +mix escript.build +mv codecrafters_shell /tmp/codecrafters-build-{{course_slug}}-elixir diff --git a/compiled_starters/elixir/.codecrafters/run.sh b/compiled_starters/elixir/.codecrafters/run.sh index 5651162..684b196 100755 --- a/compiled_starters/elixir/.codecrafters/run.sh +++ b/compiled_starters/elixir/.codecrafters/run.sh @@ -8,4 +8,4 @@ set -e # Exit on failure -exec mix run --no-compile -- "$@" +exec /tmp/codecrafters-build-{{course_slug}}-elixir "$@" diff --git a/compiled_starters/elixir/.gitignore b/compiled_starters/elixir/.gitignore index 39fc292..820cf9e 100644 --- a/compiled_starters/elixir/.gitignore +++ b/compiled_starters/elixir/.gitignore @@ -1,3 +1,6 @@ +# Ignore the compiled binary +/codecrafters_shell + # The directory Mix will write compiled artifacts to. /_build/ diff --git a/compiled_starters/elixir/lib/main.ex b/compiled_starters/elixir/lib/main.ex index a32510a..572993a 100644 --- a/compiled_starters/elixir/lib/main.ex +++ b/compiled_starters/elixir/lib/main.ex @@ -1,7 +1,7 @@ defmodule CLI do def main(_args) do # Uncomment this block to pass the first stage - IO.write("$ ") + # IO.write("$ ") # Wait for user input IO.read(:line) diff --git a/compiled_starters/elixir/mix.exs b/compiled_starters/elixir/mix.exs index 02bbc84..247299d 100644 --- a/compiled_starters/elixir/mix.exs +++ b/compiled_starters/elixir/mix.exs @@ -7,9 +7,9 @@ defmodule App.MixProject do app: :codecrafters_shell, version: "1.0.0", elixir: "~> 1.17", - escript: [main_module: CLI], start_permanent: Mix.env() == :prod, - deps: deps() + deps: deps(), + escript: [main_module: CLI] ] end diff --git a/compiled_starters/elixir/your_program.sh b/compiled_starters/elixir/your_program.sh index 4e0640b..7e9940f 100755 --- a/compiled_starters/elixir/your_program.sh +++ b/compiled_starters/elixir/your_program.sh @@ -14,11 +14,12 @@ set -e # Exit early if any commands fail # - Edit .codecrafters/compile.sh to change how your program compiles remotely ( cd "$(dirname "$0")" # Ensure compile steps are run within the repository directory - mix compile + mix escript.build + mv codecrafters_shell /tmp/codecrafters-build-{{course_slug}}-elixir ) # Copied from .codecrafters/run.sh # # - Edit this to change how your program runs locally # - Edit .codecrafters/run.sh to change how your program runs remotely -exec mix run --no-compile -- "$@" +exec /tmp/codecrafters-build-{{course_slug}}-elixir "$@" diff --git a/solutions/elixir/01-oo8/code/.codecrafters/compile.sh b/solutions/elixir/01-oo8/code/.codecrafters/compile.sh index 6bc2dcc..b499ff2 100755 --- a/solutions/elixir/01-oo8/code/.codecrafters/compile.sh +++ b/solutions/elixir/01-oo8/code/.codecrafters/compile.sh @@ -8,4 +8,5 @@ set -e # Exit on failure -mix compile +mix escript.build +mv codecrafters_shell /tmp/codecrafters-build-{{course_slug}}-elixir diff --git a/solutions/elixir/01-oo8/code/.codecrafters/run.sh b/solutions/elixir/01-oo8/code/.codecrafters/run.sh index 5651162..684b196 100755 --- a/solutions/elixir/01-oo8/code/.codecrafters/run.sh +++ b/solutions/elixir/01-oo8/code/.codecrafters/run.sh @@ -8,4 +8,4 @@ set -e # Exit on failure -exec mix run --no-compile -- "$@" +exec /tmp/codecrafters-build-{{course_slug}}-elixir "$@" diff --git a/solutions/elixir/01-oo8/code/.gitignore b/solutions/elixir/01-oo8/code/.gitignore index 39fc292..820cf9e 100644 --- a/solutions/elixir/01-oo8/code/.gitignore +++ b/solutions/elixir/01-oo8/code/.gitignore @@ -1,3 +1,6 @@ +# Ignore the compiled binary +/codecrafters_shell + # The directory Mix will write compiled artifacts to. /_build/ diff --git a/solutions/elixir/01-oo8/code/mix.exs b/solutions/elixir/01-oo8/code/mix.exs index 02bbc84..247299d 100644 --- a/solutions/elixir/01-oo8/code/mix.exs +++ b/solutions/elixir/01-oo8/code/mix.exs @@ -7,9 +7,9 @@ defmodule App.MixProject do app: :codecrafters_shell, version: "1.0.0", elixir: "~> 1.17", - escript: [main_module: CLI], start_permanent: Mix.env() == :prod, - deps: deps() + deps: deps(), + escript: [main_module: CLI] ] end diff --git a/solutions/elixir/01-oo8/code/your_program.sh b/solutions/elixir/01-oo8/code/your_program.sh index 4e0640b..7e9940f 100755 --- a/solutions/elixir/01-oo8/code/your_program.sh +++ b/solutions/elixir/01-oo8/code/your_program.sh @@ -14,11 +14,12 @@ set -e # Exit early if any commands fail # - Edit .codecrafters/compile.sh to change how your program compiles remotely ( cd "$(dirname "$0")" # Ensure compile steps are run within the repository directory - mix compile + mix escript.build + mv codecrafters_shell /tmp/codecrafters-build-{{course_slug}}-elixir ) # Copied from .codecrafters/run.sh # # - Edit this to change how your program runs locally # - Edit .codecrafters/run.sh to change how your program runs remotely -exec mix run --no-compile -- "$@" +exec /tmp/codecrafters-build-{{course_slug}}-elixir "$@" diff --git a/starter_templates/elixir/code/.codecrafters/compile.sh b/starter_templates/elixir/code/.codecrafters/compile.sh index 6bc2dcc..bc1a1da 100755 --- a/starter_templates/elixir/code/.codecrafters/compile.sh +++ b/starter_templates/elixir/code/.codecrafters/compile.sh @@ -8,4 +8,5 @@ set -e # Exit on failure -mix compile +mix escript.build +mv codecrafters_shell /tmp/codecrafters-build-shell-elixir diff --git a/starter_templates/elixir/code/.codecrafters/run.sh b/starter_templates/elixir/code/.codecrafters/run.sh index 5651162..214615b 100755 --- a/starter_templates/elixir/code/.codecrafters/run.sh +++ b/starter_templates/elixir/code/.codecrafters/run.sh @@ -8,4 +8,4 @@ set -e # Exit on failure -exec mix run --no-compile -- "$@" +exec /tmp/codecrafters-build-shell-elixir "$@" diff --git a/starter_templates/elixir/code/.gitignore b/starter_templates/elixir/code/.gitignore index 39fc292..820cf9e 100644 --- a/starter_templates/elixir/code/.gitignore +++ b/starter_templates/elixir/code/.gitignore @@ -1,3 +1,6 @@ +# Ignore the compiled binary +/codecrafters_shell + # The directory Mix will write compiled artifacts to. /_build/ diff --git a/starter_templates/elixir/code/mix.exs b/starter_templates/elixir/code/mix.exs index 02bbc84..247299d 100644 --- a/starter_templates/elixir/code/mix.exs +++ b/starter_templates/elixir/code/mix.exs @@ -7,9 +7,9 @@ defmodule App.MixProject do app: :codecrafters_shell, version: "1.0.0", elixir: "~> 1.17", - escript: [main_module: CLI], start_permanent: Mix.env() == :prod, - deps: deps() + deps: deps(), + escript: [main_module: CLI] ] end From 3df7a3ac2c8776690dfde9bbab1b88c7e2569bf1 Mon Sep 17 00:00:00 2001 From: Paul Kuruvilla Date: Tue, 13 Aug 2024 18:33:46 +0100 Subject: [PATCH 4/4] Refactor build and run scripts for Elixir compiled starters and solutions --- compiled_starters/elixir/.codecrafters/compile.sh | 2 +- compiled_starters/elixir/.codecrafters/run.sh | 2 +- compiled_starters/elixir/your_program.sh | 4 ++-- solutions/elixir/01-oo8/code/.codecrafters/compile.sh | 2 +- solutions/elixir/01-oo8/code/.codecrafters/run.sh | 2 +- solutions/elixir/01-oo8/code/your_program.sh | 4 ++-- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/compiled_starters/elixir/.codecrafters/compile.sh b/compiled_starters/elixir/.codecrafters/compile.sh index b499ff2..bc1a1da 100755 --- a/compiled_starters/elixir/.codecrafters/compile.sh +++ b/compiled_starters/elixir/.codecrafters/compile.sh @@ -9,4 +9,4 @@ set -e # Exit on failure mix escript.build -mv codecrafters_shell /tmp/codecrafters-build-{{course_slug}}-elixir +mv codecrafters_shell /tmp/codecrafters-build-shell-elixir diff --git a/compiled_starters/elixir/.codecrafters/run.sh b/compiled_starters/elixir/.codecrafters/run.sh index 684b196..214615b 100755 --- a/compiled_starters/elixir/.codecrafters/run.sh +++ b/compiled_starters/elixir/.codecrafters/run.sh @@ -8,4 +8,4 @@ set -e # Exit on failure -exec /tmp/codecrafters-build-{{course_slug}}-elixir "$@" +exec /tmp/codecrafters-build-shell-elixir "$@" diff --git a/compiled_starters/elixir/your_program.sh b/compiled_starters/elixir/your_program.sh index 7e9940f..c3939df 100755 --- a/compiled_starters/elixir/your_program.sh +++ b/compiled_starters/elixir/your_program.sh @@ -15,11 +15,11 @@ set -e # Exit early if any commands fail ( cd "$(dirname "$0")" # Ensure compile steps are run within the repository directory mix escript.build - mv codecrafters_shell /tmp/codecrafters-build-{{course_slug}}-elixir + mv codecrafters_shell /tmp/codecrafters-build-shell-elixir ) # Copied from .codecrafters/run.sh # # - Edit this to change how your program runs locally # - Edit .codecrafters/run.sh to change how your program runs remotely -exec /tmp/codecrafters-build-{{course_slug}}-elixir "$@" +exec /tmp/codecrafters-build-shell-elixir "$@" diff --git a/solutions/elixir/01-oo8/code/.codecrafters/compile.sh b/solutions/elixir/01-oo8/code/.codecrafters/compile.sh index b499ff2..bc1a1da 100755 --- a/solutions/elixir/01-oo8/code/.codecrafters/compile.sh +++ b/solutions/elixir/01-oo8/code/.codecrafters/compile.sh @@ -9,4 +9,4 @@ set -e # Exit on failure mix escript.build -mv codecrafters_shell /tmp/codecrafters-build-{{course_slug}}-elixir +mv codecrafters_shell /tmp/codecrafters-build-shell-elixir diff --git a/solutions/elixir/01-oo8/code/.codecrafters/run.sh b/solutions/elixir/01-oo8/code/.codecrafters/run.sh index 684b196..214615b 100755 --- a/solutions/elixir/01-oo8/code/.codecrafters/run.sh +++ b/solutions/elixir/01-oo8/code/.codecrafters/run.sh @@ -8,4 +8,4 @@ set -e # Exit on failure -exec /tmp/codecrafters-build-{{course_slug}}-elixir "$@" +exec /tmp/codecrafters-build-shell-elixir "$@" diff --git a/solutions/elixir/01-oo8/code/your_program.sh b/solutions/elixir/01-oo8/code/your_program.sh index 7e9940f..c3939df 100755 --- a/solutions/elixir/01-oo8/code/your_program.sh +++ b/solutions/elixir/01-oo8/code/your_program.sh @@ -15,11 +15,11 @@ set -e # Exit early if any commands fail ( cd "$(dirname "$0")" # Ensure compile steps are run within the repository directory mix escript.build - mv codecrafters_shell /tmp/codecrafters-build-{{course_slug}}-elixir + mv codecrafters_shell /tmp/codecrafters-build-shell-elixir ) # Copied from .codecrafters/run.sh # # - Edit this to change how your program runs locally # - Edit .codecrafters/run.sh to change how your program runs remotely -exec /tmp/codecrafters-build-{{course_slug}}-elixir "$@" +exec /tmp/codecrafters-build-shell-elixir "$@"