checkout.pl 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. #!/usr/bin/perl
  2. use warnings;
  3. use strict;
  4. use Cwd qw(getcwd);
  5. use POSIX qw(WEXITSTATUS);
  6. use File::Copy;
  7. open(RVV, '<', 'RepoVivadoVersion');
  8. my $VIVADO_VERSION = <RVV>; chomp $VIVADO_VERSION;
  9. close(RVV);
  10. unless ($VIVADO_VERSION) {
  11. printf "Unable to detect the Vivado version in use in this repository.\n";
  12. exit(1);
  13. }
  14. if ($ENV{PATH} !~ m!/Vivado/\Q$VIVADO_VERSION\E(/\.)?/bin!) {
  15. printf "You are not running Vivado $VIVADO_VERSION or have not sourced the environment initialization scripts. Aborting.\n";
  16. exit(1);
  17. }
  18. my %MESSAGES;
  19. printf "~~~ Destroying backup workspace! ~~~\n";
  20. system('rm', '-rf', 'workspace.bak');
  21. printf "\n";
  22. printf "~~~ Backing up and replacing current workspace\n";
  23. if (-e 'workspace') {
  24. printf "\n";
  25. printf "~"x80 ."\n";
  26. printf "~~~ Backing up workspace\n";
  27. printf "~~~\n";
  28. system('cp',
  29. '-r',
  30. 'workspace/',
  31. 'workspace.bak/');
  32. system('rm', '-rf', 'workspace');
  33. printf "~~~\n";
  34. printf "\n";
  35. }
  36. if (!mkdir('workspace')) {
  37. printf "~~~ Failed to create workspace. Aborting.\n";
  38. exit(2);
  39. }
  40. if (-e 'ip_repo_sources') {
  41. printf "\n";
  42. printf "~"x80 ."\n";
  43. printf "~~~ COPYING IP_REPO\n";
  44. printf "~~~\n";
  45. system('rsync',
  46. '-rhtci', '--del',
  47. 'ip_repo_sources/',
  48. 'workspace/ip_repo/');
  49. printf "~~~\n";
  50. printf "\n";
  51. }
  52. open(PROJECTLIST, '<', 'projects.list');
  53. while (my $ProjectCanonicalName = <PROJECTLIST>) {
  54. chomp $ProjectCanonicalName;
  55. my $SourcesDir = sprintf("sources/%s", $ProjectCanonicalName);
  56. my $ProjectDir = sprintf("%s/workspace/%s", getcwd(), $ProjectCanonicalName);
  57. $MESSAGES{$ProjectCanonicalName} = [];
  58. printf "~"x80 ."\n";
  59. printf "~~~ Processing Project: %s\n", $ProjectCanonicalName;
  60. printf "~~~\n";
  61. printf "~~~ Sourcing Project TCL in Vivado\n";
  62. system('vivado', '-mode', 'batch', '-nojournal', '-nolog', '-source', sprintf("sources/%s.tcl", $ProjectCanonicalName));
  63. if (WEXITSTATUS($?)) {
  64. push @{$MESSAGES{$ProjectCanonicalName}}, { Severity => 'CRITICAL ERROR', Message => sprintf("Vivado exited with an unexpected status code after project regeneration: %s. Aborting. The project has NOT necessarily been safely or fully created!", WEXITSTATUS($?)) };
  65. }
  66. else {
  67. printf "~~~ Running any project-specific initialization scripts\n";
  68. my @InitScripts;
  69. push @InitScripts, sprintf("initscripts/%s.pl", $ProjectCanonicalName);
  70. push @InitScripts, sprintf("initscripts/%s.sh", $ProjectCanonicalName);
  71. push @InitScripts, sprintf("initscripts/%s.py", $ProjectCanonicalName);
  72. for my $InitScript (@InitScripts) {
  73. if (-x $InitScript) {
  74. printf "~~~ Running %s\n", $InitScript;
  75. system($InitScript, sprintf("%s/%s.xpr", $ProjectDir, $ProjectCanonicalName));
  76. if (WEXITSTATUS($?)) {
  77. push @{$MESSAGES{$ProjectCanonicalName}}, { Severity => 'WARNING', Message => sprintf("Project initialization script %s exited with nonzero status: %s!", $InitScript, WEXITSTATUS($?)) };
  78. }
  79. }
  80. }
  81. my $InitScript = sprintf("initscripts/%s.tcl", $ProjectCanonicalName);
  82. if (-f $InitScript) {
  83. printf "~~~ Running %s\n", $InitScript;
  84. system('vivado', '-mode', 'batch', '-nojournal', '-nolog', '-source', $InitScript, sprintf("%s/%s.xpr", $ProjectDir, $ProjectCanonicalName));
  85. if (WEXITSTATUS($?)) {
  86. push @{$MESSAGES{$ProjectCanonicalName}}, { Severity => 'WARNING', Message => sprintf("Project initialization script %s exited with nonzero status: %s!", $InitScript, WEXITSTATUS($?)) };
  87. }
  88. }
  89. }
  90. printf "~~~\n";
  91. printf "~~~ Finished processing project %s\n", $ProjectCanonicalName;
  92. printf "\n";
  93. printf "\n";
  94. if (@{$MESSAGES{$ProjectCanonicalName}}) {
  95. printf "~"x80 ."\n";
  96. printf "~~~ MESSAGES FOR PROJECT %s\n", $ProjectCanonicalName;
  97. printf "~~~\n";
  98. for my $Message (@{$MESSAGES{$ProjectCanonicalName}}) {
  99. printf "~~~ %s: %s\n", $Message->{Severity}, $Message->{Message};
  100. }
  101. printf "~~~\n";
  102. }
  103. }
  104. my %MessageTotals;
  105. for my $ProjectCanonicalName (keys %MESSAGES) {
  106. if (@{$MESSAGES{$ProjectCanonicalName}}) {
  107. printf "\n\n\n" unless (%MessageTotals);
  108. printf "~"x80 ."\n";
  109. printf "~~~ MESSAGES FOR PROJECT %s\n", $ProjectCanonicalName;
  110. printf "~~~\n";
  111. for my $Message (@{$MESSAGES{$ProjectCanonicalName}}) {
  112. printf "~~~ %s: %s\n", $Message->{Severity}, $Message->{Message};
  113. $MessageTotals{$Message->{Severity}} = 0 unless exists($MessageTotals{$Message->{Severity}});
  114. $MessageTotals{$Message->{Severity}}++;
  115. }
  116. printf "~~~\n";
  117. }
  118. }
  119. if (grep { $_ } values %MessageTotals) {
  120. printf "~"x80 ."\n";
  121. for my $MessageType (sort keys %MessageTotals) {
  122. printf "~~~ %u %s messages\n", $MessageTotals{$MessageType}, $MessageType;
  123. }
  124. printf "~~~ Please review them carefully and make sure none are dangerous before proceeding.\n";
  125. }
  126. else {
  127. printf "~~~ No issues encountered. Projects generated and ready to use.\n";
  128. }