Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/main/pascal/PasBuild.Command.ProcessResources.pas
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ function TProcessResourcesCommand.GetName: string;

function TProcessResourcesCommand.ApplyFiltering(const AContent: string): string;
var
Now: TDateTime;
BuildDateTime: TDateTime;
begin
Result := AContent;
Now := SysUtils.Now;
BuildDateTime := TUtils.GetBuildDateTime();

// Replace project variables
Result := StringReplace(Result, '${project.name}', Config.Name, [rfReplaceAll]);
Expand All @@ -70,9 +70,9 @@ function TProcessResourcesCommand.ApplyFiltering(const AContent: string): string
Result := StringReplace(Result, '${project.license}', Config.License, [rfReplaceAll]);

// Replace build-time variables (ISO-8601 format)
Result := StringReplace(Result, '${build.date}', FormatDateTime('yyyy-mm-dd', Now), [rfReplaceAll]);
Result := StringReplace(Result, '${build.time}', FormatDateTime('hh:nn:ss', Now), [rfReplaceAll]);
Result := StringReplace(Result, '${build.timestamp}', FormatDateTime('yyyy-mm-dd''T''hh:nn:ss', Now), [rfReplaceAll]);
Result := StringReplace(Result, '${build.date}', FormatDateTime('yyyy-mm-dd', BuildDateTime), [rfReplaceAll]);
Result := StringReplace(Result, '${build.time}', FormatDateTime('hh:nn:ss', BuildDateTime), [rfReplaceAll]);
Result := StringReplace(Result, '${build.timestamp}', FormatDateTime('yyyy-mm-dd''T''hh:nn:ss', BuildDateTime), [rfReplaceAll]);
end;

function TProcessResourcesCommand.ProcessFile(const ASourceFile, ARelativePath: string): Boolean;
Expand Down
10 changes: 5 additions & 5 deletions src/main/pascal/PasBuild.Command.ProcessTestResources.pas
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ function TProcessTestResourcesCommand.GetName: string;

function TProcessTestResourcesCommand.ApplyFiltering(const AContent: string): string;
var
Now: TDateTime;
BuildDateTime: TDateTime;
begin
Result := AContent;
Now := SysUtils.Now;
BuildDateTime := TUtils.GetBuildDateTime();

// Replace project variables
Result := StringReplace(Result, '${project.name}', Config.Name, [rfReplaceAll]);
Expand All @@ -70,9 +70,9 @@ function TProcessTestResourcesCommand.ApplyFiltering(const AContent: string): st
Result := StringReplace(Result, '${project.license}', Config.License, [rfReplaceAll]);

// Replace build-time variables (ISO-8601 format)
Result := StringReplace(Result, '${build.date}', FormatDateTime('yyyy-mm-dd', Now), [rfReplaceAll]);
Result := StringReplace(Result, '${build.time}', FormatDateTime('hh:nn:ss', Now), [rfReplaceAll]);
Result := StringReplace(Result, '${build.timestamp}', FormatDateTime('yyyy-mm-dd''T''hh:nn:ss', Now), [rfReplaceAll]);
Result := StringReplace(Result, '${build.date}', FormatDateTime('yyyy-mm-dd', BuildDateTime), [rfReplaceAll]);
Result := StringReplace(Result, '${build.time}', FormatDateTime('hh:nn:ss', BuildDateTime), [rfReplaceAll]);
Result := StringReplace(Result, '${build.timestamp}', FormatDateTime('yyyy-mm-dd''T''hh:nn:ss', BuildDateTime), [rfReplaceAll]);
end;

function TProcessTestResourcesCommand.ProcessFile(const ASourceFile, ARelativePath: string): Boolean;
Expand Down
17 changes: 17 additions & 0 deletions src/main/pascal/PasBuild.Utils.pas
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,16 @@ TUtils = class
class function CollectSourceFiles(const ABaseDir: string): TStringList;
class function CollectIncludeFiles(const ABaseDir: string): TStringList;
class procedure WriteListFile(const AFilePath: string; AList: TStringList);

{ Build date utilities }
class function GetBuildDateTime(): TDateTime;
end;

implementation

uses
DateUtils;

{ Forward declaration for recursive helper }
procedure RecursiveScanDirs(const ADir: string; AList: TStringList); forward;

Expand Down Expand Up @@ -889,4 +895,15 @@ class procedure TUtils.WriteListFile(const AFilePath: string; AList: TStringList
end;
end;

class function TUtils.GetBuildDateTime(): TDateTime;
var
SourceDateEpoch: string;
begin
SourceDateEpoch := GetEnvironmentVariable('SOURCE_DATE_EPOCH');
if Length(SourceDateEpoch) > 0 then
Result := UnixToDateTime(StrToInt64(SourceDateEpoch))
else
Result := SysUtils.Now()
end;

end.