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.

121 lines
3.4 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. REBAR_MATRIX = [
  25. ("2.6.4", 15, MAX_ERLANG),
  26. ("3.7.0", 17, 21),
  27. ("3.13.2", 18, 22),
  28. ("3.15.2", 19, 23),
  29. ("3.16.0", 22, 24),
  30. ("3.18.0", 24, MAX_ERLANG)
  31. ]
  32. JTAPP2_URL = "https://github.com/davisp/jtapp2"
  33. REBAR2_URL = "https://github.com/rebar/rebar"
  34. REBAR3_URL = "https://github.com/erlang/rebar3"
  35. def init_test_dir():
  36. if not os.path.exists(TEST_DIR):
  37. os.mkdir(TEST_DIR)
  38. os.chdir(TEST_DIR)
  39. if not os.path.exists("jiffy"):
  40. sp.check_call("git clone .. jiffy", shell=True)
  41. if not os.path.exists("jtapp2"):
  42. sp.check_call("git clone {}".format(JTAPP2_URL), shell=True)
  43. if not os.path.exists("rebar"):
  44. sp.check_call("git clone {}".format(REBAR2_URL), shell=True)
  45. if not os.path.exists("rebar3"):
  46. sp.check_call("git clone {}".format(REBAR3_URL), shell=True)
  47. def gen_tests():
  48. # Check each rebar version on its last supported VM
  49. for (vsn, min_erl, max_erl) in REBAR_MATRIX:
  50. yield(vsn, ERLANG_VMS[max_erl], ERLANG_VMS[max_erl])
  51. # Mixed VM tests
  52. for (min_compat, max_compat) in ERLANG_COMPATIBILITY:
  53. for (vsn, min_erl, max_erl) in REBAR_MATRIX:
  54. # Skip any version of rebar that can't be built
  55. # on the current VM. No version curently has this
  56. # issue but we're bound to run into it eventually.
  57. if min_erl > max_compat:
  58. continue
  59. build_vm = max(min_compat, min_erl)
  60. test_vm = min(max_compat, max_erl)
  61. yield (vsn, ERLANG_VMS[build_vm], ERLANG_VMS[test_vm])
  62. def run_test(rebar_vsn, build_vm, test_vm):
  63. msg = "Checking rebar {} built with {} to compile on {}"
  64. print(msg.format(rebar_vsn, build_vm, test_vm))
  65. if rebar_vsn[:2] == "2.":
  66. rebar_dir = "rebar"
  67. else:
  68. rebar_dir = "rebar3"
  69. rebar_path = "../{}/{}".format(rebar_dir, rebar_dir)
  70. cmds = [
  71. "cd {} && git checkout -q {}".format(rebar_dir, rebar_vsn),
  72. "cd {} && git clean -ffxd".format(rebar_dir),
  73. "cd {} && asdf local erlang {}".format(rebar_dir, build_vm),
  74. "cd {} && ./bootstrap".format(rebar_dir),
  75. "cd jiffy && git clean -ffxd",
  76. "cd jiffy && asdf local erlang {}".format(test_vm),
  77. "cd jiffy && {} get-deps compile eunit".format(rebar_path),
  78. "cd jtapp2 && git clean -ffxd",
  79. "cd jtapp2 && asdf local erlang {}".format(test_vm),
  80. "cd jtapp2 && {} get-deps compile".format(rebar_path)
  81. ]
  82. for cmd in cmds:
  83. sp.check_output(cmd, shell=True)
  84. cmd = "cd jiffy && {} --version".format(rebar_path)
  85. vsn = sp.check_output(cmd, shell=True).split()
  86. assert vsn[1].decode("utf-8") == rebar_vsn
  87. if rebar_vsn.startswith("2."):
  88. assert build_vm.startswith(vsn[2].decode("utf-8"))
  89. else:
  90. # For some reason rebar3 switched to reporting the VM
  91. # that is executing rebar3, not the version that was
  92. # used to compile it.
  93. assert test_vm.startswith(vsn[4].decode("utf-8"))
  94. cmd = "erl -noshell -eval 'io:fwrite(erlang:system_info(otp_release)), halt().'"
  95. otp = sp.check_output("cd jiffy && {}".format(cmd), shell=True).decode("utf-8")
  96. assert test_vm.startswith(otp)
  97. def main():
  98. init_test_dir()
  99. for (rebar_vsn, build_vm, test_vm) in gen_tests():
  100. run_test(rebar_vsn, build_vm, test_vm)
  101. if __name__ == "__main__":
  102. main()