build_all.pl 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. #!/usr/bin/perl
  2. ################## HOW TO USE THIS FILE #####################
  3. # iar keil xpresso to build with those toolchain
  4. # clean or build for action
  5. #############################################################
  6. use List::MoreUtils 'any';
  7. use File::Spec;
  8. use File::Find;
  9. use File::Path;
  10. use File::Glob;
  11. use File::stat;
  12. use File::Basename;
  13. use Cwd;
  14. use Cwd 'abs_path';
  15. #use Time::Piece;
  16. #use Time::Seconds;
  17. $" = "\n"; # change list separator
  18. $KEIL_PATH = 'C:/Keil/UV4'; #'/C/Keil/UV4';
  19. $IAR_PATH = glob ('C:/Program*/IAR*/Embedded*/common/bin');
  20. $XPRESSO_PATH = glob ('C:/nxp/LPCXpresso_7*/lpcxpresso');
  21. $XPRESSO_PATH = "$XPRESSO_PATH;$XPRESSO_PATH/bin;$XPRESSO_PATH/tools/bin;$XPRESSO_PATH/msys/bin";
  22. $ENV{'PATH'} = $KEIL_PATH . ';' . $IAR_PATH . ';' . $XPRESSO_PATH . ';' . $ENV{'PATH'};
  23. #print $ENV{'PATH'}; die;
  24. $repo_path = abs_path(cwd . "/..");
  25. #print $repo_path; die;
  26. $device_dir = "device/device";
  27. $host_dir = "host/host";
  28. $is_build = any { /build/ } @ARGV;
  29. $is_clean = any { /clean/ } @ARGV;
  30. $is_build = 1 if !$is_clean; # default is build
  31. $is_keil = (any { /keil/ } @ARGV) || (any { /all/ } @ARGV);
  32. $is_iar = (any { /iar/ } @ARGV) || (any { /all/ } @ARGV);
  33. $is_xpresso = (any { /xpresso/ } @ARGV) || (any { /all/ } @ARGV);
  34. ################## KEIL #####################
  35. if ($is_keil)
  36. {
  37. @KEIL_PROJECT_LIST = (<$device_dir*/*.uvproj>, <$host_dir*/*.uvproj>);
  38. foreach (@KEIL_PROJECT_LIST)
  39. {
  40. /([^\/]+).uvproj/;
  41. my $log_file = "build_all_keil_" . $1 . ".txt";
  42. my $build_cmd = "Uv4 -b $_ -z -j0 -o ../../$log_file";
  43. cmd_execute($build_cmd);
  44. }
  45. }
  46. ################## IAR #####################
  47. if ($is_iar)
  48. {
  49. @IAR_PROJECT_LIST = (<$device_dir*/*.ewp>, <$host_dir*/*.ewp>);
  50. foreach (@IAR_PROJECT_LIST)
  51. {
  52. my $proj_dir = dirname $_;
  53. /([^\/]+).ewp/;
  54. my $proj_name = $1;
  55. my $log_file = "build_all_iar_" . $proj_name . ".txt";
  56. unlink $log_file; #delete log_file if existed
  57. #open project file to get configure name
  58. my $file_content = file_to_var($_);
  59. #get configure by pattern and build
  60. while ($file_content =~ /^\s*<configuration>\s*$^\s*<name>(.+)<\/name>\s*$/gm)
  61. {
  62. my $build_cmd = "IarBuild $_ -build $1 -log warnings >> $log_file";
  63. cmd_execute($build_cmd);
  64. my $out_file = "$proj_dir/$1/Exe/$proj_name.out";
  65. system("size $out_file >> $log_file");
  66. }
  67. }
  68. }
  69. ################## LPCXPRESSO #####################
  70. ($repo_path_other_dash = $repo_path) =~ s/\//\\/g;
  71. if ($is_xpresso)
  72. {
  73. $workspace_dir = "C:/Users/hathach/Dropbox/tinyusb/workspace7"; #projects must be opened in the workspace to be built
  74. @XPRESSO_PROJECT_LIST = (<$device_dir*/.cproject>, <$host_dir*/.cproject>);
  75. foreach (@XPRESSO_PROJECT_LIST)
  76. {
  77. /([^\/]+)\/.cproject/;
  78. my $log_file = "build_all_xpresso_" . $1 . ".txt";
  79. my $build_cmd = "lpcxpressoc -nosplash --launcher.suppressErrors -application org.eclipse.cdt.managedbuilder.core.headlessbuild -cleanBuild $1 -data $workspace_dir > $log_file";
  80. cmd_execute($build_cmd);
  81. #open log file to clean up output
  82. open (my $fin, $log_file) or die;
  83. my @log_content = <$fin>;
  84. close($fin);
  85. open (my $fout, ">$log_file") or die;
  86. foreach (@log_content)
  87. {
  88. unless (/Invoking: MCU C Compiler/ or /arm-none-eabi-gcc -D/ or /Finished building:/ or /^ $/)
  89. {
  90. s/Building file:.+?([^\/]+\.[ch])/\1/;
  91. s/$repo_path//;
  92. s/$repo_path_other_dash//;
  93. print $fout $_;
  94. }
  95. }
  96. }
  97. }
  98. ### call report builder ###
  99. system("perl build_report.pl");
  100. ################## HELPER #####################
  101. sub cmd_execute
  102. {
  103. print "executing: $_[0]\n...";
  104. system($_[0]);
  105. print "done\n";
  106. }
  107. sub file_to_var
  108. { #open project file to get configure name
  109. my $file_content;
  110. open(my $fin, $_[0]) or die "Can't open $_[0] to read\n";
  111. {
  112. local $/;
  113. $file_content = <$fin>;
  114. close($fin);
  115. }
  116. return $file_content;
  117. }
  118. sub var_to_file
  119. { # file name, content
  120. open(my $fout, ">$_[0]") or die "Can't open $_[0] to write\n";
  121. {
  122. print $fout $_[1];
  123. close($fout);
  124. }
  125. }