Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions mesonbuild/backend/ninjabackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,14 @@ def gcc_rsp_quote(s: str) -> str:
# from, etc.), so it must not be shell quoted.
raw_names = {'DEPFILE_UNQUOTED', 'DESC', 'pool', 'description', 'targetdep', 'dyndep'}

NINJA_QUOTE_BUILD_PAT = re.compile(r"[$ :\n]")
NINJA_QUOTE_VAR_PAT = re.compile(r"[$ \n]")
NINJA_QUOTE_BUILD_PAT = re.compile(r"[$ :]")
NINJA_QUOTE_VAR_PAT = re.compile(r"[$ ]")
NINJA_QUOTE_NEWLINE = re.compile(r"\n")

def ninja_quote(text: str, is_build_line: bool = False) -> str:
if not is_build_line:
text = NINJA_QUOTE_VAR_PAT.sub(r'$\g<0>', text)
return NINJA_QUOTE_NEWLINE.sub(r'\\n', text)
if '\n' in text:
errmsg = f'''Ninja does not support newlines in rules. The content was:

Expand All @@ -112,11 +116,7 @@ def ninja_quote(text: str, is_build_line: bool = False) -> str:
Please report this error with a test case to the Meson bug tracker.'''
raise MesonException(errmsg)

quote_re = NINJA_QUOTE_BUILD_PAT if is_build_line else NINJA_QUOTE_VAR_PAT
if ' ' in text or '$' in text or (is_build_line and ':' in text):
return quote_re.sub(r'$\g<0>', text)

return text
return NINJA_QUOTE_BUILD_PAT.sub(r'$\g<0>', text)


@dataclass
Expand Down
3 changes: 1 addition & 2 deletions mesonbuild/cargo/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,8 +611,7 @@ def _pkg_common_env(self, pkg: PackageState, subdir: str) -> T.Dict[str, str]:
'CARGO_PKG_VERSION_PRE': version_arr[3],
'CARGO_PKG_AUTHORS': ','.join(pkg.manifest.package.authors),
'CARGO_PKG_NAME': pkg.manifest.package.name,
# FIXME: description can contain newlines which breaks ninja.
#'CARGO_PKG_DESCRIPTION': pkg.manifest.package.description or '',
'CARGO_PKG_DESCRIPTION': pkg.manifest.package.description or '',
'CARGO_PKG_HOMEPAGE': pkg.manifest.package.homepage or '',
'CARGO_PKG_REPOSITORY': pkg.manifest.package.repository or '',
'CARGO_PKG_LICENSE': pkg.manifest.package.license or '',
Expand Down
14 changes: 14 additions & 0 deletions test cases/common/27 multiline string/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,17 @@ int main(void) {
}'''

assert(cc.compiles(prog), 'multiline test compile failed')

# Test we can pass multiline strings as compiler arguments.
if not get_option('backend').startswith('vs')
helloworld = '''
Hello
World
'''
exe = executable('multiline', 'multiline.c',
c_args: ['-DHELLO_WORLD_STRING="' + helloworld + '"']
)
if not meson.is_cross_build()
test('multiline run', files('test_multiline.py'), args: [exe])
endif
endif
6 changes: 6 additions & 0 deletions test cases/common/27 multiline string/multiline.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <stdio.h>
int main(void)
{
printf("%s", HELLO_WORLD_STRING);
return 0;
}
11 changes: 11 additions & 0 deletions test cases/common/27 multiline string/test_multiline.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#! /usr/bin/env python3

import sys
import subprocess

output = subprocess.check_output(sys.argv[1:], universal_newlines=True, encoding='utf-8')

assert output == '''
Hello
World
'''
Loading