Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

148 Zeilen
5.4 KiB

vor 11 Jahren
  1. -module(tdeps_update_rt).
  2. -compile(export_all).
  3. %% Exercises update deps, with recursive dependency updates.
  4. %% Initially:
  5. %% A(v0.5) -> B(v0.2.3) -> C(v1.0)
  6. %% But after updating A to 0.6:
  7. %% A(v0.6) -> B(v0.2.4) -> C(v1.1)
  8. %% -> D(v0.7)
  9. %% And after updating A to 0.7:
  10. %% A(v0.7) -> B(v0.2.5) -> C(v1.2) -> E(v2.0)
  11. %% -> D(v0.7)
  12. %% And after updating A to 0.8:
  13. %% A(v0.8) -> B(v0.2.6) -> C(v1.3) -> E(v2.1)
  14. %% -> D(v0.7)
  15. %% -> F(v0.1) -> E(v2.1)
  16. files() ->
  17. [
  18. %% A1 application
  19. {create, "apps/a1/ebin/a1.app", app(a1, [a1], "0.5")},
  20. {copy, "a.rebar.config", "apps/a1/rebar.config"},
  21. {template, "a.erl", "apps/a1/src/a1.erl", dict:from_list([{module, a1}])},
  22. {copy, "root.rebar.config", "rebar.config"},
  23. {copy, "../../rebar", "rebar"},
  24. %% B application
  25. {create, "repo/b/ebin/b.app", app(b, [], "0.2.3")},
  26. {create, "b2.app", app(b, [], "0.2.4")},
  27. {create, "b3.app", app(b, [], "0.2.5")},
  28. {create, "b4.app", app(b, [], "0.2.6")},
  29. {copy, "b.rebar.config", "repo/b/rebar.config"},
  30. {copy, "b.hrl", "repo/b/include/b.hrl"},
  31. %% C application
  32. {create, "repo/c/ebin/c.app", app(c, [], "1.0")},
  33. {create, "c2.app", app(c, [], "1.1")},
  34. {create, "c3.app", app(c, [], "1.2")},
  35. {create, "c4.app", app(c, [], "1.3")},
  36. {copy, "c.hrl", "repo/c/include/c.hrl"},
  37. %% D application
  38. {create, "repo/d/ebin/d.app", app(d, [], "0.7")},
  39. {copy, "d.hrl", "repo/d/include/d.hrl"},
  40. %% E application
  41. {create, "repo/e/ebin/e.app", app(e, [], "2.0")},
  42. {create, "e2.app", app(e, [], "2.1")},
  43. %% F application
  44. {create, "repo/f/ebin/f.app", app(f, [], "0.1")},
  45. %% update files
  46. {copy, "a2.rebar.config", "a2.rebar.config"},
  47. {copy, "a3.rebar.config", "a3.rebar.config"},
  48. {copy, "a4.rebar.config", "a4.rebar.config"},
  49. {copy, "b2.rebar.config", "b2.rebar.config"},
  50. {copy, "b3.rebar.config", "b3.rebar.config"},
  51. {copy, "b4.rebar.config", "b4.rebar.config"},
  52. {copy, "c2.hrl", "c2.hrl"},
  53. {copy, "c.rebar.config", "c.rebar.config"},
  54. {copy, "c2.rebar.config", "c2.rebar.config"},
  55. {copy, "c3.rebar.config", "c3.rebar.config"}
  56. ].
  57. apply_cmds([], _Params) ->
  58. ok;
  59. apply_cmds([Cmd | Rest], Params) ->
  60. io:format("Running: ~s (~p)\n", [Cmd, Params]),
  61. {ok, _} = retest_sh:run(Cmd, Params),
  62. apply_cmds(Rest, Params).
  63. run(_Dir) ->
  64. %% Initialize the b/c/d apps as git repos so that dependencies pull
  65. %% properly
  66. GitCmds = ["git init",
  67. "git add -A",
  68. "git config user.email 'tdeps@example.com'",
  69. "git config user.name 'tdeps'",
  70. "git commit -a -m 'Initial Commit'"],
  71. BCmds = ["git tag 0.2.3",
  72. "cp ../../b2.rebar.config rebar.config",
  73. "cp ../../b2.app ebin/b.app",
  74. "git commit -a -m 'update to 0.2.4'",
  75. "git tag 0.2.4",
  76. "cp ../../b3.rebar.config rebar.config",
  77. "cp ../../b3.app ebin/b.app",
  78. "git commit -a -m 'update to 0.2.5'",
  79. "git tag 0.2.5",
  80. "cp ../../b4.rebar.config rebar.config",
  81. "cp ../../b4.app ebin/b.app",
  82. "git commit -a -m 'update to 0.2.6'",
  83. "git tag 0.2.6"],
  84. %"git checkout 0.2.3"],
  85. CCmds = ["git tag 1.0",
  86. "cp ../../c2.hrl include/c.hrl",
  87. "cp ../../c2.app ebin/c.app",
  88. "cp ../../c.rebar.config rebar.config",
  89. "git add rebar.config",
  90. "git commit -a -m 'update to 1.1'",
  91. "git tag 1.1",
  92. "cp ../../c3.app ebin/c.app",
  93. "cp ../../c2.rebar.config rebar.config",
  94. "git commit -a -m 'update to 1.2'",
  95. "git tag 1.2",
  96. "cp ../../c4.app ebin/c.app",
  97. "cp ../../c3.rebar.config rebar.config",
  98. "git commit -a -m 'update to 1.3'",
  99. "git tag 1.3"],
  100. %"git checkout 1.0"],
  101. DCmds = ["git tag 0.7"],
  102. ECmds = ["git tag 2.0",
  103. "cp ../../e2.app ebin/e.app",
  104. "git commit -a -m 'update to 2.1'",
  105. "git tag 2.1"],
  106. FCmds = ["git tag 0.1"],
  107. ok = apply_cmds(GitCmds++BCmds, [{dir, "repo/b"}]),
  108. ok = apply_cmds(GitCmds++CCmds, [{dir, "repo/c"}]),
  109. ok = apply_cmds(GitCmds++DCmds, [{dir, "repo/d"}]),
  110. ok = apply_cmds(GitCmds++ECmds, [{dir, "repo/e"}]),
  111. ok = apply_cmds(GitCmds++FCmds, [{dir, "repo/f"}]),
  112. {ok, _} = retest_sh:run("./rebar -v get-deps", []),
  113. {ok, _} = retest_sh:run("./rebar -v compile", []),
  114. os:cmd("cp a2.rebar.config apps/a1/rebar.config"),
  115. {ok, _} = retest_sh:run("./rebar -v update-deps", []),
  116. {ok, _} = retest_sh:run("./rebar -v compile", []),
  117. os:cmd("cp a3.rebar.config apps/a1/rebar.config"),
  118. {ok, _} = retest_sh:run("./rebar -v update-deps", []),
  119. {ok, _} = retest_sh:run("./rebar -v compile", []),
  120. os:cmd("cp a4.rebar.config apps/a1/rebar.config"),
  121. {ok, _} = retest_sh:run("./rebar -v update-deps", []),
  122. {ok, _} = retest_sh:run("./rebar -v compile", []),
  123. ok.
  124. %%
  125. %% Generate the contents of a simple .app file
  126. %%
  127. app(Name, Modules, Version) ->
  128. App = {application, Name,
  129. [{description, atom_to_list(Name)},
  130. {vsn, Version},
  131. {modules, Modules},
  132. {registered, []},
  133. {applications, [kernel, stdlib]}]},
  134. io_lib:format("~p.\n", [App]).