meson.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/usr/bin/env python3
  2. # Copyright 2016 The Meson development team
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. # http://www.apache.org/licenses/LICENSE-2.0
  7. # Unless required by applicable law or agreed to in writing, software
  8. # distributed under the License is distributed on an "AS IS" BASIS,
  9. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. # See the License for the specific language governing permissions and
  11. # limitations under the License.
  12. # This file is an entry point for all commands, including scripts. Include the
  13. # strict minimum python modules for performance reasons.
  14. import sys
  15. # Check python version before importing anything else, we might have an older
  16. # Python that would error on f-string syntax for example.
  17. if sys.version_info < (3, 7):
  18. print('Meson works correctly only with python 3.7+.')
  19. print('You have python {}.'.format(sys.version))
  20. print('Please update your environment')
  21. sys.exit(1)
  22. from pathlib import Path
  23. # If we're run uninstalled, add the script directory to sys.path to ensure that
  24. # we always import the correct mesonbuild modules even if PYTHONPATH is mangled
  25. meson_exe = Path(sys.argv[0]).resolve()
  26. if (meson_exe.parent / 'mesonbuild').is_dir():
  27. sys.path.insert(0, str(meson_exe.parent))
  28. from mesonbuild import mesonmain
  29. if __name__ == '__main__':
  30. sys.exit(mesonmain.main())