[libcamera-devel] libcamera: utils: Identify the 'real' build path

Message ID 20200429151919.2341586-1-kieran.bingham@ideasonboard.com
State Accepted
Commit 9e41dfbbffc59fab90aeb7bae34f2ca91c23b16e
Headers show
Series
  • [libcamera-devel] libcamera: utils: Identify the 'real' build path
Related show

Commit Message

Kieran Bingham April 29, 2020, 3:19 p.m. UTC
Call realpath() to strip out any levels of indirection required in
referencing the root build directory.

This simplifies the debug output when reporting and parsing paths.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
---
 src/libcamera/utils.cpp | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

Comments

Laurent Pinchart April 29, 2020, 3:42 p.m. UTC | #1
Hi Kieran,

Thank you for the patch.

On Wed, Apr 29, 2020 at 04:19:19PM +0100, Kieran Bingham wrote:
> Call realpath() to strip out any levels of indirection required in
> referencing the root build directory.
> 
> This simplifies the debug output when reporting and parsing paths.

Have you read the implementation fo libcameraSourcePath() by any chance
? :-)

> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
>  src/libcamera/utils.cpp | 11 ++++++++++-
>  1 file changed, 10 insertions(+), 1 deletion(-)
> 
> diff --git a/src/libcamera/utils.cpp b/src/libcamera/utils.cpp
> index a96ca7f40cbd..fbadf350908a 100644
> --- a/src/libcamera/utils.cpp
> +++ b/src/libcamera/utils.cpp
> @@ -386,7 +386,16 @@ std::string libcameraBuildPath()
>  	if (ret == 0)
>  		return std::string();
>  
> -	return dirname(info.dli_fname) + "/../../";
> +	std::string path = dirname(info.dli_fname) + "/../../";
> +
> +	char *real = realpath(path.c_str(), nullptr);
> +	if (!real)
> +		return std::string();
> +
> +	path = real;
> +	free(real);
> +
> +	return path + "/";
>  }
>  
>  /**
Kieran Bingham April 29, 2020, 3:45 p.m. UTC | #2
On 29/04/2020 16:42, Laurent Pinchart wrote:
> Hi Kieran,
> 
> Thank you for the patch.
> 
> On Wed, Apr 29, 2020 at 04:19:19PM +0100, Kieran Bingham wrote:
>> Call realpath() to strip out any levels of indirection required in
>> referencing the root build directory.
>>
>> This simplifies the debug output when reporting and parsing paths.
> 
> Have you read the implementation fo libcameraSourcePath() by any chance
> ? :-)
> 

Indeed ;-) - This makes the output much better and several levels of
/../../ on multiple prints for me.

>> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> 
> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

Thanks.

Kieran

> 
>> ---
>>  src/libcamera/utils.cpp | 11 ++++++++++-
>>  1 file changed, 10 insertions(+), 1 deletion(-)
>>
>> diff --git a/src/libcamera/utils.cpp b/src/libcamera/utils.cpp
>> index a96ca7f40cbd..fbadf350908a 100644
>> --- a/src/libcamera/utils.cpp
>> +++ b/src/libcamera/utils.cpp
>> @@ -386,7 +386,16 @@ std::string libcameraBuildPath()
>>  	if (ret == 0)
>>  		return std::string();
>>  
>> -	return dirname(info.dli_fname) + "/../../";
>> +	std::string path = dirname(info.dli_fname) + "/../../";
>> +
>> +	char *real = realpath(path.c_str(), nullptr);
>> +	if (!real)
>> +		return std::string();
>> +
>> +	path = real;
>> +	free(real);
>> +
>> +	return path + "/";
>>  }
>>  
>>  /**
>

Patch

diff --git a/src/libcamera/utils.cpp b/src/libcamera/utils.cpp
index a96ca7f40cbd..fbadf350908a 100644
--- a/src/libcamera/utils.cpp
+++ b/src/libcamera/utils.cpp
@@ -386,7 +386,16 @@  std::string libcameraBuildPath()
 	if (ret == 0)
 		return std::string();
 
-	return dirname(info.dli_fname) + "/../../";
+	std::string path = dirname(info.dli_fname) + "/../../";
+
+	char *real = realpath(path.c_str(), nullptr);
+	if (!real)
+		return std::string();
+
+	path = real;
+	free(real);
+
+	return path + "/";
 }
 
 /**