From 82c8550fb6f124835726789b13bbc37746e16bcf Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Fri, 22 Dec 2017 21:51:03 +0200 Subject: Added documentation for project templates. --- docs/markdown/Project-templates.md | 28 ++++++++++++++++++++++++++++ docs/sitemap.txt | 1 + 2 files changed, 29 insertions(+) create mode 100644 docs/markdown/Project-templates.md (limited to 'docs') diff --git a/docs/markdown/Project-templates.md b/docs/markdown/Project-templates.md new file mode 100644 index 000000000..dd86e13db --- /dev/null +++ b/docs/markdown/Project-templates.md @@ -0,0 +1,28 @@ +--- +short-description: Project templates +... + +# Project templates (available since 0.45.0) + +To make it easier for new developers to start working, Meson ships a +tool to generate the basic setup of different kinds of projects. This +functionality can be accessed with the `meson init` command. A typical +project setup would go like this: + +```console +$ mkdir project_name +$ cd project_name +$ meson init --language=c --name=myproject --version=0.1 +``` + +This would create the build definitions for a helloworld type +project. The result can be compiled as usual. For example compiling it +with Ninja could be done like this: + +``` +$ meson builddir +$ ninja -C builddir +``` + +The generator has many different projects and settings. They can all +be listed by invoking the command `meson test --help`. diff --git a/docs/sitemap.txt b/docs/sitemap.txt index b7ee136ca..87a5eb51f 100644 --- a/docs/sitemap.txt +++ b/docs/sitemap.txt @@ -48,6 +48,7 @@ index.md Creating-releases.md Creating-OSX-packages.md Creating-Linux-binaries.md + Project-templates.md Reference-manual.md Reference-tables.md FAQ.md -- cgit v1.2.3 From 4a189cf8c53e22b747521cae93c18cac3a45cc5a Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Thu, 28 Dec 2017 00:01:31 +0200 Subject: Add unit test that checks that the sample projects compile. --- docs/markdown/Project-templates.md | 4 +++- docs/markdown/snippets/templates.md | 8 ++++++++ mesonbuild/minit.py | 8 ++++---- run_unittests.py | 15 ++++++++++++++- 4 files changed, 29 insertions(+), 6 deletions(-) create mode 100644 docs/markdown/snippets/templates.md (limited to 'docs') diff --git a/docs/markdown/Project-templates.md b/docs/markdown/Project-templates.md index dd86e13db..d8459c6e6 100644 --- a/docs/markdown/Project-templates.md +++ b/docs/markdown/Project-templates.md @@ -2,7 +2,7 @@ short-description: Project templates ... -# Project templates (available since 0.45.0) +# Project templates To make it easier for new developers to start working, Meson ships a tool to generate the basic setup of different kinds of projects. This @@ -26,3 +26,5 @@ $ ninja -C builddir The generator has many different projects and settings. They can all be listed by invoking the command `meson test --help`. + +This feature is available since Meson version 0.45.0. diff --git a/docs/markdown/snippets/templates.md b/docs/markdown/snippets/templates.md new file mode 100644 index 000000000..6f0474d8d --- /dev/null +++ b/docs/markdown/snippets/templates.md @@ -0,0 +1,8 @@ +## Project templates + +Meson ships with predefined project templates. To start a new project from +scratch, simply go to an empty directory and type: + +```meson +meson init --name=myproject --type=executable --language=c +``` diff --git a/mesonbuild/minit.py b/mesonbuild/minit.py index 29b5056e6..98817cba4 100644 --- a/mesonbuild/minit.py +++ b/mesonbuild/minit.py @@ -113,10 +113,10 @@ hello_c_template = '''#include int main(int argc, char **argv) {{ if(argc != 1) {{ - printf("%s takes not arguments.\\n", argv[0]); + printf("%s takes no arguments.\\n", argv[0]); return 1; }} - printf("This is project %s.\n", PROJECT_NAME); + printf("This is project %s.\\n", PROJECT_NAME); return 0; }} ''' @@ -138,7 +138,7 @@ hello_cpp_template = '''#include int main(int argc, char **argv) {{ if(argc != 1) {{ - printf("%s takes not arguments.\\n", argv[0]); + std::cout << argv[0] << "takes no arguments.\\n"; return 1; }} std::cout << "This is project " << PROJECT_NAME << ".\\n"; @@ -209,7 +209,7 @@ lib_cpp_test_template = '''#include <{header_file}> int main(int argc, char **argv) {{ if(argc != 1) {{ - printf("%s takes no arguments.\\n", argv[0]); + std::cout << argv[0] << " takes no arguments.\\n"; return 1; }} {namespace}::{class_name} c; diff --git a/run_unittests.py b/run_unittests.py index 184386cb7..cbdcda076 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -36,7 +36,7 @@ import mesonbuild.coredata from mesonbuild.interpreter import ObjectHolder from mesonbuild.mesonlib import is_linux, is_windows, is_osx, is_cygwin, windows_proof_rmtree from mesonbuild.mesonlib import python_command, meson_command, version_compare -from mesonbuild.environment import Environment +from mesonbuild.environment import Environment, detect_ninja from mesonbuild.mesonlib import MesonException, EnvironmentException from mesonbuild.dependencies import PkgConfigDependency, ExternalProgram @@ -1707,6 +1707,19 @@ int main(int argc, char **argv) { self.init(workdir) self.build() + def test_templates(self): + ninja = detect_ninja() + if ninja is None: + raise unittest.SkipTest('This test currently requires ninja. Fix this once "meson build" works.') + for lang in ('c', 'cpp'): + for type in ('executable', 'library'): + with tempfile.TemporaryDirectory() as tmpdir: + self._run(meson_command + ['init', '--language', lang, '--type', type], + workdir=tmpdir) + self._run(self.meson_command + ['--backend=ninja', 'builddir'], + workdir=tmpdir) + self._run(ninja, + workdir=os.path.join(tmpdir, 'builddir')) class FailureTests(BasePlatformTests): ''' -- cgit v1.2.3