scanbuild.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # Copyright 2016 The Meson development team
  2. # Licensed under the Apache License, Version 2.0 (the "License");
  3. # you may not use this file except in compliance with the License.
  4. # You may obtain a copy of the License at
  5. # http://www.apache.org/licenses/LICENSE-2.0
  6. # Unless required by applicable law or agreed to in writing, software
  7. # distributed under the License is distributed on an "AS IS" BASIS,
  8. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. # See the License for the specific language governing permissions and
  10. # limitations under the License.
  11. import os
  12. import subprocess
  13. import shutil
  14. import tempfile
  15. from ..environment import detect_ninja, detect_scanbuild
  16. def scanbuild(exelist, srcdir, blddir, privdir, logdir, args):
  17. with tempfile.TemporaryDirectory(dir=privdir) as scandir:
  18. meson_cmd = exelist + args
  19. build_cmd = exelist + ['-o', logdir, detect_ninja(), '-C', scandir]
  20. rc = subprocess.call(meson_cmd + [srcdir, scandir])
  21. if rc != 0:
  22. return rc
  23. return subprocess.call(build_cmd)
  24. def run(args):
  25. srcdir = args[0]
  26. blddir = args[1]
  27. meson_cmd = args[2:]
  28. privdir = os.path.join(blddir, 'meson-private')
  29. logdir = os.path.join(blddir, 'meson-logs/scanbuild')
  30. shutil.rmtree(logdir, ignore_errors=True)
  31. exelist = detect_scanbuild()
  32. if not exelist:
  33. print('Could not execute scan-build "%s"' % ' '.join(exelist))
  34. return 1
  35. return scanbuild(exelist, srcdir, blddir, privdir, logdir, meson_cmd)