<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="x-ua-compatible" content="ie=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="generator" content="ExDoc v0.19.1"> <title>Mix.Task.Compiler – Mix v1.7.2</title> <link rel="stylesheet" href="dist/app-240d7fc7e5.css" /> <link rel="canonical" href="https://hexdocs.pm/mix/v1.7/Mix.Task.Compiler.html" /> <script src="dist/sidebar_items-0c0044e6e4.js"></script> </head> <body data-type="modules"> <script>try { if(localStorage.getItem('night-mode')) document.body.className += ' night-mode'; } catch (e) { }</script> <div class="main"> <button class="sidebar-button sidebar-toggle"> <span class="icon-menu" aria-hidden="true"></span> <span class="sr-only">Toggle Sidebar</span> </button> <button class="sidebar-button night-mode-toggle"> <span class="icon-theme" aria-hidden="true"></span> <span class="sr-only">Toggle Theme</span> </button> <section class="sidebar"> <a href="http://elixir-lang.org/docs.html" class="sidebar-projectLink"> <div class="sidebar-projectDetails"> <h1 class="sidebar-projectName"> Mix </h1> <h2 class="sidebar-projectVersion"> v1.7.2 </h2> </div> <img src="assets/logo.png" alt="Mix" class="sidebar-projectImage"> </a> <form class="sidebar-search" action="search.html"> <button type="submit" class="search-button"> <span class="icon-search" aria-hidden="true"></span> </button> <input name="q" type="text" id="search-list" class="search-input" placeholder="Search" aria-label="Search" autocomplete="off" /> </form> <ul class="sidebar-listNav"> <li><a id="extras-list" href="#full-list">Pages</a></li> <li><a id="modules-list" href="#full-list">Modules</a></li> <li><a id="exceptions-list" href="#full-list">Exceptions</a></li> <li><a id="tasks-list" href="#full-list">Mix Tasks</a></li> </ul> <div class="gradient"></div> <ul id="full-list" class="sidebar-fullList"></ul> </section> <section class="content"> <div class="content-outer"> <div id="content" class="content-inner"> <h1> <small class="visible-xs">Mix v1.7.2</small> Mix.Task.Compiler <small>behaviour</small> <a href="https://github.com/elixir-lang/elixir/blob/v1.7.2/lib/mix/lib/mix/task.compiler.ex#L1" title="View Source" class="view-source" rel="help"> <span class="icon-code" aria-hidden="true"></span> <span class="sr-only">View Source</span> </a> </h1> <section id="moduledoc"> <p>This module defines the behaviour for a Mix task that does compilation.</p> <p>A Mix compiler task can be defined by simply using <a href="Mix.Task.Compiler.html#content"><code class="inline">Mix.Task.Compiler</code></a> in a module whose name starts with <code class="inline">Mix.Tasks.Compile.</code> and defining the <code class="inline">run/1</code> function:</p> <pre><code class="nohighlight makeup elixir"><span class="kd">defmodule</span><span class="w"> </span><span class="nc">Mix.Tasks.Compile.MyLanguage</span><span class="w"> </span><span class="k" data-group-id="8247628941-1">do</span><span class="w"> </span><span class="kn">use</span><span class="w"> </span><span class="nc">Mix.Task.Compiler</span><span class="w"> </span><span class="kd">def</span><span class="w"> </span><span class="nf">run</span><span class="p" data-group-id="8247628941-2">(</span><span class="c">_args</span><span class="p" data-group-id="8247628941-2">)</span><span class="w"> </span><span class="k" data-group-id="8247628941-3">do</span><span class="w"> </span><span class="ss">:ok</span><span class="w"> </span><span class="k" data-group-id="8247628941-3">end</span><span class="w"> </span><span class="k" data-group-id="8247628941-1">end</span></code></pre> <p>The <code class="inline">run/1</code> function returns an atom indicating the status of the compilation, and optionally can also return a list of “diagnostics” such as warnings or compilation errors. Doing this enables code editors to display issues inline without having to analyze the command-line output.</p> <p>If the compiler uses manifest files to track stale sources, it should define <code class="inline">manifests/0</code>, and if it writes any output to disk it should also define <code class="inline">clean/0</code>.</p> <p>A compiler supports the same attributes for configuration and documentation as a regular Mix task. See <a href="Mix.Task.html"><code class="inline">Mix.Task</code></a> for more information.</p> </section> <section id="summary" class="details-list"> <h1 class="section-heading"> <a class="hover-link" href="#summary"> <span class="icon-link" aria-hidden="true"></span> <span class="sr-only">Link to this section</span> </a> Summary </h1> <div class="summary-callbacks summary"> <h2> <a href="#callbacks">Callbacks</a> </h2> <div class="summary-row"> <div class="summary-signature"> <a href="#c:clean/0">clean()</a> </div> <div class="summary-synopsis"><p>Removes build artifacts and manifests</p> </div> </div> <div class="summary-row"> <div class="summary-signature"> <a href="#c:manifests/0">manifests()</a> </div> <div class="summary-synopsis"><p>Lists manifest files for the compiler</p> </div> </div> <div class="summary-row"> <div class="summary-signature"> <a href="#c:run/1">run(list)</a> </div> <div class="summary-synopsis"><p>Receives command-line arguments and performs compilation. If it produces errors, warnings, or any other diagnostic information, it should return a tuple with the status and a list of diagnostics</p> </div> </div> </div> </section> <section id="callbacks" class="details-list"> <h1 class="section-heading"> <a class="hover-link" href="#callbacks"> <span class="icon-link" aria-hidden="true"></span> <span class="sr-only">Link to this section</span> </a> Callbacks </h1> <div class="detail" id="c:clean/0"> <div class="detail-header"> <a href="#c:clean/0" class="detail-link" title="Link to this callback"> <span class="icon-link" aria-hidden="true"></span> <span class="sr-only">Link to this callback</span> </a> <span class="signature">clean()</span> <a href="https://github.com/elixir-lang/elixir/blob/v1.7.2/lib/mix/lib/mix/task.compiler.ex#L99" class="view-source" rel="help" title="View Source"> <span class="icon-code" aria-hidden="true"></span> <span class="sr-only">View Source</span> </a> <span class="note">(optional)</span> <div class="specs"> <pre>clean() :: <a href="https://hexdocs.pm/elixir/typespecs.html#basic-types">any</a>()</pre> </div> </div> <section class="docstring"> <p>Removes build artifacts and manifests.</p> </section> </div> <div class="detail" id="c:manifests/0"> <div class="detail-header"> <a href="#c:manifests/0" class="detail-link" title="Link to this callback"> <span class="icon-link" aria-hidden="true"></span> <span class="sr-only">Link to this callback</span> </a> <span class="signature">manifests()</span> <a href="https://github.com/elixir-lang/elixir/blob/v1.7.2/lib/mix/lib/mix/task.compiler.ex#L94" class="view-source" rel="help" title="View Source"> <span class="icon-code" aria-hidden="true"></span> <span class="sr-only">View Source</span> </a> <span class="note">(optional)</span> <div class="specs"> <pre>manifests() :: [<a href="https://hexdocs.pm/elixir/Path.html#t:t/0">Path.t</a>()]</pre> </div> </div> <section class="docstring"> <p>Lists manifest files for the compiler.</p> </section> </div> <div class="detail" id="c:run/1"> <div class="detail-header"> <a href="#c:run/1" class="detail-link" title="Link to this callback"> <span class="icon-link" aria-hidden="true"></span> <span class="sr-only">Link to this callback</span> </a> <span class="signature">run(list)</span> <a href="https://github.com/elixir-lang/elixir/blob/v1.7.2/lib/mix/lib/mix/task.compiler.ex#L86" class="view-source" rel="help" title="View Source"> <span class="icon-code" aria-hidden="true"></span> <span class="sr-only">View Source</span> </a> <div class="specs"> <pre>run([<a href="https://hexdocs.pm/elixir/typespecs.html#built-in-types">binary</a>()]) :: :ok | :noop | {:ok | :noop | :error, [<a href="Mix.Task.Compiler.Diagnostic.html#t:t/0">Mix.Task.Compiler.Diagnostic.t</a>()]}</pre> </div> </div> <section class="docstring"> <p>Receives command-line arguments and performs compilation. If it produces errors, warnings, or any other diagnostic information, it should return a tuple with the status and a list of diagnostics.</p> </section> </div> </section> <footer class="footer"> <p> <span class="line"> Built using <a href="https://github.com/elixir-lang/ex_doc" title="ExDoc" target="_blank" rel="help noopener">ExDoc</a> (v0.19.1), </span> <span class="line"> designed by <a href="https://twitter.com/dignifiedquire" target="_blank" rel="noopener" title="@dignifiedquire">Friedel Ziegelmayer</a>. </span> </p> </footer> </div> </div> </section> </div> <script src="dist/app-a0c90688fa.js"></script> </body> </html>