Skip to content

Commit

Permalink
Merge pull request #16 from shoo/pipe_for_command
Browse files Browse the repository at this point in the history
Add pipe for command
  • Loading branch information
shoo authored Mar 11, 2020
2 parents cef645e + 5e2e410 commit b5c6037
Show file tree
Hide file tree
Showing 10 changed files with 409 additions and 38 deletions.
41 changes: 36 additions & 5 deletions .github/runner.d
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,16 @@ void unitTest(string[] exDubOpts = null)
"--coverage",
"--compiler", config.hostCompiler] ~ exDubOpts,
null, env);
foreach (pkgName; Defines.subPkgs)
{
exec(["dub",
"test",
":" ~ pkgName,
"-a", config.hostArch,
"--coverage",
"--compiler", config.hostCompiler] ~ exDubOpts,
null, env);
}
}

///
Expand Down Expand Up @@ -347,7 +357,7 @@ void integrationTest(string[] exDubOpts = null)
{
auto dubArgs = (runOpt.dubArgs.length > 0 ? dubCommonArgs ~ runOpt.dubArgs : dubCommonArgs)
~ (!no_coverage ? ["-b=cov"] : ["-b=debug"]);
auto desc = cmd(["dub", "describe"] ~ dubArgs, runOpt.dubWorkDir, runOpt.env).parseJSON();
auto desc = cmd(["dub", "describe", "--verror"] ~ dubArgs, runOpt.dubWorkDir, runOpt.env).parseJSON();
auto targetExe = buildNormalizedPath(
desc["packages"][0]["path"].str,
desc["packages"][0]["targetPath"].str,
Expand Down Expand Up @@ -420,7 +430,7 @@ void integrationTest(string[] exDubOpts = null)
auto dubCommonArgs = [
"-a", config.targetArch,
"--compiler", config.targetCompiler] ~ exDubOpts;
auto desc = cmd(["dub", "describe", ":" ~ pkgName] ~ dubCommonArgs, null, env).parseJSON();
auto desc = cmd(["dub", "describe", ":" ~ pkgName, "--verror"] ~ dubCommonArgs, null, env).parseJSON();
if (desc["packages"][0]["targetType"].str != "executable")
return false;
auto targetExe = buildNormalizedPath(
Expand Down Expand Up @@ -478,6 +488,7 @@ void integrationTest(string[] exDubOpts = null)
writeln("## Integration Test Summary ##");
writeln("#######################################");
}
bool failed;
if (dirTests.length > 0)
{
writeln("##### Test Summary of Directory Entries");
Expand All @@ -489,6 +500,7 @@ void integrationTest(string[] exDubOpts = null)
if (res.exception)
{
writefln("[X] %s: %s", res.name, res.exception.msg);
failed = true;
}
else if (res.executed)
{
Expand All @@ -508,9 +520,9 @@ void integrationTest(string[] exDubOpts = null)
writefln("Skipped: %s / %s", subpkgTests.count!(a => !a.executed && !a.exception), subpkgTests.length);
foreach (res; subpkgTests)
{
continue;
if (res.exception)
{
failed = true;
writefln("[X] %s: %s", res.name, res.exception.msg);
}
else if (res.executed)
Expand All @@ -523,7 +535,7 @@ void integrationTest(string[] exDubOpts = null)
}
}
}

enforce(!failed, "Integration test was failed.");
}


Expand Down Expand Up @@ -583,19 +595,38 @@ void createArchive()
void exec(string[] args, string workDir = null, string[string] env = null)
{
import std.process, std.stdio;
writefln!"> %-(%-s %)"(args);
writefln!"> %s"(escapeShellCommand(args));
auto pid = spawnProcess(args, env, std.process.Config.none, workDir ? workDir : ".");
auto res = pid.wait();
enforce(res == 0, format!"Execution was failed[code=%d]."(res));
}
///
void exec(string args, string workDir = null, string[string] env = null)
{
import std.process, std.stdio;
writefln!"> %s"(args);
auto pid = spawnShell(args, env, std.process.Config.none, workDir ? workDir : ".");
auto res = pid.wait();
enforce(res == 0, format!"Execution was failed[code=%d]."(res));
}
///
string cmd(string[] args, string workDir = null, string[string] env = null)
{
import std.process;
writefln!"> %s"(escapeShellCommand(args));
auto res = execute(args, env, std.process.Config.none, size_t.max, workDir);
enforce(res.status == 0, format!"Execution was failed[code=%d]."(res.status));
return res.output;
}
///
string cmd(string args, string workDir = null, string[string] env = null)
{
import std.process;
writefln!"> %s"(args);
auto res = executeShell(args, env, std.process.Config.none, size_t.max, workDir);
enforce(res.status == 0, format!"Execution was failed[code=%d]."(res.status));
return res.output;
}

///
string getRefName()
Expand Down
91 changes: 78 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,13 @@ Save it with the extension `*.ddoc.mustache`, `*.dd.mustache`, such as `module_l
```mustache
MODULE_MENU={{# dub_pkg_info }}
$(MENU_DUBPKG {{ name }}, {{ version }},
{{# children }}{
"file": "_module_info",
"map": {
"tag_pkg":"MENU_PKG",
"tag_mod":"MENU_MOD"
}
}{{/ children }}
{{# children }}{
"file": "_module_info",
"map": {
"tag_pkg":"MENU_PKG",
"tag_mod":"MENU_MOD"
}
}{{/ children }}
)
{{/ dub_pkg_info }}
```
Expand Down Expand Up @@ -230,36 +230,101 @@ Available tags are as below:
| 7.2.8. is_module | rdmd | Lambdas | Execute dlang code with rdmd --eval and store the result to standard output. |
| 7.2.9. is_module | environemnt | Lambdas | Expand and store environment variables. |

### **{{ children }}**
As it appears above, `{{# children }} {{/ children }}` is special.
Recursive embedding is done to represent the package tree structure.
At that time, it is possible to change the contents with the information described inside. The information is in JSON format or mustache format.

- If the literal start token of `{`, `[`, `"` is included in the same line with `{{# children }}` start tag, it is treated as JSON format.
- In the case of JSON format, it is possible to take one of three types: string, array, or object.
- string: treat the string as "mustache".
- array: Interpret as command line.

- string: Treat the string as "mustache".
Example:
```
{{# children }}"foo{{ xxx }}bar"{{/ children }}
```
- array: Interpret as like command line arguments.
| Options | Type | Description |
|:-------------------|:----------------:|:----------------------------------------------|
| (first argumenet) | string | file name or path of mustache |
| `-i` / `--import` | string\[\] | search path of mustache file (first argument) |
| `-m` / `--map` | string\[stirng\] | define additional variable |
| `-u` / `--use` | string\[\] | usable section |

Example:
```
{{# children }}[
"_module_info",
"-m=tag_pkg=INFO_PKG",
"-m=tag_mod=INFO_MOD"
]{{/ children }}
```
- object: Interpret the data structure.
| Field | Type | Description |
|:--------------|:----------------:|:------------------------------------------|
| `file` | string | file name or path of mustache |
| `imports` | string\[stirng\] | search path of mustache file (file field) |
| `imports` | string\[\] | search path of mustache file (file field) |
| `contents` | string | mustache (File field takes precedence) |
| `map` | string\[stirng\] | define additional variable |
| `useSections` | string\[\] | usable section |

Example:
```
{{# children }}{
"file": "_module_info",
"map": {
"tag_pkg":"INFO_PKG",
"tag_mod":"INFO_MOD"
}
}{{/ children }}
```
- If the file is specified above, rendering will be performed with the target file.
- If none of the above, JSON parsing fails, or a muctache string is specified even in JSON format, treat it as a mustache string.
- If a mustache-style string is specified in either way, the string is rendered directly as mustache instead of a file.
### **{{ rdmd }}** and **{{ command }}**
`{{# rdmd}} {{/ rdmd}}` and `{{# command}} {{/ command}}` are also special. The result is replaced with the contents of stdout and stderr after the program is executed.
**{{ rdmd }}** executes the string contained inside as dlang source code with `rdmd --eval`
```
{{# rdmd }}
writeln("Hello, world!");
{{/ rdmd }}
```
**{{ command }}** executes the contained string as a single command line. Line breaks are interpreted as delimiters for arguments. In the case of a line break delimited, invoke the process directly. In the case of one line, the command is invoked in the shell.
```
{{# command }}
dmd
-ofbuild directory/foo
main.d
{{/ command }} {{# command}}echo "xxx"{{/ command}}
```
In either case of **{{ rdmd }}** or **{{ command }}**, the invoked program can interact with gendoc through stdio.
gendoc responds to requests from the launched guest program.
One request or response communicates via a JSON object without lines.
Guest program requests are passed line by line to the stderr.
gendoc responds to requests with one line.
The request starts with `::gendoc-request::`, followed by a JSON string.
```
::gendoc-request::{ "type": "ReqEcho", "value": {"msg": "test"} }
```
The response type corresponds to the request type.
| Request Type | Response Type |
|:----------------------|:---------------------|
| [ReqEcho](https://shoo.github.io/gendoc/shoo.github.io/gendoc/gendoc--gendoc.cmdpipe.html#.ReqEcho) | [ResEcho](https://shoo.github.io/gendoc/shoo.github.io/gendoc/gendoc--gendoc.cmdpipe.html#.ResEcho), [ResErr](https://shoo.github.io/gendoc/shoo.github.io/gendoc/gendoc--gendoc.cmdpipe.html#.ResErr) |
| [ReqInfo](https://shoo.github.io/gendoc/shoo.github.io/gendoc/gendoc--gendoc.cmdpipe.html#.ReqInfo) | [ResInfo](https://shoo.github.io/gendoc/shoo.github.io/gendoc/gendoc--gendoc.cmdpipe.html#.ResInfo), [ResErr](https://shoo.github.io/gendoc/shoo.github.io/gendoc/gendoc--gendoc.cmdpipe.html#.ResErr) |
Each piece of information is composed of a JSON object composed of `type` and `value` as follows, and the `value` includes a payload.
The following examples include line breaks and indents for readability, but do not break lines in the data actually used.
```
{
"type": "ReqInfo",
"value": { }
}
```
# License
gendoc is licensed by [Boost Software License 1.0](LICENSE)
Expand Down
18 changes: 14 additions & 4 deletions ddoc/public.ddoc
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,28 @@ LREF_ALTTEXT=<a href="#.$+">$(D $1)</a>
_=

$(COMMENT Used to generate links to symbols in other documentation pages for the same project.
e.g. $(REF parseXML, dxml, parser) for dxml.parser.parseXML)
REF=<a href="$2$(UNDERSCORE_PREFIXED_SKIP $+).html#.$1">$(D $2$(DOT_PREFIXED_SKIP $+, $1))</a>
e.g. $(REF Config, gendoc, config) for gendoc.config.Config of gendoc)
REF=<a href="$2--$2$(DOT_PREFIXED_SKIP $+).html#.$1">$(D $2$(DOT_PREFIXED_SKIP $+, $1))</a>
_=

$(COMMENT Used to generate links to symbols in other documentation pages for the other dub package.
e.g. $(REF parseXML, dxml, dxml, parser) for dxml.parser.parseXML of dxml)
REFEX=<a href="$2--$3$(DOT_PREFIXED_SKIP2 $+).html#.$1">$(D $3$(DOT_PREFIXED_SKIP2 $+, $1))</a>
_=

$(COMMENT Variant of REF which takes the link's text as its first argument.
e.g. $(REF_ALTTEXT XML parser, parseXML, dxml, parser) for dxml.parser.parseXML)
REF_ALTTEXT=<a href="$3$(UNDERSCORE_PREFIXED_SKIP2 $+).html#.$2">$(D $1)</a>
REF_ALTTEXT=<a href="$3--$3$(DOT_PREFIXED_SKIP2 $+).html#.$2">$(D $1)</a>
_=

$(COMMENT Used to generate links to the documentation page for a specific module in the same project.
e.g. $(MREF dxml, parser) for dxml.parser)
MREF=<a href="$1$(UNDERSCORE_PREFIXED $+).html">$(D $1$(DOT_PREFIXED $+))</a>
MREF=<a href="$1--$1$(DOT_PREFIXED $+).html">$(D $1$(DOT_PREFIXED $+))</a>
_=

$(COMMENT Used to generate links to the documentation page for a specific module in the other dub package.
e.g. $(MREF dxml, dxml, parser) for dxml.parser of dxml)
MREFEX=<a href="$1--$2$(DOT_PREFIXED_SKIP $+).html">$(D $1$(DOT_PREFIXED_SKIP $+))</a>
_=

$(COMMENT Used to generate links to the documentation for a symbol in Phobos.
Expand Down
1 change: 1 addition & 0 deletions ddoc/util.ddoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ _=

DOT_PREFIXED=.$1$(DOT_PREFIXED $+)
DOT_PREFIXED_SKIP=$(DOT_PREFIXED $+)
DOT_PREFIXED_SKIP2=$(DOT_PREFIXED_SKIP $+)
UNDERSCORE_PREFIXED=_$1$(UNDERSCORE_PREFIXED $+)
UNDERSCORE_PREFIXED_SKIP=$(UNDERSCORE_PREFIXED $+)
UNDERSCORE_PREFIXED_SKIP2=$(UNDERSCORE_PREFIXED_SKIP $+)
Expand Down
3 changes: 3 additions & 0 deletions source/app.d
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/*******************************************************************************
* Main source file
*/
module app;

import gendoc.main;
Expand Down
Loading

0 comments on commit b5c6037

Please sign in to comment.