rebar3使用介紹(五)自定義依賴獲取方式

rebar3使用介紹(四)自定義依賴獲取方式

每個依賴獲取方式都是 rebar_resorece behavior描述

-module(rebar_resource).

-export_type([resource/0
             ,type/0
             ,location/0
             ,ref/0]).

-type resource() :: {type(), location(), ref()}.
-type type() :: atom().
-type location() :: string().
-type ref() :: any().

-callback lock(file:filename_all(), tuple()) ->
    rebar_resource:resource().
-callback download(file:filename_all(), tuple(), rebar_state:t()) ->
    {tarball, file:filename_all()} | {ok, any()} | {error, any()}.
-callback needs_update(file:filename_all(), tuple()) ->
    boolean().
-callback make_vsn(file:filename_all()) ->
    {plain, string()} | {error, string()}.

rebar3 自帶的獲取方式有rebar_git_resource, rebar_hg_resourcerebar_pkg_resource

可以向插件一樣,自定義資源獲取,在Kelly McLaughlin的rebar3_tidy_deps資源中可以看到這方面的一個例子:

-module(rebar_tidy_deps).

-export([init/1]).

-spec init(rebar_state:t()) -> {ok, rebar_state:t()}.
init(State) ->
    {ok, rebar_state:add_resource(State, {github, rebar_github_resource})}.

rebar_github_resource實現rebar3資源行爲的此資源將添加到可用資源列表中rebar_state。將repo添加爲插件以rebar.config允許使用此資源:

{mydep, {github, "kellymclauglin/mydep.git", {tag, "1.0.1"}}}.

{plugins, [
    {rebar_tidy_deps, ".*", {git, "https://github.com/kellymclaughlin/rebar3-tidy-deps-plugin.git", {tag, "0.0.2"}}}
]}.

這一篇在開發過程中其實及其實用,因爲有些公司開發可能做了外網訪問限制,你可以將資源上傳到自己的內網服務器上,然後所有的資源都變成從你的服務器下載而不是github或者其他(當然你也可以直接把get-deps好的目錄和rebar.lock直接歸檔),甚至你可以重寫pkg和git的獲取方式,即使子依賴項,他們也會從你的服務器獲取文件而且不用破壞文件本身

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章