add options for the makefile projects

close #109
This commit is contained in:
Basile Burg 2022-05-15 09:50:05 +02:00
parent 6c4a47a48c
commit 4ed8b33e1e
1 changed files with 148 additions and 19 deletions

View File

@ -12,6 +12,37 @@ uses
type
TMakeProjectOptionsBase = class(TWritableLfmTextComponent)
strict private
fNumThreads: integer;
fSourceDirectories: TStringList;
fQuiet: boolean;
fKeepGoing: boolean;
procedure setSourceDirectories(value: TStringList);
published
property keepGoing: boolean read fKeepGoing write fKeepGoing default false;
property quiet: boolean read fQuiet write fQuiet default false;
property numThreads: integer read fNumThreads write fNumThreads default 1;
property sourceDirectories: TStringList read fSourceDirectories write setSourceDirectories;
public
constructor create(aOwner: TComponent); override;
destructor destroy(); override;
procedure assign(other: TPersistent); override;
end;
TMakeProjectOptions = class(TMakeProjectOptionsBase, IEditableOptions)
strict private
fBackup: TMakeProjectOptionsBase;
function optionedWantCategory(): string;
function optionedWantEditorKind: TOptionEditorKind;
function optionedWantContainer: TPersistent;
procedure optionedEvent(event: TOptionEditorEvent);
function optionedOptionsModified: boolean;
public
constructor create(aOwner: TComponent); override;
destructor destroy; override;
end;
TMakeProject = class(TComponent, ICommonProject)
private
@ -110,6 +141,95 @@ end;
implementation
var
makeProjectOptions: TMakeProjectOptions;
const
optFname = 'makeProjectsOptions.txt';
constructor TMakeProjectOptionsBase.create(aOwner: TComponent);
begin
inherited create(aOwner);
fNumThreads := 1;
fSourceDirectories := TStringList.Create;
fSourceDirectories.AddStrings(['src', 'import', 'include']);
end;
destructor TMakeProjectOptionsBase.destroy();
begin
fSourceDirectories.Free;
inherited;
end;
procedure TMakeProjectOptionsBase.setSourceDirectories(value: TStringList);
begin
fSourceDirectories.Assign(value);
end;
procedure TMakeProjectOptionsBase.assign(other: TPersistent);
var
src: TMakeProjectOptionsBase;
begin
if other is TMakeProjectOptionsBase then
begin
src := TMakeProjectOptionsBase(other);
fSourceDirectories.Assign(src.sourceDirectories);
fQuiet:= src.fQuiet;
fKeepGoing:= src.fKeepGoing;
fNumThreads:= src.fNumThreads;
end
else inherited;
end;
constructor TMakeProjectOptions.create(aOwner: TComponent);
var
fname: string;
begin
inherited;
fBackup := TMakeProjectOptionsBase.Create(nil);
EntitiesConnector.addObserver(self);
fname := getDocPath + optFname;
if fname.fileExists then
loadFromFile(fname);
end;
destructor TMakeProjectOptions.destroy;
begin
saveToFile(getDocPath + optFname);
EntitiesConnector.removeObserver(self);
fBackup.free;
inherited;
end;
function TMakeProjectOptions.optionedWantCategory(): string;
begin
exit('Makefile projects');
end;
function TMakeProjectOptions.optionedWantEditorKind: TOptionEditorKind;
begin
exit(oekGeneric);
end;
function TMakeProjectOptions.optionedWantContainer: TPersistent;
begin
fBackup.assign(self);
exit(self);
end;
procedure TMakeProjectOptions.optionedEvent(event: TOptionEditorEvent);
begin
case event of
oeeAccept: fBackup.assign(self);
oeeCancel: self.assign(fBackup);
oeeSelectCat:fBackup.assign(self);
end;
end;
function TMakeProjectOptions.optionedOptionsModified: boolean;
begin
exit(false);
end;
constructor TMakeProject.create(aOwner: TComponent);
begin
inherited create(aOwner);
@ -170,6 +290,7 @@ var
line1: string;
hidden: string = DirectorySeparator + '.';
f: string;
p: string;
colPos: integer;
i: integer;
begin
@ -205,24 +326,14 @@ begin
fSrcs.Sorted:=false;
srcs := TStringList.Create;
try
listFiles(srcs, fBasePath + 'src', true);
for f in srcs do
if pos(hidden, f) = 0 then
fSrcs.Add(f[fBasePath.length + 1 .. f.length]);
srcs.Clear;
listFiles(srcs, fBasePath + 'include', true);
for f in srcs do
if pos(hidden, f) = 0 then
fSrcs.Add(f[fBasePath.length + 1 .. f.length]);
srcs.Clear;
listFiles(srcs, fBasePath + 'import', true);
for f in srcs do
if pos(hidden, f) = 0 then
fSrcs.Add(f[fBasePath.length + 1 .. f.length]);
srcs.Clear;
for p in makeProjectOptions.sourceDirectories do
begin
listFiles(srcs, fBasePath + p, true);
for f in srcs do
if pos(hidden, f) = 0 then
fSrcs.Add(f[fBasePath.length + 1 .. f.length]);
srcs.Clear;
end;
finally
srcs.Free;
end;
@ -264,9 +375,15 @@ end;
function TMakeProject.getCommandLine: string;
begin
result := 'make ' + '-f ' + fFilename;
result := 'make ' + '-f' + fFilename;
if not fRuleIndex.equals(0) then
result += ' ' + fRules[fRuleIndex];
if makeProjectOptions.keepGoing then
result += ' -k';
if makeProjectOptions.quiet then
result += ' -q';
if makeProjectOptions.numThreads > 1 then
result += ' -j' + makeProjectOptions.numThreads.ToString();
end;
procedure TMakeProject.stopCompilation;
@ -396,9 +513,17 @@ begin
p := shortenPath(fFilename);
fMakeProc := TDexedProcess.create(nil);
fMakeProc.executable := 'make';
fMakeProc.Parameters.AddStrings([ '-f', fFilename]);
if not fRuleIndex.equals(0) then
fMakeProc.Parameters.Add(fRules[fRuleIndex]);
if makeProjectOptions.keepGoing then
fMakeProc.Parameters.Add(' -k');
if makeProjectOptions.quiet then
fMakeProc.Parameters.Add(' -q');
if makeProjectOptions.numThreads > 1 then
fMakeProc.Parameters.Add(' -j' + makeProjectOptions.numThreads.ToString());
fMakeProc.Options := fMakeProc.Options + [poStderrToOutPut, poUsePipes];
fMakeProc.ShowWindow := swoHIDE;
fMakeProc.CurrentDirectory := fFilename.extractFilePath;
@ -431,5 +556,9 @@ begin
result := false;
end;
initialization
makeProjectOptions:= TMakeProjectOptions.create(nil);
finalization
makeProjectOptions.free;
end.