1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 from buildconfig
import topsrcdir
11 from mozpack
import path
as mozpath
12 from mozunit
import MockedOpen
, main
13 from six
import StringIO
15 from common
import ConfigureTestSandbox
, ensure_exe_extension
, fake_short_path
16 from mozbuild
.configure
import ConfigureError
, ConfigureSandbox
17 from mozbuild
.shellutil
import quote
as shell_quote
20 class TestChecksConfigure(unittest
.TestCase
):
21 def test_checking(self
):
22 def make_test(to_exec
):
25 sandbox
= ConfigureSandbox({}, stdout
=out
, stderr
=out
)
26 base_dir
= os
.path
.join(topsrcdir
, "build", "moz.configure")
27 sandbox
.include_file(os
.path
.join(base_dir
, "checks.configure"))
28 exec(to_exec
, sandbox
)
30 self
.assertEqual(out
.getvalue(), msg
)
37 @checking('for a thing')
43 test(True, "checking for a thing... yes\n")
44 test(False, "checking for a thing... no\n")
45 test(42, "checking for a thing... 42\n")
46 test("foo", "checking for a thing... foo\n")
48 test(data
, "checking for a thing... %r\n" % data
)
50 # When the function given to checking does nothing interesting, the
51 # behavior is not altered
55 @checking('for a thing', lambda x: x)
61 test(True, "checking for a thing... yes\n")
62 test(False, "checking for a thing... no\n")
63 test(42, "checking for a thing... 42\n")
64 test("foo", "checking for a thing... foo\n")
66 test(data
, "checking for a thing... %r\n" % data
)
74 if isinstance(x, (str, bool, int)):
78 @checking('for a thing', munge)
84 test(True, "checking for a thing... yes\n")
85 test(False, "checking for a thing... not found\n")
86 test(42, "checking for a thing... 42\n")
87 test("foo", "checking for a thing... foo\n")
89 test(data
, "checking for a thing... foo bar\n")
91 KNOWN_A
= ensure_exe_extension(mozpath
.abspath("/usr/bin/known-a"))
92 KNOWN_B
= ensure_exe_extension(mozpath
.abspath("/usr/local/bin/known-b"))
93 KNOWN_C
= ensure_exe_extension(mozpath
.abspath("/home/user/bin/known c"))
94 OTHER_A
= ensure_exe_extension(mozpath
.abspath("/lib/other/known-a"))
101 prog
="/bin/configure",
103 includes
=("util.configure", "checks.configure"),
107 paths
= {self
.KNOWN_A
: None, self
.KNOWN_B
: None, self
.KNOWN_C
: None}
109 paths
.update(extra_paths
)
110 environ
= dict(environ
)
111 if "PATH" not in environ
:
112 environ
["PATH"] = os
.pathsep
.join(os
.path
.dirname(p
) for p
in paths
)
113 paths
[self
.OTHER_A
] = None
114 sandbox
= ConfigureTestSandbox(paths
, config
, environ
, [prog
] + args
, out
, out
)
115 base_dir
= os
.path
.join(topsrcdir
, "build", "moz.configure")
117 sandbox
.include_file(os
.path
.join(base_dir
, f
))
121 exec(command
, sandbox
)
123 except SystemExit as e
:
126 return config
, out
.getvalue(), status
128 def test_check_prog(self
):
129 config
, out
, status
= self
.get_result('check_prog("FOO", ("known-a",))')
130 self
.assertEqual(status
, 0)
131 self
.assertEqual(config
, {"FOO": self
.KNOWN_A
})
132 self
.assertEqual(out
, "checking for foo... %s\n" % self
.KNOWN_A
)
134 config
, out
, status
= self
.get_result(
135 'check_prog("FOO", ("unknown", "known-b", "known c"))'
137 self
.assertEqual(status
, 0)
138 self
.assertEqual(config
, {"FOO": self
.KNOWN_B
})
139 self
.assertEqual(out
, "checking for foo... %s\n" % self
.KNOWN_B
)
141 config
, out
, status
= self
.get_result(
142 'check_prog("FOO", ("unknown", "unknown-2", "known c"))'
144 self
.assertEqual(status
, 0)
145 self
.assertEqual(config
, {"FOO": fake_short_path(self
.KNOWN_C
)})
147 out
, "checking for foo... %s\n" % shell_quote(fake_short_path(self
.KNOWN_C
))
150 config
, out
, status
= self
.get_result('check_prog("FOO", ("unknown",))')
151 self
.assertEqual(status
, 1)
152 self
.assertEqual(config
, {})
157 checking for foo... not found
158 DEBUG: foo: Looking for unknown
159 ERROR: Cannot find foo
164 config
, out
, status
= self
.get_result(
165 'check_prog("FOO", ("unknown", "unknown-2", "unknown 3"))'
167 self
.assertEqual(status
, 1)
168 self
.assertEqual(config
, {})
173 checking for foo... not found
174 DEBUG: foo: Looking for unknown
175 DEBUG: foo: Looking for unknown-2
176 DEBUG: foo: Looking for 'unknown 3'
177 ERROR: Cannot find foo
182 config
, out
, status
= self
.get_result(
183 'check_prog("FOO", ("unknown", "unknown-2", "unknown 3"), '
184 "allow_missing=True)"
186 self
.assertEqual(status
, 0)
187 self
.assertEqual(config
, {})
188 self
.assertEqual(out
, "checking for foo... not found\n")
190 @unittest.skipIf(not sys
.platform
.startswith("win"), "Windows-only test")
191 def test_check_prog_exe(self
):
192 config
, out
, status
= self
.get_result(
193 'check_prog("FOO", ("unknown", "known-b", "known c"))', ["FOO=known-a.exe"]
195 self
.assertEqual(status
, 0)
196 self
.assertEqual(config
, {"FOO": self
.KNOWN_A
})
197 self
.assertEqual(out
, "checking for foo... %s\n" % self
.KNOWN_A
)
199 config
, out
, status
= self
.get_result(
200 'check_prog("FOO", ("unknown", "known-b", "known c"))',
201 ["FOO=%s" % os
.path
.splitext(self
.KNOWN_A
)[0]],
203 self
.assertEqual(status
, 0)
204 self
.assertEqual(config
, {"FOO": self
.KNOWN_A
})
205 self
.assertEqual(out
, "checking for foo... %s\n" % self
.KNOWN_A
)
207 def test_check_prog_with_args(self
):
208 config
, out
, status
= self
.get_result(
209 'check_prog("FOO", ("unknown", "known-b", "known c"))', ["FOO=known-a"]
211 self
.assertEqual(status
, 0)
212 self
.assertEqual(config
, {"FOO": self
.KNOWN_A
})
213 self
.assertEqual(out
, "checking for foo... %s\n" % self
.KNOWN_A
)
215 config
, out
, status
= self
.get_result(
216 'check_prog("FOO", ("unknown", "known-b", "known c"))',
217 ["FOO=%s" % self
.KNOWN_A
],
219 self
.assertEqual(status
, 0)
220 self
.assertEqual(config
, {"FOO": self
.KNOWN_A
})
221 self
.assertEqual(out
, "checking for foo... %s\n" % self
.KNOWN_A
)
223 path
= self
.KNOWN_B
.replace("known-b", "known-a")
224 config
, out
, status
= self
.get_result(
225 'check_prog("FOO", ("unknown", "known-b", "known c"))', ["FOO=%s" % path
]
227 self
.assertEqual(status
, 1)
228 self
.assertEqual(config
, {})
233 checking for foo... not found
234 DEBUG: foo: Looking for %s
235 ERROR: Cannot find foo
241 config
, out
, status
= self
.get_result(
242 'check_prog("FOO", ("unknown",))', ["FOO=known c"]
244 self
.assertEqual(status
, 0)
245 self
.assertEqual(config
, {"FOO": fake_short_path(self
.KNOWN_C
)})
247 out
, "checking for foo... %s\n" % shell_quote(fake_short_path(self
.KNOWN_C
))
250 config
, out
, status
= self
.get_result(
251 'check_prog("FOO", ("unknown", "unknown-2", "unknown 3"), '
252 "allow_missing=True)",
255 self
.assertEqual(status
, 1)
256 self
.assertEqual(config
, {})
261 checking for foo... not found
262 DEBUG: foo: Looking for unknown
263 ERROR: Cannot find foo
268 def test_check_prog_what(self
):
269 config
, out
, status
= self
.get_result(
270 'check_prog("CC", ("known-a",), what="the target C compiler")'
272 self
.assertEqual(status
, 0)
273 self
.assertEqual(config
, {"CC": self
.KNOWN_A
})
275 out
, "checking for the target C compiler... %s\n" % self
.KNOWN_A
278 config
, out
, status
= self
.get_result(
279 'check_prog("CC", ("unknown", "unknown-2", "unknown 3"),'
280 ' what="the target C compiler")'
282 self
.assertEqual(status
, 1)
283 self
.assertEqual(config
, {})
288 checking for the target C compiler... not found
289 DEBUG: cc: Looking for unknown
290 DEBUG: cc: Looking for unknown-2
291 DEBUG: cc: Looking for 'unknown 3'
292 ERROR: Cannot find the target C compiler
297 def test_check_prog_input(self
):
298 config
, out
, status
= self
.get_result(
301 option("--with-ccache", nargs=1, help="ccache")
302 check_prog("CCACHE", ("known-a",), input="--with-ccache")
305 ["--with-ccache=known-b"],
307 self
.assertEqual(status
, 0)
308 self
.assertEqual(config
, {"CCACHE": self
.KNOWN_B
})
309 self
.assertEqual(out
, "checking for ccache... %s\n" % self
.KNOWN_B
)
311 script
= textwrap
.dedent(
313 option(env="CC", nargs=1, help="compiler")
316 return value[0].split()[0] if value else None
317 check_prog("CC", ("known-a",), input=compiler)
320 config
, out
, status
= self
.get_result(script
)
321 self
.assertEqual(status
, 0)
322 self
.assertEqual(config
, {"CC": self
.KNOWN_A
})
323 self
.assertEqual(out
, "checking for cc... %s\n" % self
.KNOWN_A
)
325 config
, out
, status
= self
.get_result(script
, ["CC=known-b"])
326 self
.assertEqual(status
, 0)
327 self
.assertEqual(config
, {"CC": self
.KNOWN_B
})
328 self
.assertEqual(out
, "checking for cc... %s\n" % self
.KNOWN_B
)
330 config
, out
, status
= self
.get_result(script
, ["CC=known-b -m32"])
331 self
.assertEqual(status
, 0)
332 self
.assertEqual(config
, {"CC": self
.KNOWN_B
})
333 self
.assertEqual(out
, "checking for cc... %s\n" % self
.KNOWN_B
)
335 def test_check_prog_progs(self
):
336 config
, out
, status
= self
.get_result('check_prog("FOO", ())')
337 self
.assertEqual(status
, 0)
338 self
.assertEqual(config
, {})
339 self
.assertEqual(out
, "")
341 config
, out
, status
= self
.get_result('check_prog("FOO", ())', ["FOO=known-a"])
342 self
.assertEqual(status
, 0)
343 self
.assertEqual(config
, {"FOO": self
.KNOWN_A
})
344 self
.assertEqual(out
, "checking for foo... %s\n" % self
.KNOWN_A
)
346 script
= textwrap
.dedent(
348 option(env="TARGET", nargs=1, default="linux", help="target")
352 if value[0] == "linux":
353 return ("gcc", "clang")
354 if value[0] == "winnt":
355 return ("cl", "clang-cl")
356 check_prog("CC", compiler)
359 config
, out
, status
= self
.get_result(script
)
360 self
.assertEqual(status
, 1)
361 self
.assertEqual(config
, {})
366 checking for cc... not found
367 DEBUG: cc: Looking for gcc
368 DEBUG: cc: Looking for clang
369 ERROR: Cannot find cc
374 config
, out
, status
= self
.get_result(script
, ["TARGET=linux"])
375 self
.assertEqual(status
, 1)
376 self
.assertEqual(config
, {})
381 checking for cc... not found
382 DEBUG: cc: Looking for gcc
383 DEBUG: cc: Looking for clang
384 ERROR: Cannot find cc
389 config
, out
, status
= self
.get_result(script
, ["TARGET=winnt"])
390 self
.assertEqual(status
, 1)
391 self
.assertEqual(config
, {})
396 checking for cc... not found
397 DEBUG: cc: Looking for cl
398 DEBUG: cc: Looking for clang-cl
399 ERROR: Cannot find cc
404 config
, out
, status
= self
.get_result(script
, ["TARGET=none"])
405 self
.assertEqual(status
, 0)
406 self
.assertEqual(config
, {})
407 self
.assertEqual(out
, "")
409 config
, out
, status
= self
.get_result(script
, ["TARGET=winnt", "CC=known-a"])
410 self
.assertEqual(status
, 0)
411 self
.assertEqual(config
, {"CC": self
.KNOWN_A
})
412 self
.assertEqual(out
, "checking for cc... %s\n" % self
.KNOWN_A
)
414 config
, out
, status
= self
.get_result(script
, ["TARGET=none", "CC=known-a"])
415 self
.assertEqual(status
, 0)
416 self
.assertEqual(config
, {"CC": self
.KNOWN_A
})
417 self
.assertEqual(out
, "checking for cc... %s\n" % self
.KNOWN_A
)
419 def test_check_prog_configure_error(self
):
420 with self
.assertRaises(ConfigureError
) as e
:
421 self
.get_result('check_prog("FOO", "foo")')
423 self
.assertEqual(str(e
.exception
), "progs must resolve to a list or tuple!")
425 with self
.assertRaises(ConfigureError
) as e
:
427 'foo = depends(when=True)(lambda: ("a", "b"))\n'
428 'check_prog("FOO", ("known-a",), input=foo)'
433 "input must resolve to a tuple or a list with a "
434 "single element, or a string",
437 with self
.assertRaises(ConfigureError
) as e
:
439 'foo = depends(when=True)(lambda: {"a": "b"})\n'
440 'check_prog("FOO", ("known-a",), input=foo)'
445 "input must resolve to a tuple or a list with a "
446 "single element, or a string",
449 def test_check_prog_with_path(self
):
450 config
, out
, status
= self
.get_result(
451 'check_prog("A", ("known-a",), paths=["/some/path"])'
453 self
.assertEqual(status
, 1)
454 self
.assertEqual(config
, {})
459 checking for a... not found
460 DEBUG: a: Looking for known-a
466 config
, out
, status
= self
.get_result(
467 'check_prog("A", ("known-a",), paths=["%s"])'
468 % os
.path
.dirname(self
.OTHER_A
)
470 self
.assertEqual(status
, 0)
471 self
.assertEqual(config
, {"A": self
.OTHER_A
})
482 dirs
= map(mozpath
.dirname
, (self
.OTHER_A
, self
.KNOWN_A
))
483 config
, out
, status
= self
.get_result(
486 check_prog("A", ("known-a",), paths=["%s"])
488 % os
.pathsep
.join(dirs
)
491 self
.assertEqual(status
, 0)
492 self
.assertEqual(config
, {"A": self
.OTHER_A
})
503 dirs
= map(mozpath
.dirname
, (self
.KNOWN_A
, self
.KNOWN_B
))
504 config
, out
, status
= self
.get_result(
507 check_prog("A", ("known-a",), paths=["%s", "%s"])
509 % (os
.pathsep
.join(dirs
), self
.OTHER_A
)
512 self
.assertEqual(status
, 0)
513 self
.assertEqual(config
, {"A": self
.KNOWN_A
})
524 config
, out
, status
= self
.get_result(
525 'check_prog("A", ("known-a",), paths="%s")' % os
.path
.dirname(self
.OTHER_A
)
528 self
.assertEqual(status
, 1)
529 self
.assertEqual(config
, {})
534 checking for a... """ # noqa # trailing whitespace...
536 DEBUG: a: Looking for known-a
537 ERROR: Paths provided to find_program must be a list of strings, not %r
539 % mozpath
.dirname(self
.OTHER_A
)
544 not sys
.platform
.startswith("linux"),
545 "Linux-only test, assumes Java is located from a $PATH",
547 def test_java_tool_checks_linux(self
):
548 def run_configure_java(
549 mock_fs_paths
, mock_java_home
=None, mock_path
=None, args
=[]
551 script
= textwrap
.dedent(
555 return namespace(os='unknown', kernel='unknown')
556 toolchains_base_dir = depends(when=True)(lambda: '/mozbuild')
557 include('%(topsrcdir)s/build/moz.configure/java.configure')
559 % {"topsrcdir": topsrcdir
}
562 # Don't let system JAVA_HOME influence the test
563 original_java_home
= os
.environ
.pop("JAVA_HOME", None)
564 configure_environ
= {}
567 os
.environ
["JAVA_HOME"] = mock_java_home
568 configure_environ
["JAVA_HOME"] = mock_java_home
571 configure_environ
["PATH"] = mock_path
573 # * Even if the real file sysphabtem has a symlink at the mocked path, don't let
574 # realpath follow it, as it may influence the test.
575 # * When finding a binary, check the mock paths rather than the real filesystem.
576 # Note: Python doesn't allow the different "with" bits to be put in parenthesis,
577 # because then it thinks it's an un-with-able tuple. Additionally, if this is cleanly
578 # lined up with "\", black removes them and autoformats them to the block that is
580 result
= self
.get_result(
584 environ
=configure_environ
,
587 if original_java_home
:
588 os
.environ
["JAVA_HOME"] = original_java_home
591 java
= mozpath
.abspath("/usr/bin/java")
592 javac
= mozpath
.abspath("/usr/bin/javac")
593 paths
= {java
: None, javac
: None}
594 expected_error_message
= (
595 "ERROR: Could not locate Java at /mozbuild/jdk/jdk-17.0.10+7/bin, "
596 "please run ./mach bootstrap --no-system-changes\n"
599 config
, out
, status
= run_configure_java(paths
)
600 self
.assertEqual(status
, 1)
601 self
.assertEqual(config
, {})
602 self
.assertEqual(out
, expected_error_message
)
604 # An alternative valid set of tools referred to by JAVA_HOME.
605 alt_java
= mozpath
.abspath("/usr/local/bin/java")
606 alt_javac
= mozpath
.abspath("/usr/local/bin/javac")
607 alt_java_home
= mozpath
.dirname(mozpath
.dirname(alt_java
))
608 paths
= {alt_java
: None, alt_javac
: None, java
: None, javac
: None}
610 alt_path
= mozpath
.dirname(java
)
611 config
, out
, status
= run_configure_java(paths
, alt_java_home
, alt_path
)
612 self
.assertEqual(status
, 1)
613 self
.assertEqual(config
, {})
614 self
.assertEqual(out
, expected_error_message
)
616 # We can use --with-java-bin-path instead of JAVA_HOME to similar
618 config
, out
, status
= run_configure_java(
620 mock_path
=mozpath
.dirname(java
),
621 args
=["--with-java-bin-path=%s" % mozpath
.dirname(alt_java
)],
623 self
.assertEqual(status
, 0)
624 self
.assertEqual(config
, {"JAVA": alt_java
, "MOZ_JAVA_CODE_COVERAGE": False})
629 checking for java... %s
635 # If --with-java-bin-path and JAVA_HOME are both set,
636 # --with-java-bin-path takes precedence.
637 config
, out
, status
= run_configure_java(
639 mock_java_home
=mozpath
.dirname(mozpath
.dirname(java
)),
640 mock_path
=mozpath
.dirname(java
),
641 args
=["--with-java-bin-path=%s" % mozpath
.dirname(alt_java
)],
643 self
.assertEqual(status
, 0)
644 self
.assertEqual(config
, {"JAVA": alt_java
, "MOZ_JAVA_CODE_COVERAGE": False})
649 checking for java... %s
655 # --enable-java-coverage should set MOZ_JAVA_CODE_COVERAGE.
656 alt_java_home
= mozpath
.dirname(mozpath
.dirname(java
))
657 config
, out
, status
= run_configure_java(
659 mock_java_home
=alt_java_home
,
660 mock_path
=mozpath
.dirname(java
),
661 args
=["--enable-java-coverage"],
663 self
.assertEqual(status
, 1)
664 self
.assertEqual(config
, {})
666 # Any missing tool is fatal when these checks run.
668 config
, out
, status
= run_configure_java(
670 mock_path
=mozpath
.dirname(java
),
671 args
=["--enable-java-coverage"],
673 self
.assertEqual(status
, 1)
674 self
.assertEqual(config
, {})
675 self
.assertEqual(out
, expected_error_message
)
677 def test_pkg_check_modules(self
):
678 mock_pkg_config_version
= "0.10.0"
679 mock_pkg_config_path
= mozpath
.abspath("/usr/bin/pkg-config")
683 def mock_pkg_config(_
, args
):
684 if "--dont-define-prefix" in args
:
686 seen_flags
.add(args
.pop(args
.index("--dont-define-prefix")))
688 if args
[0:2] == ("--errors-to-stdout", "--print-errors"):
689 assert len(args
) == 3
691 if package
== "unknown":
694 "Package unknown was not found in the pkg-config search path.\n"
695 "Perhaps you should add the directory containing `unknown.pc'\n"
696 "to the PKG_CONFIG_PATH environment variable\n"
697 "No package 'unknown' found",
700 if package
== "valid":
702 if package
== "new > 1.1":
703 return 1, "Requested 'new > 1.1' but version of new is 1.1", ""
704 if args
[0] == "--cflags":
705 assert len(args
) == 2
706 return 0, "-I/usr/include/%s" % args
[1], ""
707 if args
[0] == "--libs":
708 assert len(args
) == 2
709 return 0, "-l%s" % args
[1], ""
710 if args
[0] == "--version":
711 return 0, mock_pkg_config_version
, ""
712 if args
[0] == "--about":
713 return 1, "Unknown option --about", ""
714 self
.fail("Unexpected arguments to mock_pkg_config: %s" % (args
,))
716 def mock_pkgconf(_
, args
):
717 if args
[0] == "--shared":
718 seen_flags
.add(args
[0])
720 if args
[0] == "--about":
721 return 0, "pkgconf {}".format(mock_pkg_config_version
), ""
722 return mock_pkg_config(_
, args
)
724 def get_result(cmd
, args
=[], bootstrapped_sysroot
=False, extra_paths
=None):
725 return self
.get_result(
728 option('--disable-compile-environment', help='compile env')
729 compile_environment = depends(when='--enable-compile-environment')(lambda: True)
730 toolchain_prefix = depends(when=True)(lambda: None)
731 target_multiarch_dir = depends(when=True)(lambda: None)
732 target_sysroot = depends(when=True)(lambda: %(sysroot)s)
733 target = depends(when=True)(lambda: None)
734 include('%(topsrcdir)s/build/moz.configure/util.configure')
735 include('%(topsrcdir)s/build/moz.configure/checks.configure')
736 # Skip bootstrapping.
738 def check_prog(*args, **kwargs):
739 del kwargs["bootstrap"]
740 return check_prog(*args, **kwargs)
741 include('%(topsrcdir)s/build/moz.configure/pkg.configure')
744 "topsrcdir": topsrcdir
,
745 "sysroot": "namespace(bootstrapped=True)"
746 if bootstrapped_sysroot
752 extra_paths
=extra_paths
,
756 extra_paths
= {mock_pkg_config_path
: mock_pkg_config
}
758 config
, output
, status
= get_result("pkg_check_modules('MOZ_VALID', 'valid')")
759 self
.assertEqual(status
, 1)
764 checking for pkg_config... not found
765 ERROR: *** The pkg-config script could not be found. Make sure it is
766 *** in your path, or set the PKG_CONFIG environment variable
767 *** to the full path to pkg-config.
772 for pkg_config
, version
, bootstrapped_sysroot
, is_pkgconf
in (
773 (mock_pkg_config
, "0.10.0", False, False),
774 (mock_pkg_config
, "0.30.0", False, False),
775 (mock_pkg_config
, "0.30.0", True, False),
776 (mock_pkgconf
, "1.1.0", True, True),
777 (mock_pkgconf
, "1.6.0", False, True),
778 (mock_pkgconf
, "1.8.0", False, True),
779 (mock_pkgconf
, "1.8.0", True, True),
782 mock_pkg_config_version
= version
783 config
, output
, status
= get_result(
784 "pkg_check_modules('MOZ_VALID', 'valid')",
785 bootstrapped_sysroot
=bootstrapped_sysroot
,
786 extra_paths
={mock_pkg_config_path
: pkg_config
},
788 self
.assertEqual(status
, 0)
793 checking for pkg_config... %s
794 checking for pkg-config version... %s
795 checking whether pkg-config is pkgconf... %s
796 checking for valid... yes
797 checking MOZ_VALID_CFLAGS... -I/usr/include/valid
798 checking MOZ_VALID_LIBS... -lvalid
801 mock_pkg_config_path
,
802 mock_pkg_config_version
,
803 "yes" if is_pkgconf
else "no",
810 "PKG_CONFIG": mock_pkg_config_path
,
811 "MOZ_VALID_CFLAGS": ("-I/usr/include/valid",),
812 "MOZ_VALID_LIBS": ("-lvalid",),
815 if version
== "1.8.0" and bootstrapped_sysroot
:
816 self
.assertEqual(seen_flags
, set(["--shared", "--dont-define-prefix"]))
817 elif version
== "1.8.0":
818 self
.assertEqual(seen_flags
, set(["--shared"]))
819 elif version
in ("1.6.0", "0.30.0") and bootstrapped_sysroot
:
820 self
.assertEqual(seen_flags
, set(["--dont-define-prefix"]))
822 self
.assertEqual(seen_flags
, set())
824 config
, output
, status
= get_result(
825 "pkg_check_modules('MOZ_UKNOWN', 'unknown')", extra_paths
=extra_paths
827 self
.assertEqual(status
, 1)
832 checking for pkg_config... %s
833 checking for pkg-config version... %s
834 checking whether pkg-config is pkgconf... no
835 checking for unknown... no
836 ERROR: Package unknown was not found in the pkg-config search path.
837 ERROR: Perhaps you should add the directory containing `unknown.pc'
838 ERROR: to the PKG_CONFIG_PATH environment variable
839 ERROR: No package 'unknown' found
841 % (mock_pkg_config_path
, mock_pkg_config_version
)
844 self
.assertEqual(config
, {"PKG_CONFIG": mock_pkg_config_path
})
846 config
, output
, status
= get_result(
847 "pkg_check_modules('MOZ_NEW', 'new > 1.1')", extra_paths
=extra_paths
849 self
.assertEqual(status
, 1)
854 checking for pkg_config... %s
855 checking for pkg-config version... %s
856 checking whether pkg-config is pkgconf... no
857 checking for new > 1.1... no
858 ERROR: Requested 'new > 1.1' but version of new is 1.1
860 % (mock_pkg_config_path
, mock_pkg_config_version
)
863 self
.assertEqual(config
, {"PKG_CONFIG": mock_pkg_config_path
})
865 # allow_missing makes missing packages non-fatal.
866 cmd
= textwrap
.dedent(
868 have_new_module = pkg_check_modules('MOZ_NEW', 'new > 1.1', allow_missing=True)
869 @depends(have_new_module)
870 def log_new_module_error(mod):
872 log.info('Module not found.')
876 config
, output
, status
= get_result(cmd
, extra_paths
=extra_paths
)
877 self
.assertEqual(status
, 0)
882 checking for pkg_config... %s
883 checking for pkg-config version... %s
884 checking whether pkg-config is pkgconf... no
885 checking for new > 1.1... no
886 WARNING: Requested 'new > 1.1' but version of new is 1.1
889 % (mock_pkg_config_path
, mock_pkg_config_version
)
892 self
.assertEqual(config
, {"PKG_CONFIG": mock_pkg_config_path
})
894 config
, output
, status
= get_result(
895 cmd
, args
=["--disable-compile-environment"], extra_paths
=extra_paths
897 self
.assertEqual(status
, 0)
898 self
.assertEqual(output
, "Module not found.\n")
899 self
.assertEqual(config
, {})
901 def mock_old_pkg_config(_
, args
):
902 if args
[0] == "--version":
903 return 0, "0.8.10", ""
904 if args
[0] == "--about":
905 return 1, "Unknown option --about", ""
906 self
.fail("Unexpected arguments to mock_old_pkg_config: %s" % args
)
908 extra_paths
= {mock_pkg_config_path
: mock_old_pkg_config
}
910 config
, output
, status
= get_result(
911 "pkg_check_modules('MOZ_VALID', 'valid')", extra_paths
=extra_paths
913 self
.assertEqual(status
, 1)
918 checking for pkg_config... %s
919 checking for pkg-config version... 0.8.10
920 checking whether pkg-config is pkgconf... no
921 ERROR: *** Your version of pkg-config is too old. You need version 0.9.0 or newer.
923 % mock_pkg_config_path
927 def test_simple_keyfile(self
):
928 includes
= ("util.configure", "checks.configure", "keyfiles.configure")
930 config
, output
, status
= self
.get_result(
931 "simple_keyfile('Mozilla API')", includes
=includes
933 self
.assertEqual(status
, 0)
938 checking for the Mozilla API key... no
942 self
.assertEqual(config
, {"MOZ_MOZILLA_API_KEY": "no-mozilla-api-key"})
944 config
, output
, status
= self
.get_result(
945 "simple_keyfile('Mozilla API')",
946 args
=["--with-mozilla-api-keyfile=/foo/bar/does/not/exist"],
949 self
.assertEqual(status
, 1)
954 checking for the Mozilla API key... no
955 ERROR: '/foo/bar/does/not/exist': No such file or directory.
959 self
.assertEqual(config
, {})
961 with
MockedOpen({"key": ""}):
962 config
, output
, status
= self
.get_result(
963 "simple_keyfile('Mozilla API')",
964 args
=["--with-mozilla-api-keyfile=key"],
967 self
.assertEqual(status
, 1)
972 checking for the Mozilla API key... no
973 ERROR: 'key' is empty.
977 self
.assertEqual(config
, {})
979 with
MockedOpen({"key": "fake-key\n"}):
980 config
, output
, status
= self
.get_result(
981 "simple_keyfile('Mozilla API')",
982 args
=["--with-mozilla-api-keyfile=key"],
985 self
.assertEqual(status
, 0)
990 checking for the Mozilla API key... yes
994 self
.assertEqual(config
, {"MOZ_MOZILLA_API_KEY": "fake-key"})
996 with
MockedOpen({"default": "default-key\n"}):
997 config
, output
, status
= self
.get_result(
998 "simple_keyfile('Mozilla API', default='default')", includes
=includes
1000 self
.assertEqual(status
, 0)
1005 checking for the Mozilla API key... yes
1009 self
.assertEqual(config
, {"MOZ_MOZILLA_API_KEY": "default-key"})
1011 with
MockedOpen({"default": "default-key\n", "key": "fake-key\n"}):
1012 config
, output
, status
= self
.get_result(
1013 "simple_keyfile('Mozilla API', default='key')", includes
=includes
1015 self
.assertEqual(status
, 0)
1020 checking for the Mozilla API key... yes
1024 self
.assertEqual(config
, {"MOZ_MOZILLA_API_KEY": "fake-key"})
1026 def test_id_and_secret_keyfile(self
):
1027 includes
= ("util.configure", "checks.configure", "keyfiles.configure")
1029 config
, output
, status
= self
.get_result(
1030 "id_and_secret_keyfile('Bing API')", includes
=includes
1032 self
.assertEqual(status
, 0)
1037 checking for the Bing API key... no
1044 "MOZ_BING_API_CLIENTID": "no-bing-api-clientid",
1045 "MOZ_BING_API_KEY": "no-bing-api-key",
1049 config
, output
, status
= self
.get_result(
1050 "id_and_secret_keyfile('Bing API')",
1051 args
=["--with-bing-api-keyfile=/foo/bar/does/not/exist"],
1054 self
.assertEqual(status
, 1)
1059 checking for the Bing API key... no
1060 ERROR: '/foo/bar/does/not/exist': No such file or directory.
1064 self
.assertEqual(config
, {})
1066 with
MockedOpen({"key": ""}):
1067 config
, output
, status
= self
.get_result(
1068 "id_and_secret_keyfile('Bing API')",
1069 args
=["--with-bing-api-keyfile=key"],
1072 self
.assertEqual(status
, 1)
1077 checking for the Bing API key... no
1078 ERROR: 'key' is empty.
1082 self
.assertEqual(config
, {})
1084 with
MockedOpen({"key": "fake-id fake-key\n"}):
1085 config
, output
, status
= self
.get_result(
1086 "id_and_secret_keyfile('Bing API')",
1087 args
=["--with-bing-api-keyfile=key"],
1090 self
.assertEqual(status
, 0)
1095 checking for the Bing API key... yes
1101 {"MOZ_BING_API_CLIENTID": "fake-id", "MOZ_BING_API_KEY": "fake-key"},
1104 with
MockedOpen({"key": "fake-key\n"}):
1105 config
, output
, status
= self
.get_result(
1106 "id_and_secret_keyfile('Bing API')",
1107 args
=["--with-bing-api-keyfile=key"],
1110 self
.assertEqual(status
, 1)
1115 checking for the Bing API key... no
1116 ERROR: Bing API key file has an invalid format.
1120 self
.assertEqual(config
, {})
1122 with
MockedOpen({"default-key": "default-id default-key\n"}):
1123 config
, output
, status
= self
.get_result(
1124 "id_and_secret_keyfile('Bing API', default='default-key')",
1127 self
.assertEqual(status
, 0)
1132 checking for the Bing API key... yes
1139 "MOZ_BING_API_CLIENTID": "default-id",
1140 "MOZ_BING_API_KEY": "default-key",
1145 {"default-key": "default-id default-key\n", "key": "fake-id fake-key\n"}
1147 config
, output
, status
= self
.get_result(
1148 "id_and_secret_keyfile('Bing API', default='default-key')",
1149 args
=["--with-bing-api-keyfile=key"],
1152 self
.assertEqual(status
, 0)
1157 checking for the Bing API key... yes
1163 {"MOZ_BING_API_CLIENTID": "fake-id", "MOZ_BING_API_KEY": "fake-key"},
1167 if __name__
== "__main__":