Skip to content

Commit

Permalink
fixup! Add serve_header.py for rapid testing on Compiler Explorer
Browse files Browse the repository at this point in the history
  • Loading branch information
falbrechtskirchinger committed Apr 27, 2022
1 parent 369eefd commit cb3fa6f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 22 deletions.
46 changes: 26 additions & 20 deletions scripts/serve_header/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ The header file is automatically amalgamated on demand.

## Prerequisites

> **Note:** All file locations are relative to the project root folder and all commands are assumed to be executed from the same root folder.
1. Make sure these Python packages are installed.
```
PyYAML
Expand All @@ -28,13 +26,14 @@ The header file is automatically amalgamated on demand.
```
$ mkcert localhost
```
The command will create two files, `localhost.pem` and `localhost-key.pem`, in the current working directory. It is recommended to create them in the top level or project root directory.
## Usage
`serve_header.py` has a builtin default configuration that will serve the header from the project folder it is homed in.
It expects to find the certificate `localhost.pem` and the private key `localhost-key.pem` in the projects root directory.
`serve_header.py` has a built-in default configuration that will serve the `single_include/nlohmann/json.hpp` header file relative to the top level or project directory it is homed in.
The built-in configuration expects the certificate `localhost.pem` and the private key `localhost-key.pem`to be located in the top level or project root directory.
To start serving the `json.hpp` header file at `https://localhost:8443/json.hpp`, run this command:
To start serving the `json.hpp` header file at `https://localhost:8443/json.hpp`, run this command from the top level or project root directory:
```
$ make serve_header
```
Expand All @@ -54,32 +53,39 @@ int main() {
}
```

> `serve_header.py` dynamically injects the macros `JSON_BUILD_COUNT` and `JSON_BUILD_TIME` into the served header. By comparing build count or time output from the compiled program with the output from `serve_header.py`, one can be reasonably sure the compiled code uses the expected revision of the header file.
> `serve_header.py` dynamically injects the macros `JSON_BUILD_COUNT` and `JSON_BUILD_TIME` into the served header file. By comparing build count or time output from the compiled program with the output from `serve_header.py`, one can be reasonably sure the compiled code uses the expected revision of the header file.
## Configuration

`serve_header.py` will try to read a configuration file `serve_header.yml` and will fallback on builtin defaults, if the file cannot be read.
`serve_header.py` will try to read a configuration file `serve_header.yml` in the top level or project root directory, and will fall back on built-in defaults if the file cannot be read.
An annotated example configuration can be found in `scripts/serve_header/serve_header.yml.example`.

## Serving `json.hpp` from multiple working trees
## Serving `json.hpp` from multiple project directory instances or working trees

`serve_header.py` was designed with the goal of supporting multiple project roots or working trees at the same time.
The recommended folder structure is shown below but `serve_header.py` can work with other structures as well, including a nested hierarchy.
The recommended directory structure is shown below but `serve_header.py` can work with other structures as well, including a nested hierarchy.
```
json/
json/ ⮜ the parent or web server root directoy
├── develop/ ⮜ the main git checkout
│ └── ...
├── feature1/
├── feature2/ any number of additional
├── feature3/ ⮜ working trees (e.g., created
└── feature4/ with git worktree)
└── feature5/
│ └── ... any number of additional
├── feature2/ ⮜ working trees (e.g., created
│ └── ... with git worktree)
└── feature3/
└── ...
```

To serve the header of each working tree at `https://localhost:8443/<worktree>/json.hpp`, a configuration file is needed.
Create the file `serve_header.yml` in the project folder `serve_header.py` is homed in:
```yaml
root: ..
```
By shifting the root folder up one level the headers from all sibling directories will be served.
1. Create the file `serve_header.yml` in the top level or project root directory of any working tree:
```yaml
root: ..
```
By shifting the web server root directory up one level, the `single_include/nlohmann/json.hpp` header files relative to each sibling directory or working tree will be served.

2. Start `serve_header.py` by running this command from the same top level or project root directory the configuration file is located in:
```
$ make serve_header
```

`serve_header.py` will automatically detect the addition or removal of working trees in the configured root folder.
`serve_header.py` will automatically detect the addition or removal of working trees anywhere within the configured web server root directory.
4 changes: 2 additions & 2 deletions scripts/serve_header/serve_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,8 @@ def send_header(self, keyword, value):
super().send_header(keyword, value)

def end_headers (self):
# intercept; called in copyfile or indirectly
# by send_head via super().send_error
# intercept; called in copyfile() or indirectly
# by send_head via super().send_error()
pass

def copyfile(self, source, outputfile):
Expand Down

0 comments on commit cb3fa6f

Please sign in to comment.