Functions & API Calls
rebar3:main/1
Purpose: Entry point from escript
Signature:
-spec main([string()]) -> no_return().
Arguments:
Args([string()]): Command-line arguments
Returns: Does not return; calls erlang:halt/1
Flow:
- Calls
rebar3:run/1 - Handles success/error
- Exits with appropriate code
rebar3:run/1
Purpose: Main execution entry point from command line
Signature:
-spec run([string()]) -> {ok, rebar_state:t()} | {error, term()}.
Arguments:
RawArgs([string()]): Command-line arguments
Returns:
{ok, State}: Successful execution with final state{error, Reason}: Error occurred
Flow:
- Start and load applications
- Call
init_config/0to create base state - Set
callertocommand_line - Call
set_options/2to process global flags - Call
run_aux/2for actual execution
rebar3:init_config/0
Purpose: Set up base configuration and initial state
Signature:
-spec init_config() -> rebar_state:t().
Returns: Initialized state record
Flow:
- Set HTTPC options via
rebar_utils:set_httpc_options/0 - Initialize logging via
rebar_log:init/2 - Read
rebar.configviarebar_config:consult_root/0 - Read
rebar.lockviarebar_config:consult_lock_file/1 - Merge locks into config via
rebar_config:merge_locks/2 - Create state via
rebar_state:new/1 - Load global config if exists
- Set escript path
- Initialize vsn cache
Example Usage:
BaseState = rebar3:init_config()
rebar_config:consult_root/0
Purpose: Read the main rebar.config file
Signature:
-spec consult_root() -> [term()].
Returns: List of configuration terms
Flow:
- Looks for
rebar.configin current directory - Parses as Erlang terms
- Returns empty list if file doesn't exist
Called From: Initialization & Configuration
rebar_config:consult_lock_file/1
Purpose: Read and parse the lock file
Signature:
-spec consult_lock_file(file:filename()) -> [term()].
Arguments:
File(file:filename()): Path torebar.lock
Returns: List of lock entries in internal format
Flow:
- Read lock file
- Detect version (beta, "1.2.0", etc.)
- Parse locks based on version
- Extract package hashes
- Expand locks with hash information
- Return internal lock format
Lock File Versions:
- Beta format:
[Locks]. - Versioned format:
{"1.2.0", Locks}. [Attrs].
rebar_state:new/0,1,2,3
Purpose: Create a new rebar state record
Signature:
-spec new() -> t().
-spec new(list()) -> t().
-spec new(t() | atom(), list()) -> t().
-spec new(t(), list(), file:filename_all()) -> t().
Arguments (for new/1):
Config(list()): Configuration terms fromrebar.config
Returns: New state record
Flow (for new/1):
- Convert config list to dict via
base_opts/1 - Create base state with opts
- Set current working directory
- Set default opts
State Record:
-record(state_t, {
dir :: file:name(),
opts = dict:new() :: rebar_dict(),
code_paths = dict:new() :: rebar_dict(),
default = dict:new() :: rebar_dict(),
escript_path :: undefined | file:filename_all(),
lock = [],
current_profiles = [default] :: [atom()],
namespace = default :: atom(),
command_args = [],
command_parsed_args = {[], []},
current_app :: undefined | rebar_app_info:t(),
project_apps = [] :: [rebar_app_info:t()],
deps_to_build = [] :: [rebar_app_info:t()],
all_plugin_deps = [] :: [rebar_app_info:t()],
all_deps = [] :: [rebar_app_info:t()],
compilers = [] :: [module()],
project_builders = [] :: [{project_type(), module()}],
resources = [],
providers = [],
allow_provider_overrides = false :: boolean()
}).
rebar_state:apply_profiles/2
Purpose: Apply configuration profiles to state
Signature:
-spec apply_profiles(t(), [atom()]) -> t().
Arguments:
State(t()): Current stateProfiles([atom()]): List of profiles to apply (e.g.,[test],[prod])
Returns: State with merged profile configuration
Flow:
- Get profiles config from state
- For each profile (except
default):- Get profile-specific options
- Merge with current opts using
rebar_opts:merge_opts/3
- Update
current_profilesfield - Return modified state
Profile Merging:
- Base configuration is from
defaultprofile - Profile-specific configs override base
- Multiple profiles stack in order given
rebar_plugins:project_plugins_install/1
Purpose: Install plugins specified in rebar.config
Signature:
-spec project_plugins_install(rebar_state:t()) -> rebar_state:t().
Arguments:
State(rebar_state:t()): Current state
Returns: State with plugins installed and providers registered
Flow:
- Get
project_pluginsfrom configuration - For each plugin:
- Fetch plugin (from Hex or Git)
- Compile plugin
- Load plugin application
- Discover and register providers from plugin
- Update state with new providers
rebar_state:create_logic_providers/2
Purpose: Register built-in providers with the state
Signature:
-spec create_logic_providers([module()], t()) -> t().
Arguments:
Providers([module()]): List of provider modulesState(t()): Current state
Returns: State with providers registered
Flow:
- For each provider module:
- Call
Module:init(State)to get provider record - Add to providers list
- Call
- Return updated state
Built-in Providers (from application env):
rebar_prv_app_discoveryrebar_prv_compilerebar_prv_cleanrebar_prv_install_depsrebar_prv_lock- And many more...
rebar_core:init_command/2
Purpose: Initialize and dispatch to the requested command
Signature:
-spec init_command(rebar_state:t(), atom()) -> {ok, rebar_state:t()} | {error, term()}.
Arguments:
State(rebar_state:t()): Current stateCommand(atom()): Command to execute (e.g.,compile,test)
Returns:
{ok, NewState}: Command executed successfully{error, Reason}: Command failed
Flow:
- Handle special commands (
do,as) - Call
process_namespace/2to resolve namespace - Call
process_command/2to execute provider chain