Skip to content

Cleanup and modernize the templates and commands used by meson init - #14086

Merged
jpakkane merged 13 commits into
mesonbuild:masterfrom
dcbaker:submit/modernize-templates
Jan 26, 2025
Merged

jpakkane merged 13 commits into
mesonbuild:masterfrom
dcbaker:submit/modernize-templates

Conversation

@dcbaker

@dcbaker dcbaker commented Jan 7, 2025

Copy link
Copy Markdown
Member

There's a couple of changes here. There's some just plain code cleanups, there's some formatting work, some replacement of deprecated methods, and some work to combine the templates and make them more powerful.

On that work I've done the following:

  • combined the "brand new project" and "add Meson to a project" paths to use the same code, this has enhanced both paths
  • updating the pkg-config API usage to use the "lib as a positional argument" approach
  • updating the way Meson version is handled to allow each template to set its own minimum
  • call meson.override_dependency() when we create the dependency for subprojects
  • use library() and <lang>_shared_args instead of shared_library

@dcbaker
dcbaker requested a review from jpakkane as a code owner January 7, 2025 17:06
from mesonbuild.templates.sampleimpl import FileHeaderImpl

if T.TYPE_CHECKING:
from ..minit import Arguments

Check failure

Code scanning / CodeQL

Module-level cyclic import

'Arguments' may not be defined if module [mesonbuild.minit](1) is imported before module [mesonbuild.templates.cpptemplates](2), as the [definition](3) of Arguments occurs after the cyclic [import](4) of mesonbuild.templates.cpptemplates. 'Arguments' may not be defined if module [mesonbuild.minit](1) is imported before module [mesonbuild.templates.cpptemplates](2), as the [definition](3) of Arguments occurs after the cyclic [import](5) of mesonbuild.templates.cpptemplates. 'Arguments' may not be defined if module [mesonbuild.minit](1) is imported before module [mesonbuild.templates.cpptemplates](2), as the [definition](6) of Arguments occurs after the cyclic [import](4) of mesonbuild.templates.cpptemplates. 'Arguments' may not be defined if module [mesonbuild.minit](1) is imported before module [mesonbuild.templates.cpptemplates](2), as the [definition](6) of Arguments occurs after the cyclic [import](5) of mesonbuild.templates.cpptemplates.
Comment thread mesonbuild/templates/ctemplates.py Fixed
from mesonbuild.templates.sampleimpl import FileHeaderImpl

if T.TYPE_CHECKING:
from ..minit import Arguments

Check failure

Code scanning / CodeQL

Module-level cyclic import

'Arguments' may not be defined if module [mesonbuild.minit](1) is imported before module [mesonbuild.templates.ctemplates](2), as the [definition](3) of Arguments occurs after the cyclic [import](4) of mesonbuild.templates.ctemplates. 'Arguments' may not be defined if module [mesonbuild.minit](1) is imported before module [mesonbuild.templates.ctemplates](2), as the [definition](3) of Arguments occurs after the cyclic [import](5) of mesonbuild.templates.ctemplates. 'Arguments' may not be defined if module [mesonbuild.minit](1) is imported before module [mesonbuild.templates.ctemplates](2), as the [definition](6) of Arguments occurs after the cyclic [import](4) of mesonbuild.templates.ctemplates. 'Arguments' may not be defined if module [mesonbuild.minit](1) is imported before module [mesonbuild.templates.ctemplates](2), as the [definition](6) of Arguments occurs after the cyclic [import](5) of mesonbuild.templates.ctemplates.
from mesonbuild.templates.sampleimpl import FileHeaderImpl

if T.TYPE_CHECKING:
from ..minit import Arguments

Check failure

Code scanning / CodeQL

Module-level cyclic import

'Arguments' may not be defined if module [mesonbuild.minit](1) is imported before module [mesonbuild.templates.cudatemplates](2), as the [definition](3) of Arguments occurs after the cyclic [import](4) of mesonbuild.templates.cudatemplates. 'Arguments' may not be defined if module [mesonbuild.minit](1) is imported before module [mesonbuild.templates.cudatemplates](2), as the [definition](3) of Arguments occurs after the cyclic [import](5) of mesonbuild.templates.cudatemplates. 'Arguments' may not be defined if module [mesonbuild.minit](1) is imported before module [mesonbuild.templates.cudatemplates](2), as the [definition](6) of Arguments occurs after the cyclic [import](4) of mesonbuild.templates.cudatemplates. 'Arguments' may not be defined if module [mesonbuild.minit](1) is imported before module [mesonbuild.templates.cudatemplates](2), as the [definition](6) of Arguments occurs after the cyclic [import](5) of mesonbuild.templates.cudatemplates.
from mesonbuild.templates.sampleimpl import FileImpl

if T.TYPE_CHECKING:
from ..minit import Arguments

Check failure

Code scanning / CodeQL

Module-level cyclic import

'Arguments' may not be defined if module [mesonbuild.minit](1) is imported before module [mesonbuild.templates.fortrantemplates](2), as the [definition](3) of Arguments occurs after the cyclic [import](4) of mesonbuild.templates.fortrantemplates. 'Arguments' may not be defined if module [mesonbuild.minit](1) is imported before module [mesonbuild.templates.fortrantemplates](2), as the [definition](3) of Arguments occurs after the cyclic [import](5) of mesonbuild.templates.fortrantemplates. 'Arguments' may not be defined if module [mesonbuild.minit](1) is imported before module [mesonbuild.templates.fortrantemplates](2), as the [definition](6) of Arguments occurs after the cyclic [import](4) of mesonbuild.templates.fortrantemplates. 'Arguments' may not be defined if module [mesonbuild.minit](1) is imported before module [mesonbuild.templates.fortrantemplates](2), as the [definition](6) of Arguments occurs after the cyclic [import](5) of mesonbuild.templates.fortrantemplates.

import typing as T

from .samplefactory import sample_generator

Check failure

Code scanning / CodeQL

Module-level cyclic import

'sample_generator' may not be defined if module [mesonbuild.templates.samplefactory](1) is imported before module [mesonbuild.templates.mesontemplates](2), as the [definition](3) of sample_generator occurs after the cyclic [import](4) of mesonbuild.templates.mesontemplates. 'sample_generator' may not be defined if module [mesonbuild.templates.samplefactory](1) is imported before module [mesonbuild.templates.mesontemplates](2), as the [definition](3) of sample_generator occurs after the cyclic [import](5) of mesonbuild.templates.mesontemplates. 'sample_generator' may not be defined if module [mesonbuild.templates.samplefactory](1) is imported before module [mesonbuild.templates.mesontemplates](2), as the [definition](3) of sample_generator occurs after the cyclic [import](6) of mesonbuild.templates.mesontemplates. 'sample_generator' may not be defined if module [mesonbuild.templates.samplefactory](1) is imported before module [mesonbuild.templates.mesontemplates](2), as the [definition](3) of sample_generator occurs after the cyclic [import](7) of mesonbuild.templates.mesontemplates. 'sample_generator' may not be defined if module [mesonbuild.templates.samplefactory](1) is imported before module [mesonbuild.templates.mesontemplates](2), as the [definition](3) of sample_generator occurs after the cyclic [import](8) of mesonbuild.templates.mesontemplates. 'sample_generator' may not be defined if module [mesonbuild.templates.samplefactory](1) is imported before module [mesonbuild.templates.mesontemplates](2), as the [definition](3) of sample_generator occurs after the cyclic [import](9) of mesonbuild.templates.mesontemplates. 'sample_generator' may not be defined if module [mesonbuild.templates.samplefactory](1) is imported before module [mesonbuild.templates.mesontemplates](2), as the [definition](3) of sample_generator occurs after the cyclic [import](10) of mesonbuild.templates.mesontemplates. 'sample_generator' may not be defined if module [mesonbuild.templates.samplefactory](1) is imported before module [mesonbuild.templates.mesontemplates](2), as the [definition](3) of sample_generator occurs after the cyclic [import](11) of mesonbuild.templates.mesontemplates. 'sample_generator' may not be defined if module [mesonbuild.templates.samplefactory](1) is imported before module [mesonbuild.templates.mesontemplates](2), as the [definition](3) of sample_generator occurs after the cyclic [import](12) of mesonbuild.templates.mesontemplates. 'sample_generator' may not be defined if module [mesonbuild.templates.samplefactory](1) is imported before module [mesonbuild.templates.mesontemplates](2), as the [definition](3) of sample_generator occurs after the cyclic [import](13) of mesonbuild.templates.mesontemplates. 'sample_generator' may not be defined if module [mesonbuild.templates.samplefactory](1) is imported before module [mesonbuild.templates.mesontemplates](2), as the [definition](3) of sample_generator occurs after the cyclic [import](14) of mesonbuild.templates.mesontemplates. 'sample_generator' may not be defined if module [mesonbuild.templates.samplefactory](1) is imported before module [mesonbuild.templates.mesontemplates](2), as the [definition](3) of sample_generator occurs after the cyclic [import](15) of mesonbuild.templates.mesontemplates. 'sample_generator' may not be defined if module [mesonbuild.templates.samplefactory](1) is imported before module [mesonbuild.templates.mesontemplates](2), as the [definition](3) of sample_generator occurs after the cyclic [import](16) of mesonbuild.templates.mesontemplates.
from mesonbuild.templates.sampleimpl import FileHeaderImpl

if T.TYPE_CHECKING:
from ..minit import Arguments

Check failure

Code scanning / CodeQL

Module-level cyclic import

'Arguments' may not be defined if module [mesonbuild.minit](1) is imported before module [mesonbuild.templates.objcpptemplates](2), as the [definition](3) of Arguments occurs after the cyclic [import](4) of mesonbuild.templates.objcpptemplates. 'Arguments' may not be defined if module [mesonbuild.minit](1) is imported before module [mesonbuild.templates.objcpptemplates](2), as the [definition](3) of Arguments occurs after the cyclic [import](5) of mesonbuild.templates.objcpptemplates. 'Arguments' may not be defined if module [mesonbuild.minit](1) is imported before module [mesonbuild.templates.objcpptemplates](2), as the [definition](6) of Arguments occurs after the cyclic [import](4) of mesonbuild.templates.objcpptemplates. 'Arguments' may not be defined if module [mesonbuild.minit](1) is imported before module [mesonbuild.templates.objcpptemplates](2), as the [definition](6) of Arguments occurs after the cyclic [import](5) of mesonbuild.templates.objcpptemplates.
from mesonbuild.templates.sampleimpl import FileHeaderImpl

if T.TYPE_CHECKING:
from ..minit import Arguments

Check failure

Code scanning / CodeQL

Module-level cyclic import

'Arguments' may not be defined if module [mesonbuild.minit](1) is imported before module [mesonbuild.templates.objctemplates](2), as the [definition](3) of Arguments occurs after the cyclic [import](4) of mesonbuild.templates.objctemplates. 'Arguments' may not be defined if module [mesonbuild.minit](1) is imported before module [mesonbuild.templates.objctemplates](2), as the [definition](3) of Arguments occurs after the cyclic [import](5) of mesonbuild.templates.objctemplates. 'Arguments' may not be defined if module [mesonbuild.minit](1) is imported before module [mesonbuild.templates.objctemplates](2), as the [definition](6) of Arguments occurs after the cyclic [import](4) of mesonbuild.templates.objctemplates. 'Arguments' may not be defined if module [mesonbuild.minit](1) is imported before module [mesonbuild.templates.objctemplates](2), as the [definition](6) of Arguments occurs after the cyclic [import](5) of mesonbuild.templates.objctemplates.
from mesonbuild.templates.sampleimpl import FileImpl

if T.TYPE_CHECKING:
from ..minit import Arguments

Check failure

Code scanning / CodeQL

Module-level cyclic import

'Arguments' may not be defined if module [mesonbuild.minit](1) is imported before module [mesonbuild.templates.rusttemplates](2), as the [definition](3) of Arguments occurs after the cyclic [import](4) of mesonbuild.templates.rusttemplates. 'Arguments' may not be defined if module [mesonbuild.minit](1) is imported before module [mesonbuild.templates.rusttemplates](2), as the [definition](3) of Arguments occurs after the cyclic [import](5) of mesonbuild.templates.rusttemplates. 'Arguments' may not be defined if module [mesonbuild.minit](1) is imported before module [mesonbuild.templates.rusttemplates](2), as the [definition](6) of Arguments occurs after the cyclic [import](4) of mesonbuild.templates.rusttemplates. 'Arguments' may not be defined if module [mesonbuild.minit](1) is imported before module [mesonbuild.templates.rusttemplates](2), as the [definition](6) of Arguments occurs after the cyclic [import](5) of mesonbuild.templates.rusttemplates.
@bruchar1

bruchar1 commented Jan 7, 2025

Copy link
Copy Markdown
Member

The commit before the last is called "templates: use library() instead of shared_library()" but I only see variable name changes in it. Should it be renamed, or should it be squashed with the last commit?

@dcbaker

dcbaker commented Jan 7, 2025

Copy link
Copy Markdown
Member Author

Derp. Squashed

@dcbaker
dcbaker force-pushed the submit/modernize-templates branch from e02b02e to 5011501 Compare January 7, 2025 19:00
@jpakkane

jpakkane commented Jan 7, 2025

Copy link
Copy Markdown
Member

C++ 14 is quite old, maybe it should be brought up to 20?

@dcbaker

dcbaker commented Jan 7, 2025

Copy link
Copy Markdown
Member Author

Sure, I've added a patch to update both C and C++ standards to more recent versions

@jpakkane

jpakkane commented Jan 7, 2025

Copy link
Copy Markdown
Member
=================================== FAILURES ===================================
______ AllPlatformTests.test_templates [Language: objc; type: executable] ______

Seems relevant.

Intel's copyright was missing on these.
@dcbaker
dcbaker force-pushed the submit/modernize-templates branch 2 times, most recently from 8d9cf6f to f9ececa Compare January 8, 2025 17:23
Comment thread mesonbuild/templates/mesontemplates.py Resolved
Comment thread mesonbuild/templates/valatemplates.py Outdated
{ltoken}_dep = declare_dependency(
include_directories: include_directories('.'),
link_with : shlib)
link_with : shlib,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sometimes we use foo : bar and sometimes foo: bar.

(I'd standardize on the former.)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gah! I thought I got them all. This is what I get for not doing a real search on [a-z]:

Without a version certain kinds of warnings will be suppressed, which is
bad.

I've picked 1.0 because it's pretty old, except for Rust where I've
maintained the 1.3.0 requirement
Meson has added 'c' automatically to vala projects since 0.59, since the
minimum version is now 1.0 this isn't needed
We have all kinds of formatting, different indents, different line break
standards.
…roperty

because abstractproperty is deprecated
This is going to allow us to re-use the implementation for the "create a
new project" in the "add meson for an existing project" path.
@dcbaker
dcbaker force-pushed the submit/modernize-templates branch from f9ececa to a2a629d Compare January 8, 2025 18:01
The command line value exists, and we'll want it soon.
This reduces duplication around the meson version, default options, etc.
It also allows us to use the default initialization for libraries
@dcbaker
dcbaker force-pushed the submit/modernize-templates branch from a2a629d to 37d0d54 Compare January 8, 2025 18:05
@jpakkane

jpakkane commented Jan 8, 2025

Copy link
Copy Markdown
Member
unittests/allplatformstests.py:2406: CalledProcessError
________ AllPlatformTests.test_templates [Language: cpp; type: library] ________

Presumably becase the compiler is too old?

@eli-schwartz

Copy link
Copy Markdown
Member

C++ 14 is quite old, maybe it should be brought up to 20?

Is that really necessary? If C++14 was fine before, I'd assume it is fine now too. Absent weird cases like Google code.

@dcbaker
dcbaker force-pushed the submit/modernize-templates branch from 37d0d54 to 2180af4 Compare January 9, 2025 00:24
@dcbaker

dcbaker commented Jan 9, 2025

Copy link
Copy Markdown
Member Author

I've dropped the C and C++ version changes as those were causing the bionic target to fail, and they're frankly not that interesting. If we really care that much I'd be more inclined to add a command line option to let the user pick their own version

@dcbaker

dcbaker commented Jan 9, 2025

Copy link
Copy Markdown
Member Author

Also, this exercise made me realize how nice it is to have a real template engine like jinja or mako :/

@dcbaker dcbaker added this to the 1.8 milestone Jan 9, 2025
@jpakkane
jpakkane merged commit aecff97 into mesonbuild:master Jan 26, 2025
@dcbaker
dcbaker deleted the submit/modernize-templates branch January 27, 2025 00:03
thesamesam added a commit to thesamesam/meson that referenced this pull request Nov 22, 2025
Respect collected sources for `meson init` as well as --executable. This
regressed in 9f0ac31 (part of
mesonbuild#14086, it's easier to see how with
the whole PR).

Also, add subtests (distinguishing between empty directories and those with some
file(s) within). We already had some of these but they weren't marked
as such.

Test `meson init` with a broken source file in the source directory as
we should fail with that, not ignore the file.

It's easier to test with a broken file than a working one as we can assert
the build should fail, it'll pass with just the 1 example file we generate.

Closes: mesonbuild#15286
thesamesam added a commit to thesamesam/meson that referenced this pull request Nov 22, 2025
Respect collected sources for `meson init` as well as --executable. This
regressed in 9f0ac31 (part of
mesonbuild#14086, it's easier to see how with
the whole PR).

Also, add subtests (distinguishing between empty directories and those with some
file(s) within). We already had some of these but they weren't marked
as such.

Test `meson init` with a broken source file in the source directory as
we should fail with that, not ignore the file.

It's easier to test with a broken file than a working one as we can assert
the build should fail, it'll pass with just the 1 example file we generate.

Closes: mesonbuild#15286
jpakkane pushed a commit that referenced this pull request Nov 23, 2025
Respect collected sources for `meson init` as well as --executable. This
regressed in 9f0ac31 (part of
#14086, it's easier to see how with
the whole PR).

Also, add subtests (distinguishing between empty directories and those with some
file(s) within). We already had some of these but they weren't marked
as such.

Test `meson init` with a broken source file in the source directory as
we should fail with that, not ignore the file.

It's easier to test with a broken file than a working one as we can assert
the build should fail, it'll pass with just the 1 example file we generate.

Closes: #15286
nirbheek pushed a commit that referenced this pull request Dec 2, 2025
Respect collected sources for `meson init` as well as --executable. This
regressed in 9f0ac31 (part of
#14086, it's easier to see how with
the whole PR).

Also, add subtests (distinguishing between empty directories and those with some
file(s) within). We already had some of these but they weren't marked
as such.

Test `meson init` with a broken source file in the source directory as
we should fail with that, not ignore the file.

It's easier to test with a broken file than a working one as we can assert
the build should fail, it'll pass with just the 1 example file we generate.

Closes: #15286
(cherry picked from commit 9104bb6)
kjmeagher pushed a commit to kjmeagher/meson that referenced this pull request Jan 11, 2026
Respect collected sources for `meson init` as well as --executable. This
regressed in 9f0ac31 (part of
mesonbuild#14086, it's easier to see how with
the whole PR).

Also, add subtests (distinguishing between empty directories and those with some
file(s) within). We already had some of these but they weren't marked
as such.

Test `meson init` with a broken source file in the source directory as
we should fail with that, not ignore the file.

It's easier to test with a broken file than a working one as we can assert
the build should fail, it'll pass with just the 1 example file we generate.

Closes: mesonbuild#15286
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants