diff mbox series

[v2,1/1] utils/genrandconfig: make default toolchain_csv path absolute

Message ID 20230215211531.331246-1-james.hilliard1@gmail.com
State New
Headers show
Series [v2,1/1] utils/genrandconfig: make default toolchain_csv path absolute | expand

Commit Message

James Hilliard Feb. 15, 2023, 9:15 p.m. UTC
The default toolchain_csv path is a relative path to the buildroot
directory.

If we run genrandconfig with a cwd that is not the buildroot directory
the default toolchain_csv path will be wrong.

To fix this make the default toolchain_csv path absolute.

Fixes:
FileNotFoundError: [Errno 2] No such file or directory: 'support/config-fragments/autobuild/toolchain-configs.csv'

Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
---
Changes v1 -> v2:
  - set default path as absolute
---
 utils/genrandconfig | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Arnout Vandecappelle Feb. 15, 2023, 9:20 p.m. UTC | #1
On 15/02/2023 22:15, James Hilliard wrote:
> The default toolchain_csv path is a relative path to the buildroot
> directory.
> 
> If we run genrandconfig with a cwd that is not the buildroot directory
> the default toolchain_csv path will be wrong.
> 
> To fix this make the default toolchain_csv path absolute.
> 
> Fixes:
> FileNotFoundError: [Errno 2] No such file or directory: 'support/config-fragments/autobuild/toolchain-configs.csv'
> 
> Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
> ---
> Changes v1 -> v2:
>    - set default path as absolute
> ---
>   utils/genrandconfig | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/utils/genrandconfig b/utils/genrandconfig
> index b3576f8a51..3552b83694 100755
> --- a/utils/genrandconfig
> +++ b/utils/genrandconfig
> @@ -801,7 +801,9 @@ if __name__ == '__main__':
>                                   dest="toolchains_csv",
>                                   help="Generate random toolchain configuration",
>                                   action='store_false')
> -    parser.set_defaults(toolchains_csv="support/config-fragments/autobuild/toolchain-configs.csv")
> +    buildroot_abs = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
> +    parser.set_defaults(toolchains_csv=os.path.join(buildroot_abs,
> +                        "support/config-fragments/autobuild/toolchain-configs.csv"))

  Sorry, that's not going to work either (if it was that easy I'd done it myself :-)

  buildrootdir can be set to something else with the -b argument, and we want it 
relative to *that* one of course.

  Regards,
  Arnout

>   
>       args = parser.parse_args()
>
James Hilliard Feb. 15, 2023, 9:29 p.m. UTC | #2
On Wed, Feb 15, 2023 at 2:20 PM Arnout Vandecappelle <arnout@mind.be> wrote:
>
>
>
> On 15/02/2023 22:15, James Hilliard wrote:
> > The default toolchain_csv path is a relative path to the buildroot
> > directory.
> >
> > If we run genrandconfig with a cwd that is not the buildroot directory
> > the default toolchain_csv path will be wrong.
> >
> > To fix this make the default toolchain_csv path absolute.
> >
> > Fixes:
> > FileNotFoundError: [Errno 2] No such file or directory: 'support/config-fragments/autobuild/toolchain-configs.csv'
> >
> > Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
> > ---
> > Changes v1 -> v2:
> >    - set default path as absolute
> > ---
> >   utils/genrandconfig | 4 +++-
> >   1 file changed, 3 insertions(+), 1 deletion(-)
> >
> > diff --git a/utils/genrandconfig b/utils/genrandconfig
> > index b3576f8a51..3552b83694 100755
> > --- a/utils/genrandconfig
> > +++ b/utils/genrandconfig
> > @@ -801,7 +801,9 @@ if __name__ == '__main__':
> >                                   dest="toolchains_csv",
> >                                   help="Generate random toolchain configuration",
> >                                   action='store_false')
> > -    parser.set_defaults(toolchains_csv="support/config-fragments/autobuild/toolchain-configs.csv")
> > +    buildroot_abs = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
> > +    parser.set_defaults(toolchains_csv=os.path.join(buildroot_abs,
> > +                        "support/config-fragments/autobuild/toolchain-configs.csv"))
>
>   Sorry, that's not going to work either (if it was that easy I'd done it myself :-)

Under what scenario would this break?

>
>   buildrootdir can be set to something else with the -b argument, and we want it
> relative to *that* one of course.

Using buildrootdir is cwd dependent, the approach I used is not as it uses the
absolute path of the genrandconfig file to compute the default toolchain_csv
abs path.

>
>   Regards,
>   Arnout
>
> >
> >       args = parser.parse_args()
> >
Arnout Vandecappelle Feb. 15, 2023, 9:46 p.m. UTC | #3
On 15/02/2023 22:29, James Hilliard wrote:
> On Wed, Feb 15, 2023 at 2:20 PM Arnout Vandecappelle <arnout@mind.be> wrote:
>>
>>
>>
>> On 15/02/2023 22:15, James Hilliard wrote:
>>> The default toolchain_csv path is a relative path to the buildroot
>>> directory.
>>>
>>> If we run genrandconfig with a cwd that is not the buildroot directory
>>> the default toolchain_csv path will be wrong.
>>>
>>> To fix this make the default toolchain_csv path absolute.
>>>
>>> Fixes:
>>> FileNotFoundError: [Errno 2] No such file or directory: 'support/config-fragments/autobuild/toolchain-configs.csv'
>>>
>>> Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
>>> ---
>>> Changes v1 -> v2:
>>>     - set default path as absolute
>>> ---
>>>    utils/genrandconfig | 4 +++-
>>>    1 file changed, 3 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/utils/genrandconfig b/utils/genrandconfig
>>> index b3576f8a51..3552b83694 100755
>>> --- a/utils/genrandconfig
>>> +++ b/utils/genrandconfig
>>> @@ -801,7 +801,9 @@ if __name__ == '__main__':
>>>                                    dest="toolchains_csv",
>>>                                    help="Generate random toolchain configuration",
>>>                                    action='store_false')
>>> -    parser.set_defaults(toolchains_csv="support/config-fragments/autobuild/toolchain-configs.csv")
>>> +    buildroot_abs = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
>>> +    parser.set_defaults(toolchains_csv=os.path.join(buildroot_abs,
>>> +                        "support/config-fragments/autobuild/toolchain-configs.csv"))
>>
>>    Sorry, that's not going to work either (if it was that easy I'd done it myself :-)
> 
> Under what scenario would this break?

  I have ~/src/buildroot/utils in my PATH, so I just run 'genrandconfig' from 
path. If I want to run it in a different worktree (e.g. ~/src/buildroot-next 
which tracks the next branch), I would go to that directory and run 
"genrandconfig", so it would use the one in ~/src/buildroot, not the one in 
~/sr/buildroot-next. In that case, of course, I want to use the 
toolchain-configs.csv from the next branch, not the one from ~/src/buildroot.


>>    buildrootdir can be set to something else with the -b argument, and we want it
>> relative to *that* one of course.
> 
> Using buildrootdir is cwd dependent,

  The default value is cwd dependent; the value you give with the -b option can 
be absolute or relative.

> the approach I used is not as it uses the
> absolute path of the genrandconfig file to compute the default toolchain_csv
> abs path.

  And my point is that it should be relative to the buildrootdir given with the 
commandline option, not relative to the place where genrandconfig happens to reside.

  TBH, I think genrandonfig has too many options :-)

  Regards,
  Arnout

> 
>>
>>    Regards,
>>    Arnout
>>
>>>
>>>        args = parser.parse_args()
>>>
James Hilliard Feb. 15, 2023, 9:57 p.m. UTC | #4
On Wed, Feb 15, 2023 at 2:46 PM Arnout Vandecappelle <arnout@mind.be> wrote:
>
>
>
> On 15/02/2023 22:29, James Hilliard wrote:
> > On Wed, Feb 15, 2023 at 2:20 PM Arnout Vandecappelle <arnout@mind.be> wrote:
> >>
> >>
> >>
> >> On 15/02/2023 22:15, James Hilliard wrote:
> >>> The default toolchain_csv path is a relative path to the buildroot
> >>> directory.
> >>>
> >>> If we run genrandconfig with a cwd that is not the buildroot directory
> >>> the default toolchain_csv path will be wrong.
> >>>
> >>> To fix this make the default toolchain_csv path absolute.
> >>>
> >>> Fixes:
> >>> FileNotFoundError: [Errno 2] No such file or directory: 'support/config-fragments/autobuild/toolchain-configs.csv'
> >>>
> >>> Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
> >>> ---
> >>> Changes v1 -> v2:
> >>>     - set default path as absolute
> >>> ---
> >>>    utils/genrandconfig | 4 +++-
> >>>    1 file changed, 3 insertions(+), 1 deletion(-)
> >>>
> >>> diff --git a/utils/genrandconfig b/utils/genrandconfig
> >>> index b3576f8a51..3552b83694 100755
> >>> --- a/utils/genrandconfig
> >>> +++ b/utils/genrandconfig
> >>> @@ -801,7 +801,9 @@ if __name__ == '__main__':
> >>>                                    dest="toolchains_csv",
> >>>                                    help="Generate random toolchain configuration",
> >>>                                    action='store_false')
> >>> -    parser.set_defaults(toolchains_csv="support/config-fragments/autobuild/toolchain-configs.csv")
> >>> +    buildroot_abs = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
> >>> +    parser.set_defaults(toolchains_csv=os.path.join(buildroot_abs,
> >>> +                        "support/config-fragments/autobuild/toolchain-configs.csv"))
> >>
> >>    Sorry, that's not going to work either (if it was that easy I'd done it myself :-)
> >
> > Under what scenario would this break?
>
>   I have ~/src/buildroot/utils in my PATH, so I just run 'genrandconfig' from
> path. If I want to run it in a different worktree (e.g. ~/src/buildroot-next
> which tracks the next branch), I would go to that directory and run
> "genrandconfig", so it would use the one in ~/src/buildroot, not the one in
> ~/sr/buildroot-next. In that case, of course, I want to use the
> toolchain-configs.csv from the next branch, not the one from ~/src/buildroot.

Well you can still do that by passing the relative path via --toolchains-csv to
override the default abs path.

>
>
> >>    buildrootdir can be set to something else with the -b argument, and we want it
> >> relative to *that* one of course.
> >
> > Using buildrootdir is cwd dependent,
>
>   The default value is cwd dependent; the value you give with the -b option can
> be absolute or relative.

Yeah, but I think making it an abs path relative to the genrandconfig
file as the
default is less likely to cause unexpected issues. Having it relative
to cwd when
not passing an option is a bit unexpected IMO.

>
> > the approach I used is not as it uses the
> > absolute path of the genrandconfig file to compute the default toolchain_csv
> > abs path.
>
>   And my point is that it should be relative to the buildrootdir given with the
> commandline option, not relative to the place where genrandconfig happens to reside.

It's still relative to cwd when passing a relative path via
--toolchains-csv, just the
default is changed to be an abs path.

>
>   TBH, I think genrandonfig has too many options :-)
>
>   Regards,
>   Arnout
>
> >
> >>
> >>    Regards,
> >>    Arnout
> >>
> >>>
> >>>        args = parser.parse_args()
> >>>
diff mbox series

Patch

diff --git a/utils/genrandconfig b/utils/genrandconfig
index b3576f8a51..3552b83694 100755
--- a/utils/genrandconfig
+++ b/utils/genrandconfig
@@ -801,7 +801,9 @@  if __name__ == '__main__':
                                 dest="toolchains_csv",
                                 help="Generate random toolchain configuration",
                                 action='store_false')
-    parser.set_defaults(toolchains_csv="support/config-fragments/autobuild/toolchain-configs.csv")
+    buildroot_abs = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
+    parser.set_defaults(toolchains_csv=os.path.join(buildroot_abs,
+                        "support/config-fragments/autobuild/toolchain-configs.csv"))
 
     args = parser.parse_args()