Skip to content

Commit

Permalink
feat(build): build configuration script (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
c-dilks committed Nov 29, 2023
1 parent 0b62279 commit 5b732b1
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 137 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ jobs:
echo '### Dependencies' >> $GITHUB_STEP_SUMMARY
echo '| Dependency | Version |' >> $GITHUB_STEP_SUMMARY
echo '| --- | --- |' >> $GITHUB_STEP_SUMMARY
for dep in python ruby meson ninja ; do
for dep in python meson ninja ; do
echo "| \`$dep\` | $($dep --version) |" >> $GITHUB_STEP_SUMMARY
done
echo "| \`fmt\` | ${{ env.fmt_version }} |" >> $GITHUB_STEP_SUMMARY
Expand All @@ -99,8 +99,10 @@ jobs:
- name: untar build
run: ls *.tar.gz | xargs -I{} tar xzvf {}
- run: tree
- name: build iguana
run: ./install.rb --hipo hipo --fmt fmt
- name: configure
run: ./configure.py --hipo hipo --fmt fmt
- name: build
run: ./install-iguana.sh
- name: dump build log
if: always()
run: cat build-iguana/meson-logs/meson-log.txt
Expand Down
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# build artifacts
*.ini
install-iguana.sh
/build*/
/iguana

# dependencies
hipo

# data files
*.hipo
24 changes: 15 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,25 @@ Dependencies likely available in your package manager:

Dependencies you may need to build yourself, unless available on a Jefferson Lab computer:
- [`hipo`](https://github.com/gavalian/hipo)
- To make `iguana` know where to find it, do one of:
- use option `--hipo` when running `install.rb`
- symlink `./hipo` to the installation
- set `$HIPO` to the installation
- use `meson` build option `-Dhipo` (or its [default](meson.options))

## Setup
Run (from any directory):
First, configure your `iguana` build using `configure.py`:
```bash
install.rb --help # print the usage guide
install.rb # default: install to ./iguana
configure.py --help
```
Alternatively, use `meson` for more control.
The `--help` option will print the usage guide.
Unless the dependencies are installed in one of the system default locations, you will need to specify the path to each of them, _e.g._,
```bash
./configure.py --hipo /path/to/hipo/installation_prefix
```
This will generate a configuration file (`.ini`) with the build settings, along with an installation script (`install-iguana.sh`).
Inspect both of them, and if they look correct, proceed with building and installing `iguana` by running:
```bash
./install-iguana.sh
```

### Note for advanced users
If you are comfortable with `meson` and dependency resolution, there is no need to run `configure.py` or `install-iguana.sh`; you may instead run `meson` commands with your preferred options.

## Troubleshooting Notes

Expand Down
79 changes: 79 additions & 0 deletions configure.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/usr/bin/env python

from configparser import ConfigParser
import argparse, os, sys, textwrap

SYSTEM_ASSUMPTION = 'assume system installation'
SEPARATOR = '-'*50

# parse user options
class Formatter(argparse.ArgumentDefaultsHelpFormatter, argparse.RawDescriptionHelpFormatter): pass
parser = argparse.ArgumentParser(
usage = f'{sys.argv[0]} [OPTION]...',
description = textwrap.dedent('''
description:
Generate a configuration file with build settings for iguana
'''),
formatter_class = Formatter
)
parser_deps = parser.add_argument_group('dependency installation paths')
parser_deps.add_argument( '--hipo', default=SYSTEM_ASSUMPTION, type=str, help='path to `hipo` installation' )
parser_deps.add_argument( '--fmt', default=SYSTEM_ASSUMPTION, type=str, help='path to `fmt` installation' )
parser_build = parser.add_argument_group('iguana build settings')
parser_build.add_argument( '--prefix', default='iguana', type=str, help='iguana installation prefix' )
parser_build.add_argument( '--build', default='build-iguana', type=str, help='iguana buildsystem directory' )
parser_build.add_argument( '--ini', default='build-iguana.ini', type=str, help='name of the output config INI file' )
args = parser.parse_args()

# set dependency paths
cmake_prefix_path = []
pkg_config_path = []
if(args.hipo != SYSTEM_ASSUMPTION):
cmake_prefix_path.append(os.path.realpath(args.hipo))
if(args.fmt != SYSTEM_ASSUMPTION):
pkg_config_path.append(os.path.realpath(args.fmt) + '/lib/pkgconfig')

# return an array of strings for meson's INI parsing
def meson_string_array(arr):
contents = ','.join(map(lambda s: f'\'{s}\'', arr))
return f'[{contents}]'

# generate the INI file
config = ConfigParser(allow_no_value=True)
config.add_section('built-in options')
config.set('built-in options', '; dependency paths')
config.set('built-in options', 'cmake_prefix_path', meson_string_array(cmake_prefix_path))
config.set('built-in options', 'pkg_config_path', meson_string_array(pkg_config_path))
config.set('built-in options', '; installation settings')
config.set('built-in options', 'prefix', f'\'{os.path.realpath(args.prefix)}\'')
with open(args.ini, 'w') as fp:
config.write(fp)
print(f'Wrote build configuration file {args.ini}:')
print(SEPARATOR)
with open(args.ini, 'r') as fp:
print(fp.read())
print(SEPARATOR)

# generate the installation script
sourceDir = os.path.dirname(os.path.realpath(__file__))
installScript = 'install-iguana.sh'
with open(installScript, 'w') as fp:
fp.write(textwrap.dedent(f'''\
#!/bin/bash
set -e
# setup
if [ ! -d {args.build} ]; then
meson setup --native-file {args.ini} {args.build} {sourceDir}
fi
# compile and install
meson install -C {args.build}
'''))
os.chmod(installScript, 0o744)
print(f'''
Generated installation script {installScript}
To proceed with iguana installation, run:
./{installScript}
''')
122 changes: 0 additions & 122 deletions install.rb

This file was deleted.

0 comments on commit 5b732b1

Please sign in to comment.