From 0eb45e21d406539caaad98bfc1740f9a11e32565 Mon Sep 17 00:00:00 2001 From: Richard Carlsson Date: Tue, 6 Dec 2016 12:14:18 +0100 Subject: Add shell shortcut for recompiling existing modules This extends the shell function c/1 and c/2 so that if the argument is a module name instead of a file name, it automatically locates the .beam file and the corresponding source file, and then recompiles the module using the same compiler options (plus any options passed to c/2). If compilation fails, the old beam file is preserved. Also adds c(Mod, Opts, Filter), where the Filter argument allows you to remove old compiler options before the new options are added. --- lib/stdlib/doc/src/c.xml | 26 ++++++++++++++++++++------ lib/stdlib/doc/src/shell.xml | 10 +++++----- 2 files changed, 25 insertions(+), 11 deletions(-) (limited to 'lib/stdlib/doc') diff --git a/lib/stdlib/doc/src/c.xml b/lib/stdlib/doc/src/c.xml index 55a77d1bc5..7666699183 100644 --- a/lib/stdlib/doc/src/c.xml +++ b/lib/stdlib/doc/src/c.xml @@ -52,13 +52,27 @@ - Compile and load code in a file. + + Compile and load a file or module. -

Compiles and then purges and loads the code for a file. - Options defaults to []. Compilation is - equivalent to:

- -compile:file(File, Options ++ [report_errors, report_warnings]) +

Compiles and then purges and loads the code for a module. + Module can be either a module name or a source + file path, with or without .erl extension. + Options defaults to [].

+

If Module is an atom and is not the path of a + source file, then the code path is searched to locate the object + file for the module and extract its original compiler options and + source path. If the source file is not found in the original + location, filelib:find_source/1 + is used to search for it relative to the directory of the object + file.

+

The source file is compiled with the the original + options appended to the given Options, the + output replacing the old object file if and only if compilation + succeeds. A function Filter can be specified + for removing elements from from the original compiler options + before the new options are added.

Notice that purging the code means that any processes lingering in old code for the module are killed without warning. For more information, see code/3.

diff --git a/lib/stdlib/doc/src/shell.xml b/lib/stdlib/doc/src/shell.xml index d6e8036d4e..f52bc39deb 100644 --- a/lib/stdlib/doc/src/shell.xml +++ b/lib/stdlib/doc/src/shell.xml @@ -165,12 +165,12 @@

Evaluates shell_default:help().

- c(File) + c(Mod) -

Evaluates shell_default:c(File). This compiles - and loads code in File and purges old versions of - code, if necessary. Assumes that the file and module names - are the same.

+

Evaluates shell_default:c(Mod). This compiles and + loads the module Mod and purges old versions of the + code, if necessary. Mod can be either a module name or a + a source file path, with or without .erl extension.

catch_exception(Bool) -- cgit v1.2.3