Skip to content

Commit

Permalink
use even more informative error message for invoking meson in a subdir
Browse files Browse the repository at this point in the history
Follow-up on commit 5a7b8d8

Sometimes, we find a parent meson.build which is also malformed, and we
shouldn't suggest that maybe the user meant to use that, if it isn't a
valid project() either. Do a rough and dirty check to see if the very
first line is a project() declaration, and if not, don't try to be
clever and suggest using it.

The "invalid source tree" error suffices here, since we're not
absolutely sure meson can be successfully run in that parent directory
and actually advising people about the wrong location is a lot more
confusing than just saying "please figure this out yourself, here is
what to look for".

Granted, we miss cases where project() comes after blank lines and/or
comments, but doing a full AST parse here is excessively overkill and
probably too painful to do, and we don't need to be *that* clever. So
let's be content with merely going above and beyond the call of duty.
  • Loading branch information
eli-schwartz committed Aug 22, 2021
1 parent aad986b commit 2a71259
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion mesonbuild/interpreterbase/interpreterbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,10 @@ def sanity_check_ast(self) -> None:
found = p
for parent in p.parents:
if (parent / 'meson.build').is_file():
found = parent
with open(parent / 'meson.build', encoding='utf-8') as f:
if f.readline().startswith('project('):
found = parent
break
else:
break

Expand Down

0 comments on commit 2a71259

Please sign in to comment.