PackageBuildRes.pas 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. {
  2. $Project$
  3. $Workfile$
  4. $Revision$
  5. $DateUTC$
  6. $Id$
  7. This file is part of the Indy (Internet Direct) project, and is offered
  8. under the dual-licensing agreement described on the Indy website.
  9. (http://www.indyproject.org/)
  10. Copyright:
  11. (c) 1993-2005, Chad Z. Hower and the Indy Pit Crew. All rights reserved.
  12. }
  13. {
  14. $Log$
  15. }
  16. {
  17. { Rev 1.0 1/24/2024 4:49:00 PM RLebeau
  18. { BuildRes.bat generation.
  19. }
  20. unit PackageBuildRes;
  21. interface
  22. uses
  23. Package;
  24. type
  25. TBuildRes = class(TPackage)
  26. private
  27. procedure RunBuildRes;
  28. public
  29. constructor Create; override;
  30. procedure Generate(ACompilers: TCompilers; const AFlags: TGenerateFlags); override;
  31. end;
  32. implementation
  33. uses
  34. SysUtils, DModule, Windows;
  35. { TBuildRes }
  36. constructor TBuildRes.Create;
  37. begin
  38. inherited;
  39. FOutputSubDir := 'Lib';
  40. end;
  41. procedure TBuildRes.Generate(ACompilers: TCompilers; const AFlags: TGenerateFlags);
  42. var
  43. LCompiler: TCompiler;
  44. begin
  45. //We don't call many of the inherited Protected methods because
  46. //those are for Packages while I'm making a unit.
  47. //inherited;
  48. FName := 'buildres';
  49. FExt := '.bat';
  50. FCompiler := ctUnversioned;
  51. FCode.Clear;
  52. FDesignTime := False;
  53. for LCompiler := Low(TCompiler) to High(TCompiler) do begin
  54. if LCompiler in ACompilers then begin
  55. Code('brcc32 System\IndySystem'+GCompilerID[LCompiler]+'.rc');
  56. end;
  57. end;
  58. for LCompiler := Low(TCompiler) to High(TCompiler) do begin
  59. if LCompiler in ACompilers then begin
  60. Code('brcc32 Core\dclIndyCore'+GCompilerID[LCompiler]+'.rc');
  61. end;
  62. end;
  63. Code('brcc32 Core\IdAboutVCL.rc');
  64. for LCompiler := Low(TCompiler) to High(TCompiler) do begin
  65. if LCompiler in ACompilers then begin
  66. Code('brcc32 Core\IndyCore'+GCompilerID[LCompiler]+'.rc');
  67. end;
  68. end;
  69. for LCompiler := Low(TCompiler) to High(TCompiler) do begin
  70. if LCompiler in ACompilers then begin
  71. Code('brcc32 Protocols\dclIndyProtocols'+GCompilerID[LCompiler]+'.rc');
  72. end;
  73. end;
  74. for LCompiler := Low(TCompiler) to High(TCompiler) do begin
  75. if LCompiler in ACompilers then begin
  76. Code('brcc32 Protocols\IndyProtocols'+GCompilerID[LCompiler]+'.rc');
  77. end;
  78. end;
  79. WriteFile;
  80. // TODO: run buildres.bat only if any .rc files were actually (re-)generated...
  81. RunBuildRes;
  82. end;
  83. procedure TBuildRes.RunBuildRes;
  84. var
  85. LPathname: string;
  86. LSubDir: string;
  87. LCmdLine: string;
  88. SI: TStartupInfo;
  89. PI: TProcessInformation;
  90. LExitCode: DWORD;
  91. begin
  92. LPathname := SysUtils.IncludeTrailingPathDelimiter(DM.OutputPath);
  93. if FOutputSubDir <> '' then begin
  94. LSubDir := SysUtils.IncludeTrailingPathDelimiter(FOutputSubDir);
  95. LPathname := LPathname + LSubDir;
  96. end;
  97. LCmdLine := 'cmd.exe /C ' + AnsiQuotedStr(LPathname + FName + FExt, '"');
  98. ZeroMemory(@SI, sizeof(SI));
  99. SI.cb := sizeof(SI);
  100. if CreateProcess(nil, PChar(LCmdLine), nil, nil, False, CREATE_NO_WINDOW, nil, PChar(LPathname), SI, PI) then
  101. begin
  102. CloseHandle(PI.hThread);
  103. WaitForSingleObject(PI.hProcess, INFINITE);
  104. GetExitCodeProcess(PI.hProcess, LExitCode);
  105. CloseHandle(PI.hProcess);
  106. if LExitCode <> 0 then
  107. WriteLn('Error from ' + LSubDir + FName + FExt);
  108. end else
  109. begin
  110. WriteLn('Unable to run ' + LSubDir + FName + FExt);
  111. end;
  112. end;
  113. end.