From 2452a737a8ad2ebf44f5087b40b5fa388a798db0 Mon Sep 17 00:00:00 2001 From: Guilhem Saurel Date: Tue, 18 Apr 2023 17:04:40 +0200 Subject: [PATCH] fix pkg config --- CHANGELOG.md | 2 ++ cmeel/build.py | 30 +++++++++++++++++++++--------- docs/main.md | 4 ++++ 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c259682..2bd370e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +- add `fix-pkg-config` option, default to `true` + ## [v0.37.0] - 2023-04-05 - autodetect `README{.md, .rst, .txt, }` diff --git a/cmeel/build.py b/cmeel/build.py index ace58b2..6c1a891 100644 --- a/cmeel/build.py +++ b/cmeel/build.py @@ -92,7 +92,7 @@ def build(wheel_directory, editable=False): # noqa: C901 TODO LOG.debug("pip freeze:") deps = check_output([sys.executable, "-m", "pip", "freeze"], text=True) for dep in deps.strip().split("\n"): - LOG.debug(f" {dep}") + LOG.debug(" %s", dep) prefix = Path(".") / "build-editable" if editable else cmeel_config.temp_dir build = prefix / "bld" @@ -129,6 +129,7 @@ def build(wheel_directory, editable=False): # noqa: C901 TODO ["cmake", "--build", "BUILD_DIR", "-t", "test"], ) check_relocatable = deprecate_build_system(pyproject, "check-relocatable", True) + fix_pkg_config = deprecate_build_system(pyproject, "fix-pkg-config", True) if deprecate_build_system(pyproject, "any", False): tag = "py3-none-any" if deprecate_build_system(pyproject, "pyver-any", False): @@ -177,21 +178,21 @@ def build(wheel_directory, editable=False): # noqa: C901 TODO run_tests, ) configure_cmd = ["cmake", "-S", source, "-B", str(build), *configure_args] - LOG.debug(f"configure environment: {configure_env}") - LOG.debug(f"configure command: {configure_cmd}") + LOG.debug("configure environment: %s", configure_env) + LOG.debug("configure command: %s", configure_cmd) check_call(configure_cmd, env=configure_env) LOG.info("build") build_cmd = ["cmake", "--build", str(build), f"-j{cmeel_config.jobs}"] - LOG.debug(f"build command: {build_cmd}") + LOG.debug("build command: %s", build_cmd) check_call(build_cmd) def launch_tests(): LOG.info("test") test_env = cmeel_config.get_test_env() cmd = [i.replace("BUILD_DIR", str(build)) for i in test_cmd] - LOG.debug(f"test environment: {test_env}") - LOG.debug(f"test command: {cmd}") + LOG.debug("test environment: %s", test_env) + LOG.debug("test command: %s", cmd) check_call(cmd, env=test_env) if run_tests and not run_tests_after_install: @@ -199,7 +200,7 @@ def launch_tests(): LOG.info("install") install_cmd = ["cmake", "--build", str(build), "-t", "install"] - LOG.debug(f"install command: {install_cmd}") + LOG.debug("install command: %s", install_cmd) check_call(install_cmd) if run_tests and run_tests_after_install: @@ -367,6 +368,17 @@ def launch_tests(): raise NonRelocatableError( f"{fc} references temporary paths:\n" + "\n".join(display), ) + if fix_pkg_config and not editable: + LOG.info("fix pkg-config files") + for fc in install.glob("**/*.pc"): + with fc.open() as f: + pc_file = f.read() + if str(install) in pc_file: + rel = str(fc.parent.relative_to(install)) + fix = "/".join(["${pcfiledir}"] + [".." for _ in rel.split("/")]) + LOG.warning("fix pkg-config %s: replace %s by %s", fc, install, fix) + with fc.open("w") as f: + f.write(pc_file.replace(str(install), fix)) if editable: LOG.info("Add .pth in wheel") with (wheel_dir / f"{distribution}.pth").open("w") as f: @@ -386,9 +398,9 @@ def launch_tests(): str(wheel_dir), ], ).decode() - LOG.debug(f"wheel pack output: {pack}") + LOG.debug("wheel pack output: %s", pack) name = Path(re.search("Repacking wheel as (.*\\.whl)\\.\\.\\.", pack).group(1)).name - LOG.debug(f"returning '{name}'") + LOG.debug("returning '%s'", name) LOG.info("done") return name diff --git a/docs/main.md b/docs/main.md index ab76a1a..be31da2 100644 --- a/docs/main.md +++ b/docs/main.md @@ -138,6 +138,10 @@ setting shouldn't provide any binary library or executable. `false` by default. Boolean setting to check generated `*.cmake` files for wrong absolute paths. `true` by default. +#### `fix-pkg-config` + +Boolean setting to fix generated `*.pc` files with wrong absolute paths. `true` by default. + ## Global config file Users can have a `cmeel/cmeel.toml` file in their `$XDG_CONFIG_HOME` directory (usually `~/.config`).