Skip to content

[bug] src\meson.build:1:0: ERROR: prefix value '/' must be an absolute path #17204

Closed
@shoeffner

Description

@shoeffner

Describe the bug

When calling meson.configure() on Windows, it fails as meson considers the --prefix=/ as not being absolute on Windows. This is briefly theorized about in issue mesonbuild/meson#12880 which is referenced in the code, but unfortunately the assumption to set / as the prefix turns out to be wrong for Windows:

18:19:38  inih/58: RUN: meson setup --native-file "C:\conan_cache\b\inihdc984b83cfbdd\b\build\generators\conan_meson_native.ini" "C:\conan_cache\b\inihdc984b83cfbdd\b\build" "C:\conan_cache\inih574f2c03001fa\s\src" --prefix=/
18:19:38  conanvcvars.bat: Activating environment Visual Studio 17 - amd64 - winsdk_version=None - vcvars_ver=14.4
18:19:39  [vcvarsall.bat] Environment initialized for: 'x64'
18:19:40  [vcvarsall.bat] Environment initialized for: 'x64'
18:19:40  The Meson build system
18:19:40  Version: 1.6.0
18:19:40  Source dir: C:\conan_cache\inih574f2c03001fa\s\src
18:19:40  Build dir: C:\conan_cache\b\inihaa284fe8813d4\b\build
18:19:40  Build type: native build
18:19:40  
18:19:40  ..\..\..\..\inih574f2c03001fa\s\src\meson.build:1:0: ERROR: prefix value '/' must be an absolute path
18:19:40  
18:19:40  A full log can be found at C:\conan_cache\b\inihaa284fe8813d4\b\build\meson-logs\meson-log.txt

Replacing / with C:\ fixes it, however! One way to achieve this is to use f' --prefix={os.path.abspath("/")}' instead of the plain /. Another option is os.path.abspath('.').split(os.path.sep)[0]+os.path.sep from stackoverflow, but I believe os.path.abspath should be sufficient and work on all relevant OSs.

Conan versions: Tested with 2.4.1 and 2.8.1, also checked source from develop2 branch and it's still there
OS: Windows (Container: mcr.microsoft.com/dotnet/framework/runtime:4.8-windowsservercore-ltsc2022)
Meson: 1.6.0

How to reproduce it

This is a (not-so-minimal-but-)working example recipe. It's a bit convoluted as I extracted the bits and pieces from our shared code base etc., but in general it's enough to run any meson.configure() on Windows to trigger the error.

from conan import ConanFile
from conan.tools.meson import Meson, MesonToolchain
from conan.tools.cmake import cmake_layout
from conan.tools.files import collect_libs
from conan.tools.scm import Git

class Recipe(ConanFile):
    name = "inih"
    version = "58"
    url = "https://github.com/benhoyt/inih.git"
    package_type = "shared-library"
    settings = "os", "compiler", "build_type", "arch"
    options = {"fPIC": [True, False], "shared": [True, False]}

    def config_options(self):
        if self.settings.get_safe("os") == "Windows":
            self.options.rm_safe("fPIC")
        else:
            self.options.fPIC = True
        self.options.shared = True

    def generate(self):
        tc = MesonToolchain(self)
        tc.project_options["with_INIReader"] = True
        tc.project_options["distro_install"] = True
        if self.settings.os == "Windows":
            tc.project_options["default_library"] = "shared"
        tc.generate()

    def layout(self):
        cmake_layout(self, src_folder="src")

    def source(self):
        git = Git(self)
        git.clone(
            self.url,
            ".",
            ["--branch", f"r{self.version}", "--depth", "1"],
            hide_url=False,
        )

    def build(self):
        meson = Meson(self)
        meson.configure()
        meson.build()

    def package(self):
        meson = Meson(self)
        meson.install()

    def package_info(self):
        self.cpp_info.libs = collect_libs(self)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions