Commit Graph

620 Commits

Author SHA1 Message Date
Martin Storsjö 9d8906363e Support identifying msvc dependency prefix with a path starting with a backslash 2020-09-18 05:30:49 +00:00
Nirbheek Chauhan faba48d853 backends: Treat build target as generator only when it's the first arg
Otherwise it might be an argument to a script that just inspects the
binary itself.
2020-09-17 22:25:37 +00:00
Nirbheek Chauhan 9fb839687b minstall: Add version field to install data
And check the install data in the same way that mtest checks
serialisation data.

Fixes https://github.com/mesonbuild/meson/issues/2354
2020-09-10 12:38:05 +00:00
Jon Turney 7996ca3d55 ninja: Generate all STATIC_LINKER rules
Don't stop generating STATIC_LINKER rules at the first MachineChoice
which isn't available (i.e. generate a STATIC_LINKER rule, even if
STATIC_LINKER_FOR_BUILD isn't needed)

Also warn about internal errors which lead to non-existent rule
references, rather than exploding with a KeyError.
2020-09-10 07:20:41 +00:00
Daniel Mensinger 23818fc5a3
typing: more fixes 2020-09-08 20:15:58 +02:00
Jussi Pakkanen 97177bc12a
Merge pull request #7689 from scivision/fortran_inc
correct Fortran include algorithm
2020-09-06 20:28:39 +03:00
Paolo Bonzini 492afe50a4 environment: use ExternalProgram to find ninja
This allows the NINJA environment variable to support all the Windows special
cases, especially allowing an absolute path without extension.

Based on a patch by Yonggang Luo.

Fixes: #7659
Suggested-by: Nirbheek Chauhan <nirbheek@centricular.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2020-09-04 15:38:12 +02:00
Michael Hirsch 34f7fee741
fortran: make include scanning also work for CMake subprojects
also fixed PEP8

I originally implemented the "include" scanning,
but hadn't made a test for this case
2020-09-02 22:59:04 -04:00
Paolo Bonzini 71d33a5721 backends: do not look for extra paths unnecessarily
extra_paths only matter for the host machine if using an exe_wrapper.
However, because CustomTarget.for_machine is always MachineChoice.HOST,
they were computed unnecessarily in as_meson_exe_cmdline.

Defer computation of extra_paths until after we have found out if the
custom target executable is really for the host or the build machine,
so that we can use exe_for_machine; for_machine then becomes unused
and can be removed.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2020-08-31 23:01:05 +03:00
Jussi Pakkanen e9a71ebf60
Merge pull request #7607 from bonzini/speedup
Various speedups from profiling QEMU's meson.build
2020-08-22 18:40:03 +03:00
Xavier Claessens 1c403e20e7 Interpreter: Fix c_stdlib usage
- Exceptions raised during subproject setup were ignored.
- Allow c_stdlib in native file, was already half supported.
- Eliminate usage of subproject variable name by overriding
  '<lang>_stdlib' dependency name.
2020-08-18 14:47:38 -04:00
Paolo Bonzini cbde13850f ninjabackend: avoid lambdas
The lambda in NinjaBuildElement.write is quite expensive, totalling 0.3s
just to do a couple function calls.  Since it is used just once, simply
inline it.

On a QEMU build, the total time spent in write from this series goes from
5.321s to 3.238s, though part of it can be attributed to previous patches.
2020-08-18 08:11:25 +02:00
Paolo Bonzini b14601da7b ninjabackend: optimize length_estimate
Optimize the regular expression so that the variable expansion part
always ends up in group 1, and the trailer after the variable is discarded
in the same match.  Do not use re.sub to remove braces, and do not bother
building the expanded command, just adjust the estimated length on the fly.

functools.reduce is extremely slow, so I am keeping ' '.join(chunk).

On a QEMU build the time spend in the function goes from 1.072s to 0.757s.
2020-08-18 08:11:25 +02:00
Paolo Bonzini 3d4fb02e29 ninjabackend: optimize ninja_quote
Use regular expressions to quickly weed out strings that require quoting
On a QEMU build the time spent in ninja_quote goes from 1.978s to 1.281s,
with str.replace being kicked completely out of the profile.
2020-08-18 08:11:19 +02:00
Nirbheek Chauhan 9fdb97733b ninjabackend: Fix coverage rule generation
Without the parenthesis, the command evaluates to `[]` if
`use_llvm_cov` is `False`.

Also fix tests to actually check whether or not coverage reports are
generated.

Fixes https://github.com/mesonbuild/meson/issues/7553
2020-08-15 08:41:52 +00:00
Marcel Hollerbach 903d5dd8a7 ninjabackend: check if target has compiler attribute
otherwise we are getting errors like:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/mesonbuild/mesonmain.py", line 131, in run
    return options.run_func(options)
  File "/usr/local/lib/python3.6/dist-packages/mesonbuild/msetup.py", line 245, in run
    app.generate()
  File "/usr/local/lib/python3.6/dist-packages/mesonbuild/msetup.py", line 159, in generate
    self._generate(env)
  File "/usr/local/lib/python3.6/dist-packages/mesonbuild/msetup.py", line 215, in _generate
    intr.backend.generate()
  File "/usr/local/lib/python3.6/dist-packages/mesonbuild/backend/ninjabackend.py", line 518, in generate
    self.generate_coverage_rules()
  File "/usr/local/lib/python3.6/dist-packages/mesonbuild/backend/ninjabackend.py", line 991, in generate_coverage_rules
    self.generate_coverage_command(e, [])
  File "/usr/local/lib/python3.6/dist-packages/mesonbuild/backend/ninjabackend.py", line 975, in generate_coverage_command
    for compiler in target.compilers.values():
AttributeError: 'RunTarget' object has no attribute 'compilers'

This extends the 109 generatecode test case to also define a test, so
coverage can really detect something.
2020-07-28 17:59:03 +03:00
Nirbheek Chauhan 07e62fb42b Don't spam about usage of rspfiles to stdout
Put it in the log file if necessary. Users don't need to know this.
It's very spammy.
2020-07-22 10:11:09 -04:00
Martin Storsjö 43129a11ed Fix a comment about cross compilation with clang-cl [skip ci]
This comment was added in 0fbd09609f, where the case of a forward
slash was added for the case when cross compiling.
2020-07-19 14:58:23 +03:00
Nirbheek Chauhan 848fcb6a53 Enable target override_options for llvm-ir
This was missed somehow when the feature was added a few years ago.
2020-07-13 15:28:51 +00:00
Dylan Baker 93c3ec7e2d compilers: Return CompilerArgs from compiler instance
Since the CompileArgs class already needs to know about the compiler,
and we really need at least per-lanaguage if not per-compiler
CompilerArgs classes, let's get the CompilerArgs instance from the
compiler using a method.
2020-06-22 12:06:10 -07:00
Dylan Baker 9d0ad66c29 compilers: Split CompilerArgs into a separate module
I've also moved this out of the compilers pacakge because we're soon
going to need it in linkers, and that creates some serious spagetti
2020-06-22 12:06:10 -07:00
Cary Converse a198e5d191 coverage: llvm-cov support 2020-06-17 23:02:50 -04:00
Nirbheek Chauhan eab0e5a8b3 windows: Canonicalize `:` in filenames
Fixes https://github.com/mesonbuild/meson/issues/7265
2020-06-14 14:55:49 +00:00
Jussi Pakkanen 801dc03070
Merge pull request #7245 from dankegel/response-files-when-needed-tidied
Make ninja backend only use response files when needed, on linux too
2020-06-08 00:33:46 +03:00
Dan Kegel 10e6a989ba ninja: response file threshold now more accurate, overridable, portable. 2020-06-05 14:15:32 -07:00
Jon Turney 5ca37e7961 ninja: Add ninja variable DEPFILE_UNQUOTED with unquoted DEPFILE value
It's assumed that where we use DEPFILE in command or rspfile_content, it
can be quoted by quoting the ninja variable (e.g. $DEPFILE ->
'$DEPFILE')

This is nearly always true, but not for gcc response files, where
backslash is always an escape, even inside single quotes.

So this fails if the value of DEPFILE contains backslashes (e.g. a
Windows path)

Do some special casing, adding DEPFILE_UNQUOTED, so that the value of
depfile is not shell quoted (so ninja can use it to locate the depfile
to read), but the value of DEPFILE used in command or rspfile_content is
shell/response file quoted)

(It would seem this also exists as a more general problem with built-in
ninja variables: '$out' appearing in command is fine, unless one of the
output filenames contains a single quote.  Although forbidding shell
metacharacters in filenames seems a reasonable way to solve that.)

(How does this even work, currently? Backslashes in the value of all
ninja variables, including DEPFILE were escaped, which protected them
against being treated as escapes in the gcc response file.  And
fortunately, the empty path elements indicated by a double backslash in
the value of depfile are ignored when ninja opens that file to read it.)
2020-06-05 14:15:32 -07:00
Jon Turney abf8bf488e ninja: Specifically implement gcc rspfile style quoting
This differs from sh-quoting in that a backslash *always* escapes the
following character, even inside single quotes.  Yes, really.

https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=libiberty/argv.c#l176
2020-06-05 14:15:32 -07:00
Jon Turney aca93df184 backend: There is no need for 'compiler-specific escaping' anymore
Now that all command-line escaping for ninja is dealt with in the ninja
backend, escape_extra_args() shouldn't need to do anything.

But tests of existing behaviour rely on all backslashes in defines being
C escaped: This means that Windows-style paths including backslashes can
be safely used, but makes it impossible to have a define containing a C
escape.
2020-06-05 14:15:32 -07:00
Jon Turney eb60c041f9 ninja: Implement Windows-style command line quoting
We avoided having to get this right previously, as we'd always use a
response file if possible.

But this is so insane, I can't imagine it's right.

See also: subprocess.list2cmdline() internal method
2020-06-05 14:15:32 -07:00
Jon Turney fbacf87af5 ninja: Quoting in rspfile depends on the compiler, not the shell
In certain exotic configurations, the style of quoting expected in the
response file may not match that expected by the shell.

e.g. under MSYS2, ninja invokes commands via CreateProcess (which
results in cmd-style quoting processed by parse_cmdline or
CommandLineToArgvW), but gcc will use sh-style quoting in any response
file it reads.

Future work: The rspfile quoting style should be a method of the
compiler or linker object, rather than hardcoded in ninjabackend.

(In fact, can_linker_accept_rsp() should be extended to do this, since
if we can accept rsp, we should know the quoting style)
2020-06-05 14:15:32 -07:00
Jon Turney 9cec5f3521 ninja: Push ninja and shell quoting down into NinjaRule
Rather than ad-hoc avoiding quoting where harmful, identify arguments
which contain shell constructs and ninja variables, and don't apply
quoting to those arguments.

This is made more complex by some arguments which might contain ninja
variables anywhere, not just at start, e.g. '/Fo$out'

(This implementation would fall down if there was an argument which
contained both a literal $ or shell metacharacter and a ninja variable,
but there are no instances of such a thing and it seems unlikely)

$DEPFILE needs special treatment.  It's used in the special variable
depfile, so it's value can't be shell quoted (as it used as a filename
to read by ninja).  So instead that variable needs to be shell quoted
when it appears in a command.

(Test common/129, which uses a depfile with a space in it's name,
exercises that)

If 'targetdep' is not in raw_names, test cases/rust all fail.
2020-06-05 14:15:32 -07:00
Jon Turney 92ee8932cd ninja: Refcount rsp and non-rsp rule usage separately
We need to count rsp and non-rsp references separately, which we need to
do after build statement variables have been set so we can tell the
difference, which introduces a bit of complexity.
2020-06-05 14:15:32 -07:00
Jon Turney 9967a2276d ninja: Expose response file rules in compdb
Possibly this should now be done by marking rules as being wanted in compdb, rather
than listing the rule names...
2020-06-05 14:15:32 -07:00
Jon Turney f9c03dfd29 ninja: Only use response files when needed
Writing rsp files on Windows is moderately expensive, so only use them
when the command line is long enough to need them.

This also makes the output of 'ninja -v' useful more often (something
like 'cl @exec@exe/main.c.obj.rsp' is not very useful if you don't have
the response file to look at)

For a rule where using a rspfile is possible, write rspfile and
non-rspfile versions of that rule.  Choose which one to use for each
build statement, depending on the anticpated length of the command line.
2020-06-05 14:15:32 -07:00
Jon Turney 50f98f3726 ninja: Rename 'rule' -> 'rulename' in NinjaBuildElement
Rename 'rule' to 'rulename' in the NinjaBuildElement class, we're going
to want a reference to the NinjaRule object as well.
2020-06-05 14:15:32 -07:00
Marcel Hollerbach cca06e4c33 ninjabackend: cache calls to normpaths
calls to normpaths are expansive. We should cache the results. This
safes 2s in the configure time of efl.
2020-06-05 09:02:23 +02:00
Daniel Mensinger a340b413ef ninja: Always use to_native on CompilerArgs (fixes #7167) 2020-05-27 20:23:58 +03:00
georgev93 6f199db95b Use --internal script call to call delwithsuffix when cleaning up the gcno and gcda files in a coverage enabled build. Otherwise, meson will crash when running from an MSI installation. 2020-05-26 02:48:57 +03:00
Jussi Pakkanen 751ea3df72
Merge pull request #7103 from dankegel/bug4027-rpath-remember
Let .pc files and LDFLAGS provide rpaths.
2020-05-18 23:17:34 +03:00
Dan Kegel d7235c5905 Let .pc files specify rpath.
Fixes #4027
2020-05-16 20:25:58 +00:00
Nirbheek Chauhan b1e3440e59 ninjabackend: Treat GNOME gir/typelib as libraries
When classifying generated sources, we were treating gir/typelib files
generated by gobject-introspection as headers. This is bad because it
serializes the build by adding order-only dependencies to every target
even though sources will never actually use them for anything.

Treat them as libraries, which is somewhat more accurate.
2020-05-15 08:39:25 +00:00
Nirbheek Chauhan a25f0741e8 ninjabackend: Use order-only gen-header deps for gen-sources
We do not need to *always* rebuild generated sources when a generated
header changes. We will get that information from the compiler's
dependency file, and ninja will track it for us. This is exactly the
same as static sources.

However, we do need an order-only dependency on all generated headers,
because we cannot know what headers will be needed at compile time
(which is when the compiler's dependency file is generated).

This fixes spurious rebuilds and relinking in many cases.
2020-05-15 08:39:25 +00:00
Michael Brockus 3ac437cecf
rm python2 %s from backends.py and ninjabackend.py 2020-05-03 14:00:15 +03:00
John Ericson 278c294aa4 Compiler options per lang
A current rather untyped storage of options is one of the things that
contributes to the options code being so complex. This takes a small
step in synching down by storing the compiler options in dicts per
language.

Future work might be replacing the langauge strings with an enum, and
defaultdict with a custom struct, just like `PerMachine` and
`MachineChoice`.
2020-04-20 23:23:15 +03:00
Michael e04b0ae6b6 fix ninja version inconsistent 2020-04-20 19:31:21 +03:00
Marc-André Lureau a54506fe46 Handle BuildTarget as custom_target() argument #6914 2020-04-11 23:18:43 +03:00
ClausKlein 00104b1081 Remove my notes from sources
changes acording review comments
2020-03-19 19:11:10 +02:00
ClausKlein f72c990bfd Use os.path.normpath() for include paths
This make relative pathes shorter an too give a chance to
de-duplicate -isystem flags just like -I flags.

Fix common test case 203 for OSX build host too
2020-03-19 19:11:10 +02:00
Dylan Baker 06b1a317d2 Make use of unholder
We have a lot of cases of code like:
```python
if hasattr(var, 'held_object'):
    var = var.held_object`
```

replace that with the unholder function.
2020-03-05 09:58:52 -08:00
Jussi Pakkanen 0fbd09609f Clang-cl cross fix from Dale Curtis. Closes #5639. 2020-02-27 23:50:03 +02:00