Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 53 additions & 67 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ Additionally, `HOMCC` provides sandboxed compiler execution for remote compilati

## Table of Contents
1. [Installation](#installation)
2. [Usage and Configuration](#usage-and-configuration)
2. [Usage](#usage)
1. [Client: `homcc`](#client-homcc)
2. [Server: `homccd`](#server-homccd)
3. [Documentation](#documentation)
4. [Development](#development)
3. [Configuration](#configuration)
4. [Documentation](#documentation)
5. [Development](#development)
1. [Setup](#setup)
2. [Testing](#testing)
3. [Linting](#linting)
Expand All @@ -55,49 +56,17 @@ Additionally, `HOMCC` provides sandboxed compiler execution for remote compilati
```


## Usage and Configuration
## Usage

### Client: `homcc`
- Follow the client [Installation](#installation) guide
- Find usage description and `homcc` defaults:
```sh
$ homcc --help
```
- Overwrite defaults globally via a `client.conf` configuration file if necessary:
- <table>
<tr align="center"><th><code>client.conf</code> file locations</th></tr>
<tr valign="top"><td>
<code>$HOMCC_DIR/client.conf</code><br/>
<code>~/.homcc/client.conf</code><br/>
<code>~/.config/homcc/client.conf</code><br/>
<code>/etc/homcc/client.conf</code>
</td></tr>
</table>
- <table>
<tr align="center"><th>Example: <code>client.conf</code></th><th>Explanation</th></tr>
<tr valign="top">
<td><sub><pre lang="ini">
# homcc: client.conf
compiler=g++
timeout=60
compression=lzo
profile=jammy
log_level=DEBUG
verbose=True
</pre></sub></td>
<td><sub><pre>
# Comment
Default compiler
Default timeout value in seconds
Default compression algorithm: {lzo, lzma}
Profile to specify the schroot environment for remote compilations
Detail level for log messages: {DEBUG, INFO, WARNING, ERROR, CRITICAL}
Enable verbosity mode which implies detailed and colored logging
</pre></sub></td>
</tr>
</table>
- Specify your remote compilation server via the `$HOMCC_HOSTS` environment variable or in a dedicated `hosts` file:
- <table>
- Use `homcc` by specifying `CCACHE_PREFIX=homcc` in your `conan` profile or IDE of choice!
- Specify your remote compilation server via the `$HOMCC_HOSTS` environment variable or in a dedicated `hosts` file:<br/>
<table>
<tr align="center"><th><code>hosts</code> file locations</th></tr>
<tr valign="top"><td>
<code>$HOMCC_DIR/hosts</code><br/>
Expand All @@ -106,7 +75,7 @@ Additionally, `HOMCC` provides sandboxed compiler execution for remote compilati
<code>/etc/homcc/hosts</code>
</td></tr>
</table>
- Possible `hosts` formats:
- Possible `hosts` formats:
- `HOST` format:
- `HOST`: TCP connection to specified `HOST` with default port `3633`
- `HOST:PORT`: TCP connection to specified `HOST` with specified `PORT`
Expand All @@ -119,26 +88,25 @@ Additionally, `HOMCC` provides sandboxed compiler execution for remote compilati
- `lzo`: Lempel-Ziv-Oberhumer compression algorithm
- `lzma`: Lempel-Ziv-Markov chain algorithm
- No compression is used per default, specifying `lzo` is however advised
- <table>
<table>
<tr align="center"><th>Example: <code>hosts</code></th><th>Explanation</th></tr>
<tr valign="top">
<td><sub><pre>
# homcc: hosts
localhost
remotehost/12
192.168.0.1:3633/21
[FC00::1]:3633/42,lzo
</pre></sub></td>
<td><sub><pre>
# Comment
Named "remotehost" host with limit of 12
IPv4 "192.168.0.1" host at port 3633 with limit of 21
IPv6 "FC00::1" host at port 3633 with limit of 42 and lzo compression
"localhost" host with default limit of 2
Named "remotehost" TCP host with limit of 12 at default port 3633
IPv4 "192.168.0.1" TCP host at port 3633 with limit of 21
IPv6 "FC00::1" TCP host at port 3633 with limit of 42 and lzo compression
</pre></sub></td>
</tr>
</table>

:exclamation: **WARNING**: Currently do not include `localhost` in your `hosts` file!
- Use `homcc` by specifying `CCACHE_PREFIX=homcc` in your `conan` profile or IDE of choice and have `CONAN_CPU_COUNT` smaller or equal to the sum of all remote host limits, e.g. `≤ 12+21+42`!
</table>


### Server: `homccd`
Expand All @@ -147,43 +115,61 @@ Additionally, `HOMCC` provides sandboxed compiler execution for remote compilati
```sh
$ homccd --help
```
- Overwrite defaults globally via a `server.conf` configuration file if necessary:
- <table>
<tr align="center"><th><code>server.conf</code> file locations</th></tr>
- \[Optional]:
Set up your `schroot` environments at `/etc/schroot/schroot.conf` or in the `/etc/schroot/chroot.d/` directory and mount the `/tmp/` directory to enable sandboxed compiler execution.
Currently, in order for these changes to apply, you have to restart `homccd`:
```sh
$ sudo systemctl restart homccd.service
```


## Configuration
- Overwrite defaults globally via a `homcc.conf` configuration file:
<table>
<tr align="center"><th><code>homcc.conf</code> file locations</th></tr>
<tr valign="top"><td>
<code>$HOMCC_DIR/server.conf</code><br/>
<code>~/.homcc/server.conf</code><br/>
<code>~/.config/homcc/server.conf</code><br/>
<code>/etc/homcc/server.conf</code>
<code>$HOMCC_DIR/homcc.conf</code><br/>
<code>~/.homcc/homcc.conf</code><br/>
<code>~/.config/homcc/homcc.conf</code><br/>
<code>/etc/homcc/homcc.conf</code>
</td></tr>
</table>
- <table>
<tr align="center"><th>Example: <code>server.conf</code></th><th>Explanation</th></tr>
</table>
- :exclamation: Explicit configuration is currently not necessary, only do this if you know exactly what you are doing!
<table>
<tr align="center"><th>Example: <code>homcc.conf</code></th><th>Explanation</th></tr>
<tr valign="top">
<td><sub><pre lang="ini">
# homccd: server.conf
[homcc]
compiler=g++
timeout=60
compression=lzo
profile=jammy
log_level=DEBUG
verbose=True
[homccd]
limit=64
port=3633
address=0.0.0.0
log_level=DEBUG
verbose=True
</pre></sub></td>
<td><sub><pre>
# Comment
# Client configuration
Default compiler
Default timeout value in seconds
Default compression algorithm: {lzo, lzma}
Profile to specify the schroot environment for remote compilations
Detail level for log messages: {DEBUG, INFO, WARNING, ERROR, CRITICAL}
Enable verbosity mode which implies detailed and colored logging
# Server configuration
Maximum limit of concurrent compilations
TCP port to listen on
IP address to listen on
Detail level for log messages: {DEBUG, INFO, WARNING, ERROR, CRITICAL}
Enable verbosity mode which implies detailed and colored logging
</pre></sub></td>
</tr>
</table>
- \[Optional]:
Set up your `schroot` environments at `/etc/schroot/schroot.conf` or in the `/etc/schroot/chroot.d/` directory and mount the `/tmp/` directory to enable sandboxed compiler execution.
Currently, in order for these changes to apply, you have to restart `homccd`:
```sh
$ sudo systemctl restart homccd.service
```
</table>


## Documentation
Expand Down
10 changes: 6 additions & 4 deletions homcc/client/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
ClientConfig,
Host,
LogLevel,
load_config_file,
load_hosts,
parse_cli_args,
parse_config,
Expand All @@ -45,7 +44,7 @@
def main():
# load and parse arguments and configuration information
homcc_args_dict, compiler_arguments = parse_cli_args(sys.argv[1:])
homcc_config: ClientConfig = parse_config(load_config_file())
homcc_config: ClientConfig = parse_config()
logging_config: LoggingConfig = LoggingConfig(
config=FormatterConfig.COLORED,
formatter=Formatter.CLIENT,
Expand Down Expand Up @@ -101,6 +100,9 @@ def main():
continue

if host.is_local():
if has_local:
logger.warning("Multiple localhost hosts provided!")

has_local = True
localhost = host

Expand All @@ -121,8 +123,8 @@ def main():
if (timeout := homcc_args_dict["timeout"]) is not None:
homcc_config.timeout = timeout

# force local compilation on specific conditions; TODO(s.pirsch): this should probably be removed!
if compiler_arguments.is_linking_only():
# force local compilation on specific conditions
if compiler_arguments.is_linking_only(): # TODO(s.pirsch): this should probably be removed!
logger.debug("Linking [%s] to %s", ", ".join(compiler_arguments.object_files), compiler_arguments.output)
sys.exit(compile_locally(compiler_arguments, localhost))

Expand Down
47 changes: 30 additions & 17 deletions homcc/client/parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,20 @@
from dataclasses import dataclass
from enum import Enum
from pathlib import Path
from typing import Any, Dict, Iterable, List, Optional, Tuple, Union
from typing import Any, Dict, List, Optional, Tuple, Union

from homcc.common.arguments import Arguments
from homcc.common.compression import Compression
from configparser import ConfigParser, SectionProxy
from homcc.common.logging import LogLevel
from homcc.common.parsing import default_locations, load_config_file_from, parse_config_keys
from homcc.common.parsing import HOMCC_CONFIG_FILENAME, default_locations, parse_configs
from homcc.client.errors import HostParsingError, NoHostsFoundError

logger = logging.getLogger(__name__)

HOMCC_HOSTS_ENV_VAR: str = "$HOMCC_HOSTS"
HOMCC_HOSTS_FILENAME: str = "hosts"
HOMCC_CLIENT_CONFIG_FILENAME: str = "client.conf"
HOMCC_CLIENT_CONFIG_SECTION: str = "homcc"


class ConnectionType(str, Enum):
Expand Down Expand Up @@ -170,22 +171,34 @@ def __init__(
compiler: Optional[str] = None,
compression: Optional[str] = None,
profile: Optional[str] = None,
timeout: Union[float, str] = None,
timeout: Optional[float] = None,
log_level: Optional[str] = None,
verbose: Optional[str] = None,
verbose: Optional[bool] = None,
):
self.compiler = compiler or Arguments.DEFAULT_COMPILER
self.compression = Compression.from_name(compression)
self.profile = profile
self.timeout = float(timeout) if timeout is not None else None
self.timeout = timeout
self.log_level = LogLevel[log_level] if log_level else None
self.verbose = verbose is not None and verbose

# additional parsing step for verbosity
self.verbose = verbose is not None and re.match(r"^true$", verbose, re.IGNORECASE) is not None

@staticmethod
def keys() -> Iterable[str]:
return ClientConfig.__annotations__.keys()
@classmethod
def from_config_section(cls, homcc_config: SectionProxy) -> ClientConfig:
compiler: Optional[str] = homcc_config.get("compiler")
compression: Optional[str] = homcc_config.get("compression")
profile: Optional[str] = homcc_config.get("profile")
timeout: Optional[float] = homcc_config.getfloat("timeout")
log_level: Optional[str] = homcc_config.get("log_level")
verbose: Optional[bool] = homcc_config.getboolean("verbose")

return ClientConfig(
compiler=compiler,
compression=compression,
profile=profile,
timeout=timeout,
log_level=log_level,
verbose=verbose,
)


def parse_cli_args(args: List[str]) -> Tuple[Dict[str, Any], Arguments]:
Expand Down Expand Up @@ -385,10 +398,10 @@ def filtered_lines(text: str) -> List[str]:
raise NoHostsFoundError("No hosts information were found!")


def parse_config(config_lines: List[str]) -> ClientConfig:
return ClientConfig(**parse_config_keys(ClientConfig.keys(), config_lines))
def parse_config(filenames: List[Path] = None) -> ClientConfig:
cfg: ConfigParser = parse_configs(filenames or default_locations(HOMCC_CONFIG_FILENAME))

if HOMCC_CLIENT_CONFIG_SECTION not in cfg.sections():
return ClientConfig()

def load_config_file(config_file_locations: Optional[List[Path]] = None) -> List[str]:
"""Load the client config file as parameterized by config_file_locations or from the default homcc locations"""
return load_config_file_from(config_file_locations or default_locations(HOMCC_CLIENT_CONFIG_FILENAME))
return ClientConfig.from_config_section(cfg[HOMCC_CLIENT_CONFIG_SECTION])
Loading