Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File: Add full_path() method #12408

Merged
merged 1 commit into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/markdown/snippets/file-full-path.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## File object now has `full_path()` method

Returns a full path pointing to the file. This is useful for printing the path
with e.g [[message]] function for debugging purpose.

**NOTE:** In most cases using the object itself will do the same job
as this and will also allow Meson to setup dependencies correctly.
12 changes: 11 additions & 1 deletion docs/yaml/objects/file.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
name: file
long_name: File
description: Opaque object that stores the path to an existing file
description: Object that stores the path to an existing file

methods:
- name: full_path
returns: str
xclaesse marked this conversation as resolved.
Show resolved Hide resolved
since: 1.4.0
description: |
Returns a full path pointing to the file. This is useful for printing the
path with e.g [[message]] function for debugging purpose.
**NOTE:** In most cases using the object itself will do the same job
as this and will also allow Meson to setup dependencies correctly.
11 changes: 10 additions & 1 deletion mesonbuild/interpreter/interpreterobjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,16 @@ class IncludeDirsHolder(ObjectHolder[build.IncludeDirs]):
pass

class FileHolder(ObjectHolder[mesonlib.File]):
pass
def __init__(self, file: mesonlib.File, interpreter: 'Interpreter'):
super().__init__(file, interpreter)
self.methods.update({'full_path': self.full_path_method,
})

@noPosargs
@noKwargs
@FeatureNew('file.full_path', '1.4.0')
def full_path_method(self, args: T.List[TYPE_var], kwargs: TYPE_kwargs) -> str:
xclaesse marked this conversation as resolved.
Show resolved Hide resolved
return self.held_object.absolute_path(self.env.source_dir, self.env.build_dir)

class HeadersHolder(ObjectHolder[build.Headers]):
pass
Expand Down
6 changes: 6 additions & 0 deletions test cases/common/74 file object/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,9 @@ test('fobj', executable('fobj', prog0, lib0))

subdir('subdir1')
subdir('subdir2')

# Use fs.as_posix() because / operator replaces \ with / in the path, but
# full_path() method is not doing that. This is a pretty inconsistent across all
# Meson APIs.
fs = import('fs')
assert(fs.as_posix(prog0[0].full_path()) == fs.as_posix(meson.current_source_dir() / 'prog.c'))
Loading