Bug 482983 - Meson project with missing dependency re configures in infinite loop
Summary: Meson project with missing dependency re configures in infinite loop
Status: RESOLVED FIXED
Alias: None
Product: kdevelop
Classification: Applications
Component: Build tools: Meson (show other bugs)
Version: 5.12.230802
Platform: Neon Linux
: NOR normal
Target Milestone: ---
Assignee: kdevelop-bugs-null
URL:
Keywords: qt6
Depends on:
Blocks:
 
Reported: 2024-03-09 14:31 UTC by frmdstryr
Modified: 2024-04-05 10:54 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In: 5.14
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description frmdstryr 2024-03-09 14:31:22 UTC
SUMMARY

If a required dependency is missing in a project using the meson build system KDevelop keeps trying to reconfigure the project in an infinite loop. 


STEPS TO REPRODUCE
1. Clone a project that uses meson (eg horizon-eda)
2. Add a missing dependency or uninstall a required dependency
3. Configure the project in KDevelop or in a terminal

OBSERVED RESULT

KDevelop keeps trying to reconfigure in an infinite loop.

EXPECTED RESULT

It should run configure once, fail, then stop.

SOFTWARE/OS VERSIONS
Windows: 
macOS: 
Linux/KDE Plasma: 6.0.0
(available in About System)
KDE Plasma Version: 6.0.0
KDE Frameworks Version: 6.0.0
Qt Version: 6.6.2

ADDITIONAL INFORMATION

It seems like there is something triggering a reconfigure on a file change since running meson in a separate terminal in the build folder causes KDevelop to start reconfiguring.
Comment 1 Igor Kushnir 2024-03-09 14:57:51 UTC
A fix merge request at https://invent.kde.org/kdevelop/kdevelop/-/merge_requests is welcome. Note that few KDevelop developers use Meson, so the KDevMesonManager plugin is not actively maintained. But users occasionally contribute small fixes to Meson support.
Comment 2 frmdstryr 2024-03-09 20:50:20 UTC
(In reply to Igor Kushnir from comment #1)
> A fix merge request at
> https://invent.kde.org/kdevelop/kdevelop/-/merge_requests is welcome. Note
> that few KDevelop developers use Meson, so the KDevMesonManager plugin is
> not actively maintained. But users occasionally contribute small fixes to
> Meson support.

I pushed a branch that stops the loop to github https://github.com/KDE/kdevelop/compare/master...frmdstryr:kdevelop:meson-info-only-reparse-if-contents-changed .  I had problems pushing to invent.
Comment 3 Igor Kushnir 2024-03-10 11:42:47 UTC
(In reply to frmdstryr from comment #2)
> I pushed a branch that stops the loop to github
> https://github.com/KDE/kdevelop/compare/master...frmdstryr:kdevelop:meson-info-only-reparse-if-contents-changed
> .  I had problems pushing to invent.
What problem? Did you fork the KDevelop repository? Tried pushing to an SSH URL, e.g. git@invent.kde.org:frmdstryr/kdevelop.git ? If the bug is present only in the branch work/apol/kf6, target it in your merge request.
Comment 4 frmdstryr 2024-03-27 13:10:33 UTC
(In reply to Igor Kushnir from comment #3)
> (In reply to frmdstryr from comment #2)
> > I pushed a branch that stops the loop to github
> > https://github.com/KDE/kdevelop/compare/master...frmdstryr:kdevelop:meson-info-only-reparse-if-contents-changed
> > .  I had problems pushing to invent.
> What problem? Did you fork the KDevelop repository? Tried pushing to an SSH
> URL, e.g. git@invent.kde.org:frmdstryr/kdevelop.git ? If the bug is present
> only in the branch work/apol/kf6, target it in your merge request.

I figured it out and pushed to https://invent.kde.org/frmdstryr/kdevelop/-/tree/meson-info-only-reparse-if-contents-changed?ref_type=heads . 

This issue is unrelated to KF6 from what I can tell. The file watcher triggers when the meson file stats change even if no contents changed.
Comment 5 Igor Kushnir 2024-03-27 19:16:46 UTC
(In reply to frmdstryr from comment #4)
> This issue is unrelated to KF6 from what I can tell. The file watcher
> triggers when the meson file stats change even if no contents changed.
Rebase on master and create a merge request at https://invent.kde.org/kdevelop/kdevelop/-/merge_requests please. Maybe expand the commit message to explain the bug and the fix better. Add the following after a blank line at the bottom of the commit message to comment and automatically close this bug when merged:
BUG: 482983
FIXED-IN: 5.14
Comment 6 Bug Janitor Service 2024-03-29 20:15:22 UTC
A possibly relevant merge request was started @ https://invent.kde.org/kdevelop/kdevelop/-/merge_requests/545
Comment 7 Igor Kushnir 2024-03-30 09:03:39 UTC
I cannot reproduce the infinite loop when I add a bogus dependency to the simple meson project created from a KDevelop template (Standard=>Terminal=>Meson C++):
```
+ bb=dependency('missingd', version:'>=5.0')
 executable('kdev-meson-cpp-test-project',
            'main.cpp',
            include_directories : incdir
+           , dependencies : bb
```

The configuration job fails once and is not restarted:
```
Run-time dependency missingd found: NO (tried pkgconfig and cmake)

meson.build:15:3: ERROR: Dependency "missingd" not found, tried pkgconfig and cmake

A full log can be found at /path/to/kdev-meson-cpp-test-project/build/meson-logs/meson-log.txt
*** Failure: Exit code 1 ***
```

Is some additional configuration of the project or KDevelop needed?
Comment 8 frmdstryr 2024-03-30 11:04:10 UTC
(In reply to Igor Kushnir from comment #7)
> I cannot reproduce the infinite loop when I add a bogus dependency to the
> simple meson project created from a KDevelop template
> (Standard=>Terminal=>Meson C++):
> ```
> + bb=dependency('missingd', version:'>=5.0')
>  executable('kdev-meson-cpp-test-project',
>             'main.cpp',
>             include_directories : incdir
> +           , dependencies : bb
> ```
> 
> The configuration job fails once and is not restarted:
> ```
> Run-time dependency missingd found: NO (tried pkgconfig and cmake)
> 
> meson.build:15:3: ERROR: Dependency "missingd" not found, tried pkgconfig
> and cmake
> 
> A full log can be found at
> /path/to/kdev-meson-cpp-test-project/build/meson-logs/meson-log.txt
> *** Failure: Exit code 1 ***
> ```
> 
> Is some additional configuration of the project or KDevelop needed?

Does the build/meson-info/meson-info.json file exist?  It occurred for a project (https://github.com/horizon-eda/horizon) that was already imported and built but then I updated a library version that meson could not find.
Comment 9 frmdstryr 2024-03-30 11:19:25 UTC
(In reply to frmdstryr from comment #8)
> (In reply to Igor Kushnir from comment #7)
> > I cannot reproduce the infinite loop when I add a bogus dependency to the
> > simple meson project created from a KDevelop template
> > (Standard=>Terminal=>Meson C++):
> > ```
> > + bb=dependency('missingd', version:'>=5.0')
> >  executable('kdev-meson-cpp-test-project',
> >             'main.cpp',
> >             include_directories : incdir
> > +           , dependencies : bb
> > ```
> > 
> > The configuration job fails once and is not restarted:
> > ```
> > Run-time dependency missingd found: NO (tried pkgconfig and cmake)
> > 
> > meson.build:15:3: ERROR: Dependency "missingd" not found, tried pkgconfig
> > and cmake
> > 
> > A full log can be found at
> > /path/to/kdev-meson-cpp-test-project/build/meson-logs/meson-log.txt
> > *** Failure: Exit code 1 ***
> > ```
> > 
> > Is some additional configuration of the project or KDevelop needed?
> 
> Does the build/meson-info/meson-info.json file exist?  It occurred for a
> project (https://github.com/horizon-eda/horizon) that was already imported
> and built but then I updated a library version that meson could not find.

I also cannot reproduce with the template project, let me see what else it required for this to happen.
Comment 10 frmdstryr 2024-03-30 12:02:45 UTC
(In reply to frmdstryr from comment #9)
> (In reply to frmdstryr from comment #8)
> > (In reply to Igor Kushnir from comment #7)
> > > I cannot reproduce the infinite loop when I add a bogus dependency to the
> > > simple meson project created from a KDevelop template
> > > (Standard=>Terminal=>Meson C++):
> > > ```
> > > + bb=dependency('missingd', version:'>=5.0')
> > >  executable('kdev-meson-cpp-test-project',
> > >             'main.cpp',
> > >             include_directories : incdir
> > > +           , dependencies : bb
> > > ```
> > > 
> > > The configuration job fails once and is not restarted:
> > > ```
> > > Run-time dependency missingd found: NO (tried pkgconfig and cmake)
> > > 
> > > meson.build:15:3: ERROR: Dependency "missingd" not found, tried pkgconfig
> > > and cmake
> > > 
> > > A full log can be found at
> > > /path/to/kdev-meson-cpp-test-project/build/meson-logs/meson-log.txt
> > > *** Failure: Exit code 1 ***
> > > ```
> > > 
> > > Is some additional configuration of the project or KDevelop needed?
> > 
> > Does the build/meson-info/meson-info.json file exist?  It occurred for a
> > project (https://github.com/horizon-eda/horizon) that was already imported
> > and built but then I updated a library version that meson could not find.
> 
> I also cannot reproduce with the template project, let me see what else it
> required for this to happen.

Ok, it was more complicated to reproduce:

1. Create the project using the meson template 
2. Build the project
3. Add a line in meson.build to introduce an error like a non-existent library or missing version
4. Run prune
5. Run build or configure again and the loop should start

There may be an better/easier way to fix it since it seems like a race condition because there is a watch on create and dirty it so the job appears to be running twice in parallel.
Comment 11 Igor Kushnir 2024-03-30 17:53:38 UTC
(In reply to frmdstryr from comment #10)
> There may be an better/easier way to fix it since it seems like a race
> condition because there is a watch on create and dirty it so the job appears
> to be running twice in parallel.
Sorry, haven't noticed the suggestion about a better fix before reviewing your merge request. I think the Meson configure job creates the file. The MESON_FAILED_CONFIGURATION branch in MesonBuilder::configure() is taken. But I don't know how to fix this properly. Detect the configure loop and break it somehow? Would that be better than the relatively simple and safe file hash sum approach in the merge request?
Comment 12 Igor Kushnir 2024-04-05 10:54:22 UTC
Git commit 341638803895bd9910f8d79a4942733b21f75ff3 by Igor Kushnir, on behalf of Jairus Martin.
Committed on 05/04/2024 at 10:54.
Pushed by igorkushnir into branch 'master'.

Only reparse project if meson-info contents change

Currently there is a file watcher that reloads the project when the
meson-info.json file changes. If the project fails to configure,
kdevelop keeps attempting to reconfigure in a loop because the
meson-info.json file keeps getting rewritten. This change makes it
only reconfigure if the contents of the watched file are actually
changed avoiding the loop.
FIXED-IN: 5.14

M  +25   -0    plugins/meson/mesonmanager.cpp
M  +1    -0    plugins/meson/mesonmanager.h

https://invent.kde.org/kdevelop/kdevelop/-/commit/341638803895bd9910f8d79a4942733b21f75ff3