aboutsummaryrefslogtreecommitdiff
path: root/unittests
diff options
context:
space:
mode:
authorXavier Claessens <xavier.claessens@collabora.com>2022-09-13 09:38:19 -0400
committerEli Schwartz <eschwartz93@gmail.com>2022-09-28 19:36:13 -0400
commit2dfd952eb99590878430510644ffe99dd4a6a41d (patch)
tree53001a096d997511a8d12a44cf5019a2ff8d5a2b /unittests
parenta58ec322b3a9a07af83ea268341c16f972f52791 (diff)
downloadmeson-2dfd952eb99590878430510644ffe99dd4a6a41d.zip
meson-2dfd952eb99590878430510644ffe99dd4a6a41d.tar.gz
meson-2dfd952eb99590878430510644ffe99dd4a6a41d.tar.bz2
Move classes used by scripts to their own module
Those classes are used by wrapper scripts and we should not have to import the rest of mesonlib, build.py, and all their dependencies for that. This renames mesonlib/ directory to utils/ and add a mesonlib.py module that imports everything from utils/ to not have to change `import mesonlib` everywhere. It allows to import utils.core without importing the rest of mesonlib.
Diffstat (limited to 'unittests')
-rw-r--r--unittests/allplatformstests.py32
-rw-r--r--unittests/internaltests.py2
2 files changed, 31 insertions, 3 deletions
diff --git a/unittests/allplatformstests.py b/unittests/allplatformstests.py
index 34997ce..7382f40 100644
--- a/unittests/allplatformstests.py
+++ b/unittests/allplatformstests.py
@@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-from mesonbuild.mesonlib.universal import windows_proof_rm
import subprocess
import re
import json
@@ -42,7 +41,8 @@ from mesonbuild.mesonlib import (
BuildDirLock, MachineChoice, is_windows, is_osx, is_cygwin, is_dragonflybsd,
is_sunos, windows_proof_rmtree, python_command, version_compare, split_args, quote_arg,
relpath, is_linux, git, search_version, do_conf_file, do_conf_str, default_prefix,
- MesonException, EnvironmentException, OptionKey
+ MesonException, EnvironmentException, OptionKey, ExecutableSerialisation, EnvironmentVariables,
+ windows_proof_rm
)
from mesonbuild.compilers.mixins.clang import ClangCompiler
@@ -4409,3 +4409,31 @@ class AllPlatformTests(BasePlatformTests):
self.setconf(["-Dopt=val"])
newmtime = os.path.getmtime(filename)
self.assertEqual(oldmtime, newmtime)
+
+ def test_scripts_loaded_modules(self):
+ '''
+ Simulate a wrapped command, as done for custom_target() that capture
+ output. The script will print all python modules loaded and we verify
+ that it contains only an acceptable subset. Loading too many modules
+ slows down the build when many custom targets get wrapped.
+ '''
+ es = ExecutableSerialisation(python_command + ['-c', 'exit(0)'], env=EnvironmentVariables())
+ p = Path(self.builddir, 'exe.dat')
+ with p.open('wb') as f:
+ pickle.dump(es, f)
+ cmd = self.meson_command + ['--internal', 'test_loaded_modules', '--unpickle', str(p)]
+ p = subprocess.run(cmd, stdout=subprocess.PIPE)
+ all_modules = json.loads(p.stdout.splitlines()[0])
+ meson_modules = [m for m in all_modules if 'meson' in m]
+ expected_meson_modules = [
+ 'mesonbuild',
+ 'mesonbuild._pathlib',
+ 'mesonbuild.utils',
+ 'mesonbuild.utils.core',
+ 'mesonbuild.mesonmain',
+ 'mesonbuild.mlog',
+ 'mesonbuild.scripts',
+ 'mesonbuild.scripts.meson_exe',
+ 'mesonbuild.scripts.test_loaded_modules'
+ ]
+ self.assertEqual(sorted(expected_meson_modules), sorted(meson_modules))
diff --git a/unittests/internaltests.py b/unittests/internaltests.py
index 8581512..e37eb55 100644
--- a/unittests/internaltests.py
+++ b/unittests/internaltests.py
@@ -13,7 +13,6 @@
# limitations under the License.
from configparser import ConfigParser
-from mesonbuild.mesonlib.universal import OptionType
from pathlib import Path
from unittest import mock
import contextlib
@@ -43,6 +42,7 @@ from mesonbuild.interpreterbase import typed_pos_args, InvalidArguments, typed_k
from mesonbuild.mesonlib import (
LibType, MachineChoice, PerMachine, Version, is_windows, is_osx,
is_cygwin, is_openbsd, search_version, MesonException, OptionKey,
+ OptionType
)
from mesonbuild.interpreter.type_checking import in_set_validator, NoneType
from mesonbuild.dependencies import PkgConfigDependency