summaryrefslogtreecommitdiff
path: root/src/rebar_base_compiler.erl
diff options
context:
space:
mode:
authorTristan Sloughter <t@crashfast.com>2018-10-05 08:29:07 -0600
committerGitHub <noreply@github.com>2018-10-05 08:29:07 -0600
commitdec484643c233fda9c17d38c1854ba7f3f37547b (patch)
treecc3c83d55ca3c24000e52f4db8a4a0a5603fae2e /src/rebar_base_compiler.erl
parent6ea0a600b4f560565ca963b69c86b9e9cb0ea0b8 (diff)
compiler behaviour (#1893)
* add compile type for dynamic project compilation * new rebar_compiler abstraction for running multiple compilers rebar_compiler is a new behaviour that a plugin can implement to be called on any ues of the compile provider to compile source files and keep track of their dependencies. * fix check that modules in .app modules list are from src_dirs * use project_type to find module for building projects * allow plugins to add project builders and compilers
Diffstat (limited to 'src/rebar_base_compiler.erl')
-rw-r--r--src/rebar_base_compiler.erl33
1 files changed, 9 insertions, 24 deletions
diff --git a/src/rebar_base_compiler.erl b/src/rebar_base_compiler.erl
index 00b0533..2fb3a12 100644
--- a/src/rebar_base_compiler.erl
+++ b/src/rebar_base_compiler.erl
@@ -33,6 +33,8 @@
run/8,
ok_tuple/2,
error_tuple/4,
+ report/1,
+ maybe_report/1,
format_error_source/2]).
-type desc() :: term().
@@ -94,14 +96,14 @@ run(Config, FirstFiles, SourceDir, SourceExt, TargetDir, TargetExt,
TargetDir :: file:filename(),
SourceExt :: string(),
TargetExt :: string().
-run(Config, FirstFiles, SourceDir, SourceExt, TargetDir, TargetExt,
+run(Config, FirstFiles, SourceDirs, SourceExt, TargetDir, TargetExt,
Compile3Fn, Opts) ->
%% Convert simple extension to proper regex
SourceExtRe = "^(?!\\._).*\\" ++ SourceExt ++ [$$],
Recursive = proplists:get_value(recursive, Opts, true),
%% Find all possible source files
- FoundFiles = rebar_utils:find_files(SourceDir, SourceExtRe, Recursive),
+ FoundFiles = rebar_utils:find_files_in_dirs(SourceDirs, SourceExtRe, Recursive),
%% Remove first files from found files
RestFiles = [Source || Source <- FoundFiles,
not lists:member(Source, FirstFiles)],
@@ -111,7 +113,7 @@ run(Config, FirstFiles, SourceDir, SourceExt, TargetDir, TargetExt,
run(Config, FirstFiles, RestFiles,
fun(S, C) ->
- Target = target_file(S, SourceDir, SourceExt,
+ Target = target_file(S, SourceExt,
TargetDir, TargetExt),
simple_compile_wrapper(S, Target, Compile3Fn, C, CheckLastMod)
end).
@@ -160,32 +162,15 @@ simple_compile_wrapper(Source, Target, Compile3Fn, Config, true) ->
%% @private take a basic source set of file fragments and a target location,
%% create a file path and name for a compile artifact.
--spec target_file(SourceFile, SourceDir, SourceExt, TargetDir, TargetExt) -> File when
+-spec target_file(SourceFile, SourceExt, TargetDir, TargetExt) -> File when
SourceFile :: file:filename(),
- SourceDir :: file:filename(),
TargetDir :: file:filename(),
SourceExt :: string(),
TargetExt :: string(),
File :: file:filename().
-target_file(SourceFile, SourceDir, SourceExt, TargetDir, TargetExt) ->
- BaseFile = remove_common_path(SourceFile, SourceDir),
- filename:join([TargetDir, filename:basename(BaseFile, SourceExt) ++ TargetExt]).
-
-%% @private removes the common prefix between two file paths.
-%% The remainder of the first file path passed will have its ending returned
-%% when either path starts diverging.
--spec remove_common_path(file:filename(), file:filename()) -> file:filename().
-remove_common_path(Fname, Path) ->
- remove_common_path1(filename:split(Fname), filename:split(Path)).
-
-%% @private given two lists of file fragments, discard the identical
-%% prefixed sections, and return the final bit of the first operand
-%% as a filename.
--spec remove_common_path1([string()], [string()]) -> file:filename().
-remove_common_path1([Part | RestFilename], [Part | RestPath]) ->
- remove_common_path1(RestFilename, RestPath);
-remove_common_path1(FilenameParts, _) ->
- filename:join(FilenameParts).
+target_file(SourceFile, SourceExt, TargetDir, TargetExt) ->
+ %% BaseFile = remove_common_path(SourceFile, SourceDir),
+ filename:join([TargetDir, filename:basename(SourceFile, SourceExt) ++ TargetExt]).
%% @private runs the compile function `CompileFn' on every file
%% passed internally, along with the related project configuration.