Commit Graph

69 Commits

Author SHA1 Message Date
Dan Hawson c34ee374a7
fix the use of setup --profile-self in combination with --genvslite
After the recent change to the backend `generate(...)` signature for
'--genvslite', `profile.runctx('...')` needs to construct the correct
cmd string and also extract the return result from `locals()`.
2023-07-03 15:34:34 -04:00
Eli Schwartz db0c24e627
genvslite: greatly simplify the implementation of non-genvslite backends
By avoiding Java-style variable naming, the code becomes considerably
more readable while simultaneously becoming *more* easy to understand.
It's no longer necessary to ask questions like "what's a captured
buildtype" when trying to read through the code for a backend, because
it can be dismissed as not relevant to the current context by re-reading
it as "context for vslite".

The primary goal here has been to revert regressions in the developer
experience for users of the ninja backend, so there may still be issues
in vs2010backend.py

Post-facto application of issues that were raised during review,
ignored, and merged despite such.
2023-07-02 18:03:21 -04:00
Eli Schwartz 098ac5e0a6
genvslite: fix badly overflowing line lengths
Function comments that overflow the screen width by coming after code,
instead of on their own line, are hard to read. Same applies to message
strings that are all on one line. Fix by reflowing them.

Post-facto application of issues that were caught during post-merge
review, after the genvslite PR was merged without a full review.
2023-07-02 18:03:21 -04:00
GertyP 36bf53bdfd
Experimental 'genvslite' WIP. (#11049)
* Capture all compile args from the first round of ninja backend generation for all languages used in building the targets so that these args, defines, and include paths can be applied to the .vcxproj's intellisense fields for all buildtypes/configurations.

Solution generation is now set up for mutiple build configurations (buildtypes) when using '--genvslite'.

All generated vcxprojs invoke the same high-level meson compile to build all targets;  there's no selective target building (could add this later).  Related to this, we skip pointlessly generating vcxprojs for targets that aren't buildable (BuildTarget-derived), which aren't of interest to the user anyway.

When using --genvslite, no longer inject '<ProjectReference ...>' dependencies on which a generated .vcxproj depends because that imposes a forced visual studio build dependency, which we don't want, since we're essentially bypassing VS's build in favour of running 'meson compile ...'.

When populating the vcxproj's shared intellisense defines, include paths, and compiler options fields, we choose the most frequent src file language, since this means more project src files can simply reference the project shared fields and fewer files of non-primary language types need to populate their full set of intellisense fields.  This makes for smaller .vcxproj files.

Paths for generated source/header/etc files, left alone, would be added to solution projects relative to the '..._vs' build directory, where they're never generated;  they're generated under the respective '..._[debug/opt/release]' ninja build directories that correspond to the solution build configuration. Although VS doesn't allow conditional src/header listings in vcxprojs (at least not in a simple way that I'm aware of), we can ensure these generated sources get adjusted to at least reference locations under one of the concrete build directories (I've chosen '..._debug') under which they will be generated.

Testing with --genvslite has revealed that, in some cases, the presence of 'c:\windows\system32;c:\windows' on the 'Path' environment variable (via the make-style project's ExecutablePath element) is critical to getting the 'meson compile ...' build to succeed.  Not sure whether this is some 'find and guess' implicit defaults behaviour within meson or within the MSVC compiler that some projects may rely on. Feels weird but not sure of a better solution than forcibly adding these to the Path environment variable (the Executable Path property of the project).

Added a new windows-only test to windowstests.py ('test_genvslite') to exercise the --genvslite option along with checking that the 'msbuild' command invokes the 'meson compile ...' of the build-type-appropriate-suffixed temporary build dir and checks expected program output.

Check and report error if user specifies a non-ninja backend with a 'genvslite' setup, since that conflicts with the stated behaviour of genvslite.  Also added this test case to 'WindowsTests.test_genvslite'

I had problems tracking down some problematic environment variable behaviour, which appears to need a work-around. See further notes on VSINSTALLDIR, in windowstests.py, test_genvslite.
'meson setup --help' clearly states that positional arguments are ... [builddir] [sourcedir].  However, BasePlatformTests.init(...) was passing these in the order [sourcedir] [builddir].  This was producing failures, saying, "ERROR: Neither directory contains a build file meson.build." but when using the correct ordering, setup now succeeds.

Changed regen, run_tests, and run_install utility projects to be simpler makefile projects instead, with commands to invoke the appropriate '...meson.py --internal regencheck ...' (or install/test) on the '[builddir]_[buildtype]' as appropriate for the curent VS configuration.  Also, since the 'regen.vcxproj' utility didn't work correctly with '--genvslite' setup build dirs, and getting it to fully work would require more non-trivial intrusion into new parts of meson (i.e. '--internal regencheck', '--internal regenerate', and perhaps also 'setup --reconfigure'), for now, the REGEN project is replaced with a simpler, lighter-weight RECONFIGURE utility proj, which is unlinked from any solution build dependencies and which simply runs 'meson setup --reconfigure [builddir]_[buildtype] [srcdir]' on each of the ninja-backend build dirs for each buildtype.
Yes, although this will enable the building/compiling to be correctly configured, it can leave the solution/vcxprojs stale and out-of-date, it's simple for the user to 'meson setup --genvslite ...' to fully regenerate an updated, correct solution again. However, I've noted this down as a 'fixme' to consider implementing the full regen behaviour for the genvslite case.

* Review feedback changes -
- Avoid use of 'captured_compile_args_per_buildtype_and_target' as an 'out' param.
- Factored a little msetup.py, 'run(...)' macro/looping setup steps, for genvslite, out into a 'run_genvslite_setup' func.

* Review feedback:  Fixed missing spaces between multi-line strings.

* 'backend_name' assignment gets immediately overwritten in 'genvslite' case so moved it into else/non-genvslite block.

* Had to bump up 'test cases/unit/113 genvslites/...' up to 114; it collided with a newly added test dir again.

* Changed validation of 'capture' and 'captured_compile_args_...' to use MesonBugException instead of MesonException.

* Changed some function param and closing brace indentation.
2023-06-28 15:29:57 +03:00
Eli Schwartz 418063cc47
pkgconfig: move uninstalled devenv handling from setup to the module hook
msetup.py doesn't need to know the gory details of PkgConfigDependency,
or directly import it at program startup. It's also slightly wasteful to
generate a devenv for the -uninstalled directory when a project doesn't
even, in the end, use the pkgconfig module anyway.
2023-06-26 13:10:25 -04:00
Eli Schwartz 620bdf5895
add profiling startup import check and testcase to count it 2023-06-26 13:08:57 -04:00
Eli Schwartz cd6c3ca55e
msetup: place profiling logs in the log directory 2023-06-25 12:12:11 -04:00
Eli Schwartz 4a2530802c
update the devenv module hooks to support generic modifications to Build
We may want to do things like update install scripts as well, which have
to happen before generating the backend. Instead of adding one module
method per thing to do, use a single function that allows for modifying
the Build object directly.
2023-05-02 19:28:35 -04:00
Xavier Claessens 9c526974dc
msetup: Allow (re)configure of not empty builddir
Also prevent from using a parent directory as builddir by mistake.

Co-authored-by: Volker Weißmann <volker.weissmann@gmx.de>
Co-authored-by: Charles Brunet <charles.brunet@optelgroup.com>
2023-03-30 17:10:53 -04:00
Xavier Claessens 0418a40e68
msetup: use more consistent exceptions on exit
- MesonException for errors is clearer than SystemExit('error message')
  and provides meson-formatted "ERROR: ..."

- `raise SystemExit` with no parameter isn't obvious that it intends to
  exit successfully

While clarifying the latter, it was observed to cause
test_preprocessor_checks_CPPFLAGS() failure to be ignored. That test
checks get_define() on both c and cpp compilers, which means we need to
define either CPPFLAGS or both CFLAGS+CXXFLAGS.
2023-03-30 17:10:53 -04:00
Xavier Claessens b30cd5d2d5 Make --vsenv a readonly builtin option
We need to remember its value when reconfiguring, but the Build object
is not reused, only coredata is.

This also makes CLI more consistent by allowing `-Dvsenv=true` syntax.

Fixes: #11309
2023-03-29 09:33:41 -04:00
Xavier Claessens 89fe81835b Allow --reconfigure and --wipe of empty builddir
This allows to run setup command regardless whether the builddir has
been configured or not previously. This is useful for example with
scripts that always repeat all options.
  meson setup builddir --reconfigure -Dfoo=bar
2023-03-27 17:50:48 -04:00
Eli Schwartz c2db6eb2e2 msetup: clarify error message when wrong directories are specified
This can happen from typos, which then confusingly claim that neither
build directory has a meson.build file because the implicit . directory
was not actually one of the directories. Instead a random command line
argument was interpreted as a directory name.

Fixes #11472
2023-02-28 09:10:15 -05:00
Eli Schwartz 680b5ff819
treewide: add future annotations import 2023-02-01 17:01:30 -05:00
Dylan Baker 76bead7e15 msetup: do some stupid casting to make mypy happy
mypy is pretty dumb when it comes to unions of callables (pylance is
also dumb in this regard), and can't figure out that our use of
`mlog.debug | mlog.log` is perfectly safe. We also can't annotate them
properly to cast them to a valid subset of arguments because you can't
have splats in `typing.Callable`, so I've done enough to make it work.
2023-01-03 14:49:02 -05:00
Dylan Baker 5794805f8e
pylint: enable used-before-assignment
The one case of this was a false-positive, but what we were doing
(checking locals()) is not idiomatic. I've replaced the call to
`locals()` with the obvious `var: T.Optional[str] = None` with check
instead.
2022-11-29 23:26:05 -05:00
Eli Schwartz 9ed5cfda15
avoid importing the entire codebase at first startup
We want to optimize out some internal codepaths used at build time by
avoiding work such as argparse. This doesn't work particularly well when
the argparse arguments are imported before then. Between them, they
indirectly import pretty much all code anywhere, and msetup alone
imports most of it.

Also make sure the regenerate internal script goes directly to msetup.
2022-09-19 15:19:00 -04:00
Eli Schwartz d395b1a768
fix up some message strings that don't include "setup" in the configure command 2022-08-22 00:23:14 -04:00
Xavier Claessens 5a34dcedf7 devenv: Use PkgConfigDependency.get_env()
This ensures that PKG_CONFIG_PATH, PKG_CONFIG_LIBDIR and
PKG_CONFIG_SYSROOT_DIR are also set properly.
2022-05-04 00:16:32 +03:00
Xavier Claessens c4b8c23eb1 Add API for modules that wants to define their devenv 2022-02-28 09:03:27 -05:00
Xavier Claessens 928078982c Add --vsenv command line option and active VS only when needed 2021-10-10 23:15:18 +03:00
Eli Schwartz 3cddb0e5c6
deprecate layout=flat and warn people never to use it
It's broken in various circumstances, no one seems to actually use it,
CI doesn't test it, no one is committed to maintaining it, etc. etc.
etc.

Also, projects doing trivially reasonable things, such as generating
"foo/util.py" and "bar/util.py", create clashing output names. This will
never, ever, ever, ever work with layout=flat.

Closes #996
Closes #1521
Closes #1908
Closes #7133
Closes #7135
Closes #7480
Closes #8378
2021-09-12 10:52:33 -04:00
Eli Schwartz 49d861763c
msetup: make xcode unsupported warning actually show
Until we invoke interpreter.Interpreter(b, ...) the coredata options
still have their default values and thus cannot be used sensibly.
Currently the warning never shows (other than, unsurprising in
retrospect, during --internal regenerate).
2021-09-12 02:19:49 -04:00
Xavier Claessens 5e55a0bb2b interpreter: Add summary of all user defined options
It is a commonly needed information to help debugging build issues. We
already were printing options with non-default value at the end of the
configure but outside of the summary.

Keeping the list of user defined options in the interpreter will also in
the future be useful to use new default value on reconfigure.
2021-09-02 19:38:29 -04:00
Daniel Mensinger 3e396b3782
fix: Always explicitly set encoding for text files (fixes #8263) 2021-06-29 11:28:08 +02:00
Xavier Claessens d9b9eecd54 msetup: Restore .gitignore after wipe 2021-04-17 22:54:03 -04:00
Xavier Claessens 20a90cf709 cmd_line_file.txt: Use cross/native file path resolved by coredata
This fix issue when using --wipe and the machine file was passed as a
pipe and written locally, or when the file was resolved in XDG_DATA_HOME
or XDG_DATA_DIRS.

Fixes: #8560
2021-03-22 14:45:10 -04:00
Xavier Claessens 598e968993 Add `meson devenv` command and meson.add_devenv() 2021-03-16 09:00:50 -04:00
Eli Schwartz 6a0fabc647
mass rewrite of string formatting to use f-strings everywhere
performed by running "pyupgrade --py36-plus" and committing the results
2021-03-04 17:16:11 -05:00
Dylan Baker e81acbd606 Use a single coredata dictionary for options
This patches takes the options work to it's logical conclusion: A single
flat dictionary of OptionKey: UserOptions. This allows us to simplify a
large number of cases, as we don't need to check if an option is in this
dict or that one (or any of 5 or 6, actually).
2021-01-04 12:20:58 -08:00
Dylan Baker 71db6b04a3 use OptionKey for builtin and base options
I would have prefered to do these seperatately, but they are combined in
some cases, so it was much easier to convert them together.

this eliminates the builtins_per_machine dict, as it's duplicated with
the OptionKey's machine parameter.
2021-01-04 12:20:40 -08:00
Samuel Longchamps e11218c153 Incorrect source-build directory error when using network paths on Windows 2020-12-28 22:14:48 +00:00
Jussi Pakkanen 7437d9862a Add VCS ignore files to build dir on creation. Closes #6509. 2020-12-13 10:01:06 +00:00
Corey McNeish b6dc4d5e5c Fix host machine reporting typo in msetup.py 2020-11-07 12:03:24 +02:00
Nirbheek Chauhan 7fbdf38ce3 mcompile: Add some basic XCode support
I wrote this to convert run_tests.get_backend_commands() over to the
new meson wrappers, but that turned out to be harder than I expected,
so just splitting this out for now.
2020-09-13 20:44:30 +03:00
Daniel Mensinger 23818fc5a3
typing: more fixes 2020-09-08 20:15:58 +02:00
Daniel Mensinger c637b913c9
typing: fully annotate mcompile, minit, and msetup 2020-09-08 20:15:57 +02:00
Laurent Pinchart c5d2299cac Fix symlink deletion with --wipe option
When wiping a build tree with --wipe, every entry in the build directory
is removed with mesonlib.windows_proof_rmtree() for directories and
mesonlib.windows_proof_rm() for other files. Symlinks to directories are
considered directories, resulting in the former being called. This
causes an exception to be raised, as the implementation calls
shutil.rmtree(), which isn't allowed on symlinks.

Fix this by using mesonlib.windows_proof_rm() for symlinks.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-04-29 18:55:17 +03:00
Jens Carl 2008cb2109
Fix typo in help of option '--wipe' [skip ci] 2020-04-10 17:27:51 +03:00
Michael Brockus 98ddd52ced
Cherry-picking - (rm python2 % add python3 .format) (#6725) 2020-03-03 21:45:43 +02:00
Marcel Hollerbach 66bf339e33 meson: unbreak --profile-self
This broke in 668610c0d2.
2020-02-12 04:00:10 +05:30
Daniel Mensinger 668610c0d2 backend: refactor: set self.interpreter in the constructor 2020-01-28 21:18:25 +02:00
Daniel Mensinger 09b53c534f types: import typing as T (fixes #6333) 2020-01-08 15:28:17 +01:00
Michael Hirsch, Ph.D 6e708208dd CI: add initial type annotation checking 2019-11-07 22:18:21 +02:00
Xavier Claessens 2e7f0ce557 Print user defined options in meson-log.txt
It can be useful to know what options have been passed to the command
line, excluding default values.

Closes: #5956
2019-09-25 22:50:48 +03:00
John Ericson d8335fb032 Put native file before cross file in options list
I think this makes more sense by matching how build comes before host.
Native builds are also more common than cross builds.
2019-08-12 01:21:32 +03:00
Jussi Pakkanen 8764e4f579 Print only host platform info in some cases during native builds
Build and target info is confusing in that case. However still log that
information, as it is useful in case something slips out of sync and
needs to be debugged.
2019-08-11 20:38:35 +03:00
Dylan Baker 56f7e5c74f coredata: Correctly handle receiving a pipe for native/cross files
* coredata: Correctly handle receiving a pipe for native/cross files

In some cases a cross/native file may be a pipe, such as when using bash
process replacement `meson --native-file
<([binaries]llvm-config='/opt/bin/llvm-config')`, for example. In this
case we copy the contents of the pipe into a file in the meson-private
directory so we can create a proper ninja dependency, and be able to
reload the file on --wipe/--reconfigure. This requires some extra
negotiation to preserve these native/cross files.

Fixes #5505

* run_unitests: Add a unit test for native files that are pipes

Using mkfifo.
2019-06-23 17:53:17 +03:00
Clouds a0cf7ad3d8 fix error when show default config of list
the error would occurs when specifying c_winlibs
2019-05-05 21:26:11 +03:00
Elliott Sales de Andrade eaed4aecbe Run postconf scripts absolutely last.
Introspection is broken if they are run any earlier.
2019-04-13 04:30:59 +00:00