Newer
Older
dub_jkp / test / issue2377-dynLib-dep-extra-files.script.d
@Martin Kinkelin Martin Kinkelin on 17 Sep 2022 4 KB [add tests]
  1. /+ dub.sdl:
  2. name "issue2377_dynlib_dep_extra_files"
  3. +/
  4.  
  5. module issue2377_dynlib_dep_extra_files.script;
  6.  
  7. import std.exception : enforce;
  8. import std.file;
  9. import std.path;
  10.  
  11. version (DigitalMars) version (Windows) version = DMD_Windows;
  12. version (DMD_Windows) {
  13. void main() {
  14. import std.stdio;
  15. writeln("WARNING: skipping test '" ~ __FILE_FULL_PATH__.baseName ~ "' with DMD on Windows.");
  16. }
  17. } else:
  18.  
  19. void main() {
  20. import std.process : environment;
  21.  
  22. version (Windows) enum exeExt = ".exe";
  23. else enum exeExt = "";
  24. const dub = environment.get("DUB", buildPath(__FILE_FULL_PATH__.dirName.dirName, "bin", "dub"~exeExt));
  25.  
  26. enum testDir = buildPath(__FILE_FULL_PATH__.dirName, "issue2377-dynLib-dep-extra-files");
  27.  
  28. // 1. `parent` as root package (depending on dynamic/static dep1, which depends on dynamic/static dep2)
  29. chdir(buildPath(testDir, "parent"));
  30. if (exists("output"))
  31. rmdirRecurse("output");
  32.  
  33. // 1.1 dynlib config
  34. run(dub ~ " build -c dynlib");
  35. chdir("output/dynlib");
  36. assertDynLibExists("parent");
  37. assertDynLibExists("dep1");
  38. assertDynLibExists("dep2");
  39. version (Windows) {
  40. assertFileExists("parent.pdb");
  41. assertFileExists("parent.lib");
  42. assertFileExists("parent.exp");
  43. assertFileExists("dep1.pdb");
  44. assertFileExists("dep1.lib");
  45. assertFileExists("dep1.exp");
  46. assertFileExists("dep2.pdb");
  47. assertFileExists("dep2.lib");
  48. assertFileExists("dep2.exp");
  49. }
  50. chdir("../..");
  51.  
  52. // 1.2 dynlib_static config
  53. run(dub ~ " build -c dynlib_static");
  54. chdir("output/dynlib_static");
  55. assertDynLibExists("parent");
  56. version (Windows) {
  57. assertFileExists("parent.pdb");
  58. assertFileExists("parent.lib");
  59. assertFileExists("parent.exp");
  60. }
  61. enforce(!canFindFiles("*dep*"), "unexpected dependency files in statically linked dynlib output dir");
  62. chdir("../..");
  63.  
  64. // 1.3 exe_static config
  65. run(dub ~ " build -c exe_static");
  66. chdir("output/exe_static");
  67. version (Windows) run(`.\parent.exe`);
  68. else run("./parent");
  69. version (Windows) {
  70. assertFileExists("parent.pdb");
  71. enforce(!exists("parent.lib"), "unexpected import .lib for executable");
  72. enforce(!exists("parent.exp"), "unexpected .exp file for executable");
  73. }
  74. enforce(!canFindFiles("*dep*"), "unexpected dependency files in statically linked executable output dir");
  75. chdir("../..");
  76.  
  77. // 1.4 exe_dynamic config
  78. run(dub ~ " build -c exe_dynamic");
  79. chdir("output/exe_dynamic");
  80. version (Windows) run(`.\parent.exe`);
  81. else run(`LD_LIBRARY_PATH=".:${LD_LIBRARY_PATH:-}" ./parent`);
  82. assertDynLibExists("dep1");
  83. assertDynLibExists("dep2");
  84. version (Windows) {
  85. assertFileExists("dep1.pdb");
  86. assertFileExists("dep2.pdb");
  87. enforce(!canFindFiles("*.lib"), "unexpected import libs in dynamically linked executable output dir");
  88. enforce(!canFindFiles("*.exp"), "unexpected .exp files in dynamically linked executable output dir");
  89. }
  90. chdir("../..");
  91.  
  92. // 2. `framework` as root package (targetType `none`)
  93. chdir(buildPath(testDir, "framework"));
  94. run(dub ~ " build");
  95. assertDynLibExists("dep1");
  96. assertDynLibExists("dep2");
  97. version (Windows) {
  98. assertFileExists("dep1.pdb");
  99. assertFileExists("dep1.lib");
  100. assertFileExists("dep1.exp");
  101. assertFileExists("dep2.pdb");
  102. assertFileExists("dep2.lib");
  103. assertFileExists("dep2.exp");
  104. }
  105. }
  106.  
  107. void run(string command) {
  108. import std.process;
  109. const status = spawnShell(command).wait();
  110. enforce(status == 0, "command '" ~ command ~ "' failed");
  111. }
  112.  
  113. void assertFileExists(string path) {
  114. enforce(exists(path), "expected file '" ~ path ~ "' not found");
  115. }
  116.  
  117. void assertDynLibExists(string name) {
  118. version (Windows) {
  119. enum prefix = "";
  120. enum suffix = ".dll";
  121. } else version (OSX) {
  122. enum prefix = "lib";
  123. enum suffix = ".dylib";
  124. } else {
  125. enum prefix = "lib";
  126. enum suffix = ".so";
  127. }
  128.  
  129. assertFileExists(prefix ~ name ~ suffix);
  130. }
  131.  
  132. bool canFindFiles(string pattern) {
  133. auto entries = dirEntries(".", pattern, SpanMode.shallow);
  134. return !entries.empty();
  135. }