The source code and dockerfile for the GSW2024 AI Lab.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

93 lines
3.8 KiB

2 months ago
  1. #!/usr/bin/env python3
  2. from jinja2 import *
  3. import os
  4. def datamerge(a, b):
  5. """Merges two lists or dictionaries."""
  6. if isinstance(a, list) and isinstance(b, list):
  7. return a + b
  8. elif isinstance(a, dict) and isinstance(b, dict):
  9. res = a.copy()
  10. for k,v in b.items():
  11. if k in res:
  12. res[k] = datamerge(res[k], v)
  13. else:
  14. res[k] = v
  15. return res
  16. else:
  17. return b
  18. def addon_apt(sources, packages):
  19. """Standard addon for apt."""
  20. return {
  21. "apt": {
  22. "sources": sources,
  23. "packages": packages
  24. }
  25. }
  26. # List of predefined properties.
  27. # Can be extended.
  28. properties = {
  29. "dependencies": {"stage": "dependencies", "script": ["TASK=dependencies"]},
  30. "build": {"stage": "build"},
  31. "xcode7.3": {"os": "osx", "osx_image": "xcode7.3", "env": []},
  32. "xcode8.2": {"os": "osx", "osx_image": "xcode8.2", "env": []},
  33. "xcode8.3": {"os": "osx", "osx_image": "xcode8.3", "env": []},
  34. "xcode9": {"os": "osx", "osx_image": "xcode9", "env": []},
  35. "xcode9.1": {"os": "osx", "osx_image": "xcode9.1", "env": []},
  36. "xcode9.2": {"os": "osx", "osx_image": "xcode9.2", "env": []},
  37. "xcode9.3": {"os": "osx", "osx_image": "xcode9.3", "env": []},
  38. "linux": {"os": "linux"},
  39. "clang-3.8": {"env": ["CC=clang-3.8 CXX=clang++-3.8"], "compiler": "clang++-3.8", "addons": addon_apt(["llvm-toolchain-precise-3.8"], ["clang-3.8", "libstdc++-6-dev"])},
  40. "clang-3.9": {"env": ["CC=clang-3.9 CXX=clang++-3.9"], "compiler": "clang++-3.9", "addons": addon_apt(["llvm-toolchain-trusty-3.9"], ["clang-3.9", "libstdc++-8-dev"])},
  41. "clang-4.0": {"env": ["CC=clang-4.0 CXX=clang++-4.0"], "compiler": "clang++-4.0", "addons": addon_apt(["llvm-toolchain-trusty-4.0"], ["clang-4.0", "libstdc++-8-dev"])},
  42. "clang-5.0": {"env": ["CC=clang-5.0 CXX=clang++-5.0"], "compiler": "clang++-5.0", "addons": addon_apt(["llvm-toolchain-trusty-5.0"], ["clang-5.0", "libstdc++-8-dev"])},
  43. "clang-6.0": {"env": ["CC=clang-6.0 CXX=clang++-6.0"], "compiler": "clang++-6.0", "addons": addon_apt(["llvm-toolchain-trusty-6.0"], ["clang-6.0", "libstdc++-8-dev"])},
  44. "g++-5": {"env": ["CC=gcc-5 CXX=g++-5"], "compiler": "g++-5", "addons": addon_apt([],["g++-5"])},
  45. "g++-6": {"env": ["CC=gcc-6 CXX=g++-6"], "compiler": "g++-6", "addons": addon_apt([],["g++-6"])},
  46. "g++-7": {"env": ["CC=gcc-7 CXX=g++-7"], "compiler": "g++-7", "addons": addon_apt([],["g++-7"])},
  47. "g++-8": {"env": ["CC=gcc-8 CXX=g++-8"], "compiler": "g++-8", "addons": addon_apt([],["g++-8"])},
  48. "task.coverity": {"env": ["TASK=coverity"]},
  49. "task.sonarcloud": {"env": ["TASK=sonarcloud"]},
  50. "task.doxygen": {"env": ["TASK=doxygen"], "addons": addon_apt([],["doxygen", "ghostscript", "latex-xcolor", "pgf", "texinfo", "texlive", "texlive-font-utils", "texlive-latex-extra"])},
  51. "task.pycarl": {"env": ["TASK=pycarl"], "addons": addon_apt([],["python3"])},
  52. "task.addons": {"env": ["TASK=addons"]},
  53. "task.tidy": {"env": ["TASK=tidy"]},
  54. "j1": {"script": ["MAKE_PARALLEL=-j1"]},
  55. "build.sh": {"script": ["source .ci/build.sh"]},
  56. "mayfail": {"allow_failure": True},
  57. }
  58. def propertymapper(j):
  59. """Merges the properties of a job into the job itself."""
  60. if "properties" not in j: return j
  61. res = j.copy()
  62. for p in j["properties"]:
  63. res = datamerge(res, properties[p])
  64. return res
  65. def render_template(jobs, cached, template = "travis.yml.tpl", filename = "../.travis.yml"):
  66. """Applies the propertymapper to the list of jobs and renders the jobs into the given template."""
  67. jobs = map(propertymapper, jobs)
  68. jobs = sorted(jobs, key = lambda x: (-len(x["stage"]),x["priority"]))
  69. j2_env = Environment(loader = FileSystemLoader(os.path.dirname(__file__)), keep_trailing_newline = True)
  70. tpl = j2_env.get_template(template)
  71. res = tpl.render(cached = cached, jobs = jobs)
  72. open(filename, "w").write(res)
  73. def job(priority, properties):
  74. """Creates a new job with the given priority and properties."""
  75. return {
  76. "priority": priority,
  77. "properties": properties,
  78. }