├── .gitignore ├── LICENSE.md ├── README.md ├── rebar.config ├── rebar.lock └── src ├── rebar3_prv_vendor_apply.erl ├── rebar3_prv_vendor_store.erl ├── rebar3_vendor.app.src └── rebar3_vendor.erl /.gitignore: -------------------------------------------------------------------------------- 1 | # project 2 | _build 3 | erl_crash.dump 4 | *.beam 5 | 6 | # vim 7 | .*.sw[a-z] 8 | *.un~ 9 | Session.vim 10 | 11 | # intellij 12 | .idea 13 | *.iml 14 | 15 | # OSX ignores 16 | .DS_Store 17 | .AppleDouble 18 | .LSOverride 19 | Icon 20 | 21 | ._* 22 | .Spotlight-V100 23 | .Trashes 24 | .AppleDB 25 | .AppleDesktop 26 | Network Trash Folder 27 | Temporary Items 28 | .apdisk 29 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # The MIT License (MIT) 2 | 3 | Copyright (c) 2016, Tristan Sloughter , Roberto Ostinelli and Neato Robotics, Inc. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Hex pm](https://img.shields.io/hexpm/v/rebar3_vendor.svg)](https://hex.pm/packages/rebar3_vendor) 2 | 3 | # Rebar3 Vendoring Plugin 4 | 5 | Plugin for storing vendored dependencies and applying the vendored deps to your local project. 6 | 7 | ## Install 8 | Add the plugin to your rebar config, which should be at `~/.config/rebar3/rebar.config`: 9 | 10 | ```erlang 11 | {plugins, [rebar3_vendor]}. 12 | ``` 13 | 14 | ## Usage 15 | To store the fetched dependencies under `./deps/` for committing: 16 | 17 | ``` 18 | $ rebar3 vendor store 19 | ``` 20 | 21 | To take the vendored dependencies from `./deps/` and place them under the build directory in the appropriate place: 22 | 23 | ``` 24 | $ rebar3 vendor apply 25 | ``` 26 | -------------------------------------------------------------------------------- /rebar.config: -------------------------------------------------------------------------------- 1 | {erl_opts, [debug_info]}. 2 | {deps, []}. -------------------------------------------------------------------------------- /rebar.lock: -------------------------------------------------------------------------------- 1 | []. 2 | -------------------------------------------------------------------------------- /src/rebar3_prv_vendor_apply.erl: -------------------------------------------------------------------------------- 1 | -module(rebar3_prv_vendor_apply). 2 | 3 | -export([init/1, do/1, format_error/1]). 4 | 5 | -define(PROVIDER, apply). 6 | -define(NAMESPACE, vendor). 7 | -define(DEPS, []). 8 | 9 | %% =================================================================== 10 | %% Public API 11 | %% =================================================================== 12 | -spec init(rebar_state:t()) -> {ok, rebar_state:t()}. 13 | init(State) -> 14 | Provider = providers:create([ 15 | {name, ?PROVIDER}, 16 | {module, ?MODULE}, 17 | {namespace, ?NAMESPACE}, 18 | {bare, true}, 19 | {deps, ?DEPS}, 20 | {example, "rebar3 vendor apply"}, 21 | {opts, []}, 22 | {short_desc, ""}, 23 | {desc, ""} 24 | ]), 25 | {ok, rebar_state:add_provider(State, Provider)}. 26 | 27 | 28 | -spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}. 29 | do(State) -> 30 | rebar_api:info("Applying vendored dependencies...", []), 31 | %% init 32 | DepsDir = rebar_dir:deps_dir(State), 33 | VendorDir = filename:join(rebar_dir:root_dir(State), "deps"), 34 | %% empty lib directory 35 | rebar_file_utils:rm_rf(DepsDir), 36 | filelib:ensure_dir(filename:join(DepsDir, "dummy.beam")), 37 | %% extract 38 | [begin 39 | Filename = filename:basename(Filepath, ".zip"), 40 | rebar_api:info("Extracting ~s", [Filename]), 41 | zip:extract(Filepath, [{cwd, DepsDir}]) 42 | end || Filepath <- filelib:wildcard(filename:join(VendorDir, "*.zip"))], 43 | {ok, State}. 44 | 45 | -spec format_error(any()) -> iolist(). 46 | format_error(Reason) -> 47 | io_lib:format("~p", [Reason]). -------------------------------------------------------------------------------- /src/rebar3_prv_vendor_store.erl: -------------------------------------------------------------------------------- 1 | -module(rebar3_prv_vendor_store). 2 | 3 | -export([init/1, do/1, format_error/1]). 4 | 5 | -define(PROVIDER, store). 6 | -define(NAMESPACE, vendor). 7 | -define(DEPS, [{default, install_deps}, {default, lock}]). 8 | 9 | %% =================================================================== 10 | %% Public API 11 | %% =================================================================== 12 | -spec init(rebar_state:t()) -> {ok, rebar_state:t()}. 13 | init(State) -> 14 | Provider = providers:create([ 15 | {name, ?PROVIDER}, 16 | {module, ?MODULE}, 17 | {namespace, ?NAMESPACE}, 18 | {bare, true}, 19 | {deps, ?DEPS}, 20 | {example, "rebar3 vendor store"}, 21 | {opts, []}, 22 | {short_desc, "Makes a copy of dependencies to deps/ for vendoring."}, 23 | {desc, ""} 24 | ]), 25 | {ok, rebar_state:add_provider(State, Provider)}. 26 | 27 | 28 | -spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}. 29 | do(State) -> 30 | %% init 31 | AllDeps = rebar_state:lock(State), 32 | DepsDir = rebar_dir:deps_dir(State), 33 | VendorDir = filename:join(rebar_dir:root_dir(State), "deps"), 34 | filelib:ensure_dir(filename:join([VendorDir, "dummy.beam"])), 35 | %% clean deps to ensure that no compile code is included 36 | clean_all_deps(State), 37 | %% zip all dependencies in the /deps directory 38 | rebar_api:info("Vendoring dependencies...", []), 39 | [begin 40 | %% get info 41 | Name = binary_to_list(rebar_app_info:name(Dep)), 42 | Vsn = get_vsn(Dep, State), 43 | %% prepare filename 44 | Filename = iolist_to_binary([Name, "-", Vsn, ".zip"]), 45 | Filepath = binary_to_list(filename:join([VendorDir, Filename])), 46 | %% purge other versions if they exist 47 | purge_other_versions(VendorDir, Filepath, Name), 48 | %% create zip if doesn't exist 49 | create_zip_if_not_exist(DepsDir, Filepath, Name) 50 | end || Dep <- AllDeps, not(rebar_app_info:is_checkout(Dep))], 51 | %% return 52 | {ok, State}. 53 | 54 | -spec format_error(any()) -> iolist(). 55 | format_error(Reason) -> 56 | io_lib:format("~p", [Reason]). 57 | 58 | -spec clean_all_deps(rebar_state:t()) -> ok. 59 | clean_all_deps(State) -> 60 | %% temporary hack: add the 'all' option to be able to clean all dependencies 61 | {Args, Other} = rebar_state:command_parsed_args(State), 62 | State1 = rebar_state:command_parsed_args(State, {Args ++ [{all, true}], Other}), 63 | {ok, _} = rebar_prv_clean:do(State1), 64 | ok. 65 | 66 | -spec get_vsn(rebar_app_info:t(), rebar_state:t()) -> binary() | string(). 67 | get_vsn(Dep, State) -> 68 | case rebar_fetch:lock_source(Dep, State) of 69 | {git, _, {ref, Ref}} -> Ref; 70 | {pkg, _, Vsn0} -> Vsn0; 71 | {pkg, _, Vsn0, _} -> Vsn0 72 | end. 73 | 74 | -spec purge_other_versions(file:filename_all(), file:filename_all(), binary() | string()) -> list(). 75 | purge_other_versions(VendorDir, Filepath, Name) -> 76 | OtherFilepathPattern = filelib:wildcard(filename:join(VendorDir, string:concat(Name, "-*.zip"))), 77 | [begin 78 | rebar_api:info(" - ~s", [filename:basename(OtherFilepath, ".zip")]), 79 | ok = file:delete(OtherFilepath) 80 | end || OtherFilepath <- OtherFilepathPattern, OtherFilepath =/= Filepath]. 81 | 82 | create_zip_if_not_exist(DepsDir, Filepath, Name) -> 83 | case filelib:is_file(Filepath) of 84 | true -> 85 | rebar_api:debug("Skipping ~s: already vendored.", [filename:basename(Filepath, ".zip")]); 86 | false -> 87 | %% create zip ===> 88 | rebar_api:info(" + ~s", [filename:basename(Filepath, ".zip")]), 89 | {ok, _} = zip:create(Filepath, [Name], [{cwd, DepsDir}]) 90 | end. 91 | -------------------------------------------------------------------------------- /src/rebar3_vendor.app.src: -------------------------------------------------------------------------------- 1 | {application, rebar3_vendor, [ 2 | {description, "Rebar3 plugin for vendoring dependencies."}, 3 | {vsn, "0.4.0"}, 4 | {registered, []}, 5 | {applications, [kernel, stdlib]}, 6 | {env, []}, 7 | {modules, []}, 8 | {maintainers, ["Roberto Ostinelli"]}, 9 | {licenses, ["MIT"]}, 10 | {links, [ 11 | {"Github", "http://github.com/ostinelli/rebar3_vendor"} 12 | ]} 13 | ]}. 14 | -------------------------------------------------------------------------------- /src/rebar3_vendor.erl: -------------------------------------------------------------------------------- 1 | -module(rebar3_vendor). 2 | 3 | -export([init/1]). 4 | 5 | -spec init(rebar_state:t()) -> {ok, rebar_state:t()}. 6 | init(State) -> 7 | {ok, State1} = rebar3_prv_vendor_store:init(State), 8 | {ok, State2} = rebar3_prv_vendor_apply:init(State1), 9 | {ok, State2}. 10 | --------------------------------------------------------------------------------