Skip to content

Commit 144b59e

Browse files
authored
add docs for v1.1.0 release (#78)
1 parent c0c73ab commit 144b59e

File tree

6 files changed

+384
-3
lines changed

6 files changed

+384
-3
lines changed

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ pre-requisites in your local environment.
2222
It uses containers to build projects, all pre-requisites are installed cleanly
2323
and consistently inside the container.
2424

25+
Please read [Use Cases](docs/UseCases.md) to find out what HyperMake helps.
26+
2527
_Features_
2628

2729
- Brings back the experience of _make_
@@ -71,8 +73,7 @@ brew install hmake
7173
Alternatively, download from Github [releases](https://github.com/evo-cloud/hmake/releases)
7274

7375
```
74-
curl -s https://github.com/evo-cloud/hmake/releases/download/v1.1.0rc4/hmake-linux-amd64.tar.gz | sudo tar -C /usr/local/bin -zx
75-
chmod a+rx /usr/local/bin/hmake
76+
curl -s https://github.com/evo-cloud/hmake/releases/download/v1.1.0/hmake-linux-amd64.tar.gz | sudo tar -C /usr/local/bin -zx
7677
```
7778

7879
If you are on Mac OS, change `linux` above to `darwin`.
@@ -120,6 +121,8 @@ Summary file is stored as `hmake.summary.json`.
120121

121122
Please read the following documents if more detailed information is needed
122123

124+
- [Quick Start](docs/QuickStart.md) is a step-by-step guide to write your first
125+
HyperMake file for your project;
123126
- References are list of specifications including
124127
- [File Format](docs/FileFormat.md) defines the format of _hmake_ files;
125128
- [Command line](docs/CommandLine.md) specification;
@@ -152,6 +155,11 @@ If you meet any issues or have specific problems, please check
152155
[FAQ and Best Practices](docs/FAQ.md) if there's already a solution.
153156
Feel free to email the MAINTAINERS for any questions.
154157

158+
## References
159+
160+
See [References](docs/References.md) for some real projects using _HyperMake_.
161+
They are good samples of using _HyperMake_.
162+
155163
## License
156164

157165
MIT

docs/FAQ.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,67 @@
3939
**A**: Depending. If it's a project in Go, yes. If it depends on native Mac OS
4040
libraries, it's possible when cross compiling toolchain and libraries are
4141
installed on Linux.
42+
43+
- **Q**: Why target is skipped but output file is not present?<br>
44+
**A**: Property `artifacts` is not specified in the target. _HyperMake_ checks
45+
both input and output files to determine if a target is up-to-date. Property
46+
`watches` lists the input files whose last modification time is checked, and
47+
property `artifacts` lists the output files whose presence is checked.
48+
If `artifacts` is not specified, _HyperMake_ assumes the target doesn't generate
49+
output files.
50+
51+
- **Q**: What's the `artifacts` if the target doesn't output files?<br>
52+
**A**: No need to specify `artifacts` if there's no output file. Some targets
53+
like docker build doesn't output files, it will automatically check if the
54+
image exists. To explicitly rebuild the target, use `-r TARGET`, `-b` or `-R`
55+
options.
56+
57+
- **Q**: I want to run some commands, which are specific to my local environment,
58+
before certain targets. But I don't want to put them in `HyperMake` file.<br>
59+
**A**: You can create a `.hmakerc` in project root, and exclude that file using
60+
`.gitignore`. The `settings` in `.hmakerc` will override those in `HyperMake`
61+
and use `before` to inject your local targets into `HyperMake`, e.g.
62+
63+
```yaml
64+
---
65+
format: hypermake.v0
66+
targets:
67+
pre-build:
68+
description: my local task before build
69+
before:
70+
- build
71+
cmds:
72+
- do something
73+
settings:
74+
property: my-value
75+
```
76+
77+
- **Q**: How to map a volume from a folder relative to project root?<br>
78+
**A**: In top-level `HyperMake`, use relative path for source of the volume,
79+
in `*.hmake` files under sub-directories, prefix `-/` to a relative path. E.g.
80+
81+
```yaml
82+
targets:
83+
example:
84+
volumes:
85+
- '-/run:/var/run'
86+
```
87+
88+
Anyway, in `volumes`, prefix `-/` can always be used to indicate a path
89+
relative to project root. Please read [Docker Driver](DockerDriver.md) for
90+
details.
91+
92+
- **Q**: Where can I find the output of my target after running `hmake`?<br>
93+
**A**: `hmake` creates a hidden folder `.hmake` under project root. The output
94+
of a target is saved in `.hmake/TARGET.log`.
95+
96+
- **Q**: Does `hmake` print logs?<br>
97+
**A**: Yes. `hmake` writes its own debug logs in `.hmake/hmake.debug.log`.
98+
99+
- **Q**: What're the recommended entries in `.gitignore`?<br>
100+
**A**: Put the following entries in `.gitignore`:
101+
102+
```
103+
.hmake
104+
.hmakerc
105+
```

docs/QuickStart.md

Lines changed: 264 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,264 @@
1+
# Quick Start Guide
2+
3+
This is a guide to write a HyperMake file for your project for the first time.
4+
5+
## Before Start
6+
7+
You need a project, of course. Let's make a simple _Hello World_ C++ project,
8+
and see how HyperMake can help.
9+
10+
Here's the project directory layout:
11+
12+
```
13+
ProjectRoot
14+
|
15+
+--inc/
16+
+--src/
17+
+--hello.cpp
18+
```
19+
20+
In `hello.cpp`:
21+
22+
```cpp
23+
#include <iostream>
24+
25+
int main(int argc, char *argv[]) {
26+
std::cout << "Hello World!" << std::endl;
27+
return 0;
28+
}
29+
```
30+
31+
To build it, use `g++ -o hello src/hello.cpp`. You will need toolchain installed.
32+
Now, let's create a `HyperMake` to simplify the build.
33+
34+
## Create `HyperMake`
35+
36+
Create a file called `HyperMake` under `ProjectRoot`.
37+
It's a _YAML_ file, so let's start with:
38+
39+
```yaml
40+
---
41+
format: hypermake.v0
42+
name: hello
43+
description: The Hello World Project
44+
```
45+
46+
The first line `---` is optional but recommended, as YAML parser will treat it
47+
as the beginning of a new document.
48+
49+
`format` is required and must be assigned with `hypermake.v0`.
50+
_hmake_ only parses YAML files with `format: hypermake.v0`.
51+
`name` specifies the project name, which is required.
52+
`description` gives more information about the project. It's optional.
53+
54+
## Adding targets
55+
56+
The most important part is the section defining targets:
57+
58+
```yaml
59+
---
60+
format: hypermake.v0
61+
name: hello
62+
description: The Hello World Project
63+
64+
targets:
65+
build:
66+
description: build hello binary
67+
image: 'gcc:4.9'
68+
cmds:
69+
- g++ -o hello src/hello.cpp
70+
```
71+
72+
We defined one target above: `build`. It has three properties:
73+
74+
- `description`: a brief intro about what the target does;
75+
- `image`: the docker image used to create the container and run commands;
76+
- `cmds`: a list of commands to execute inside the container.
77+
78+
Now, we can use `hmake build` to build the project, and type
79+
80+
```
81+
./hello
82+
```
83+
84+
to show `Hello World`.
85+
86+
Under the hood, `hmake` creates a container temporarily, and maps current project
87+
root to `/src` inside container and run the commands inside the container.
88+
89+
Are you feeling boring type `hmake build` every time? Why not just `hmake`?
90+
Let's move on with default targets.
91+
92+
## Settings
93+
94+
The default targets can be specified inside `settings` section:
95+
96+
```yaml
97+
---
98+
format: hypermake.v0
99+
name: hello
100+
description: The Hello World Project
101+
102+
targets:
103+
build:
104+
description: build hello binary
105+
image: 'gcc:4.9'
106+
cmds:
107+
- g++ -o hello src/hello.cpp
108+
109+
settings:
110+
default-targets:
111+
- build
112+
```
113+
114+
With `default-targets` specified in `settings`, we can type `hmake` without
115+
arguments and it will run targets defined in `default-targets`.
116+
117+
The `settings` section defines properties which are common to all targets.
118+
For example, we can define common properties for `docker`. Let's move `image`
119+
property to settings:
120+
121+
```yaml
122+
---
123+
format: hypermake.v0
124+
name: hello
125+
description: The Hello World Project
126+
127+
targets:
128+
build:
129+
description: build hello binary
130+
cmds:
131+
- g++ -o hello src/hello.cpp
132+
133+
settings:
134+
default-targets:
135+
- build
136+
docker:
137+
image: 'gcc:4.9'
138+
```
139+
140+
As we moved `image` to `settings/docker`, we can remove `images` from target
141+
`build`. And all targets will have `image: 'gcc:4.9'` by default.
142+
143+
## Watches and Artifacts
144+
145+
Let's do some tricks here: `touch src/hello.cpp` or modify the file, and then
146+
type `hmake`. You will see the `build` target is skipped:
147+
148+
```
149+
HyperMake v1.1.0 https://github.com/evo-cloud/hmake
150+
151+
=> build 21:56:42.277
152+
:] build
153+
╔══════╤═══════╤════════╤════════════╤════════════╤═════╗
154+
║Target│Result │Duration│Start │Finish │Error║
155+
╠══════╪═══════╪════════╪════════════╪════════════╪═════╣
156+
║build │Skipped│ │21:56:42.277│21:56:42.277│ ║
157+
╚══════╧═══════╧════════╧════════════╧════════════╧═════╝
158+
OK
159+
```
160+
161+
This is definitely not what we want. The problem is _hmake_ doesn't know which
162+
files are input and which are output. Let's tell _hmake_ by adding `watches` and
163+
`artifacts` to target `build`:
164+
165+
```yaml
166+
targets:
167+
build:
168+
description: build hello binary
169+
watches:
170+
- inc
171+
- src
172+
cmds:
173+
- g++ -o hello src/hello.cpp
174+
artifacts:
175+
- hello
176+
```
177+
178+
The items in `watches` can be a path to a directory or a file, or with wildcards
179+
matching a list of files/directories. If the item is a directory, all sub-directories
180+
and files are watched recursively.
181+
`artifacts` lists the output files. _hmake_ rebuilds the target if any of the
182+
artifacts is missing. Wildcard is not allowed here, and directory is not matched
183+
recursively.
184+
185+
Some targets doesn't require input files or generate output files. In this case
186+
command line options can be used to explicitly rebuild the target: `-R`, `-r`, or
187+
`-b`. See [Command Line](CommandLine.md) for details.
188+
189+
## Dependencies
190+
191+
As the project is so simple that we can use an existing docker image `gcc:4.9` which
192+
contains toolchain we need.
193+
However in most cases, the existing docker images are not always good enough, and
194+
we want to install extra bits to build the project.
195+
Then we need to build our own toolchain image.
196+
197+
Let's use `cmake` to build our project, by adding `CMakeList.txt` under project root:
198+
199+
```
200+
cmake_minimum_required(VERSION 2.8.0)
201+
project(hello CXX)
202+
include_directories("inc")
203+
add_executable(hello src/hello.cpp)
204+
```
205+
206+
Then we will need `cmake` in toolchain image, let's build one based on `gcc:4.9`.
207+
Create a folder `toolchain` under project root and put a `Dockerfile` inside it:
208+
209+
```
210+
FROM gcc:4.9
211+
RUN apt-get update && apt-get install -y cmake && apt-get clean
212+
```
213+
214+
And update `HyperMake`:
215+
216+
```yaml
217+
---
218+
format: hypermake.v0
219+
name: hello
220+
description: The Hello World Project
221+
222+
targets:
223+
toolchain:
224+
description: build our own toolchain image
225+
watches:
226+
- toolchain
227+
build: toolchain
228+
229+
build:
230+
description: build hello binary
231+
after:
232+
- toolchain
233+
watches:
234+
- inc
235+
- src
236+
cmds:
237+
- rm -fr rel && mkdir -p rel
238+
- cd rel && cmake .. && make
239+
artifacts:
240+
- rel/hello
241+
242+
settings:
243+
default-targets:
244+
- build
245+
docker:
246+
image: 'cmake-gcc:4.9'
247+
```
248+
249+
Target `toolchain` is added, with property `build`, _hmake_ knows to build a
250+
docker image, using `toolchain/Dockerfile`. And as `image: cmake-gcc:4.9` is specified
251+
in `settings`, the built image will be `cmake-gcc:4.9`.
252+
253+
In target `build`, `after` specifies `toolchain` must succeed before `build` is able
254+
to run. Because `build` will use the image `cmake-gcc:4.9` generated by `toolchain`.
255+
256+
Now, type `hmake` and it will first run `toolchain` to build `cmake-gcc:4.9` and
257+
the run `build` to call `cmake` to build the binary.
258+
259+
## More
260+
261+
The above covers the basic features of _HyperMake_.
262+
There are a lot more useful features.
263+
Please read documents listed in [README](../README.md) for more details, and take
264+
a look at `examples` for real samples.

docs/References.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Reference Projects
2+
3+
If you are using _HyperMake_, please let us know!
4+
And feel free to send pull request updating this file with link to your own project!
5+
6+
- [hmake](https://github.com/evo-cloud/hmake) itself!
7+
- [tbus](https://github.com/robotalks/tbus) The Things Bus for robotics, IoT etc.
8+
- [zupi](https://github.com/evo-bots/zupi) The ZuPi robot project

0 commit comments

Comments
 (0)