### Install Rebar3 Locally Source: https://github.com/tsloughter/rebar3.org/blob/master/content/en/docs/getting-started.md Installs a compiled version of Rebar3 to your local cache and provides instructions to add it to your system's PATH. ```Shell $ ./rebar3 local install ===> Extracting rebar3 libs to ~/.cache/rebar3/lib... ===> Writing rebar3 run script ~/.cache/rebar3/bin/rebar3... ===> Add to $PATH for use: export PATH=$PATH:~/.cache/rebar3/bin ``` -------------------------------- ### Upgrade Rebar3 Locally Source: https://github.com/tsloughter/rebar3.org/blob/master/content/en/docs/getting-started.md Upgrades a locally installed Rebar3 to the latest stable release, fetching and installing it in the same manner as the initial installation. ```Shell $ rebar3 local upgrade ===> Extracting rebar3 libs to ~/.cache/rebar3/lib... ===> Writing rebar3 run script ~/.cache/rebar3/bin/rebar3... ===> Add to $PATH for use: export PATH=$PATH:~/.cache/rebar3/bin ``` -------------------------------- ### Build Rebar3 from Source Source: https://github.com/tsloughter/rebar3.org/blob/master/content/en/docs/getting-started.md Clones the Rebar3 GitHub repository and uses the bootstrap script to compile it from source, generating necessary wrapper scripts for Windows. ```Shell $ git clone https://github.com/erlang/rebar3.git $ cd rebar3 $ ./bootstrap ``` -------------------------------- ### rebar3 Extended Start Script Hooks Configuration Source: https://github.com/tsloughter/rebar3.org/blob/master/content/en/docs/deployment/releases.md Example Erlang configuration for defining pre and post hooks for start, stop, and install_upgrade operations. ```Erlang {extended_start_script_hooks, [ {pre_start, [{custom, "hooks/pre_start"}]}, {post_start, [ {pid, "/tmp/foo.pid"}, {wait_for_process, some_process}, {custom, "hooks/post_start"} ]}, {pre_stop, [{custom, "hooks/pre_stop"}]}, {post_stop, [{custom, "hooks/post_stop"}]} ]}, {post_stop, [{custom, "hooks/post_stop"}]} ]}. ``` -------------------------------- ### Create New Rebar3 Project Source: https://github.com/tsloughter/rebar3.org/blob/master/content/en/docs/getting-started.md Generates a new Erlang project using a Rebar3 template, creating a standard OTP project structure with necessary configuration files. ```Shell $ rebar3 new umbrella myproj ===> Writing apps/myproj/src/myproj_app.erl ===> Writing apps/myproj/src/myproj_sup.erl ===> Writing apps/myproj/src/myproj.app.src ===> Writing rebar.config ===> Writing config/sys.config ===> Writing config/vm.args ===> Writing .gitignore ===> Writing LICENSE ===> Writing README.md ``` -------------------------------- ### Rebar3 Windows Wrapper Script Source: https://github.com/tsloughter/rebar3.org/blob/master/content/en/docs/getting-started.md A batch script for Windows to run the Rebar3 escript from PowerShell or cmd.exe, ensuring proper execution. ```PowerShell @echo off setlocal set rebarscript=%~f0 escript.exe "%rebarscript:.cmd=%%" %* ``` -------------------------------- ### Rebar3 Release Configuration Example Source: https://github.com/tsloughter/rebar3.org/blob/master/content/en/docs/deployment/releases.md A basic `rebar.config` example showing the structure for defining a release with Rebar3, including application dependencies and release mode. ```erlang %% rebar.config {relx, [{release, {, "0.0.1"}, []}, {mode, dev}]}. ``` -------------------------------- ### Rebar3 Shell Example for Testing NIFs Source: https://github.com/tsloughter/rebar3.org/blob/master/content/en/docs/tutorials/building_c_cpp.md Demonstrates how to start an Erlang shell using Rebar3 and interact with the compiled NIF, including calling the 'repeat' function and receiving a message. ```shell $ rebar3 shell ===> Verifying dependencies... ===> Compiling test_nif Erlang/OTP 17 [erts-6.3] [source] [64-bit] [smp:4:4] [async-threads:0] [kernel-poll:false] Eshell V6.3 (abort with ^G) 1> test_nif:repeat(self(), hello). ok 2> receive X -> X end. hello ``` -------------------------------- ### Example Rebar3 Configuration with Profiles Source: https://github.com/tsloughter/rebar3.org/blob/master/content/en/docs/configuration/profiles.md A comprehensive example of a rebar.config file demonstrating multiple profiles: 'prod' for production builds, 'native' for HiPE compilation, and 'test' for testing configurations. It illustrates how to set various options like compiler flags and dependencies per profile. ```Erlang {deps, [...]}. {relx, [ ... ]}. {profiles, [ {prod, [ {erl_opts, [no_debug_info, warnings_as_errors]}, {relx, [{dev_mode, false}]} ]}, {native, [ {erl_opts, [{native, {hipe, o3}}]}] }, {test, [ {deps, [meck]}, {erl_opts, [debug_info]} ]} ]}. ``` -------------------------------- ### rebar3 Start Script Commands Source: https://github.com/tsloughter/rebar3.org/blob/master/content/en/docs/deployment/releases.md Lists and describes the core commands for managing an Erlang release using the rebar3 extended start script. ```APIDOC foreground Start release with output to stdout remote Connect remote shell to running node console Start the release with an interactive shell console_clean Start an interactive shell without the release's applications rpc [Mod [Fun [Args]]] Run apply(Mod, Fun, Args) on running node eval [Exprs] Run expressions on running node status Verify node is running and then run status hook scripts restart Restart the applications but not the VM reboot Reboot the entire VM stop Stop the running node pid Print the PID of the OS process ping Print pong if the node is alive daemon Start release in the background with run_erl (named pipes) daemon_attach Connect to node started as daemon with to_erl (named pipes) ``` -------------------------------- ### Start Hugo Development Server Source: https://github.com/tsloughter/rebar3.org/blob/master/README.md Starts the Hugo local web server for development, which automatically reloads changes. ```shell $ hugo server ``` -------------------------------- ### Run Release Plugin Configuration Source: https://github.com/tsloughter/rebar3.org/blob/master/content/en/docs/configuration/plugins.md Configures the rebar3_run plugin to simplify starting the release console. ```Erlang {plugins, [rebar3_run]}. ``` -------------------------------- ### Starting Multiple Erlang Nodes with Environment Variables Source: https://github.com/tsloughter/rebar3.org/blob/master/content/en/docs/deployment/releases.md A bash script demonstrating how to start multiple Erlang nodes concurrently, each with unique environment variables for name and port, leveraging Rebar3 releases. ```bash #!/bin/bash export RELX_REPLACE_OS_VARS=true for i in `seq 1 10`; do NODE_NAME=node_$i PORT=808$i _build/default/rel//bin/ foreground & sleep 1 done ``` -------------------------------- ### Erlang Configuration Profiles Example Source: https://github.com/tsloughter/rebar3.org/blob/master/content/en/docs/configuration/profiles.md Demonstrates how Rebar3 handles configuration options across different profiles, showing how the order of profile application affects the final list of options for the Erlang compiler. ```Erlang {profiles, [ {prod, [ {erl_opts, [no_debug_info, warnings_as_errors]}, ]}, {native, [ {erl_opts, [{native, {hipe, o3}}, {d, 'NATIVE'}]} ]}, {test, [ {erl_opts, [debug_info]} ]} ]}. ``` -------------------------------- ### Rebar3 Dependency Tree Output Example Source: https://github.com/tsloughter/rebar3.org/blob/master/content/en/docs/configuration/dependencies.md An example of the output from the `rebar3 tree` command, showing a detailed breakdown of the project's dependencies, including their versions and sources (e.g., git repo, hex package). ```plain ├─ bootstrap-0.0.2 (git repo) ├─ dirmon-0.1.0 (project app) ├─ file_monitor-0.1 (git repo) ├─ peeranha-0.1.0 (git repo) │ ├─ gproc-git (git repo) │ ├─ interclock-0.1.2 (git repo) │ │ ├─ bitcask-1.7.0 (git repo) │ │ │ └─ lager-2.1.1 (hex package) │ │ │ └─ goldrush-0.1.6 (hex package) │ │ └─ itc-1.0.0 (git repo) │ └─ merklet-1.0.0 (git repo) ├─ recon-2.2.2 (git repo) └─ uuid-1.5.0 (git repo) └─ quickrand-1.5.0 (git repo) ``` -------------------------------- ### Rebar3 Commands for C/C++ Project Setup Source: https://github.com/tsloughter/rebar3.org/blob/master/content/en/docs/tutorials/building_c_cpp.md Demonstrates the Rebar3 commands to create a new Erlang library project and initialize it with a CMake-based C/C++ structure. ```shell $ rebar3 new lib test_nif ===> Writing test_nif/src/test_nif.erl ===> Writing test_nif/src/test_nif.app.src ===> Writing test_nif/rebar.config ===> Writing test_nif/.gitignore ===> Writing test_nif/LICENSE ===> Writing test_nif/README.md $ cd test_nif $ rebar3 new cmake ===> Writing c_src/Makefile ``` -------------------------------- ### Rebar3 escriptize Example Configuration Source: https://github.com/tsloughter/rebar3.org/blob/master/content/en/docs/commands.md An example of how to configure escriptize settings within a Rebar3 project, specifically shown in the context of a `relx` configuration. ```erlang {escript_emu_args, "%%! +sbtu +A0 -noinput\n"}. {escript_incl_apps, [getopt, erlware_commons, bbmustache, providers, relx]}. ``` -------------------------------- ### Rebar3 Pre-hooks Example for Building Merl Source: https://github.com/tsloughter/rebar3.org/blob/master/content/en/docs/configuration/configuration.md An example demonstrating the use of `pre_hooks` in Rebar3 to execute shell commands for building the 'merl' project on different operating systems, including specific commands for EUnit tests. ```erlang {pre_hooks, [{" (linux|darwin|solaris)", compile, "make -C \"$REBAR_DEPS_DIR/merl\" all -W test"}, {" (freebsd|netbsd|openbsd)", compile, "gmake -C \"$REBAR_DEPS_DIR/merl\" all"}, {"win32", compile, "make -C \"%REBAR_DEPS_DIR%/merl\" all -W test"}, {eunit, "erlc -I include/erlydtl_preparser.hrl -o test test/erlydtl_extension_testparser.yrl"}, {" (linux|darwin|solaris)", eunit, "make -C \"$REBAR_DEPS_DIR/merl\" test"}, {" (freebsd|netbsd|openbsd)", eunit, "gmake -C \"$REBAR_DEPS_DIR/merl\" test"}, {"win32", eunit, "make -C \"%REBAR_DEPS_DIR%/merl\" test"} ]} ``` -------------------------------- ### Rebar3 Configuration for Releases (rebar.config) Source: https://github.com/tsloughter/rebar3.org/blob/master/content/en/docs/basic_usage.md Example rebar.config showing relx configuration for release building, including development and production profiles. ```erlang {relx, [{release, {myrel, "0.0.1"}, [myrel]}, {dev_mode, true}, {include_erts, false}, {extended_start_script, true} ]}. {profiles, [ {prod, [{relx, [{dev_mode, false}, {include_erts, true}]} ]} ]}. ``` -------------------------------- ### Install PostCSS and Fetch Docsy Theme Source: https://github.com/tsloughter/rebar3.org/blob/master/README.md Installs PostCSS dependencies (autoprefixer, postcss-cli) using npm and updates the Docsy theme submodule. ```shell $ npm install -D --save autoprefixer $ npm install -D --save postcss-cli $ cd themes/docsy $ git submodule update -f --init ``` -------------------------------- ### Configure Rebar3 Start Script Extensions Source: https://github.com/tsloughter/rebar3.org/blob/master/content/en/docs/deployment/releases.md Defines custom shell scripts to be appended to the Rebar3 start script, allowing for application-specific commands. The configuration is done within the `rebar.config` file. ```erlang %% start script extensions {extended_start_script_extensions, [ {status, "extensions/status"} ]}. ``` -------------------------------- ### Rebar3 Configuration Example Source: https://github.com/tsloughter/rebar3.org/blob/master/layouts/shortcodes/blocks/cover.html This snippet demonstrates a basic configuration pattern in Rebar3, likely used within a template or configuration file. It shows variable assignment and default value handling. ```erlang {{ $col_id := .Get "color" | default "dark" }} {{/* Height can be one of: auto, min, med, max, full. */}} {{ $height := .Get "height" | default "max" }} ``` -------------------------------- ### Rebar3 Project Structure Examples Source: https://github.com/tsloughter/rebar3.org/blob/master/content/en/docs/tutorials/from_rebar2_to_rebar3.md Illustrates the two primary directory structures supported by Rebar3 for OTP applications: a single-directory structure and an umbrella structure. ```plain src/*.{erl,app.src} ``` ```plain apps/app1/src/*.{erl,app.src} apps/app2/src/*.{erl,app.src} apps/app3/src/*.{erl,app.src} ``` ```plain lib/app1/src/*.{erl,app.src} lib/app2/src/*.{erl,app.src} lib/app3/src/*.{erl,app.src} ``` -------------------------------- ### rebar3 Release Handling Commands Source: https://github.com/tsloughter/rebar3.org/blob/master/content/en/docs/deployment/releases.md Details commands for installing, upgrading, and managing different versions of an Erlang release. ```APIDOC unpack [Version] Unpack a release tarball install [Version] Install a release uninstall [Version] Uninstall a release upgrade [Version] Upgrade the running release to a new version downgrade [Version] Downgrade the running release to a new version versions Print versions of the release available ``` -------------------------------- ### Erlang Provider Skeleton Source: https://github.com/tsloughter/rebar3.org/blob/master/content/en/docs/tutorials/building_plugins.md The basic Erlang code structure for a rebar3 provider, including module definition, behavior, exports, and initial provider setup. ```erlang -module(todo_prv). -behaviour(provider). -export([init/1, do/1, format_error/1]). -define(PROVIDER, todo). -define(DEPS, [app_discovery]). %% =================================================================== %% Public API %% =================================================================== -spec init(rebar_state:t()) -> {ok, rebar_state:t()}. init(State) -> Provider = providers:create([ {name, ?PROVIDER}, % The 'user friendly' name of the task {module, ?MODULE}, % The module implementation of the task {bare, true}, % The task can be run by the user, always true {deps, ?DEPS}, % The list of dependencies {example, "rebar provider_todo"}, % How to use the plugin {opts, []} % list of options understood by the plugin {short_desc, "example rebar3 plugin"}, {desc, ""} ]), {ok, rebar_state:add_provider(State, Provider)}. -spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}. do(State) -> {ok, State}. -spec format_error(any()) -> iolist(). format_error(Reason) -> io_lib:format("~p", [Reason]). ``` -------------------------------- ### Configure Test Dependencies with rebar3 Profiles Source: https://github.com/tsloughter/rebar3.org/blob/master/content/en/docs/basic_usage.md Demonstrates how to use rebar3 profiles to manage dependencies that are only required for testing. It shows how to define a `test` profile in `rebar.config` and lists an example dependency (`meck`) for testing purposes. ```Erlang {profiles, [ {test, [ {deps, [ {meck, "0.9.0"} ]} ]} ]}. % Output structure for test dependencies: % _build/ % └── test % └── lib % └── meck ``` -------------------------------- ### Example Game Server Extension Script Source: https://github.com/tsloughter/rebar3.org/blob/master/content/en/docs/deployment/releases.md A bash script demonstrating a custom command extension for a game server. It handles a 'help' command and retrieves server status using `relx_nodetool eval` to execute Erlang code. ```bash #!/bin/bash case $1 in help) echo "bin/gameserver status" ;; *) ;; esac # get the status tuple from gameserver Status=$(relx_nodetool eval "pool_debug:status(json).") # now print it out code="Json = binary_to_list($Status), io:format(\"~p~n\", [Json]), halt()." echo $(erl -boot no_dot_erlang -sasl errlog_type error -noshell -eval "$code") ``` -------------------------------- ### Rebar3 Plugin Initialization Source: https://github.com/tsloughter/rebar3.org/blob/master/content/en/docs/extending/custom_dep_resources.md Example of how to initialize a Rebar3 plugin, specifically for adding a custom resource. It demonstrates exporting the init function and using `rebar_state:add_resource/2`. ```erlang -module(my_rebar_plugin). -export([init/1]). -spec init(rebar_state:t()) -> {ok, rebar_state:t()}. init(State) -> {ok, rebar_state:add_resource(State, {Tag, Module})}. ``` -------------------------------- ### Run Todo Plugin Source: https://github.com/tsloughter/rebar3.org/blob/master/content/en/docs/tutorials/building_plugins.md Demonstrates how to execute the 'todo' plugin from the command line after it has been configured and compiled by Rebar3. ```shell → rebar3 todo ``` -------------------------------- ### Erlang Test Setup with Breakpoint Source: https://github.com/tsloughter/rebar3.org/blob/master/content/en/docs/tutorials/using_breakpoints_to_debug_tests.md Sets up a Common Test suite in Erlang, starts an application, checks supervisor children, and inserts a breakpoint if no workers are found. It asserts the expected number of workers. ```erlang -include_lib("common_test/include/ct.hrl"). -include_lib("stdlib/include/assert.hrl). -compile(export_all). all() -> [start]. start(_Config) -> ?assertEqual(ok, application:start(break_check)), Props = supervisor:count_children(break_check_sup), case proplists:get_value(workers, Props) of 0 -> r3:break(); _ -> ignore end, ?assertEqual(1, proplists:get_value(workers, Props)), ok. ``` -------------------------------- ### Rebar3 EUnit Command Help Source: https://github.com/tsloughter/rebar3.org/blob/master/content/en/docs/testing/eunit.md Displays detailed help information for the 'rebar3 eunit' command, including available options and their usage. ```Shell $ rebar3 help eunit ``` -------------------------------- ### Using a Rebar3 Plugin Source: https://github.com/tsloughter/rebar3.org/blob/master/content/en/docs/tutorials/building_plugins.md Demonstrates how to add a plugin to your rebar.config file and then execute it from the command line. ```erlang {plugins, [{plugin_name, {git, "git@host:user/name-of-plugin.git", {tag, "1.0.0"}}} ]}. ``` ```shell $ rebar3 plugin_name ===> Fetching plugin_name ===> Compiling plugin_name ``` -------------------------------- ### Run Todo Plugin with Dependencies Source: https://github.com/tsloughter/rebar3.org/blob/master/content/en/docs/tutorials/building_plugins.md This shell command demonstrates running the 'todo' plugin after it has been configured to scan dependencies. The output shows Rebar3 fetching and compiling dependencies before running the plugin. ```shell → rebar3 todo ===> Fetching todo ===> Compiling todo ===> Fetching bootstrap ===> Fetching file_monitor ===> Fetching recon [...] Application dirmon /Users/ferd/code/self/figsync/apps/dirmon/src/dirmon_tracker.erl TODO: Peeranha should expose the UUID from a node. Application meck /Users/ferd/code/self/figsync/_deps/meck/src/meck_proc.erl TODO: What to do here? TODO: What to do here? ``` -------------------------------- ### Display Todo Plugin Help Source: https://github.com/tsloughter/rebar3.org/blob/master/content/en/docs/tutorials/building_plugins.md Shows how to view the help message for the 'todo' Rebar3 plugin, which includes its usage and a brief description of its functionality. ```shell → rebar3 help todo Scans top-level application source and find instances of TODO: in commented out content to report it to the user. Usage: rebar todo [-d] ``` -------------------------------- ### Complex Dependency Tree Example Source: https://github.com/tsloughter/rebar3.org/blob/master/content/en/docs/configuration/dependencies.md An example of a more complex dependency tree, showing how nested dependencies and versioning can affect the overall project structure. This helps in understanding scenarios like version conflicts and automatic dependency fetching. ```plain A B C1 / \ / \ / \ D E F G H I2 | | J K | I1 ``` -------------------------------- ### Custom Resource Callback Module Example Source: https://github.com/tsloughter/rebar3.org/blob/master/content/en/docs/extending/custom_dep_resources.md A comprehensive example of a Rebar3 custom resource callback module. It includes implementations for `init`, `lock`, `download`, `make_vsn`, and `needs_update`, showcasing how to handle custom dependency logic. ```erlang -module(my_rebar_plugin_resource). -export([init/2, lock/2, download/4, needs_update/2, make_vsn/1]). %% Initialize the custom dep resource plugin init(Type, _RebarState) -> CustomState = #{}, Resource = rebar_resource_v2:new( Type, % type tag such as 'git' or 'hg' ?MODULE, % this callback module CustomState % anything you want to carry around for next calls ), {ok, Resource}. lock(AppInfo, CustomState) -> %% Extract info such as {Type, ResourcePath, ...} as declared %% in rebar.config SourceTuple = rebar_app_info:source(AppInfo), %% Annotate and modify the source tuple to make it absolutely %% and indeniably unambiguous (for example, with git this means %% transforming a branch name into an immutable ref) ... %% Return the unambiguous source tuple ModifiedSource. download(TmpDir, AppInfo, RebarState, CustomState) -> %% Extract info such as {Type, ResourcePath, ...} as declared %% in rebar.config SourceTuple = rebar_app_info:source(AppInfo)), %% Download the resource defined by SourceTuple, which should be %% an OTP application or library, into TmpDir ... ok. make_vsn(Dir, CustomState) -> %% Extract a version number from the application. This is useful %% when defining the version in the .app.src file as `{version, Type}`, %% which means it should be derived from the build information. For %% the `git' resource, this means looking for the last tag and adding %% commit-specific information ... {plain, "0.1.2"}. needs_update(AppInfo, CustomState) -> %% Extract the Source tuple if needed SourceTuple = rebar_app_info:source(AppInfo), %% Base version in the current file OriginalVsn = rebar_app_info:original_vsn(AppInfo) %% Check if the copy in the current install matches %% the defined value in the source tuple. On a conflict, %% return `true', otherwise `false' ..., Bool. ``` -------------------------------- ### Create Rebar3 Plugin Source: https://github.com/tsloughter/rebar3.org/blob/master/content/en/docs/tutorials/building_plugins.md Commands to generate a new rebar3 plugin project and initialize a Git repository. ```shell → rebar3 new plugin todo desc="example rebar3 plugin" ... → cd todo → git init Initialized empty Git repository in /Users/ferd/code/self/todo/.git/ ``` -------------------------------- ### Rebar3 New Command Usage Source: https://github.com/tsloughter/rebar3.org/blob/master/content/en/docs/tutorials/templates.md Demonstrates how to use the Rebar3 `new` command to list available templates and create new projects or files based on those templates. It shows the output of listing templates and applying a custom template. ```shell $ ./rebar3 new app (built-in): OTP Application ct_suite (custom): A basic Common Test suite for an OTP application lib (built-in): OTP Library application (no processes) release (built-in): OTP Release structure for executable programs plugin (built-in): Rebar3 plugin ``` ```shell $ ./rebar3 new help ct_suite ct_suite: custom template (/home/ferd/.config/rebar3/templates/ct_suite.template) Description: A basic Common Test suite for an OTP application Variables: name="suite" (Name of the suite, prepended to the standard _SUITE suffix) date="2014-11-10" datetime="2014-11-10T18:46:33+00:00" author_name="Anonymous" author_email="anonymous@example.org" copyright_year="2014" apps_dir="apps/" (Directory where applications will be created if needed) ``` ```shell $ ./rebar3 new ct_suite demo ===> Writing test/demo_SUITE.erl ``` -------------------------------- ### Application Syntax in Releases Source: https://github.com/tsloughter/rebar3.org/blob/master/content/en/docs/deployment/releases.md Illustrates the different ways to specify applications within a rebar3 release configuration, including basic names and tuples with options. ```erlang {release, {myrelease, "0.1.0"}, [, ]} ``` ```erlang % No options specified myapp % All options specified {myapp, "1.1.0", transient, [otherapp]} % Some options specified {myapp, "1.1.0"} {myapp, "1.1.0", transient} {myapp, "1.1.0", [otherapp]} {myapp, transient} {myapp, [otherapp]} {myapp, transient, [otherapp]} ``` -------------------------------- ### Updated Rebar3 Provider Description Source: https://github.com/tsloughter/rebar3.org/blob/master/content/en/docs/tutorials/building_plugins.md Modified provider options for a rebar3 plugin, updating the example usage and short/long descriptions. ```erlang Provider = providers:create([ {name, ?PROVIDER}, % The 'user friendly' name of the task {module, ?MODULE}, % The module implementation of the task {bare, true}, % The task can be run by the user, always true {deps, ?DEPS}, % The list of dependencies {example, "rebar todo"}, % How to use the plugin {opts, []}, % list of options understood by the plugin {short_desc, "Reports TODOs in source code"}, {desc, "Scans top-level application source and find " "instances of TODO: in commented out content " "to report it to the user." ]), ``` -------------------------------- ### Rebar3 Lock Command Source: https://github.com/tsloughter/rebar3.org/blob/master/content/en/docs/commands.md Gets unbuilt dependencies to be added to the `rebar.lock` file. Dependencies are downloaded but their build scripts have not necessarily run. ```APIDOC lock Get unbuilt dependencies to be added to the `rebar.lock` file. They will just have been downloaded, but none of their build script should have run. Though this is not necessarily true with pre/post hooks and dep plugins. ``` -------------------------------- ### Create New Release Project with Rebar3 Source: https://github.com/tsloughter/rebar3.org/blob/master/content/en/docs/basic_usage.md Generates a new project with a release structure and default relx configuration in rebar.config. ```shell $ rebar3 new release myrel ===> Writing myrel/apps/myrel/src/myrel_app.erl ===> Writing myrel/apps/myrel/src/myrel_sup.erl ===> Writing myrel/apps/myrel/src/myrel.app.src ===> Writing myrel/rebar.config ===> Writing myrel/config/sys.config ===> Writing myrel/config/vm.args ===> Writing myrel/.gitignore ===> Writing myrel/LICENSE ===> Writing myrel/README.md ``` -------------------------------- ### Rebar3 Override Example: Remove Compiler Warnings Source: https://github.com/tsloughter/rebar3.org/blob/master/content/en/docs/configuration/configuration.md Shows how to remove the 'warnings_as_errors' compiler option for all applications or for a specific application using overrides. ```Erlang {overrides, [ %% For all apps: {del, [{erl_opts, [warnings_as_errors]}]}, %% Or for just one app: {del, one_app, [{erl_opts, [warnings_as_errors]}]} ]}. ``` -------------------------------- ### Rebar3 Template Instantiation Source: https://github.com/tsloughter/rebar3.org/blob/master/content/en/docs/tutorials/templates.md Demonstrates how to create a new project using a Rebar3 template, specifying variables on the command line. The command `rebar3 new [variable=value ...]` generates the project structure. ```Shell $ ./rebar3 new plugin name=demo author_name="Fred H." ... $ ./rebar3 new plugin demo author_name="Fred H." ... ``` -------------------------------- ### Rebar3 Override Example: Debug Info Source: https://github.com/tsloughter/rebar3.org/blob/master/content/en/docs/configuration/configuration.md Demonstrates how to use overrides to enforce compilation with debug information for all dependencies, and how to disable it for production profiles. ```Erlang {overrides, [{override, [{erl_opts, [debug_info]}]}]}. {profiles, [{prod, [{overrides, [{override, [{erl_opts,[no_debug_info]}]}]}, {relx, [{dev_mode, false}, {include_erts, true}]}]}]} ``` -------------------------------- ### Debugging with rebar3 Shell and recon_trace Source: https://github.com/tsloughter/rebar3.org/blob/master/content/en/docs/tutorials/using_breakpoints_to_debug_tests.md Demonstrates how to start a rebar3 shell, trigger a breakpoint, and use `recon_trace` to inspect supervisor behavior. ```shell $ rebar3 shell --start-clean ... 1> r3:async_do(ct). ===> This feature is experimental and may be modified or removed at any time. ok 2> Verifying dependencies... Compiling break_check Running Common Test suites... %%% start_SUITE: === BREAK === ``` ```erlang %% Set up a trace for all functions in the supervisor, returning their result 2> recon_trace:calls({break_check_sup, '_', fun(_) -> return_trace() end}, 10). 0 %% 0 functions matching on a wildcard means the module is likely not loaded, %% so let's do that 3> l(break_check_sup). {module,break_check_sup} %% Try setting the trace call again 4> recon_trace:calls({break_check_sup, '_', fun(_) -> return_trace() end}, 10). 4 % <-- and now we have a match 5> r3:resume(). ok 13:34:51.207925 <0.249.0> break_check_sup:start_link() 13:34:51.208075 <0.250.0> break_check_sup:init([]) 13:34:51.208197 <0.250.0> break_check_sup:init/1 --> {ok, {{one_for_all,0,1},[]}} 13:34:51.208350 <0.249.0> break_check_sup:start_link/0 --> {ok,<0.250.0>} 7> ``` -------------------------------- ### Rebar3 Overlays Configuration Source: https://github.com/tsloughter/rebar3.org/blob/master/content/en/docs/deployment/releases.md Shows how to configure Rebar3 overlays in `rebar.config` to include files and templates in a release. Demonstrates actions like creating directories, copying files, and processing templates. ```erlang {relx, [ ... {overlay_vars, "vars.config"}, {overlay, [{mkdir, "log/sasl"}, {template, "priv/app.config", "etc/app.config"}, {copy, "Procfile", "Procfile"}]} ]}. ``` -------------------------------- ### Rebar3 Provider Interface Implementation Source: https://github.com/tsloughter/rebar3.org/blob/master/content/en/docs/tutorials/building_plugins.md Provides a template for implementing a Rebar3 provider, including the required init, do, and format_error callbacks. ```erlang -module(provider_template). -behaviour(provider). -export([init/1, do/1, format_error/1]). %% =================================================================== %% Public API %% =================================================================== %% Called when rebar3 first boots, before even parsing the arguments %% or commands to be run. Purely initiates the provider, and nothing %% else should be done here. -spec init(rebar_state:t()) -> {ok, rebar_state:t()}. init(State) -> Provider = providers:create([Options]), {ok, rebar_state:add_provider(State, Provider)}. %% Run the code for the plugin. The command line argument are parsed %% and dependencies have been run. -spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}. do(State) -> {ok, State}. %% When an exception is raised or a value returned as %% `{error, {?MODULE, Reason}}` will see the `format_error(Reason)` %% function called for them, so a string can be formatted explaining %% the issue. -spec format_error(any()) -> iolist(). format_error(Reason) -> io_lib:format("~p", [Reason]). ``` -------------------------------- ### Rebar3 New Command Usage Source: https://github.com/tsloughter/rebar3.org/blob/master/content/en/docs/tutorials/templates.md Lists available built-in Rebar3 templates and provides help for specific templates. The `rebar3 new` command lists templates, and `rebar3 new help ` shows details and variables for a given template. ```Shell $ ./rebar3 new app (built-in): Complete OTP Application structure. cmake (built-in): Standalone Makefile for building C/C++ in c_src escript (built-in): Complete escriptized application structure lib (built-in): Complete OTP Library application (no processes) structure plugin (built-in): Rebar3 plugin project structure release (built-in): OTP Release structure for executable programs ``` ```Shell $ ./rebar3 new help plugin plugin: built-in template Description: Rebar3 plugin Variables: name="myplugin" (Name of the plugin) desc="A rebar plugin" (Short description of the plugin's purpose) date="2014-11-10" datetime="2014-11-10T18:29:41+00:00" author_name="Anonymous" author_email="anonymous@example.org" copyright_year="2014" apps_dir="apps/" (Directory where applications will be created if needed) ``` -------------------------------- ### Rebar3 QuickCheck Plugin Configuration Source: https://github.com/tsloughter/rebar3.org/blob/master/content/en/docs/configuration/plugins.md This snippet shows how to enable the rebar3_eqc plugin in your Rebar3 project configuration. It's a common setup for projects using Erlang QuickCheck. ```Erlang {plugins, [rebar3_eqc]}. ``` -------------------------------- ### Rebar3 Shell Execution and Breakpoint Trigger Source: https://github.com/tsloughter/rebar3.org/blob/master/content/en/docs/tutorials/using_breakpoints_to_debug_tests.md Demonstrates running a Rebar3 shell, starting a Common Test suite asynchronously, and triggering a breakpoint during the test execution. ```shell $ rebar3 shell --start-clean ... 1> r3:async_do(ct). ===> This feature is experimental and may be modified or removed at any time. ok 2> Verifying dependencies... Compiling break_check Running Common Test suites... %%% start_SUITE: === BREAK === ``` -------------------------------- ### Declare Dependencies in rebar.config Source: https://github.com/tsloughter/rebar3.org/blob/master/content/en/docs/basic_usage.md Shows how to specify project dependencies in the `rebar.config` file, including version constraints and alternative sources like Git repositories. It also illustrates how to list applications in the `.app.src` file. ```Erlang {deps, [ {elli, "~> 3.3.0"}, % package {elli, {git, "git://github.com/elli-lib/elli.git", {tag, "3.3.0"}}} % alternatively, source ] }. {application, , [{description, ""}, {vsn, }, {registered, []}, {modules, []}, {applications, [kernel, stdlib, elli]}, {mod, {_app, []}}, {env, []} ]}. % Version types for : % "string()" - Literal string version. % {git, short | long} - Git commit hash. % {file, File} - Content of a file. % {cmd, string()} - Output of a shell command. ``` -------------------------------- ### Dependency Tree Structure Example Source: https://github.com/tsloughter/rebar3.org/blob/master/content/en/docs/configuration/dependencies.md A plain text representation of a dependency tree, illustrating the hierarchical relationships between project dependencies and their sub-dependencies. This format is often used in documentation or command-line output. ```plain A B | | C D ``` -------------------------------- ### Rebar3 Provider Initialization Source: https://github.com/tsloughter/rebar3.org/blob/master/content/en/docs/extending/custom_compiler_plugins.md Initializes a Rebar3 provider, setting its name, namespace, module, dependencies, example usage, and description. This function adds the custom provider to the Rebar3 state. ```erlang -spec init(rebar_state:t()) -> {ok, rebar_state:t()}. init(State) -> Provider = providers:create([ {name, ?PROVIDER}, {namespace, ?NAMESPACE}, {module, ?MODULE}, {bare, true}, {deps, ?DEPS}, {example, "rebar3 exc compile"}, {opts, []}, {short_desc, "An example rebar compile plugin"}, {desc, ""} ]), {ok, rebar_state:add_provider(State, Provider)}. ``` -------------------------------- ### Rebar3 Overlay Actions Source: https://github.com/tsloughter/rebar3.org/blob/master/content/en/docs/deployment/releases.md Lists and describes the supported actions within Rebar3's overlay configuration: `mkdir` for creating directories, `copy` for file duplication, and `template` for file copying with variable expansion. ```erlang - `mkdir` to create a directory within the release - `copy` to copy a file from a local directory to a location within the release - `template` to behave the way `copy` does, but with variable expansion in it. ``` -------------------------------- ### Place Extension Scripts in Release Source: https://github.com/tsloughter/rebar3.org/blob/master/content/en/docs/deployment/releases.md Specifies how to copy custom extension scripts into the correct location within the generated release using Rebar3's `overlay` configuration. This ensures the start script can find and execute them. ```erlang {copy, "scripts/extensions/status", "bin/extensions/status"}, ``` -------------------------------- ### Rebar3 Configuration for C/C++ Build Hooks Source: https://github.com/tsloughter/rebar3.org/blob/master/content/en/docs/tutorials/building_c_cpp.md Shows how to configure Rebar3's `rebar.config` to execute 'make' or 'gmake' commands before compilation and 'clean' commands after cleaning for C/C++ code. ```erlang {pre_hooks, [{" (linux|darwin|solaris)", compile, "make -C c_src"}, {" (freebsd)", compile, "gmake -C c_src"}]}. {post_hooks, [{" (linux|darwin|solaris)", clean, "make -C c_src clean"}, {" (freebsd)", clean, "gmake -C c_src clean"}]} ``` -------------------------------- ### Rebar API Functions Source: https://github.com/tsloughter/rebar3.org/blob/master/content/en/docs/tutorials/building_plugins.md Provides a reference for commonly used functions in the `rebar_api` module for writing Rebar3 providers. These functions cover logging, environment interaction, and code path management. ```APIDOC Function | Usage ---|--- abort() | Interrupts program flow. abort(FormatString, Args) | Interrupts program flow; displays an ERROR message along with it. Equivalent to calling rebar_api:error(FormatString, Args) followed by rebar_api:abort(). console(FormatString, Args) | Prints to the console. info(FormatString, Args) | Logs with the severity INFO. warn(FormatString, Args) | Logs with the severity WARNING. error(FormatString, Args) | Logs with the severity ERROR. debug(FormatString, Args) | Logs with the severity DEBUG. expand_env_variable(InStr, VarName, RawVarValue) | Given the env variable FOO, we want to expand all references to it in InStr. References can have two forms: $FOO and ${FOO}. The form $FOO is delimited by whitespace characters or the end of a line (eol). get_arch() | Returns the 'architecture' as a string of the form "$OTP_VSN-$SYSTEM_$ARCH-WORDSIZE. Final strings will look like "17-x86_64-apple-darwin13.4.0-8" or "17-x86_64-unknown-linux-gnu-8". wordsize() | Returns the true wordsize of the emulator, i.e. the size of a pointer, in bytes as an string. add_deps_to_path(RebarState) | The project's dependencies are added to the code path. Useful when a tool is invoked and needs to have global stateful access to libraries. restore_code_path(RebarState) | Revert the code path to only include the libraries required to run Rebar3 and its plugins. This is the desired state for Rebar3 to avoid conflicts with user-provided tools. ssl_opts(Url) | Returns the [ssl](https://hosting.review/web-hosting-glossary/#12) options to use with httpc to make a secure and verified HTTP request. ``` -------------------------------- ### Create New Project with rebar3 Source: https://github.com/tsloughter/rebar3.org/blob/master/content/en/docs/basic_usage.md Demonstrates how to use the `rebar3 new` command to create different types of Erlang projects, such as applications, libraries, or umbrella projects. It shows the typical output generated by the command. ```Shell $ rebar3 new app myapp ===> Writing myapp/src/myapp_app.erl ===> Writing myapp/src/myapp_sup.erl ===> Writing myapp/src/myapp.app.src ===> Writing myapp/rebar.config ===> Writing myapp/.gitignore ===> Writing myapp/LICENSE ===> Writing myapp/README.md ``` -------------------------------- ### Rebar3 Dynamic Dependency Configuration Script Source: https://github.com/tsloughter/rebar3.org/blob/master/content/en/docs/configuration/config_script.md An example Erlang script for rebar.config that allows specifying a local directory for dependencies via the REBAR_DEPS environment variable. It demonstrates how to modify the configuration based on environment settings. ```Erlang case os:getenv("REBAR_DEPS") of false -> CONFIG; % env var not defined [] -> CONFIG; % env var set to empty string Dir -> lists:keystore(deps_dir, 1, CONFIG, {deps_dir, Dir}) end. ```