Build.PL 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use Config;
  5. use File::Spec;
  6. my %prereqs = qw(
  7. Devel::CheckLib 0
  8. Encode 0
  9. Encode::Locale 1.05
  10. ExtUtils::CppGuess 0
  11. ExtUtils::MakeMaker 6.80
  12. ExtUtils::ParseXS 3.35
  13. File::Basename 0
  14. File::Spec 0
  15. Getopt::Long 0
  16. Module::Build::WithXSpp 0.14
  17. Moo 1.003001
  18. POSIX 0
  19. Scalar::Util 0
  20. Test::More 0
  21. Thread::Semaphore 0
  22. IO::Scalar 0
  23. threads 1.96
  24. Time::HiRes 0
  25. Unicode::Normalize 0
  26. );
  27. my %recommends = qw(
  28. Class::XSAccessor 0
  29. Test::Harness 0
  30. Thread::Queue 0
  31. threads::shared 0
  32. );
  33. my $sudo = grep { $_ eq '--sudo' } @ARGV;
  34. my $gui = grep { $_ eq '--gui' } @ARGV;
  35. my $xs_only = grep { $_ eq '--xs' } @ARGV;
  36. if ($gui) {
  37. %prereqs = qw(
  38. Class::Accessor 0
  39. Wx 0.9918
  40. Socket 2.016
  41. );
  42. %recommends = qw(
  43. Growl::GNTP 0.15
  44. Wx::GLCanvas 0
  45. OpenGL 0
  46. LWP::UserAgent 0
  47. Net::Bonjour 0
  48. );
  49. if ($^O eq 'MSWin32') {
  50. $recommends{"Win32::TieRegistry"} = 0;
  51. # we need an up-to-date Win32::API because older aren't thread-safe (GH #2517)
  52. $prereqs{'Win32::API'} = 0.79;
  53. }
  54. } elsif ($xs_only) {
  55. %prereqs = %recommends = ();
  56. }
  57. my @missing_prereqs = ();
  58. if ($ENV{SLIC3R_NO_AUTO}) {
  59. foreach my $module (sort keys %prereqs) {
  60. my $version = $prereqs{$module};
  61. next if eval "use $module $version; 1";
  62. push @missing_prereqs, $module if exists $prereqs{$module};
  63. print "Missing prerequisite $module $version\n";
  64. }
  65. foreach my $module (sort keys %recommends) {
  66. my $version = $recommends{$module};
  67. next if eval "use $module $version; 1";
  68. print "Missing optional $module $version\n";
  69. }
  70. } else {
  71. my @try = (
  72. $ENV{CPANM} // (),
  73. File::Spec->catfile($Config{sitebin}, 'cpanm'),
  74. File::Spec->catfile($Config{installscript}, 'cpanm'),
  75. );
  76. my $cpanm;
  77. foreach my $path (@try) {
  78. if (-e $path) { # don't use -x because it fails on Windows
  79. $cpanm = $path;
  80. last;
  81. }
  82. }
  83. if (!$cpanm) {
  84. if ($^O =~ /^(?:darwin|linux)$/ && system(qw(which cpanm)) == 0) {
  85. $cpanm = 'cpanm';
  86. }
  87. }
  88. die <<'EOF'
  89. cpanm was not found. Please install it before running this script.
  90. There are several ways to install cpanm, try one of these:
  91. apt-get install cpanminus
  92. curl -L http://cpanmin.us | perl - --sudo App::cpanminus
  93. cpan App::cpanminus
  94. If it is installed in a non-standard location you can do:
  95. CPANM=/path/to/cpanm perl Build.PL
  96. EOF
  97. if !$cpanm;
  98. my @cpanm_args = ();
  99. push @cpanm_args, "--sudo" if $sudo;
  100. # install local::lib without --local-lib otherwise it's not usable afterwards
  101. if (!eval "use local::lib qw(local-lib); 1") {
  102. my $res = system $cpanm, @cpanm_args, 'local::lib';
  103. warn "Warning: local::lib is required. You might need to run the `cpanm --sudo local::lib` command in order to install it.\n"
  104. if $res != 0;
  105. }
  106. push @cpanm_args, ('--local-lib', 'local-lib');
  107. # make sure our cpanm is updated (old ones don't support the ~ syntax)
  108. system $cpanm, @cpanm_args, 'App::cpanminus';
  109. my %modules = (%prereqs, %recommends);
  110. foreach my $module (sort keys %modules) {
  111. my $version = $modules{$module};
  112. my @cmd = ($cpanm, @cpanm_args);
  113. # temporary workaround for upstream bug in test
  114. push @cmd, '--notest'
  115. if $module =~ /^(?:OpenGL|Math::PlanePath|Test::Harness|IO::Scalar)$/;
  116. push @cmd, "$module~$version";
  117. my $res = system @cmd;
  118. if ($res != 0) {
  119. if (exists $prereqs{$module}) {
  120. push @missing_prereqs, $module;
  121. } else {
  122. printf "Don't worry, this module is optional.\n";
  123. }
  124. }
  125. }
  126. if (!$gui) {
  127. # clean xs directory before reinstalling, to make sure Build is called
  128. # with current perl binary
  129. if (-e './xs/Build') {
  130. if ($^O eq 'MSWin32') {
  131. system '.\xs\Build', 'distclean';
  132. } else {
  133. system './xs/Build', 'distclean';
  134. }
  135. }
  136. my $res = system $cpanm, @cpanm_args, '--reinstall', '--verbose', './xs';
  137. if ($res != 0) {
  138. die "The XS/C++ code failed to compile, aborting\n";
  139. }
  140. }
  141. }
  142. if (@missing_prereqs) {
  143. printf "The following prerequisites failed to install: %s\n", join(', ', @missing_prereqs);
  144. exit 1;
  145. } elsif (!$gui) {
  146. eval "use App::Prove; 1" or die "Failed to load App::Prove";
  147. my $res = App::Prove->new->run ? 0 : 1;
  148. if ($res == 0) {
  149. print "If you also want to use the GUI you can now run `perl Build.PL --gui` to install the required modules.\n";
  150. } else {
  151. print "Some tests failed. Please report the failure to the author!\n";
  152. }
  153. exit $res;
  154. }
  155. __END__