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.

139 lines
4.3 KiB

  1. #!/usr/bin/env python3
  2. import os
  3. import shutil
  4. import subprocess as sp
  5. TEST_DIR = ".jiffy-compile-check"
  6. ERLANG_VMS = {
  7. 15: "R15B03-1",
  8. 16: "R16B03-1",
  9. 17: "17.5.6.10",
  10. 18: "18.3.4.11",
  11. 19: "19.3.6.13",
  12. 20: "20.3.8.26",
  13. 21: "21.3.8.24",
  14. 22: "22.3.4.24",
  15. 23: "23.3.4.11",
  16. 24: "24.2.1",
  17. 25: "25.0-rc1"
  18. }
  19. MAX_ERLANG = max(ERLANG_VMS.keys())
  20. ERLANG_COMPATIBILITY = [
  21. (15, 24),
  22. (22, MAX_ERLANG)
  23. ]
  24. # The rebar3 compatibility matrix was created using the
  25. # ranges in this blog post:
  26. # https://ferd.ca/you-ve-got-to-upgrade-rebar3.html
  27. REBAR_MATRIX = [
  28. ("2.6.4", 15, MAX_ERLANG),
  29. ("3.7.0", 17, 21),
  30. ("3.13.2", 18, 22),
  31. ("3.15.2", 19, 23),
  32. ("3.16.0", 22, 24),
  33. ("3.18.0", 24, MAX_ERLANG)
  34. ]
  35. JTAPP2_URL = "https://github.com/davisp/jtapp2"
  36. REBAR2_URL = "https://github.com/rebar/rebar"
  37. REBAR3_URL = "https://github.com/erlang/rebar3"
  38. # Prevent rebar3 from reading any global configuration. The need
  39. # for setting HOME instead of REBAR3_* variables is because the
  40. # plugin cache can't be set via environment so we just use a
  41. # hammer and set a fake HOME.
  42. os.environ["ASDF_CONFIG_FILE"] = os.path.expanduser("~/.asdfrc")
  43. os.environ["ASDF_DATA_DIR"] = os.path.expanduser("~/.asdf")
  44. os.environ["HOME"] = "./hopefully-not-a-directory"
  45. def init_test_dir():
  46. if not os.path.exists(TEST_DIR):
  47. os.mkdir(TEST_DIR)
  48. os.chdir(TEST_DIR)
  49. if not os.path.exists("jiffy"):
  50. sp.check_call("git clone .. jiffy", shell=True)
  51. if not os.path.exists("jtapp2"):
  52. sp.check_call("git clone {}".format(JTAPP2_URL), shell=True)
  53. if not os.path.exists("rebar"):
  54. sp.check_call("git clone {}".format(REBAR2_URL), shell=True)
  55. if not os.path.exists("rebar3"):
  56. sp.check_call("git clone {}".format(REBAR3_URL), shell=True)
  57. def gen_tests():
  58. # Check each rebar version on its last supported VM
  59. for (vsn, min_erl, max_erl) in REBAR_MATRIX:
  60. yield(vsn, ERLANG_VMS[max_erl], ERLANG_VMS[max_erl])
  61. # Mixed VM tests
  62. for (min_compat, max_compat) in ERLANG_COMPATIBILITY:
  63. for (vsn, min_erl, max_erl) in REBAR_MATRIX:
  64. if max_erl < min_compat:
  65. continue
  66. if min_erl > max_compat:
  67. continue
  68. build_vm = max(min_compat, min_erl)
  69. test_vm = min(max_compat, max_erl)
  70. yield (vsn, ERLANG_VMS[build_vm], ERLANG_VMS[test_vm])
  71. def run_test(rebar_vsn, build_vm, test_vm):
  72. msg = "Checking rebar {} built with {} to compile on {}"
  73. print(msg.format(rebar_vsn, build_vm, test_vm))
  74. if rebar_vsn[:2] == "2.":
  75. rebar_dir = "rebar"
  76. else:
  77. rebar_dir = "rebar3"
  78. rebar_path = "../{}/{}".format(rebar_dir, rebar_dir)
  79. cmds = [
  80. "cd {} && git checkout -q {}".format(rebar_dir, rebar_vsn),
  81. "cd {} && git clean -ffxd".format(rebar_dir),
  82. "cd {} && asdf local erlang {}".format(rebar_dir, build_vm),
  83. "cd {} && ./bootstrap".format(rebar_dir),
  84. "cd jiffy && git clean -ffxd",
  85. "cd jiffy && asdf local erlang {}".format(test_vm),
  86. "cd jiffy && {} get-deps".format(rebar_path),
  87. "cd jiffy && {} compile".format(rebar_path),
  88. "cd jiffy && {} eunit".format(rebar_path),
  89. "cd jtapp2 && git clean -ffxd",
  90. "cd jtapp2 && asdf local erlang {}".format(test_vm),
  91. "cd jtapp2 && {} get-deps".format(rebar_path),
  92. "cd jtapp2 && {} compile".format(rebar_path),
  93. "cd jtapp2 && {} eunit".format(rebar_path)
  94. ]
  95. for cmd in cmds:
  96. sp.check_output(cmd, shell=True)
  97. cmd = "cd jiffy && {} --version".format(rebar_path)
  98. vsn = sp.check_output(cmd, shell=True).split()
  99. assert vsn[1].decode("utf-8") == rebar_vsn
  100. if rebar_vsn.startswith("2."):
  101. assert build_vm.startswith(vsn[2].decode("utf-8"))
  102. else:
  103. # For some reason rebar3 switched to reporting the VM
  104. # that is executing rebar3, not the version that was
  105. # used to compile it.
  106. assert test_vm.startswith(vsn[4].decode("utf-8"))
  107. cmd = "erl -noshell -eval 'io:fwrite(erlang:system_info(otp_release)), halt().'"
  108. otp = sp.check_output("cd jiffy && {}".format(cmd), shell=True).decode("utf-8")
  109. assert test_vm.startswith(otp)
  110. def main():
  111. init_test_dir()
  112. for (rebar_vsn, build_vm, test_vm) in gen_tests():
  113. run_test(rebar_vsn, build_vm, test_vm)
  114. if __name__ == "__main__":
  115. main()