From 80ee0f85f97b145058e2ca93090501f33a980a23 Mon Sep 17 00:00:00 2001 From: Daniel Mensinger Date: Sat, 24 Nov 2018 17:51:13 +0100 Subject: Added release snippet --- docs/markdown/snippets/introspect_target_new.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 docs/markdown/snippets/introspect_target_new.md (limited to 'docs') diff --git a/docs/markdown/snippets/introspect_target_new.md b/docs/markdown/snippets/introspect_target_new.md new file mode 100644 index 000000000..cf0fd6a52 --- /dev/null +++ b/docs/markdown/snippets/introspect_target_new.md @@ -0,0 +1,7 @@ +## New `include_directories` and `extra_args` keys for the target introspection + +Meson now also prints the include directories and extra compiler arguments for +the target introspection (`meson introspect --targets`). + +The `include_directories` key stores a list of absolute paths and the `extra_args` +key holds a dict of compiler arguments for each language. -- cgit v1.2.3 From 8288555aa1dcab1ae38831d40529c6a2fbe3c8fd Mon Sep 17 00:00:00 2001 From: Daniel Mensinger Date: Sun, 25 Nov 2018 21:40:38 +0100 Subject: mintro: Added option to introspect multiple parameters at once --- docs/markdown/snippets/introspect_multiple.md | 12 +++++ mesonbuild/mintro.py | 71 +++++++++++++++++---------- 2 files changed, 56 insertions(+), 27 deletions(-) create mode 100644 docs/markdown/snippets/introspect_multiple.md (limited to 'docs') diff --git a/docs/markdown/snippets/introspect_multiple.md b/docs/markdown/snippets/introspect_multiple.md new file mode 100644 index 000000000..b7266f805 --- /dev/null +++ b/docs/markdown/snippets/introspect_multiple.md @@ -0,0 +1,12 @@ +## Added option to introspect multiple parameters at once + +Meson introspect can now print the results of multiple parameters +in a single call. The results are then printed as a single JSON +object. + +The format for a single command was not changed to keep backward +compatibility. + +Furthermore the option `-a,--all` and `-i,--indent` was added to +print all introspection information in one go and format the +JSON output (the default is still compact JSON). \ No newline at end of file diff --git a/mesonbuild/mintro.py b/mesonbuild/mintro.py index 5372b3024..70f0f09df 100644 --- a/mesonbuild/mintro.py +++ b/mesonbuild/mintro.py @@ -57,6 +57,10 @@ def add_arguments(parser): help='Information about projects.') parser.add_argument('--backend', choices=cdata.backendlist, dest='backend', default='ninja', help='The backend to use for the --buildoptions introspection.') + parser.add_argument('-a', '--all', action='store_true', dest='all', default=False, + help='Print all available information.') + parser.add_argument('-i', '--indent', dest='indent', type=int, default=0, + help='Number of spaces used for indentation.') parser.add_argument('builddir', nargs='?', default='.', help='The build directory') def determine_installed_path(target, installdata): @@ -89,7 +93,7 @@ def list_installed(installdata): res[path] = os.path.join(installdata.prefix, installdir, os.path.basename(path)) for path, installpath, unused_custom_install_mode in installdata.man: res[path] = os.path.join(installdata.prefix, installpath) - print(json.dumps(res)) + return res def include_dirs_to_path(inc_dirs, src_root, build_root): result = [] @@ -235,7 +239,7 @@ def list_targets(coredata, builddata, installdata): t['installed'] = False t['build_by_default'] = target.build_by_default tlist.append(t) - print(json.dumps(tlist, indent=2)) + return tlist def list_target_files(target_name, coredata, builddata): try: @@ -249,7 +253,7 @@ def list_target_files(target_name, coredata, builddata): if isinstance(i, mesonlib.File): i = os.path.join(i.subdir, i.fname) out.append(i) - print(json.dumps(out)) + return out class BuildoptionsOptionHelper: # mimic an argparse namespace @@ -429,7 +433,7 @@ def list_buildoptions(coredata): add_keys(optlist, dir_options, 'directory') add_keys(optlist, coredata.user_options, 'user') add_keys(optlist, test_options, 'test') - print(json.dumps(optlist)) + return optlist def add_keys(optlist, options, section): keys = list(options.keys()) @@ -466,7 +470,7 @@ def find_buildsystem_files_list(src_dir): def list_buildsystem_files(builddata): src_dir = builddata.environment.get_source_dir() filelist = find_buildsystem_files_list(src_dir) - print(json.dumps(filelist)) + return filelist def list_deps(coredata): result = [] @@ -475,7 +479,7 @@ def list_deps(coredata): result += [{'name': d.name, 'compile_args': d.get_compile_args(), 'link_args': d.get_link_args()}] - print(json.dumps(result)) + return result def list_tests(testdata): result = [] @@ -496,7 +500,7 @@ def list_tests(testdata): to['suite'] = t.suite to['is_parallel'] = t.is_parallel result.append(to) - print(json.dumps(result)) + return result def list_projinfo(builddata): result = {'version': builddata.project_version, @@ -508,7 +512,7 @@ def list_projinfo(builddata): 'descriptive_name': builddata.projects.get(k)} subprojects.append(c) result['subprojects'] = subprojects - print(json.dumps(result)) + return result class ProjectInfoInterperter(astinterpreter.AstInterpreter): def __init__(self, source_root, subdir): @@ -593,25 +597,38 @@ def run(options): except FileNotFoundError: installdata = None - if options.list_targets: - list_targets(coredata, builddata, installdata) - elif options.list_installed: - list_installed(installdata) - elif options.target_files is not None: - list_target_files(options.target_files, coredata, builddata) - elif options.buildsystem_files: - list_buildsystem_files(builddata) - elif options.buildoptions: - list_buildoptions(coredata) - elif options.tests: - list_tests(testdata) - elif options.benchmarks: - list_tests(benchmarkdata) - elif options.dependencies: - list_deps(coredata) - elif options.projectinfo: - list_projinfo(builddata) - else: + results = [] + + if options.all or options.list_targets: + results += [('targets', list_targets(coredata, builddata, installdata))] + if options.all or options.list_installed: + results += [('installed', list_installed(installdata))] + if options.target_files is not None: + results += [('target_files', list_target_files(options.target_files, coredata, builddata))] + if options.all or options.buildsystem_files: + results += [('buildsystem_files', list_buildsystem_files(builddata))] + if options.all or options.buildoptions: + results += [('buildoptions', list_buildoptions(coredata))] + if options.all or options.tests: + results += [('tests', list_tests(testdata))] + if options.all or options.benchmarks: + results += [('benchmarks', list_tests(benchmarkdata))] + if options.all or options.dependencies: + results += [('dependencies', list_deps(coredata))] + if options.all or options.projectinfo: + results += [('projectinfo', list_projinfo(builddata))] + + indent = options.indent if options.indent > 0 else None + + if len(results) == 0: print('No command specified') return 1 + elif len(results) == 1: + # Make to keep the existing output format for a single option + print(json.dumps(results[0][1], indent=indent)) + else: + out = {} + for i in results: + out[i[0]] = i[1] + print(json.dumps(out, indent=indent)) return 0 -- cgit v1.2.3 From b91c5aad854bff3a13c27aa1a6ade85ded216207 Mon Sep 17 00:00:00 2001 From: Daniel Mensinger Date: Thu, 29 Nov 2018 14:21:07 +0100 Subject: Update intro dump on meson configure --- docs/markdown/snippets/introspect_multiple.md | 11 ++++++----- mesonbuild/mconf.py | 2 ++ mesonbuild/mintro.py | 20 ++++++++++++++++++-- run_unittests.py | 26 ++++++++++++++++++++++++++ test cases/unit/49 introspection/meson.build | 2 +- 5 files changed, 53 insertions(+), 8 deletions(-) (limited to 'docs') diff --git a/docs/markdown/snippets/introspect_multiple.md b/docs/markdown/snippets/introspect_multiple.md index b7266f805..d05eae69a 100644 --- a/docs/markdown/snippets/introspect_multiple.md +++ b/docs/markdown/snippets/introspect_multiple.md @@ -1,12 +1,13 @@ ## Added option to introspect multiple parameters at once -Meson introspect can now print the results of multiple parameters -in a single call. The results are then printed as a single JSON +Meson introspect can now print the results of multiple introspection +commands in a single call. The results are then printed as a single JSON object. The format for a single command was not changed to keep backward compatibility. -Furthermore the option `-a,--all` and `-i,--indent` was added to -print all introspection information in one go and format the -JSON output (the default is still compact JSON). \ No newline at end of file +Furthermore the option `-a,--all`, `-i,--indent` and `-f,--force-new` +were added to print all introspection information in one go, format the +JSON output (the default is still compact JSON) and foce use the new +output format, even if only one introspection command was given. \ No newline at end of file diff --git a/mesonbuild/mconf.py b/mesonbuild/mconf.py index 28589dab0..eca32bf6b 100644 --- a/mesonbuild/mconf.py +++ b/mesonbuild/mconf.py @@ -14,6 +14,7 @@ import os from . import (coredata, mesonlib, build) +from . import mintro def add_arguments(parser): coredata.register_builtin_arguments(parser) @@ -162,6 +163,7 @@ def run(options): c.print_conf() if save: c.save() + mintro.update_build_options(c.coredata, builddir) except ConfException as e: print('Meson configurator encountered an error:') raise e diff --git a/mesonbuild/mintro.py b/mesonbuild/mintro.py index 326cd6ca1..04850c63e 100644 --- a/mesonbuild/mintro.py +++ b/mesonbuild/mintro.py @@ -487,8 +487,7 @@ def run(options): if options.all or options.benchmarks: toextract += ['benchmarks'] if options.all or options.buildoptions: - coredata = cdata.load(options.builddir) - results += [list_buildoptions(coredata)] + toextract += ['buildoptions'] if options.all or options.buildsystem_files: toextract += ['buildsystem_files'] if options.all or options.dependencies: @@ -550,3 +549,20 @@ def generate_introspection_file(builddata: build.Build, backend: backends.Backen with open(outfile, 'w') as fp: json.dump(outdict, fp) + +def update_build_options(coredata, builddir): + outfile = os.path.join(builddir, INTROSPECTION_OUTPUT_FILE) + outfile = os.path.abspath(outfile) + + with open(outfile, 'r') as fp: + outdict = json.load(fp) + + intro_info = [ + list_buildoptions(coredata) + ] + + for i in intro_info: + outdict[i[0]] = i[1] + + with open(outfile, 'w') as fp: + json.dump(outdict, fp) diff --git a/run_unittests.py b/run_unittests.py index 811df6bd3..492a22c1a 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -3256,6 +3256,32 @@ recommended as it is not supported on some platforms''') self.assertEqual(res_all, res_file) + def test_introspect_config_update(self): + testdir = os.path.join(self.unit_test_dir, '49 introspection') + introfile = os.path.join(self.builddir, 'meson-introspection.json') + self.init(testdir) + self.assertPathExists(introfile) + with open(introfile, 'r') as fp: + res1 = json.load(fp) + + self.setconf('-Dcpp_std=c++14') + self.setconf('-Dbuildtype=release') + + for idx, i in enumerate(res1['buildoptions']): + if i['name'] == 'cpp_std': + res1['buildoptions'][idx]['value'] = 'c++14' + if i['name'] == 'buildtype': + res1['buildoptions'][idx]['value'] = 'release' + if i['name'] == 'optimization': + res1['buildoptions'][idx]['value'] = '3' + if i['name'] == 'debug': + res1['buildoptions'][idx]['value'] = False + + with open(introfile, 'r') as fp: + res2 = json.load(fp) + + self.assertDictEqual(res1, res2) + class FailureTests(BasePlatformTests): ''' Tests that test failure conditions. Build files here should be dynamically diff --git a/test cases/unit/49 introspection/meson.build b/test cases/unit/49 introspection/meson.build index bd5d51a89..09b1d4f8d 100644 --- a/test cases/unit/49 introspection/meson.build +++ b/test cases/unit/49 introspection/meson.build @@ -1,4 +1,4 @@ -project('introspection', ['c', 'cpp'], version: '1.2.3', default_options: ['cpp_std=c++11']) +project('introspection', ['c', 'cpp'], version: '1.2.3', default_options: ['cpp_std=c++11', 'buildtype=debug']) dep1 = dependency('zlib') -- cgit v1.2.3 From b034f52656c19f378fc144abd9087e7526b1e27f Mon Sep 17 00:00:00 2001 From: Daniel Mensinger Date: Thu, 29 Nov 2018 14:53:28 +0100 Subject: Filenames are now lists --- docs/markdown/snippets/introspect_multiple.md | 7 ++++++- mesonbuild/build.py | 3 +++ mesonbuild/mintro.py | 6 +----- run_unittests.py | 6 +++--- 4 files changed, 13 insertions(+), 9 deletions(-) (limited to 'docs') diff --git a/docs/markdown/snippets/introspect_multiple.md b/docs/markdown/snippets/introspect_multiple.md index d05eae69a..17d0a3f97 100644 --- a/docs/markdown/snippets/introspect_multiple.md +++ b/docs/markdown/snippets/introspect_multiple.md @@ -10,4 +10,9 @@ compatibility. Furthermore the option `-a,--all`, `-i,--indent` and `-f,--force-new` were added to print all introspection information in one go, format the JSON output (the default is still compact JSON) and foce use the new -output format, even if only one introspection command was given. \ No newline at end of file +output format, even if only one introspection command was given. + +Additionlly the format of target was changed: + - `filename` is now a list of output filenames + - `install_filename` is now also a list of installed files + - New: the `sources` key. It stores the source files of a target and there compiler parameters diff --git a/mesonbuild/build.py b/mesonbuild/build.py index 4fa6bde63..642c2d5f0 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -2120,6 +2120,9 @@ class RunTarget(Target): def get_filename(self): return self.name + def get_outputs(self): + return [self.name] + def type_suffix(self): return "@run" diff --git a/mesonbuild/mintro.py b/mesonbuild/mintro.py index 04850c63e..cf1aeffde 100644 --- a/mesonbuild/mintro.py +++ b/mesonbuild/mintro.py @@ -93,11 +93,7 @@ def list_targets(builddata: build.Build, installdata, backend: backends.Backend) if not isinstance(target, build.Target): raise RuntimeError('Something weird happened. File a bug.') - fname = target.get_filename() - if isinstance(fname, list): - fname = [os.path.join(target.subdir, x) for x in fname] - else: - fname = os.path.join(target.subdir, fname) + fname = [os.path.join(target.subdir, x) for x in target.get_outputs()] t = { 'name': target.get_basename(), diff --git a/run_unittests.py b/run_unittests.py index 492a22c1a..1977fe0c1 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -1436,7 +1436,7 @@ class AllPlatformTests(BasePlatformTests): # Get name of static library targets = self.introspect('--targets') self.assertEqual(len(targets), 1) - libname = targets[0]['filename'] + libname = targets[0]['filename'][0] # Build and get contents of static library self.build() before = self._run(['ar', 't', os.path.join(self.builddir, libname)]).split() @@ -3168,7 +3168,7 @@ recommended as it is not supported on some platforms''') ('name', str), ('id', str), ('type', str), - ('filename', str), + ('filename', list), ('build_by_default', bool), ('sources', list), ('installed', bool), @@ -4368,7 +4368,7 @@ class LinuxlikeTests(BasePlatformTests): break self.assertIsInstance(docbook_target, dict) ifile = self.introspect(['--target-files', 'generated-gdbus-docbook@cus'])[0] - self.assertEqual(t['filename'], 'gdbus/generated-gdbus-doc-' + os.path.basename(ifile)) + self.assertListEqual(t['filename'], ['gdbus/generated-gdbus-doc-' + os.path.basename(ifile)]) def test_build_rpath(self): if is_cygwin(): -- cgit v1.2.3 From b11df88395a6543ab1ea9354050f0b885959854a Mon Sep 17 00:00:00 2001 From: Daniel Mensinger Date: Thu, 29 Nov 2018 16:19:01 +0100 Subject: Documentation and unit test update --- docs/markdown/IDE-integration.md | 103 +++++++++++++++++++----- docs/markdown/snippets/introspect_target_new.md | 7 -- mesonbuild/mintro.py | 7 +- run_unittests.py | 11 ++- test cases/unit/49 introspection/meson.build | 2 +- 5 files changed, 93 insertions(+), 37 deletions(-) delete mode 100644 docs/markdown/snippets/introspect_target_new.md (limited to 'docs') diff --git a/docs/markdown/IDE-integration.md b/docs/markdown/IDE-integration.md index c75392cae..a6c89bb7e 100644 --- a/docs/markdown/IDE-integration.md +++ b/docs/markdown/IDE-integration.md @@ -4,39 +4,86 @@ short-description: Meson's API to integrate Meson support into an IDE # IDE integration -Meson has exporters for Visual Studio and XCode, but writing a custom backend for every IDE out there is not a scalable approach. To solve this problem, Meson provides an API that makes it easy for any IDE or build tool to integrate Meson builds and provide an experience comparable to a solution native to the IDE. +Meson has exporters for Visual Studio and XCode, but writing a custom backend for every IDE out there is not a scalable approach. To solve this problem, Meson provides an API that makes it easy for any IDE or build tools to integrate Meson builds and provide an experience comparable to a solution native to the IDE. -The basic tool for this is `meson introspect`. +The basic resource for this is the `meson-introspection.json` file in the build directory. -The first thing to do when setting up a Meson project in an IDE is to select the source and build directories. For this example we assume that the source resides in an Eclipse-like directory called `workspace/project` and the build tree is nested inside it as `workspace/project/build`. First we initialise Meson by running the following command in the source directory. +The first thing to do when setting up a Meson project in an IDE is to select the source and build directories. For this example we assume that the source resides in an Eclipse-like directory called `workspace/project` and the build tree is nested inside it as `workspace/project/build`. First, we initialize Meson by running the following command in the source directory. meson builddir -For the remainder of the document we assume that all commands are executed inside the build directory unless otherwise specified. +The `meson-introspection.json` can then be found in the root of this build directory. It will be automatically updated when meson is (re)configured, or the build options change. As a result, an IDE can watch for changes in this file to know when something changed. -The first thing you probably want is to get a list of top level targets. For that we use the introspection tool. It comes with extensive command line help so we recommend using that in case problems appear. +The basic JSON format structure defined as follows: - meson introspect --targets +```json +{ + "benchmarks": [], + "buildoptions": [], + "buildsystem_files": ["just", "a", "list", "of", "meson", "files"], + "dependencies": [], + "installed": {}, + "projectinfo": { + "version": "1.2.3", + "descriptive_name": "Project Name", + "subprojects": [] + }, + "targets": [], + "tests": [] +} +``` -The JSON formats will not be specified in this document. The easiest way of learning them is to look at sample output from the tool. +The content of each JSON entry in this format is further specified in the remainder of this document. -Once you have a list of targets, you probably need the list of source files that comprise the target. To get this list for a target, say `exampletarget`, issue the following command. +## The `targets` section - meson introspect --target-files exampletarget +The most important entry for an IDE is probably the `targets` section. Here each target with its sources and compiler parameters is specified. The JSON format for one target is defined as follows: -In order to make code completion work, you need the compiler flags for each compilation step. Meson does not provide this itself, but the Ninja tool Meson uses to build does provide it. To find out the compile steps necessary to build target foo, issue the following command. +```json +{ + "name": "Name of the target", + "id": "The internal ID meson uses", + "type": "", + "filename": ["list", "of", "generate", "files"], + "build_by_default": true / false, + "sources": [], + "installed": true / false, +} +``` - ninja -t commands foo +If the key `installed` is set to `true`, the key `install_filename` will also be present. It stores the installation location for each file in `filename`. If one file in `filename` is not installed, its corresponding install location is set to `null`. -Note that if the target has dependencies (such as generated sources), then the commands for those show up in this list as well, so you need to do some filtering. Alternatively you can grab every command invocation in the [Clang tools db](https://clang.llvm.org/docs/JSONCompilationDatabase.html) format that is written to a file called `compile_commands.json` in the build directory. +A target usually generates only one file. However, it is possible for custom targets to have multiple outputs. -## Build Options +### Target sources + +The `sources` entry stores a list of all source objects of the target. With this information, an IDE can provide code completion for all source files. + +```json +{ + "language": "language ID", + "compiler": ["The", "compiler", "command"], + "parameters": ["list", "of", "compiler", "parameters"], + "source_files": ["list", "of", "all", "source", "files", "for", "this", "language"] +} +``` -The next thing to display is the list of options that can be set. These include build type and so on. Here's how to extract them. +### Possible values for `type` - meson introspect --buildoptions +The following table shows all valid types for a target. -This command returns a list of all supported buildoptions with the format: + value of `type` | Description + ---------------- | ------------------------------------------------------------------------------------------------- + `executable` | This target will generate an executable file + `static library` | Target for a static library + `shared library` | Target for a shared library + `shared module` | A shared library that is meant to be used with dlopen rather than linking into something else + `custom` | A custom target + `unknown target` | The current target format is unknown. This is probably a bug + +## Build Options + +The list of all build options (build type, warning level, etc.) is stored in the `buildoptions` list. Here is the JSON format for each option. ```json { @@ -85,11 +132,29 @@ Because of this options for the subprojects can differ. Compilation and unit tests are done as usual by running the `ninja` and `ninja test` commands. A JSON formatted result log can be found in `workspace/project/builddir/meson-logs/testlog.json`. -When these tests fail, the user probably wants to run the failing test in a debugger. To make this as integrated as possible, extract the test test setups with this command. +When these tests fail, the user probably wants to run the failing test in a debugger. To make this as integrated as possible, extract the tests from the `tests` and `benchmarks` entries. +This provides you with all the information needed to run the test: what command to execute, command line arguments and environment variable settings. - meson introspect --tests +```json +{ + "name": "name of the test", + "workdir": "the working directory (can be null)", + "timeout": "the test timeout", + "suite": ["list", "of", "test", "suites"], + "is_parallel": true / false, + "cmd": ["command", "to", "run"], + "env": { + "VARIABLE1": "value 1", + "VARIABLE2": "value 2" + } +} +``` -This provides you with all the information needed to run the test: what command to execute, command line arguments and environment variable settings. +# Programmatic interface + +Meson also provides the `meson introspect` for project introspection via the command line. Use `meson introspect -h` to see all available options. + +This API can also work without a build directory for the `--projectinfo` command. # Existing integrations diff --git a/docs/markdown/snippets/introspect_target_new.md b/docs/markdown/snippets/introspect_target_new.md deleted file mode 100644 index cf0fd6a52..000000000 --- a/docs/markdown/snippets/introspect_target_new.md +++ /dev/null @@ -1,7 +0,0 @@ -## New `include_directories` and `extra_args` keys for the target introspection - -Meson now also prints the include directories and extra compiler arguments for -the target introspection (`meson introspect --targets`). - -The `include_directories` key stores a list of absolute paths and the `extra_args` -key holds a dict of compiler arguments for each language. diff --git a/mesonbuild/mintro.py b/mesonbuild/mintro.py index cf1aeffde..5643b1a8c 100644 --- a/mesonbuild/mintro.py +++ b/mesonbuild/mintro.py @@ -106,12 +106,7 @@ def list_targets(builddata: build.Build, installdata, backend: backends.Backend) if installdata and target.should_install(): t['installed'] = True - t['install_filename'] = [] - - for i in target.outputs: - fname = intall_lookuptable.get(i) - if fname is not None: - t['install_filename'] += [fname] + t['install_filename'] = [intall_lookuptable.get(x, None) for x in target.get_outputs()] else: t['installed'] = False tlist.append(t) diff --git a/run_unittests.py b/run_unittests.py index 1977fe0c1..db88c9b05 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -1224,7 +1224,10 @@ class BasePlatformTests(unittest.TestCase): self.assertEqual(len(pathlist1), len(pathlist2)) worklist = list(zip(pathlist1, pathlist2)) for i in worklist: - self.assertPathEqual(i[0], i[1]) + if i[0] == None: + self.assertEqual(i[0], i[1]) + else: + self.assertPathEqual(i[0], i[1]) def assertPathBasenameEqual(self, path, basename): msg = '{!r} does not end with {!r}'.format(path, basename) @@ -1510,8 +1513,8 @@ class AllPlatformTests(BasePlatformTests): intro = intro[::-1] self.assertPathListEqual(intro[0]['install_filename'], ['/usr/include/diff.h', '/usr/bin/diff.sh']) self.assertPathListEqual(intro[1]['install_filename'], ['/opt/same.h', '/opt/same.sh']) - self.assertPathListEqual(intro[2]['install_filename'], ['/usr/include/first.h']) - self.assertPathListEqual(intro[3]['install_filename'], ['/usr/bin/second.sh']) + self.assertPathListEqual(intro[2]['install_filename'], ['/usr/include/first.h', None]) + self.assertPathListEqual(intro[3]['install_filename'], [None, '/usr/bin/second.sh']) def test_uninstall(self): exename = os.path.join(self.installdir, 'usr/bin/prog' + exe_suffix) @@ -3213,7 +3216,7 @@ recommended as it is not supported on some platforms''') self.assertListEqual(res['buildsystem_files'], ['meson.build', 'sharedlib/meson.build', 'staticlib/meson.build']) # Check dependencies - dependencies_to_find = ['zlib'] + dependencies_to_find = ['threads'] for i in res['dependencies']: assertKeyTypes(dependencies_typelist, i) if i['name'] in dependencies_to_find: diff --git a/test cases/unit/49 introspection/meson.build b/test cases/unit/49 introspection/meson.build index 09b1d4f8d..14d880b06 100644 --- a/test cases/unit/49 introspection/meson.build +++ b/test cases/unit/49 introspection/meson.build @@ -1,6 +1,6 @@ project('introspection', ['c', 'cpp'], version: '1.2.3', default_options: ['cpp_std=c++11', 'buildtype=debug']) -dep1 = dependency('zlib') +dep1 = dependency('threads') subdir('sharedlib') subdir('staticlib') -- cgit v1.2.3 From b9c4913cf032144eed0cb6308aaff4e77a825f08 Mon Sep 17 00:00:00 2001 From: Daniel Mensinger Date: Sun, 2 Dec 2018 19:53:34 +0100 Subject: Updated documentation --- docs/markdown/IDE-integration.md | 40 ++++++++++++--------------- docs/markdown/snippets/introspect_multiple.md | 3 ++ 2 files changed, 20 insertions(+), 23 deletions(-) (limited to 'docs') diff --git a/docs/markdown/IDE-integration.md b/docs/markdown/IDE-integration.md index a6c89bb7e..bd5dff26e 100644 --- a/docs/markdown/IDE-integration.md +++ b/docs/markdown/IDE-integration.md @@ -6,38 +6,32 @@ short-description: Meson's API to integrate Meson support into an IDE Meson has exporters for Visual Studio and XCode, but writing a custom backend for every IDE out there is not a scalable approach. To solve this problem, Meson provides an API that makes it easy for any IDE or build tools to integrate Meson builds and provide an experience comparable to a solution native to the IDE. -The basic resource for this is the `meson-introspection.json` file in the build directory. +All the resources required for such a IDE integration can be found in the `meson-info` directory in the build directory. The first thing to do when setting up a Meson project in an IDE is to select the source and build directories. For this example we assume that the source resides in an Eclipse-like directory called `workspace/project` and the build tree is nested inside it as `workspace/project/build`. First, we initialize Meson by running the following command in the source directory. meson builddir -The `meson-introspection.json` can then be found in the root of this build directory. It will be automatically updated when meson is (re)configured, or the build options change. As a result, an IDE can watch for changes in this file to know when something changed. +With this command meson will configure the project and also generate introspection information that is stored in `intro-*.json` files in the `meson-info` directory. All files will be automatically updated when meson is (re)configured, or the build options change. Thus, an IDE can watch for changes in this directory to know when something changed. -The basic JSON format structure defined as follows: +The `meson-info` directory should contain the following files: -```json -{ - "benchmarks": [], - "buildoptions": [], - "buildsystem_files": ["just", "a", "list", "of", "meson", "files"], - "dependencies": [], - "installed": {}, - "projectinfo": { - "version": "1.2.3", - "descriptive_name": "Project Name", - "subprojects": [] - }, - "targets": [], - "tests": [] -} -``` + File | Description + ------------------------------- | --------------------------------------------------------------------- + `intro-benchmarks.json` | Lists all benchmarks + `intro-buildoptions.json` | Contains a full list of meson configuration options for the project + `intro-buildsystem_files.json` | Full list of all meson build files + `intro-dependencies.json` | Lists all dependencies used in the project + `intro-installed.json` | Contains mapping of files to their installed location + `intro-projectinfo.json` | Stores basic information about the project (name, version, etc.) + `intro-targets.json` | Full list of all build targets + `intro-tests.json` | Lists all tests with instructions how to run them -The content of each JSON entry in this format is further specified in the remainder of this document. +The content of the JSON files is further specified in the remainder of this document. ## The `targets` section -The most important entry for an IDE is probably the `targets` section. Here each target with its sources and compiler parameters is specified. The JSON format for one target is defined as follows: +The most important file for an IDE is probably `intro-targets.json`. Here each target with its sources and compiler parameters is specified. The JSON format for one target is defined as follows: ```json { @@ -57,7 +51,7 @@ A target usually generates only one file. However, it is possible for custom tar ### Target sources -The `sources` entry stores a list of all source objects of the target. With this information, an IDE can provide code completion for all source files. +The `intro-sources.json` file stores a list of all source objects of the target. With this information, an IDE can provide code completion for all source files. ```json { @@ -83,7 +77,7 @@ The following table shows all valid types for a target. ## Build Options -The list of all build options (build type, warning level, etc.) is stored in the `buildoptions` list. Here is the JSON format for each option. +The list of all build options (build type, warning level, etc.) is stored in the `intro-buildoptions.json` file. Here is the JSON format for each option. ```json { diff --git a/docs/markdown/snippets/introspect_multiple.md b/docs/markdown/snippets/introspect_multiple.md index 17d0a3f97..151421950 100644 --- a/docs/markdown/snippets/introspect_multiple.md +++ b/docs/markdown/snippets/introspect_multiple.md @@ -12,6 +12,9 @@ were added to print all introspection information in one go, format the JSON output (the default is still compact JSON) and foce use the new output format, even if only one introspection command was given. +A complete introspection dump is also stored in the `meson-info` +directory. This dump will alwys be (re)generated on every meson run. + Additionlly the format of target was changed: - `filename` is now a list of output filenames - `install_filename` is now also a list of installed files -- cgit v1.2.3 From fde10eaee9886f5834a4ab92deadfd39b2d05424 Mon Sep 17 00:00:00 2001 From: Daniel Mensinger Date: Tue, 11 Dec 2018 17:59:35 +0100 Subject: Updated the docs --- docs/markdown/IDE-integration.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'docs') diff --git a/docs/markdown/IDE-integration.md b/docs/markdown/IDE-integration.md index bd5dff26e..6fb232161 100644 --- a/docs/markdown/IDE-integration.md +++ b/docs/markdown/IDE-integration.md @@ -58,7 +58,8 @@ The `intro-sources.json` file stores a list of all source objects of the target. "language": "language ID", "compiler": ["The", "compiler", "command"], "parameters": ["list", "of", "compiler", "parameters"], - "source_files": ["list", "of", "all", "source", "files", "for", "this", "language"] + "sources": ["list", "of", "all", "source", "files", "for", "this", "language"], + "generated_sources": ["list", "of", "all", "soruce", "files", "that", "where", "generated", "somewhere", "else"] } ``` -- cgit v1.2.3 From eb2cc9eccd240fd76c290b77bd28c8285b313b5c Mon Sep 17 00:00:00 2001 From: textshell Date: Fri, 28 Dec 2018 21:18:01 +0100 Subject: Update docs/markdown/snippets/introspect_multiple.md Co-Authored-By: mensinda --- docs/markdown/snippets/introspect_multiple.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs') diff --git a/docs/markdown/snippets/introspect_multiple.md b/docs/markdown/snippets/introspect_multiple.md index 151421950..38bd90cc2 100644 --- a/docs/markdown/snippets/introspect_multiple.md +++ b/docs/markdown/snippets/introspect_multiple.md @@ -13,7 +13,7 @@ JSON output (the default is still compact JSON) and foce use the new output format, even if only one introspection command was given. A complete introspection dump is also stored in the `meson-info` -directory. This dump will alwys be (re)generated on every meson run. +directory. This dump will be (re)generated each time meson updates the configuration of the build directory. Additionlly the format of target was changed: - `filename` is now a list of output filenames -- cgit v1.2.3 From c1838d9e4ce6539b6d6694ea0a7935ad07521006 Mon Sep 17 00:00:00 2001 From: textshell Date: Fri, 28 Dec 2018 21:18:39 +0100 Subject: Update docs/markdown/snippets/introspect_multiple.md Co-Authored-By: mensinda --- docs/markdown/snippets/introspect_multiple.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs') diff --git a/docs/markdown/snippets/introspect_multiple.md b/docs/markdown/snippets/introspect_multiple.md index 38bd90cc2..75580d379 100644 --- a/docs/markdown/snippets/introspect_multiple.md +++ b/docs/markdown/snippets/introspect_multiple.md @@ -15,7 +15,7 @@ output format, even if only one introspection command was given. A complete introspection dump is also stored in the `meson-info` directory. This dump will be (re)generated each time meson updates the configuration of the build directory. -Additionlly the format of target was changed: +Additionlly the format of `meson introspect target` was changed: - `filename` is now a list of output filenames - `install_filename` is now also a list of installed files - New: the `sources` key. It stores the source files of a target and there compiler parameters -- cgit v1.2.3 From 7cf0e307074f11028c383a85616ff7c5a3a1b529 Mon Sep 17 00:00:00 2001 From: textshell Date: Fri, 28 Dec 2018 21:20:15 +0100 Subject: Update docs/markdown/IDE-integration.md Co-Authored-By: mensinda --- docs/markdown/IDE-integration.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'docs') diff --git a/docs/markdown/IDE-integration.md b/docs/markdown/IDE-integration.md index 6fb232161..765c2c412 100644 --- a/docs/markdown/IDE-integration.md +++ b/docs/markdown/IDE-integration.md @@ -59,7 +59,7 @@ The `intro-sources.json` file stores a list of all source objects of the target. "compiler": ["The", "compiler", "command"], "parameters": ["list", "of", "compiler", "parameters"], "sources": ["list", "of", "all", "source", "files", "for", "this", "language"], - "generated_sources": ["list", "of", "all", "soruce", "files", "that", "where", "generated", "somewhere", "else"] + "generated_sources": ["list", "of", "all", "source", "files", "that", "where", "generated", "somewhere", "else"] } ``` @@ -155,4 +155,4 @@ This API can also work without a build directory for the `--projectinfo` command - [Gnome Builder](https://wiki.gnome.org/Apps/Builder) - [Eclipse CDT](https://www.eclipse.org/cdt/) (experimental) -- [Meson Cmake Wrapper](https://github.com/prozum/meson-cmake-wrapper) (for cmake IDEs) \ No newline at end of file +- [Meson Cmake Wrapper](https://github.com/prozum/meson-cmake-wrapper) (for cmake IDEs) -- cgit v1.2.3 From 2e81631d0c892d4842412c5244d9374b390f3787 Mon Sep 17 00:00:00 2001 From: Daniel Mensinger Date: Sun, 30 Dec 2018 10:59:58 +0100 Subject: Keep 'filename' and 'install_filename' as strings --- docs/markdown/snippets/introspect_multiple.md | 3 +-- mesonbuild/mintro.py | 5 +++-- run_unittests.py | 25 ++++++++++++++++--------- 3 files changed, 20 insertions(+), 13 deletions(-) (limited to 'docs') diff --git a/docs/markdown/snippets/introspect_multiple.md b/docs/markdown/snippets/introspect_multiple.md index 75580d379..53278e6af 100644 --- a/docs/markdown/snippets/introspect_multiple.md +++ b/docs/markdown/snippets/introspect_multiple.md @@ -16,6 +16,5 @@ A complete introspection dump is also stored in the `meson-info` directory. This dump will be (re)generated each time meson updates the configuration of the build directory. Additionlly the format of `meson introspect target` was changed: - - `filename` is now a list of output filenames - - `install_filename` is now also a list of installed files + - New: the `sources` key. It stores the source files of a target and there compiler parameters diff --git a/mesonbuild/mintro.py b/mesonbuild/mintro.py index 9372ed897..4de16ca3f 100644 --- a/mesonbuild/mintro.py +++ b/mesonbuild/mintro.py @@ -99,14 +99,15 @@ def list_targets(builddata: build.Build, installdata, backend: backends.Backend) 'name': target.get_basename(), 'id': idname, 'type': target.get_typename(), - 'filename': fname, + 'filename': fname[0], # TODO Change this to the full list in a seperate PR 'build_by_default': target.build_by_default, 'sources': backend.get_introspection_data(idname, target) } if installdata and target.should_install(): t['installed'] = True - t['install_filename'] = [intall_lookuptable.get(x, None) for x in target.get_outputs()] + # TODO Change this to the full list in a seperate PR + t['install_filename'] = [intall_lookuptable.get(x, None) for x in target.get_outputs()][0] else: t['installed'] = False tlist.append(t) diff --git a/run_unittests.py b/run_unittests.py index 821ab0969..69fac132e 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -1439,7 +1439,7 @@ class AllPlatformTests(BasePlatformTests): # Get name of static library targets = self.introspect('--targets') self.assertEqual(len(targets), 1) - libname = targets[0]['filename'][0] + libname = targets[0]['filename'] # TODO Change filename back to a list again # Build and get contents of static library self.build() before = self._run(['ar', 't', os.path.join(self.builddir, libname)]).split() @@ -1496,13 +1496,16 @@ class AllPlatformTests(BasePlatformTests): intro = self.introspect('--targets') if intro[0]['type'] == 'executable': intro = intro[::-1] - self.assertPathListEqual(intro[0]['install_filename'], ['/usr/lib/libstat.a']) - self.assertPathListEqual(intro[1]['install_filename'], ['/usr/bin/prog' + exe_suffix]) + self.assertPathListEqual([intro[0]['install_filename']], ['/usr/lib/libstat.a']) + self.assertPathListEqual([intro[1]['install_filename']], ['/usr/bin/prog' + exe_suffix]) def test_install_introspection_multiple_outputs(self): ''' Tests that the Meson introspection API exposes multiple install filenames correctly without crashing https://github.com/mesonbuild/meson/pull/4555 + + Reverted to the first file only because of https://github.com/mesonbuild/meson/pull/4547#discussion_r244173438 + TODO Change the format to a list officialy in a followup PR ''' if self.backend is not Backend.ninja: raise unittest.SkipTest('{!r} backend can\'t install files'.format(self.backend.name)) @@ -1511,10 +1514,14 @@ class AllPlatformTests(BasePlatformTests): intro = self.introspect('--targets') if intro[0]['type'] == 'executable': intro = intro[::-1] - self.assertPathListEqual(intro[0]['install_filename'], ['/usr/include/diff.h', '/usr/bin/diff.sh']) - self.assertPathListEqual(intro[1]['install_filename'], ['/opt/same.h', '/opt/same.sh']) - self.assertPathListEqual(intro[2]['install_filename'], ['/usr/include/first.h', None]) - self.assertPathListEqual(intro[3]['install_filename'], [None, '/usr/bin/second.sh']) + #self.assertPathListEqual(intro[0]['install_filename'], ['/usr/include/diff.h', '/usr/bin/diff.sh']) + #self.assertPathListEqual(intro[1]['install_filename'], ['/opt/same.h', '/opt/same.sh']) + #self.assertPathListEqual(intro[2]['install_filename'], ['/usr/include/first.h', None]) + #self.assertPathListEqual(intro[3]['install_filename'], [None, '/usr/bin/second.sh']) + self.assertPathListEqual([intro[0]['install_filename']], ['/usr/include/diff.h']) + self.assertPathListEqual([intro[1]['install_filename']], ['/opt/same.h']) + self.assertPathListEqual([intro[2]['install_filename']], ['/usr/include/first.h']) + self.assertPathListEqual([intro[3]['install_filename']], [None]) def test_uninstall(self): exename = os.path.join(self.installdir, 'usr/bin/prog' + exe_suffix) @@ -3173,7 +3180,7 @@ recommended as it is not supported on some platforms''') ('name', str), ('id', str), ('type', str), - ('filename', list), + ('filename', str), ('build_by_default', bool), ('sources', list), ('installed', bool), @@ -4396,7 +4403,7 @@ class LinuxlikeTests(BasePlatformTests): break self.assertIsInstance(docbook_target, dict) ifile = self.introspect(['--target-files', 'generated-gdbus-docbook@cus'])[0] - self.assertListEqual(t['filename'], ['gdbus/generated-gdbus-doc-' + os.path.basename(ifile)]) + self.assertListEqual([t['filename']], ['gdbus/generated-gdbus-doc-' + os.path.basename(ifile)]) def test_build_rpath(self): if is_cygwin(): -- cgit v1.2.3 From 1268597df590413539099f0f3797fae7bcb5c09a Mon Sep 17 00:00:00 2001 From: Daniel Mensinger Date: Sun, 30 Dec 2018 11:09:08 +0100 Subject: Slight modification of the wording --- docs/markdown/IDE-integration.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs') diff --git a/docs/markdown/IDE-integration.md b/docs/markdown/IDE-integration.md index 765c2c412..4b5c3605a 100644 --- a/docs/markdown/IDE-integration.md +++ b/docs/markdown/IDE-integration.md @@ -12,7 +12,7 @@ The first thing to do when setting up a Meson project in an IDE is to select the meson builddir -With this command meson will configure the project and also generate introspection information that is stored in `intro-*.json` files in the `meson-info` directory. All files will be automatically updated when meson is (re)configured, or the build options change. Thus, an IDE can watch for changes in this directory to know when something changed. +With this command meson will configure the project and also generate introspection information that is stored in `intro-*.json` files in the `meson-info` directory. The introspection dump will be automatically updated when meson is (re)configured, or the build options change. Thus, an IDE can watch for changes in this directory to know when something changed. The `meson-info` directory should contain the following files: -- cgit v1.2.3 From 5c39dd0668ffe301aee66453b86591bbdb29a954 Mon Sep 17 00:00:00 2001 From: Daniel Mensinger Date: Sun, 30 Dec 2018 11:31:03 +0100 Subject: Doc updates and throw if no target type is set --- docs/markdown/IDE-integration.md | 3 ++- mesonbuild/backend/backends.py | 8 +------- mesonbuild/build.py | 15 ++++++++------- 3 files changed, 11 insertions(+), 15 deletions(-) (limited to 'docs') diff --git a/docs/markdown/IDE-integration.md b/docs/markdown/IDE-integration.md index 4b5c3605a..639f4a02e 100644 --- a/docs/markdown/IDE-integration.md +++ b/docs/markdown/IDE-integration.md @@ -74,7 +74,8 @@ The following table shows all valid types for a target. `shared library` | Target for a shared library `shared module` | A shared library that is meant to be used with dlopen rather than linking into something else `custom` | A custom target - `unknown target` | The current target format is unknown. This is probably a bug + `run` | A Meson run target + `jar` | A Java JAR target ## Build Options diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py index b3b6df93c..0291e7e98 100644 --- a/mesonbuild/backend/backends.py +++ b/mesonbuild/backend/backends.py @@ -1183,10 +1183,4 @@ class Backend: 'generated_sources': [] }] - return [{ - 'language': 'unknown', - 'compiler': [], - 'parameters': [], - 'sources': [], - 'generated_sources': [] - }] + return [] diff --git a/mesonbuild/build.py b/mesonbuild/build.py index 642c2d5f0..5a243a446 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -345,7 +345,8 @@ a hard error in the future.''' % name) self.install = False self.build_always_stale = False self.option_overrides = {} - self.typename = 'unknown target' + if not hasattr(self, 'typename'): + raise RuntimeError('Target type is not set for target class "{}". This is a bug'.format(type(self).__name__)) def get_install_dir(self, environment): # Find the installation directory. @@ -1365,10 +1366,10 @@ class Executable(BuildTarget): known_kwargs = known_exe_kwargs def __init__(self, name, subdir, subproject, is_cross, sources, objects, environment, kwargs): + self.typename = 'executable' if 'pie' not in kwargs and 'b_pie' in environment.coredata.base_options: kwargs['pie'] = environment.coredata.base_options['b_pie'].value super().__init__(name, subdir, subproject, is_cross, sources, objects, environment, kwargs) - self.typename = 'executable' # Unless overridden, executables have no suffix or prefix. Except on # Windows and with C#/Mono executables where the suffix is 'exe' if not hasattr(self, 'prefix'): @@ -1455,10 +1456,10 @@ class StaticLibrary(BuildTarget): known_kwargs = known_stlib_kwargs def __init__(self, name, subdir, subproject, is_cross, sources, objects, environment, kwargs): + self.typename = 'static library' if 'pic' not in kwargs and 'b_staticpic' in environment.coredata.base_options: kwargs['pic'] = environment.coredata.base_options['b_staticpic'].value super().__init__(name, subdir, subproject, is_cross, sources, objects, environment, kwargs) - self.typename = 'static library' if 'cs' in self.compilers: raise InvalidArguments('Static libraries not supported for C#.') if 'rust' in self.compilers: @@ -1515,6 +1516,7 @@ class SharedLibrary(BuildTarget): known_kwargs = known_shlib_kwargs def __init__(self, name, subdir, subproject, is_cross, sources, objects, environment, kwargs): + self.typename = 'shared library' self.soversion = None self.ltversion = None # Max length 2, first element is compatibility_version, second is current_version @@ -1527,7 +1529,6 @@ class SharedLibrary(BuildTarget): # The import library that GCC would generate (and prefer) self.gcc_import_filename = None super().__init__(name, subdir, subproject, is_cross, sources, objects, environment, kwargs) - self.typename = 'shared library' if 'rust' in self.compilers: # If no crate type is specified, or it's the generic lib type, use dylib if not hasattr(self, 'rust_crate_type') or self.rust_crate_type == 'lib': @@ -1850,8 +1851,8 @@ class CustomTarget(Target): ]) def __init__(self, name, subdir, subproject, kwargs, absolute_paths=False): - super().__init__(name, subdir, subproject, False) self.typename = 'custom' + super().__init__(name, subdir, subproject, False) self.dependencies = [] self.extra_depends = [] self.depend_files = [] # Files that this target depends on but are not on the command line. @@ -2092,8 +2093,8 @@ class CustomTarget(Target): class RunTarget(Target): def __init__(self, name, command, args, dependencies, subdir, subproject): - super().__init__(name, subdir, subproject, False) self.typename = 'run' + super().__init__(name, subdir, subproject, False) self.command = command self.args = args self.dependencies = dependencies @@ -2130,6 +2131,7 @@ class Jar(BuildTarget): known_kwargs = known_jar_kwargs def __init__(self, name, subdir, subproject, is_cross, sources, objects, environment, kwargs): + self.typename = 'jar' super().__init__(name, subdir, subproject, is_cross, sources, objects, environment, kwargs) for s in self.sources: if not s.endswith('.java'): @@ -2137,7 +2139,6 @@ class Jar(BuildTarget): for t in self.link_targets: if not isinstance(t, Jar): raise InvalidArguments('Link target %s is not a jar target.' % t) - self.typename = 'jar' self.filename = self.name + '.jar' self.outputs = [self.filename] self.java_args = kwargs.get('java_args', []) -- cgit v1.2.3 From 84948ea6cd61c54404d6e0df82594a56e19fe01f Mon Sep 17 00:00:00 2001 From: Daniel Mensinger Date: Sun, 30 Dec 2018 11:37:50 +0100 Subject: Renamed `--force-new` to `--force-dict-output` --- docs/markdown/snippets/introspect_multiple.md | 2 +- mesonbuild/mintro.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'docs') diff --git a/docs/markdown/snippets/introspect_multiple.md b/docs/markdown/snippets/introspect_multiple.md index 53278e6af..97fdf8c81 100644 --- a/docs/markdown/snippets/introspect_multiple.md +++ b/docs/markdown/snippets/introspect_multiple.md @@ -7,7 +7,7 @@ object. The format for a single command was not changed to keep backward compatibility. -Furthermore the option `-a,--all`, `-i,--indent` and `-f,--force-new` +Furthermore the option `-a,--all`, `-i,--indent` and `-f,--force-dict-output` were added to print all introspection information in one go, format the JSON output (the default is still compact JSON) and foce use the new output format, even if only one introspection command was given. diff --git a/mesonbuild/mintro.py b/mesonbuild/mintro.py index 4de16ca3f..4a20e6bfa 100644 --- a/mesonbuild/mintro.py +++ b/mesonbuild/mintro.py @@ -62,7 +62,7 @@ def add_arguments(parser): help='Print all available information.') parser.add_argument('-i', '--indent', dest='indent', type=int, default=0, help='Number of spaces used for indentation.') - parser.add_argument('-f', '--force-new', action='store_true', dest='force_new', default=False, + parser.add_argument('-f', '--force-dict-output', action='store_true', dest='force_dict', default=False, help='Always use the new JSON format for multiple entries (even for 0 and 1 introspection commands)') parser.add_argument('builddir', nargs='?', default='.', help='The build directory') @@ -504,10 +504,10 @@ def run(options): indent = options.indent if options.indent > 0 else None - if len(results) == 0 and not options.force_new: + if len(results) == 0 and not options.force_dict: print('No command specified') return 1 - elif len(results) == 1 and not options.force_new: + elif len(results) == 1 and not options.force_dict: # Make to keep the existing output format for a single option print(json.dumps(results[0][1], indent=indent)) else: -- cgit v1.2.3 From 02734cc5c34faabe8ec0685139451f8349469993 Mon Sep 17 00:00:00 2001 From: Daniel Mensinger Date: Sun, 30 Dec 2018 12:38:55 +0100 Subject: Better documentation --- docs/markdown/snippets/introspect_multiple.md | 1 + mesonbuild/mintro.py | 6 ++++-- run_unittests.py | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) (limited to 'docs') diff --git a/docs/markdown/snippets/introspect_multiple.md b/docs/markdown/snippets/introspect_multiple.md index 97fdf8c81..2a885e41f 100644 --- a/docs/markdown/snippets/introspect_multiple.md +++ b/docs/markdown/snippets/introspect_multiple.md @@ -18,3 +18,4 @@ directory. This dump will be (re)generated each time meson updates the configura Additionlly the format of `meson introspect target` was changed: - New: the `sources` key. It stores the source files of a target and there compiler parameters + - Added new target types (`jar`, `shared module`) diff --git a/mesonbuild/mintro.py b/mesonbuild/mintro.py index fa92a1ae1..ce9d81e8d 100644 --- a/mesonbuild/mintro.py +++ b/mesonbuild/mintro.py @@ -472,8 +472,10 @@ def run(options): list_buildoptions_from_source(sourcedir, options.backend) return 0 if not os.path.isdir(datadir) or not os.path.isdir(infodir): - print('Current directory is not a build dir. Please specify it or ' - 'change the working directory to it.') + print('Current directory is not a meson build directory.' + 'Please specify a valid build dir or change the working directory to it.' + 'It is also possible that the build directory was generated with an old' + 'meson version. Please regenerate it in this case.') return 1 results = [] diff --git a/run_unittests.py b/run_unittests.py index 69fac132e..349375e3e 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -2569,7 +2569,7 @@ int main(int argc, char **argv) { for t in t_intro: id = t['id'] tf_intro = self.introspect(['--target-files', id]) - tf_intro = list(map(lambda x: os.path.relpath(x, testdir), tf_intro)) + #tf_intro = list(map(lambda x: os.path.relpath(x, testdir), tf_intro)) TODO make paths absolute in future PR self.assertEqual(tf_intro, expected[id]) self.wipe() @@ -2585,7 +2585,7 @@ int main(int argc, char **argv) { id = t['id'] tf_intro = self.introspect(['--target-files', id]) print(tf_intro) - tf_intro = list(map(lambda x: os.path.relpath(x, testdir), tf_intro)) + #tf_intro = list(map(lambda x: os.path.relpath(x, testdir), tf_intro)) TODO make paths absolute in future PR print(tf_intro) self.assertEqual(tf_intro, expected[id]) self.wipe() -- cgit v1.2.3 From 1e374feb1ce09e866f9625a3ea378b58fddaf768 Mon Sep 17 00:00:00 2001 From: textshell Date: Sun, 30 Dec 2018 22:34:57 +0100 Subject: Update docs/markdown/IDE-integration.md Co-Authored-By: mensinda --- docs/markdown/IDE-integration.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs') diff --git a/docs/markdown/IDE-integration.md b/docs/markdown/IDE-integration.md index 639f4a02e..1b79c7480 100644 --- a/docs/markdown/IDE-integration.md +++ b/docs/markdown/IDE-integration.md @@ -38,7 +38,7 @@ The most important file for an IDE is probably `intro-targets.json`. Here each t "name": "Name of the target", "id": "The internal ID meson uses", "type": "", - "filename": ["list", "of", "generate", "files"], + "filename": ["list", "of", "generated", "files"], "build_by_default": true / false, "sources": [], "installed": true / false, -- cgit v1.2.3 From fb4bdd3330b5857cc0187dec1c75f307fe8889f8 Mon Sep 17 00:00:00 2001 From: textshell Date: Sun, 30 Dec 2018 22:35:42 +0100 Subject: Update docs/markdown/IDE-integration.md Co-Authored-By: mensinda --- docs/markdown/IDE-integration.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs') diff --git a/docs/markdown/IDE-integration.md b/docs/markdown/IDE-integration.md index 1b79c7480..81fd43f20 100644 --- a/docs/markdown/IDE-integration.md +++ b/docs/markdown/IDE-integration.md @@ -128,7 +128,7 @@ Because of this options for the subprojects can differ. Compilation and unit tests are done as usual by running the `ninja` and `ninja test` commands. A JSON formatted result log can be found in `workspace/project/builddir/meson-logs/testlog.json`. -When these tests fail, the user probably wants to run the failing test in a debugger. To make this as integrated as possible, extract the tests from the `tests` and `benchmarks` entries. +When these tests fail, the user probably wants to run the failing test in a debugger. To make this as integrated as possible, extract the tests from the `intro-tests.json` and `intro-benchmarks.json` files. This provides you with all the information needed to run the test: what command to execute, command line arguments and environment variable settings. ```json -- cgit v1.2.3 From 248adbab9ad0775e513b920e9047b2e93664ae2e Mon Sep 17 00:00:00 2001 From: textshell Date: Sun, 30 Dec 2018 22:35:56 +0100 Subject: Update docs/markdown/snippets/introspect_multiple.md Co-Authored-By: mensinda --- docs/markdown/snippets/introspect_multiple.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs') diff --git a/docs/markdown/snippets/introspect_multiple.md b/docs/markdown/snippets/introspect_multiple.md index 2a885e41f..3bbe6ccc2 100644 --- a/docs/markdown/snippets/introspect_multiple.md +++ b/docs/markdown/snippets/introspect_multiple.md @@ -9,7 +9,7 @@ compatibility. Furthermore the option `-a,--all`, `-i,--indent` and `-f,--force-dict-output` were added to print all introspection information in one go, format the -JSON output (the default is still compact JSON) and foce use the new +JSON output (the default is still compact JSON) and force use the new output format, even if only one introspection command was given. A complete introspection dump is also stored in the `meson-info` -- cgit v1.2.3 From bd8bad46c3fad6e53e259f73408a73eeca920dc7 Mon Sep 17 00:00:00 2001 From: Daniel Mensinger Date: Sun, 30 Dec 2018 23:04:59 +0100 Subject: Code cleanup and renamed variables --- docs/markdown/IDE-integration.md | 4 ++-- docs/markdown/snippets/introspect_multiple.md | 2 +- mesonbuild/backend/ninjabackend.py | 5 ++--- mesonbuild/mintro.py | 8 +++----- run_unittests.py | 4 ++-- 5 files changed, 10 insertions(+), 13 deletions(-) (limited to 'docs') diff --git a/docs/markdown/IDE-integration.md b/docs/markdown/IDE-integration.md index 81fd43f20..d4554aea4 100644 --- a/docs/markdown/IDE-integration.md +++ b/docs/markdown/IDE-integration.md @@ -40,7 +40,7 @@ The most important file for an IDE is probably `intro-targets.json`. Here each t "type": "", "filename": ["list", "of", "generated", "files"], "build_by_default": true / false, - "sources": [], + "target_sources": [], "installed": true / false, } ``` @@ -51,7 +51,7 @@ A target usually generates only one file. However, it is possible for custom tar ### Target sources -The `intro-sources.json` file stores a list of all source objects of the target. With this information, an IDE can provide code completion for all source files. +The `intro-targets.json` file also stores a list of all source objects of the target in the `target_sources`. With this information, an IDE can provide code completion for all source files. ```json { diff --git a/docs/markdown/snippets/introspect_multiple.md b/docs/markdown/snippets/introspect_multiple.md index 3bbe6ccc2..0d53d4806 100644 --- a/docs/markdown/snippets/introspect_multiple.md +++ b/docs/markdown/snippets/introspect_multiple.md @@ -7,7 +7,7 @@ object. The format for a single command was not changed to keep backward compatibility. -Furthermore the option `-a,--all`, `-i,--indent` and `-f,--force-dict-output` +Furthermore the option `-a,--all`, `-i,--indent` and `-f,--force-object-output` were added to print all introspection information in one go, format the JSON output (the default is still compact JSON) and force use the new output format, even if only one introspection command was given. diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index 23da39e8e..b7df33a01 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -343,7 +343,7 @@ int dummy; lang = comp.get_language() tgt = self.introspection_data[id] # Find an existing entry or create a new one - id_hash = (lang, CompilerArgs) + id_hash = (lang, parameters) src_block = tgt.get(id_hash, None) if src_block is None: # Convert parameters @@ -351,7 +351,7 @@ int dummy; parameters = parameters.to_native(copy=True) parameters = comp.compute_parameters_with_absolute_paths(parameters, self.build_dir) if target.is_cross: - parameters += comp.get_cross_extra_flags(self.environment, False) + parameters.insert(0, comp.get_cross_extra_flags(self.environment, False)) # The new entry src_block = { 'language': lang, @@ -360,7 +360,6 @@ int dummy; 'sources': [], 'generated_sources': [], } - self._intro_last_index = len(tgt) tgt[id_hash] = src_block # Make source files absolute sources = [x.absolute_path(self.source_dir, self.build_dir) if isinstance(x, File) else os.path.normpath(os.path.join(self.build_dir, x)) diff --git a/mesonbuild/mintro.py b/mesonbuild/mintro.py index 63cf7fb9b..cba10f34d 100644 --- a/mesonbuild/mintro.py +++ b/mesonbuild/mintro.py @@ -35,8 +35,6 @@ from .compilers import compilers import sys, os import pathlib -INTROSPECTION_OUTPUT_FILE = 'meson-introspection.json' - def add_arguments(parser): parser.add_argument('--targets', action='store_true', dest='list_targets', default=False, help='List top level targets.') @@ -62,7 +60,7 @@ def add_arguments(parser): help='Print all available information.') parser.add_argument('-i', '--indent', dest='indent', type=int, default=0, help='Number of spaces used for indentation.') - parser.add_argument('-f', '--force-dict-output', action='store_true', dest='force_dict', default=False, + parser.add_argument('-f', '--force-object-output', action='store_true', dest='force_dict', default=False, help='Always use the new JSON format for multiple entries (even for 0 and 1 introspection commands)') parser.add_argument('builddir', nargs='?', default='.', help='The build directory') @@ -104,7 +102,7 @@ def list_targets(builddata: build.Build, installdata, backend: backends.Backend) 'type': target.get_typename(), 'filename': fname, 'build_by_default': target.build_by_default, - 'sources': backend.get_introspection_data(idname, target) + 'target_sources': backend.get_introspection_data(idname, target) } if installdata and target.should_install(): @@ -276,7 +274,7 @@ def list_target_files(target_name, targets, builddata: build.Build): print('Target with the ID "{}" could not be found'.format(target_name)) sys.exit(1) - for i in tgt['sources']: + for i in tgt['target_sources']: result += i['sources'] + i['generated_sources'] # TODO Remove this line in a future PR with other breaking changes diff --git a/run_unittests.py b/run_unittests.py index 4b4d86b03..f7737ab57 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -3182,7 +3182,7 @@ recommended as it is not supported on some platforms''') ('type', str), ('filename', str), ('build_by_default', bool), - ('sources', list), + ('target_sources', list), ('installed', bool), ] @@ -3260,7 +3260,7 @@ recommended as it is not supported on some platforms''') self.assertEqual(i['build_by_default'], tgt[1]) self.assertEqual(i['installed'], tgt[2]) targets_to_find.pop(i['name'], None) - for j in i['sources']: + for j in i['target_sources']: assertKeyTypes(targets_sources_typelist, j) self.assertDictEqual(targets_to_find, {}) -- cgit v1.2.3 From 428f85e8605034e30f835542f2d26600e967f4f0 Mon Sep 17 00:00:00 2001 From: Daniel Mensinger Date: Tue, 1 Jan 2019 22:57:16 +0100 Subject: Updated the docs [skip ci] --- docs/markdown/IDE-integration.md | 73 +++++++++++++++++++++++++++++----------- 1 file changed, 54 insertions(+), 19 deletions(-) (limited to 'docs') diff --git a/docs/markdown/IDE-integration.md b/docs/markdown/IDE-integration.md index d4554aea4..25d262a5d 100644 --- a/docs/markdown/IDE-integration.md +++ b/docs/markdown/IDE-integration.md @@ -4,15 +4,28 @@ short-description: Meson's API to integrate Meson support into an IDE # IDE integration -Meson has exporters for Visual Studio and XCode, but writing a custom backend for every IDE out there is not a scalable approach. To solve this problem, Meson provides an API that makes it easy for any IDE or build tools to integrate Meson builds and provide an experience comparable to a solution native to the IDE. +Meson has exporters for Visual Studio and XCode, but writing a custom backend +for every IDE out there is not a scalable approach. To solve this problem, +Meson provides an API that makes it easy for any IDE or build tools to +integrate Meson builds and provide an experience comparable to a solution +native to the IDE. -All the resources required for such a IDE integration can be found in the `meson-info` directory in the build directory. +All the resources required for such a IDE integration can be found in +the `meson-info` directory in the build directory. -The first thing to do when setting up a Meson project in an IDE is to select the source and build directories. For this example we assume that the source resides in an Eclipse-like directory called `workspace/project` and the build tree is nested inside it as `workspace/project/build`. First, we initialize Meson by running the following command in the source directory. +The first thing to do when setting up a Meson project in an IDE is to select +the source and build directories. For this example we assume that the source +resides in an Eclipse-like directory called `workspace/project` and the build +tree is nested inside it as `workspace/project/build`. First, we initialize +Meson by running the following command in the source directory. meson builddir -With this command meson will configure the project and also generate introspection information that is stored in `intro-*.json` files in the `meson-info` directory. The introspection dump will be automatically updated when meson is (re)configured, or the build options change. Thus, an IDE can watch for changes in this directory to know when something changed. +With this command meson will configure the project and also generate +introspection information that is stored in `intro-*.json` files in the +`meson-info` directory. The introspection dump will be automatically updated +when meson is (re)configured, or the build options change. Thus, an IDE can +watch for changes in this directory to know when something changed. The `meson-info` directory should contain the following files: @@ -31,7 +44,9 @@ The content of the JSON files is further specified in the remainder of this docu ## The `targets` section -The most important file for an IDE is probably `intro-targets.json`. Here each target with its sources and compiler parameters is specified. The JSON format for one target is defined as follows: +The most important file for an IDE is probably `intro-targets.json`. Here each +target with its sources and compiler parameters is specified. The JSON format +for one target is defined as follows: ```json { @@ -45,13 +60,19 @@ The most important file for an IDE is probably `intro-targets.json`. Here each t } ``` -If the key `installed` is set to `true`, the key `install_filename` will also be present. It stores the installation location for each file in `filename`. If one file in `filename` is not installed, its corresponding install location is set to `null`. +If the key `installed` is set to `true`, the key `install_filename` will also +be present. It stores the installation location for each file in `filename`. +If one file in `filename` is not installed, its corresponding install location +is set to `null`. -A target usually generates only one file. However, it is possible for custom targets to have multiple outputs. +A target usually generates only one file. However, it is possible for custom +targets to have multiple outputs. ### Target sources -The `intro-targets.json` file also stores a list of all source objects of the target in the `target_sources`. With this information, an IDE can provide code completion for all source files. +The `intro-targets.json` file also stores a list of all source objects of the +target in the `target_sources`. With this information, an IDE can provide code +completion for all source files. ```json { @@ -63,6 +84,12 @@ The `intro-targets.json` file also stores a list of all source objects of the ta } ``` +It should be noted that the compiler parameters stored in the `parameters` +differ from the actual parameters used to compile the file. This is because +the parameters are optimized for the usage in an IDE to provide autocompletion +support, etc. It is thus not recommended to use this introspection information +for actual compilation. + ### Possible values for `type` The following table shows all valid types for a target. @@ -79,7 +106,8 @@ The following table shows all valid types for a target. ## Build Options -The list of all build options (build type, warning level, etc.) is stored in the `intro-buildoptions.json` file. Here is the JSON format for each option. +The list of all build options (build type, warning level, etc.) is stored in +the `intro-buildoptions.json` file. Here is the JSON format for each option. ```json { @@ -99,7 +127,8 @@ The supported types are: - integer - array -For the type `combo` the key `choices` is also present. Here all valid values for the option are stored. +For the type `combo` the key `choices` is also present. Here all valid values +for the option are stored. The possible values for `section` are: @@ -117,19 +146,24 @@ Since Meson 0.50.0 it is also possible to get the default buildoptions without a build directory by providing the root `meson.build` instead of a build directory to `meson introspect --buildoptions`. -Running `--buildoptions` without a build directory produces the same output as running -it with a freshly configured build directory. +Running `--buildoptions` without a build directory produces the same output as +running it with a freshly configured build directory. -However, this behavior is not guaranteed if subprojects are present. Due to internal -limitations all subprojects are processed even if they are never used in a real meson run. -Because of this options for the subprojects can differ. +However, this behavior is not guaranteed if subprojects are present. Due to +internal limitations all subprojects are processed even if they are never used +in a real meson run. Because of this options for the subprojects can differ. ## Tests -Compilation and unit tests are done as usual by running the `ninja` and `ninja test` commands. A JSON formatted result log can be found in `workspace/project/builddir/meson-logs/testlog.json`. +Compilation and unit tests are done as usual by running the `ninja` and +`ninja test` commands. A JSON formatted result log can be found in +`workspace/project/builddir/meson-logs/testlog.json`. -When these tests fail, the user probably wants to run the failing test in a debugger. To make this as integrated as possible, extract the tests from the `intro-tests.json` and `intro-benchmarks.json` files. -This provides you with all the information needed to run the test: what command to execute, command line arguments and environment variable settings. +When these tests fail, the user probably wants to run the failing test in a +debugger. To make this as integrated as possible, extract the tests from the +`intro-tests.json` and `intro-benchmarks.json` files. This provides you with +all the information needed to run the test: what command to execute, command +line arguments and environment variable settings. ```json { @@ -148,7 +182,8 @@ This provides you with all the information needed to run the test: what command # Programmatic interface -Meson also provides the `meson introspect` for project introspection via the command line. Use `meson introspect -h` to see all available options. +Meson also provides the `meson introspect` for project introspection via the +command line. Use `meson introspect -h` to see all available options. This API can also work without a build directory for the `--projectinfo` command. -- cgit v1.2.3 From bcb8146280ed89d1fabc3136e2e65a6173b31214 Mon Sep 17 00:00:00 2001 From: Daniel Mensinger Date: Wed, 2 Jan 2019 21:58:04 +0100 Subject: Indent flag only toggles --- docs/markdown/snippets/introspect_multiple.md | 3 ++- mesonbuild/mintro.py | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'docs') diff --git a/docs/markdown/snippets/introspect_multiple.md b/docs/markdown/snippets/introspect_multiple.md index 0d53d4806..131bf58ee 100644 --- a/docs/markdown/snippets/introspect_multiple.md +++ b/docs/markdown/snippets/introspect_multiple.md @@ -13,7 +13,8 @@ JSON output (the default is still compact JSON) and force use the new output format, even if only one introspection command was given. A complete introspection dump is also stored in the `meson-info` -directory. This dump will be (re)generated each time meson updates the configuration of the build directory. +directory. This dump will be (re)generated each time meson updates the +configuration of the build directory. Additionlly the format of `meson introspect target` was changed: diff --git a/mesonbuild/mintro.py b/mesonbuild/mintro.py index c0cefdbe9..3382e0da0 100644 --- a/mesonbuild/mintro.py +++ b/mesonbuild/mintro.py @@ -56,8 +56,8 @@ def add_arguments(parser): help='The backend to use for the --buildoptions introspection.') parser.add_argument('-a', '--all', action='store_true', dest='all', default=False, help='Print all available information.') - parser.add_argument('-i', '--indent', dest='indent', type=int, default=0, - help='Number of spaces used for indentation.') + parser.add_argument('-i', '--indent', action='store_true', dest='indent', default=False, + help='Enable pretty printed JSON.') parser.add_argument('-f', '--force-object-output', action='store_true', dest='force_dict', default=False, help='Always use the new JSON format for multiple entries (even for 0 and 1 introspection commands)') parser.add_argument('builddir', nargs='?', default='.', help='The build directory') @@ -457,7 +457,7 @@ def list_projinfo_from_source(sourcedir, indent): def run(options): datadir = 'meson-private' infodir = 'meson-info' - indent = options.indent if options.indent > 0 else None + indent = 4 if options.indent else None if options.builddir is not None: datadir = os.path.join(options.builddir, datadir) infodir = os.path.join(options.builddir, infodir) -- cgit v1.2.3 From 0b0ec5895c6db491cb1fefaadbdc091c1e77189a Mon Sep 17 00:00:00 2001 From: Daniel Mensinger Date: Sat, 5 Jan 2019 18:04:01 +0100 Subject: Fixed typo [skip ci] --- docs/markdown/snippets/introspect_multiple.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs') diff --git a/docs/markdown/snippets/introspect_multiple.md b/docs/markdown/snippets/introspect_multiple.md index 131bf58ee..06df733ef 100644 --- a/docs/markdown/snippets/introspect_multiple.md +++ b/docs/markdown/snippets/introspect_multiple.md @@ -18,5 +18,5 @@ configuration of the build directory. Additionlly the format of `meson introspect target` was changed: - - New: the `sources` key. It stores the source files of a target and there compiler parameters + - New: the `sources` key. It stores the source files of a target and their compiler parameters - Added new target types (`jar`, `shared module`) -- cgit v1.2.3 From 52071c6d4ee15c750f8a8620e038b78627db890e Mon Sep 17 00:00:00 2001 From: Daniel Mensinger Date: Sat, 5 Jan 2019 18:04:44 +0100 Subject: Fixed missing dots [skip ci] --- docs/markdown/snippets/introspect_multiple.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'docs') diff --git a/docs/markdown/snippets/introspect_multiple.md b/docs/markdown/snippets/introspect_multiple.md index 06df733ef..67f517a2a 100644 --- a/docs/markdown/snippets/introspect_multiple.md +++ b/docs/markdown/snippets/introspect_multiple.md @@ -18,5 +18,5 @@ configuration of the build directory. Additionlly the format of `meson introspect target` was changed: - - New: the `sources` key. It stores the source files of a target and their compiler parameters - - Added new target types (`jar`, `shared module`) + - New: the `sources` key. It stores the source files of a target and their compiler parameters. + - Added new target types (`jar`, `shared module`). -- cgit v1.2.3