Skip to content

Commit

Permalink
fix pkg config
Browse files Browse the repository at this point in the history
  • Loading branch information
nim65s committed Apr 18, 2023
1 parent 2199247 commit 2452a73
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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, }`
Expand Down
30 changes: 21 additions & 9 deletions cmeel/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -177,29 +178,29 @@ 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:
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:
Expand Down Expand Up @@ -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:
Expand All @@ -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
4 changes: 4 additions & 0 deletions docs/main.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`).
Expand Down

0 comments on commit 2452a73

Please sign in to comment.