work on #10, guess output kind

This commit is contained in:
Basile Burg 2015-09-17 03:56:25 +02:00
parent ef8d72138c
commit a146f6ec36
1 changed files with 78 additions and 55 deletions

View File

@ -12,6 +12,7 @@ type
TCEDubProject = class(TComponent, ICECommonProject) TCEDubProject = class(TComponent, ICECommonProject)
private private
fPackageName: string;
fFilename: string; fFilename: string;
fModified: boolean; fModified: boolean;
fJSON: TJSONObject; fJSON: TJSONObject;
@ -26,6 +27,7 @@ type
fBasePath: string; fBasePath: string;
// //
procedure updateFields; procedure updateFields;
procedure updatePackageNameFromJson;
procedure udpateConfigsFromJson; procedure udpateConfigsFromJson;
procedure updateSourcesFromJson; procedure updateSourcesFromJson;
procedure updateTargetKindFromJson; procedure updateTargetKindFromJson;
@ -67,7 +69,7 @@ type
// these 9 built types always exist // these 9 built types always exist
TDubBuildType = (plain, debug, release, unittest, docs, ddox, profile, cov, unittestcov); TDubBuildType = (plain, debug, release, unittest, docs, ddox, profile, cov, unittestcov);
// returns true iffilename is a valid dub project. Only json format is supported. // returns true if filename is a valid dub project. Only json format is supported.
function isValidDubProject(const filename: string): boolean; function isValidDubProject(const filename: string): boolean;
const const
@ -115,6 +117,11 @@ begin
exit(self); exit(self);
end; end;
function TCEDubProject.modified: boolean;
begin
exit(fModified);
end;
function TCEDubProject.filename: string; function TCEDubProject.filename: string;
begin begin
exit(fFilename); exit(fFilename);
@ -250,6 +257,23 @@ end;
{$ENDREGION --------------------------------------------------------------------} {$ENDREGION --------------------------------------------------------------------}
{$REGION ICECommonProject: actions ---------------------------------------------} {$REGION ICECommonProject: actions ---------------------------------------------}
procedure TCEDubProject.dubProcOutput(proc: TProcess);
var
lst: TStringList;
str: string;
msgs: ICEMessagesDisplay;
begin
lst := TStringList.Create;
msgs := getMessageDisplay;
try
processOutputToStrings(proc, lst);
for str in lst do
msgs.message(str, self as ICECommonProject, amcProj, amkAuto);
finally
lst.Free;
end;
end;
function TCEDubProject.compile: boolean; function TCEDubProject.compile: boolean;
var var
dubproc: TProcess; dubproc: TProcess;
@ -295,50 +319,7 @@ begin
end; end;
{$ENDREGION --------------------------------------------------------------------} {$ENDREGION --------------------------------------------------------------------}
{$REGION JSON to internal fields -----------------------------------------------}
function isValidDubProject(const filename: string): boolean;
var
maybe: TCEDubProject;
begin
result := true;
// avoid the project to notify the observers, current project is not replaced
EntitiesConnector.beginUpdate;
maybe := TCEDubProject.create(nil);
EntitiesConnector.removeSubject(maybe);
try
try
maybe.loadFromFile(filename);
if maybe.json = nil then
result := false
else if maybe.json.Find('name') = nil then
result := false;
except
result := false;
end;
finally
maybe.Free;
EntitiesConnector.endUpdate;
end;
end;
procedure TCEDubProject.dubProcOutput(proc: TProcess);
var
lst: TStringList;
str: string;
msgs: ICEMessagesDisplay;
begin
lst := TStringList.Create;
msgs := getMessageDisplay;
try
processOutputToStrings(proc, lst);
for str in lst do
msgs.message(str, self as ICECommonProject, amcProj, amkAuto);
finally
lst.Free;
end;
end;
function TCEDubProject.getCurrentCustomConfig: TJSONObject; function TCEDubProject.getCurrentCustomConfig: TJSONObject;
var var
item: TJSONData; item: TJSONData;
@ -356,6 +337,15 @@ begin
result := confs.Objects[fConfigIx]; result := confs.Objects[fConfigIx];
end; end;
procedure TCEDubProject.updatePackageNameFromJson;
var
value: TJSONData;
begin
value := fJSON.Find('name');
if value <> nil then fPackageName := value.AsString
else fPackageName := '';
end;
procedure TCEDubProject.udpateConfigsFromJson; procedure TCEDubProject.udpateConfigsFromJson;
var var
i: integer; i: integer;
@ -498,36 +488,69 @@ end;
procedure TCEDubProject.updateTargetKindFromJson; procedure TCEDubProject.updateTargetKindFromJson;
var var
guess: boolean = false; found: boolean = false;
conf: TJSONObject; conf: TJSONObject;
src: string;
begin begin
fBinKind := executable; fBinKind := executable;
if fJSON = nil then exit; if fJSON = nil then exit;
// note: in Coedit this is only used to known if output can be launched // note: in Coedit this is only used to known if output can be launched
guess := not findTargetKindInd(fJSON); found := findTargetKindInd(fJSON);
conf := getCurrentCustomConfig; conf := getCurrentCustomConfig;
if conf <> nil then if conf <> nil then
guess := guess and findTargetKindInd(conf); found := found or findTargetKindInd(conf);
if guess then if not found then
begin begin
// TODO-cDUB: guess target kind for src in fSrcs do
// app.d in sourceRelative ? exe : lib begin
if (src = 'source' + DirectorySeparator + 'app.d')
or (src = 'src' + DirectorySeparator + 'app.d')
or (src = 'source' + DirectorySeparator + 'main.d')
or (src = 'src' + DirectorySeparator + 'main.d')
or (src = 'source' + DirectorySeparator + fPackageName + DirectorySeparator + 'app.d')
or (src = 'src' + DirectorySeparator + fPackageName + DirectorySeparator + 'app.d')
or (src = 'source' + DirectorySeparator + fPackageName + DirectorySeparator + 'main.d')
or (src = 'src' + DirectorySeparator + fPackageName + DirectorySeparator + 'main.d')
then fBinKind:= executable
else fBinKind:= staticlib;
end;
end; end;
end; end;
procedure TCEDubProject.updateFields; procedure TCEDubProject.updateFields;
begin begin
updatePackageNameFromJson;
udpateConfigsFromJson; udpateConfigsFromJson;
updateSourcesFromJson; updateSourcesFromJson;
updateTargetKindFromJson; updateTargetKindFromJson;
end; end;
{$ENDREGION}
function TCEDubProject.modified: boolean; function isValidDubProject(const filename: string): boolean;
var
maybe: TCEDubProject;
begin begin
exit(fModified); result := true;
// avoid the project to notify the observers, current project is not replaced
EntitiesConnector.beginUpdate;
maybe := TCEDubProject.create(nil);
EntitiesConnector.removeSubject(maybe);
try
try
maybe.loadFromFile(filename);
if maybe.json = nil then
result := false
else if maybe.json.Find('name') = nil then
result := false;
except
result := false;
end;
finally
maybe.Free;
EntitiesConnector.endUpdate;
end;
end; end;
{$ENDREGION --------------------------------------------------------------------}
end. end.