Skip to content

Commit

Permalink
build: add RCDB to resolve-dependencies.py, and remove INI and env …
Browse files Browse the repository at this point in the history
…var support
  • Loading branch information
c-dilks committed Aug 4, 2024
1 parent 63d6ab3 commit a3429c8
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 67 deletions.
2 changes: 1 addition & 1 deletion doc/ifarm.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
```bash
meson/resolve-dependencies.py --help # prints the usage guide
```
Use the `--env` option and set the resulting environment variables.
Use the resulting arguments when setting up or configuring your build directory.

## Build and Install

Expand Down
17 changes: 14 additions & 3 deletions doc/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ The following sections (🟩) list the dependencies and how to obtain them.
> git log --tags --decorate --simplify-by-decoration --oneline # list all the tags (latest first)
> git checkout 1.0.0 # checkout the tag '1.0.0'
> ```
<!--`-->
### 🟩 `meson`: Build system used by Iguana
<https://mesonbuild.com/>
Expand Down Expand Up @@ -63,6 +64,16 @@ cmake --install build-hipo
- After installation, depending on ROOT's installation prefix you may also need to set your environment so
ROOT may be found; this is typically done by `source /path/to/root/bin/thisroot.sh`

### 🟩 Optional: `RCDB`: Run Condition Database
<https://github.com/JeffersonLab/rcdb>
- RCDB is optional, but needed for algorithms that use, _e.g._, the beam energy
- You do not need to compile RCDB, just clone the repository

> [!NOTE]
> As of July 2024, the most recent tagged version of RCDB is quite far behind
> the current main branch, so you may just use the latest main branch version
> (`master`).
<a name="building"></a>
## 🟠 Building and Installing

Expand All @@ -80,10 +91,9 @@ Use [`meson/resolve-dependencies.py`](../meson/resolve-dependencies.py) to help
/path/to/iguana-source/meson/resolve-dependencies.py --help # prints the usage guide
```
Tell it where your dependencies are installed and it will tell you the build options
that you need for Step 2; you can also choose to write those build options to an INI (native) file.
that you need for Step 2.

Alternatively, you may use environment variables; see the [note on dependency
resolution](dependency_resolution.md) for more general guidance.
See the [note on dependency resolution](dependency_resolution.md) for more general guidance.


### 🟩 Step 2: Generate a build directory
Expand Down Expand Up @@ -142,6 +152,7 @@ meson install # installs Iguana to your prefix (build option 'prefix')
> meson setup --wipe /path/to/iguana-source
> ```
> This will preserve your build options; then try to rebuild.
<!--`-->
<a name="env"></a>
Expand Down
103 changes: 40 additions & 63 deletions meson/resolve-dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,20 @@ class Formatter(argparse.ArgumentDefaultsHelpFormatter, argparse.RawDescriptionH
parser_deps.add_argument('--fmt', default=SYSTEM_ASSUMPTION, type=str, help='path to `fmt` installation')
parser_deps.add_argument('--yaml', default=SYSTEM_ASSUMPTION, type=str, help='path to `yaml-cpp` installation')
parser_deps.add_argument('--root', default=SYSTEM_ASSUMPTION, type=str, help='path to `ROOT` installation')
parser_deps.add_argument('--rcdb', default='$RCDB_HOME', type=str, help='path to `RCDB` installation')
parser_output = parser.add_argument_group('output control')
parser_output.add_argument('--cli', default=False, action=argparse.BooleanOptionalAction, help='only print the `meson` CLI options, and nothing else')
parser_output.add_argument('--env', default=False, action=argparse.BooleanOptionalAction, help='generate environment variable `export` commands instead')
parser_output.add_argument('--ini', default=NOT_USED, type=str, help='if set, generate an INI file (meson native file) with this name; you may then use it with `meson setup --native-file=_____`')
parser_output.add_argument('--verbose', default=False, action=argparse.BooleanOptionalAction, help='verbose output')
args = parser.parse_args()

# verbosity
verbose = not args.cli
def print_verbose(message):
if(verbose):
if(args.verbose):
print(message)

# functions to set dependency paths
pkg_config_path = set()
cmake_prefix_path = set()
extra_args = []
def use_system(dep):
print_verbose(f'{dep}: {SYSTEM_ASSUMPTION}')
def use_pkg_config(dep, pc_file, arg):
Expand All @@ -63,71 +62,49 @@ def use_cmake(dep, arg):
cmake_prefix_path.add(path)
else:
use_system(dep)
def use_env_var(dep, build_var_name, user_val, env_var_name):
if(user_val == f'${env_var_name}'):
if env_var_name in os.environ:
print_verbose(f'{dep}: using environment variable "{env_var_name}" for build variable "{build_var_name}"')
extra_args.append([build_var_name, os.environ[env_var_name]])
else:
print(f'{dep}: you did not specify where {dep} is found, and the fallback environment variable "${env_var_name}" is not set; {dep} will be ignored', file=sys.stderr)
else:
print_verbose(f'{dep}: using user value "{user_val}" for build variable "{build_var_name}"')
extra_args.append([build_var_name, user_val])

# resolve dependencies #########################
use_pkg_config('hipo', 'hipo4.pc', args.hipo)
use_pkg_config('fmt', 'fmt.pc', args.fmt)
use_pkg_config('yaml', 'yaml-cpp.pc', args.yaml)
use_cmake('ROOT', args.root)
use_env_var('rcdb', 'rcdb:home', args.rcdb, 'RCDB_HOME')
################################################


# generate a native file
if(args.ini!=NOT_USED):
def ini_string_arr(arr):
contents = ','.join(map(lambda s: f'\'{s}\'', arr))
return f'[{contents}]'
ini_config = ConfigParser(allow_no_value=True)
ini_config.add_section('built-in options')
if(len(cmake_prefix_path) > 0):
ini_config.set('built-in options', 'cmake_prefix_path', ini_string_arr(cmake_prefix_path))
if(len(pkg_config_path) > 0):
ini_config.set('built-in options', 'pkg_config_path', ini_string_arr(pkg_config_path))
with open(args.ini, 'w') as fp:
ini_config.write(fp)

# generate CLI options
if(verbose or args.cli):
if(len(pkg_config_path)==0 and len(cmake_prefix_path)==0):
print_verbose(textwrap.dedent(f'''
==========================================================================================
All of your dependencies are assumed to be in the system default locations.
- If they are not, please run:
{sys.argv[0]} --help
- Otherwise, you do not need to set or modify any build options for dependency resolution.
==========================================================================================
'''))
exit(0)
else:
if(args.env):
print_verbose(textwrap.dedent('''
==================================================
| Here are the environment variables you need: |
==================================================
'''))
else:
print_verbose(textwrap.dedent('''
===============================================
| Here are the build options that you need: |
===============================================
'''))
cli_opts = []
if(len(pkg_config_path) > 0):
if(args.env):
cli_opts.append(f'export PKG_CONFIG_PATH={":".join(pkg_config_path)}' + '${PKG_CONFIG_PATH:+:${PKG_CONFIG_PATH}}')
else:
cli_opts.append(f'--pkg-config-path={",".join(pkg_config_path)}')
if(len(cmake_prefix_path) > 0):
if(args.env):
cli_opts.append(f'export CMAKE_PREFIX_PATH={":".join(cmake_prefix_path)}' + '${CMAKE_PREFIX_PATH:+:${CMAKE_PREFIX_PATH}}')
else:
cli_opts.append(f'--cmake-prefix-path={",".join(cmake_prefix_path)}')
if(args.ini==NOT_USED):
if(args.env):
for cli_opt in cli_opts:
print(cli_opt)
else:
print(f'{" ".join(cli_opts)}')
else:
print(f'--native-file={args.ini}')
print_verbose('\n')
if(len(pkg_config_path)==0 and len(cmake_prefix_path)==0 and len(extra_args)==0):
print_verbose(textwrap.dedent(f'''
==========================================================================================
All of your dependencies are assumed to be in the system default locations.
- If they are not, please run:
{sys.argv[0]} --help
- Otherwise, you do not need to set or modify any build options for dependency resolution.
==========================================================================================
'''))
else:
print_verbose(textwrap.dedent('''
===============================================
| Here are the build options that you need: |
===============================================
'''))
cli_opts = []
if(len(pkg_config_path) > 0):
cli_opts.append(f'--pkg-config-path={",".join(pkg_config_path)}')
if(len(cmake_prefix_path) > 0):
cli_opts.append(f'--cmake-prefix-path={",".join(cmake_prefix_path)}')
if(len(extra_args) > 0):
for extra_arg in extra_args:
cli_opts.append(f'-D{extra_arg[0]}={extra_arg[1]}')
print(f'{" ".join(cli_opts)}')
print_verbose('\n')

0 comments on commit a3429c8

Please sign in to comment.