Skip to content

Commit 7b70452

Browse files
committed
Fix setup:data_dir() in zomp context, no auto-verify if zomp
1 parent 9aedff7 commit 7b70452

13 files changed

Lines changed: 137 additions & 14 deletions

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,5 +119,6 @@ in [`setup`](http://github.com/uwiger/setup/blob/master/doc/setup.md).
119119
<tr><td><a href="http://github.com/uwiger/setup/blob/master/doc/setup.md" class="module">setup</a></td></tr>
120120
<tr><td><a href="http://github.com/uwiger/setup/blob/master/doc/setup_file.md" class="module">setup_file</a></td></tr>
121121
<tr><td><a href="http://github.com/uwiger/setup/blob/master/doc/setup_gen.md" class="module">setup_gen</a></td></tr>
122-
<tr><td><a href="http://github.com/uwiger/setup/blob/master/doc/setup_lib.md" class="module">setup_lib</a></td></tr></table>
122+
<tr><td><a href="http://github.com/uwiger/setup/blob/master/doc/setup_lib.md" class="module">setup_lib</a></td></tr>
123+
<tr><td><a href="http://github.com/uwiger/setup/blob/master/doc/setup_zomp.md" class="module">setup_zomp</a></td></tr></table>
123124

doc/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,5 +119,6 @@ in [`setup`](setup.md).
119119
<tr><td><a href="setup.md" class="module">setup</a></td></tr>
120120
<tr><td><a href="setup_file.md" class="module">setup_file</a></td></tr>
121121
<tr><td><a href="setup_gen.md" class="module">setup_gen</a></td></tr>
122-
<tr><td><a href="setup_lib.md" class="module">setup_lib</a></td></tr></table>
122+
<tr><td><a href="setup_lib.md" class="module">setup_lib</a></td></tr>
123+
<tr><td><a href="setup_zomp.md" class="module">setup_zomp</a></td></tr></table>
123124

doc/edoc-info

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
%% encoding: UTF-8
22
{application,setup}.
3-
{modules,[setup,setup_file,setup_gen,setup_lib]}.
3+
{modules,[setup,setup_file,setup_gen,setup_lib,setup_zomp]}.

doc/setup.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,17 @@ Example:
104104
```
105105

106106

107+
### <a name="Running_in_Zomp_(zx)">Running in Zomp (zx)</a> ###
108+
109+
Setup detects if it's running in a Zomp context, and then maps
110+
the directory names to sensible `zx` defaults:
111+
* `home()` : `ZompDir/etc/Realm/App/Vsn`
112+
* `data_dir()`: `ZompDir/var/Realm/App/Vsn/setup.data`
113+
* `log_dir() : `ZompDir/log/Realm/App`
114+
115+
By default, setup will not automatically verify these directories.
116+
117+
107118
### <a name="Customizing_setup">Customizing setup</a> ###
108119

109120
The following environment variables can be used to customize `setup`:
@@ -135,7 +146,7 @@ other mode hooks by explicitly calling [`run_hooks/1`](#run_hooks-1).
135146
the directories used by setup actually exist. This behavior can be disabled through
136147
the environment variable `{verify_directories, false}`. This can be desirable
137148
if setup is used mainly e.g. for environment variable expansion, but not for
138-
disk storage.
149+
disk storage. If running in a Zomp context, the default is `false`.
139150
* `{run_timeout, Millisecs}` - Set a time limit for how long it may take for
140151
setup to process the setup hooks. Default is `infinity`. If the timeout
141152
is exceeded, the application start sequence will be aborted, which will

doc/setup_file.md

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
## Function Index ##
1010

1111

12-
<table width="100%" border="1" cellspacing="0" cellpadding="2" summary="function index"><tr><td valign="top"><a href="#close-1">close/1</a></td><td></td></tr><tr><td valign="top"><a href="#consult-1">consult/1</a></td><td>Like <a docgen-rel="seemfa" docgen-href="file#consult/1" href="file.md#consult-1"><code>file:consult/1</code></a>, but supports paths into <code>zip</code> and <code>escript</code> archives.</td></tr><tr><td valign="top"><a href="#consult_binary-1">consult_binary/1</a></td><td>Like <a docgen-rel="seemfa" docgen-href="file#consult/1" href="file.md#consult-1"><code>file:consult/1</code></a>, but operates directly on a binary.</td></tr><tr><td valign="top"><a href="#eval_binary-1">eval_binary/1</a></td><td>Like <a docgen-rel="seemfa" docgen-href="file#script/1" href="file.md#script-1"><code>file:script/1</code></a>, but operates directly on a binary.</td></tr><tr><td valign="top"><a href="#eval_binary-2">eval_binary/2</a></td><td>Like <a docgen-rel="seemfa" docgen-href="file#script/2" href="file.md#script-2"><code>file:script/2</code></a>, but operates directly on a binary.</td></tr><tr><td valign="top"><a href="#list_dir-1">list_dir/1</a></td><td>Like <a docgen-rel="seemfa" docgen-href="file#list_dir/1" href="file.md#list_dir-1"><code>file:list_dir/1</code></a>, but supports paths into <code>zip</code> and <code>escript</code> archives.</td></tr><tr><td valign="top"><a href="#open-2">open/2</a></td><td></td></tr><tr><td valign="top"><a href="#read_file-1">read_file/1</a></td><td>Like <a docgen-rel="seemfa" docgen-href="file#read_file/1" href="file.md#read_file-1"><code>file:read_file/1</code></a>, but supports paths into <code>zip</code> and <code>escript</code> archives.</td></tr><tr><td valign="top"><a href="#script-1">script/1</a></td><td>Like <a docgen-rel="seemfa" docgen-href="file#script/1" href="file.md#script-1"><code>file:script/1</code></a>, but supports paths into <code>zip</code> and <code>escript</code> archives.</td></tr><tr><td valign="top"><a href="#script-2">script/2</a></td><td>Like <a docgen-rel="seemfa" docgen-href="file#script/2" href="file.md#script-2"><code>file:script/2</code></a>, but supports paths into <code>zip</code> and <code>escript</code> archives.</td></tr></table>
12+
<table width="100%" border="1" cellspacing="0" cellpadding="2" summary="function index"><tr><td valign="top"><a href="#close-1">close/1</a></td><td></td></tr><tr><td valign="top"><a href="#consult-1">consult/1</a></td><td>Like <a docgen-rel="seemfa" docgen-href="file#consult/1" href="file.md#consult-1"><code>file:consult/1</code></a>, but supports paths into <code>zip</code> and <code>escript</code> archives.</td></tr><tr><td valign="top"><a href="#consult_binary-1">consult_binary/1</a></td><td>Like <a docgen-rel="seemfa" docgen-href="file#consult/1" href="file.md#consult-1"><code>file:consult/1</code></a>, but operates directly on a binary.</td></tr><tr><td valign="top"><a href="#eval_binary-1">eval_binary/1</a></td><td>Like <a docgen-rel="seemfa" docgen-href="file#script/1" href="file.md#script-1"><code>file:script/1</code></a>, but operates directly on a binary.</td></tr><tr><td valign="top"><a href="#eval_binary-2">eval_binary/2</a></td><td>Like <a docgen-rel="seemfa" docgen-href="file#script/2" href="file.md#script-2"><code>file:script/2</code></a>, but operates directly on a binary.</td></tr><tr><td valign="top"><a href="#list_dir-1">list_dir/1</a></td><td>Like <a docgen-rel="seemfa" docgen-href="file#list_dir/1" href="file.md#list_dir-1"><code>file:list_dir/1</code></a>, but supports paths into <code>zip</code> and <code>escript</code> archives.</td></tr><tr><td valign="top"><a href="#open-2">open/2</a></td><td></td></tr><tr><td valign="top"><a href="#path_consult-2">path_consult/2</a></td><td></td></tr><tr><td valign="top"><a href="#path_open-3">path_open/3</a></td><td></td></tr><tr><td valign="top"><a href="#path_script-2">path_script/2</a></td><td></td></tr><tr><td valign="top"><a href="#path_script-3">path_script/3</a></td><td></td></tr><tr><td valign="top"><a href="#read_file-1">read_file/1</a></td><td>Like <a docgen-rel="seemfa" docgen-href="file#read_file/1" href="file.md#read_file-1"><code>file:read_file/1</code></a>, but supports paths into <code>zip</code> and <code>escript</code> archives.</td></tr><tr><td valign="top"><a href="#script-1">script/1</a></td><td>Like <a docgen-rel="seemfa" docgen-href="file#script/1" href="file.md#script-1"><code>file:script/1</code></a>, but supports paths into <code>zip</code> and <code>escript</code> archives.</td></tr><tr><td valign="top"><a href="#script-2">script/2</a></td><td>Like <a docgen-rel="seemfa" docgen-href="file#script/2" href="file.md#script-2"><code>file:script/2</code></a>, but supports paths into <code>zip</code> and <code>escript</code> archives.</td></tr></table>
1313

1414

1515
<a name="functions"></a>
@@ -93,6 +93,46 @@ producing a result.
9393

9494
`open(File, Opts) -> any()`
9595

96+
<a name="path_consult-2"></a>
97+
98+
### path_consult/2 ###
99+
100+
<pre><code>
101+
path_consult(Path, Filename) -&gt; {ok, Terms, FullName} | {error, Reason}
102+
</code></pre>
103+
104+
<ul class="definitions"><li><code>Path = [Dir]</code></li><li><code>Dir = <a href="http://www.erlang.org/doc/man/file.html#type-name_all">file:name_all()</a></code></li><li><code>Filename = <a href="http://www.erlang.org/doc/man/file.html#type-name_all">file:name_all()</a></code></li><li><code>Terms = [term()]</code></li><li><code>FullName = <a href="http://www.erlang.org/doc/man/file.html#type-filename_all">file:filename_all()</a></code></li><li><code>Reason = <a href="http://www.erlang.org/doc/man/file.html#type-posix">file:posix()</a> | badarg | terminated | system_limit | {Line::integer(), Mod::module(), Term::term()}</code></li></ul>
105+
106+
<a name="path_open-3"></a>
107+
108+
### path_open/3 ###
109+
110+
<pre><code>
111+
path_open(Path, Filename, Modes) -&gt; {ok, IoDevice, FullName} | {error, Reason}
112+
</code></pre>
113+
114+
<ul class="definitions"><li><code>Path = [Dir::<a href="http://www.erlang.org/doc/man/file.html#type-name_all">file:name_all()</a>]</code></li><li><code>Filename = <a href="http://www.erlang.org/doc/man/file.html#type-name_all">file:name_all()</a></code></li><li><code>Modes = [<a href="http://www.erlang.org/doc/man/file.html#type-mode">file:mode()</a> | directory]</code></li><li><code>IoDevice = <a href="http://www.erlang.org/doc/man/file.html#type-io_device">file:io_device()</a></code></li><li><code>FullName = <a href="http://www.erlang.org/doc/man/file.html#type-filename_all">file:filename_all()</a></code></li><li><code>Reason = <a href="http://www.erlang.org/doc/man/file.html#type-posix">file:posix()</a> | badarg | system_limit</code></li></ul>
115+
116+
<a name="path_script-2"></a>
117+
118+
### path_script/2 ###
119+
120+
<pre><code>
121+
path_script(Path, Filename) -&gt; {ok, Value, FullName} | {error, Reason}
122+
</code></pre>
123+
124+
<ul class="definitions"><li><code>Path = [Dir::<a href="http://www.erlang.org/doc/man/file.html#type-name_all">file:name_all()</a>]</code></li><li><code>Filename = <a href="http://www.erlang.org/doc/man/file.html#type-name_all">file:name_all()</a></code></li><li><code>Value = term()</code></li><li><code>FullName = <a href="http://www.erlang.org/doc/man/file.html#type-filename_all">file:filename_all()</a></code></li><li><code>Reason = <a href="http://www.erlang.org/doc/man/file.html#type-posix">file:posix()</a> | badarg | terminated | system_limit | {Line::integer(), Mod::module(), Term::term()}</code></li></ul>
125+
126+
<a name="path_script-3"></a>
127+
128+
### path_script/3 ###
129+
130+
<pre><code>
131+
path_script(Path, Filename, Bindings) -&gt; {ok, Value, FullName} | {error, Reason}
132+
</code></pre>
133+
134+
<ul class="definitions"><li><code>Path = [Dir::<a href="http://www.erlang.org/doc/man/file.html#type-name_all">file:name_all()</a>]</code></li><li><code>Filename = <a href="http://www.erlang.org/doc/man/file.html#type-name_all">file:name_all()</a></code></li><li><code>Bindings = <a href="http://www.erlang.org/doc/man/erl_eval.html#type-binding_struct">erl_eval:binding_struct()</a></code></li><li><code>Value = term()</code></li><li><code>FullName = <a href="http://www.erlang.org/doc/man/file.html#type-filename_all">file:filename_all()</a></code></li><li><code>Reason = <a href="http://www.erlang.org/doc/man/file.html#type-posix">file:posix()</a> | badarg | terminated | system_limit | {Line::integer(), Mod::module(), Term::term()}</code></li></ul>
135+
96136
<a name="read_file-1"></a>
97137

98138
### read_file/1 ###

doc/setup_zomp.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2+
3+
# Module setup_zomp #
4+
* [Function Index](#index)
5+
* [Function Details](#functions)
6+
7+
<a name="index"></a>
8+
9+
## Function Index ##
10+
11+
12+
<table width="100%" border="1" cellspacing="0" cellpadding="2" summary="function index"><tr><td valign="top"><a href="#default_dir-1">default_dir/1</a></td><td></td></tr><tr><td valign="top"><a href="#is_zomp_context-0">is_zomp_context/0</a></td><td></td></tr><tr><td valign="top"><a href="#setup_conf_path-0">setup_conf_path/0</a></td><td></td></tr><tr><td valign="top"><a href="#update_env-0">update_env/0</a></td><td></td></tr></table>
13+
14+
15+
<a name="functions"></a>
16+
17+
## Function Details ##
18+
19+
<a name="default_dir-1"></a>
20+
21+
### default_dir/1 ###
22+
23+
`default_dir(X1) -> any()`
24+
25+
<a name="is_zomp_context-0"></a>
26+
27+
### is_zomp_context/0 ###
28+
29+
`is_zomp_context() -> any()`
30+
31+
<a name="setup_conf_path-0"></a>
32+
33+
### setup_conf_path/0 ###
34+
35+
`setup_conf_path() -> any()`
36+
37+
<a name="update_env-0"></a>
38+
39+
### update_env/0 ###
40+
41+
`update_env() -> any()`
42+

ebin/setup.app

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{application,setup,
22
[{description,"Generic setup utility for Erlang-based systems"},
3-
{vsn,"2.2.3"},
3+
{vsn,"2.2.5"},
44
{registered,[]},
55
{applications,[kernel,stdlib]},
66
{mod,{setup_app,[]}},

src/setup.app.src

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
{application, setup,
1818
[
1919
{description, "Generic setup application for Erlang-based systems"},
20-
{vsn, git},
20+
{vsn, "zomp"},
2121
{registered, []},
2222
{applications, [
2323
kernel,

src/setup.app.src.script

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
%% -*- erlang-mode; erlang-indent-level: 4; indent-tabs-mode: nil -*-
2+
3+
[{application, Name, Opts}] = CONFIG.
4+
case lists:keyfind(vsn, 1, Opts) of
5+
{vsn, "zomp"} ->
6+
ZompMetaF = filename:join(filename:dirname(filename:dirname(SCRIPT)), "zomp.meta"),
7+
{ok, ZMeta} = file:consult(ZompMetaF),
8+
{_, {_, _, {Vmaj,Vmin,Vpatch}}} = lists:keyfind(package_id, 1, ZMeta),
9+
VsnStr = unicode:characters_to_list(io_lib:fwrite("~w.~w.~w", [Vmaj, Vmin, Vpatch])),
10+
Opts1 = lists:keyreplace(vsn, 1, Opts, {vsn, VsnStr}),
11+
[{application, Name, Opts1}];
12+
_ ->
13+
CONFIG
14+
end.

src/setup.erl

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,15 @@
104104
%% {ok,"/Users/uwiger/git/setup/foo"}
105105
%% </pre>
106106
%%
107+
%% == Running in Zomp (zx) ==
108+
%% Setup detects if it's running in a Zomp context, and then maps
109+
%% the directory names to sensible `zx' defaults:
110+
%% * `home()' : `ZompDir/etc/Realm/App/Vsn'
111+
%% * `data_dir()': `ZompDir/var/Realm/App/Vsn/setup.data'
112+
%% * `log_dir() : `ZompDir/log/Realm/App'
113+
%%
114+
%% By default, setup will not automatically verify these directories.
115+
%%
107116
%% == Customizing setup ==
108117
%% The following environment variables can be used to customize `setup':
109118
%% * `{home, Dir}' - The topmost directory of the running system. This should
@@ -134,7 +143,7 @@
134143
%% the directories used by setup actually exist. This behavior can be disabled through
135144
%% the environment variable `{verify_directories, false}'. This can be desirable
136145
%% if setup is used mainly e.g. for environment variable expansion, but not for
137-
%% disk storage.
146+
%% disk storage. If running in a Zomp context, the default is `false'.
138147
%% * `{run_timeout, Millisecs}' - Set a time limit for how long it may take for
139148
%% setup to process the setup hooks. Default is `infinity'. If the timeout
140149
%% is exceeded, the application start sequence will be aborted, which will
@@ -263,7 +272,12 @@ setup_dir(Key, Default, Vis) ->
263272
end.
264273

265274
maybe_verify_directories() ->
266-
case get_env(setup, verify_directories, true) of
275+
IsZomp = setup_zomp:is_zomp_context(),
276+
%% If zomp context, we rely on zomp to verify the directories.
277+
%% Apps need to verify any sub-directories they need anyway.
278+
%%
279+
%% The default action is: verify if not in zomp, otherwise not.
280+
case get_env(setup, verify_directories, not IsZomp) of
267281
true ->
268282
verify_directories();
269283
false ->

0 commit comments

Comments
 (0)