Skip to content

Commit

Permalink
feat: convert build to meson
Browse files Browse the repository at this point in the history
Convert the build system from a Makefile to meson. constants.go is
replaced by an internal 'constants' package that serves the same
purpose. This commit also drops the COPR RPM spec file.

Signed-off-by: Link Dupont <[email protected]>
  • Loading branch information
subpop committed Feb 14, 2023
1 parent 300f98f commit a488835
Show file tree
Hide file tree
Showing 28 changed files with 231 additions and 499 deletions.
51 changes: 0 additions & 51 deletions .copr/Makefile

This file was deleted.

6 changes: 3 additions & 3 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ jobs:
go-version: ${{ matrix.go }}

- name: Go build (source)
run: make
run: go build -v ./...

- name: Go build (tests)
run: make tests
run: go test -v ./...

- name: Go vet
run: make vet
run: go vet -v ./...
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@
/yggd.1.gz
/yggd.bash
/yggdrasil.spec
/doc/tags.toml
184 changes: 0 additions & 184 deletions Makefile

This file was deleted.

57 changes: 13 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,58 +8,27 @@ exchanging data with its worker processes through a D-Bus message broker.

## Installation

The easiest way to install yggdrasil is by using the include `Makefile`. Because
The easiest way to compile and install yggdrasil is using `meson`. Because
yggdrasil runs as a privileged system daemon, systemd unit files and D-Bus
policy files must be installed in specific directories in order for the service
to start.

The default target will build all _yggdrasil_ binaries and ancillary data files.
The `Makefile` also includes an `install` target to install the binaries and
data into distribution-appropriate locations. To override the installation
directory (commonly referred to as the `DESTDIR`), set the `DESTDIR` variable
when running the `install` target. Additional variables can be used to further
configure the installation prefix and related directories.

```
PREFIX ?= /usr/local
BINDIR ?= $(PREFIX)/bin
SBINDIR ?= $(PREFIX)/sbin
LIBEXECDIR ?= $(PREFIX)/libexec
SYSCONFDIR ?= $(PREFIX)/etc
DATADIR ?= $(PREFIX)/share
DATAROOTDIR ?= $(PREFIX)/share
MANDIR ?= $(DATADIR)/man
DOCDIR ?= $(PREFIX)/doc
LOCALSTATEDIR ?= $(PREFIX)/var
```

Any of these variables can be overridden by passing a value to `make`. For
example:

```bash
make PREFIX=/usr SYSCONFDIR=/etc LOCALSTATEDIR=/var
make PREFIX=/usr SYSCONFDIR=/etc LOCALSTATEDIR=/var DESTDIR=/tmp/rpmbuildroot install
```

### Branding

_yggdrasil_ can be rebranded by setting some additional `make` variables:

```
SHORTNAME := ygg # Used as a prefix to binary names. Cannot contain spaces.
LONGNAME := yggdrasil # Used as file and directory names. Cannot contain spaces.
SUMMARY := yggdrasil # Used as a long-form description. Can contain spaces and punctuation.
```

For example, to brand _yggdrasil_ as `bunnies`, compile as follows:
Generally, it is recommended to follow your distribution's packaging guidelines
for compiling Go programs and installing projects using `meson`. What follows is
a generally acceptable set of steps to setup, compile and install yggdrasil
using `meson`.

```bash
make PREFIX=/usr SYSCONFDIR=/etc LOCALSTATEDIR=/var SHORTNAME=bnns LONGNAME=bunnies SUMMARY="Bunnies have a way of proliferating." install
# Set up the project according to distribution-specific directory locations
meson setup --prefix /usr/local --sysconfdir /etc --localstatedir /var builddir
# Compile
meson compile -C builddir
# Install
meson install -C builddir
```

This will build `yggd`, but install it into `DESTDIR` as `bnnsd`. Accordingly,
the systemd service will be named `bunnies.service` with a `Description=`
directive of "Bunnies have a way of proliferating.".
`meson` includes an optional `--destdir` to its `install` subcommand to aid in
packaging.

## Configuration

Expand Down
7 changes: 4 additions & 3 deletions cmd/yggctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@ import (
"git.sr.ht/~spc/go-log"

"github.com/redhatinsights/yggdrasil"
"github.com/redhatinsights/yggdrasil/internal/constants"
"github.com/urfave/cli/v2"
)

var DeveloperBuild = true

func main() {
app := cli.NewApp()
app.Name = yggdrasil.ShortName + "ctl"
app.Version = yggdrasil.Version
app.Usage = "control and interact with " + yggdrasil.ShortName + "d"
app.Name = "yggctl"
app.Version = constants.Version
app.Usage = "control and interact with yggd"

app.Flags = []cli.Flag{
&cli.BoolFlag{
Expand Down
7 changes: 7 additions & 0 deletions cmd/yggctl/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
yggctl = custom_target('yggctl',
build_always_stale: true,
output: 'yggd',
command: [go, 'build', gobuildflags, '-o', '@OUTPUT@', '-ldflags', goldflags, 'github.com/redhatinsights/yggdrasil/cmd/yggctl'],
install: false,
install_dir: get_option('sbindir')
)
3 changes: 2 additions & 1 deletion cmd/yggd/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/google/uuid"
"github.com/redhatinsights/yggdrasil"
"github.com/redhatinsights/yggdrasil/internal/config"
"github.com/redhatinsights/yggdrasil/internal/constants"
"github.com/redhatinsights/yggdrasil/internal/transport"
"github.com/redhatinsights/yggdrasil/internal/work"
"github.com/redhatinsights/yggdrasil/ipc"
Expand Down Expand Up @@ -214,7 +215,7 @@ func (c *Client) ConnectionStatus() (*yggdrasil.ConnectionStatus, error) {
}
}

tagsFilePath := filepath.Join(yggdrasil.SysconfDir, yggdrasil.LongName, "tags.toml")
tagsFilePath := filepath.Join(constants.ConfigDir, "tags.toml")

var tagMap map[string]string
if _, err := os.Stat(tagsFilePath); !os.IsNotExist(err) {
Expand Down
Loading

0 comments on commit a488835

Please sign in to comment.