From 2f080b1f2e9ca076d04af8c67d18004970a03658 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 1 Mar 2020 15:00:29 -0800 Subject: add -C to meson init --- docs/markdown/snippets/cd_arguments_with_init_command.md | 5 +++++ mesonbuild/minit.py | 7 +++++++ 2 files changed, 12 insertions(+) create mode 100644 docs/markdown/snippets/cd_arguments_with_init_command.md diff --git a/docs/markdown/snippets/cd_arguments_with_init_command.md b/docs/markdown/snippets/cd_arguments_with_init_command.md new file mode 100644 index 0000000..d6441e6 --- /dev/null +++ b/docs/markdown/snippets/cd_arguments_with_init_command.md @@ -0,0 +1,5 @@ +## Added `-C` argument to `meson init` command + +The meson init assumes that it is run inside the project +root directory. If this isn't the case, you can now use +`-C` to specify the actual project source directory. diff --git a/mesonbuild/minit.py b/mesonbuild/minit.py index 85d4a0f..2cb225c 100644 --- a/mesonbuild/minit.py +++ b/mesonbuild/minit.py @@ -18,6 +18,8 @@ from pathlib import Path from enum import Enum import subprocess import shutil +import sys +import os import re from glob import glob from mesonbuild import mesonlib @@ -210,6 +212,7 @@ def add_arguments(parser): Meson project. ''' parser.add_argument("srcfiles", metavar="sourcefile", nargs="*", help="source files. default: all recognized files in current directory") + parser.add_argument('-C', default='.', dest='wd', help='directory to cd into before running') parser.add_argument("-n", "--name", help="project name. default: name of current directory") parser.add_argument("-e", "--executable", help="executable name. default: project name") parser.add_argument("-d", "--deps", help="dependencies, comma-separated") @@ -224,6 +227,10 @@ def run(options) -> int: ''' Here we generate the new Meson sample project. ''' + if not Path(options.wd).exists(): + sys.exit('Project source root directory not found. Run this command in build directory root.') + os.chdir(options.wd) + if not glob('*'): autodetect_options(options, sample=True) if not options.language: -- cgit v1.1