mirror of https://gitlab.com/basile.b/dexed.git
dub project, target type
This commit is contained in:
parent
54fdeeed9c
commit
5452333f5a
|
@ -16,17 +16,21 @@ type
|
||||||
private
|
private
|
||||||
fFilename: string;
|
fFilename: string;
|
||||||
fModified: boolean;
|
fModified: boolean;
|
||||||
fJson: TJSONObject;
|
fJSON: TJSONObject;
|
||||||
|
fSrcs: TStringList;
|
||||||
fProjectSubject: TCEProjectSubject;
|
fProjectSubject: TCEProjectSubject;
|
||||||
fConfigsCount: integer;
|
fConfigsCount: integer;
|
||||||
fBuildTypes: TStringList;
|
fBuildTypes: TStringList;
|
||||||
fConfigs: TStringList;
|
fConfigs: TStringList;
|
||||||
fBuiltTypeIx: integer;
|
fBuiltTypeIx: integer;
|
||||||
fConfigIx: integer;
|
fConfigIx: integer;
|
||||||
|
fBinKind: TProjectBinaryKind;
|
||||||
//
|
//
|
||||||
procedure updateFields;
|
procedure updateFields;
|
||||||
procedure udpateConfigsFromJson;
|
procedure udpateConfigsFromJson;
|
||||||
procedure updateSourcesFromJson;
|
procedure updateSourcesFromJson;
|
||||||
|
procedure updateTargetKindFromJson;
|
||||||
|
function findTargetKindIn(value: TJSONObject): boolean;
|
||||||
procedure dubProcOutput(proc: TProcess);
|
procedure dubProcOutput(proc: TProcess);
|
||||||
//
|
//
|
||||||
function getFormat: TCEProjectFormat;
|
function getFormat: TCEProjectFormat;
|
||||||
|
@ -53,7 +57,7 @@ type
|
||||||
function compile: boolean;
|
function compile: boolean;
|
||||||
function run(const runArgs: string = ''): boolean;
|
function run(const runArgs: string = ''): boolean;
|
||||||
//
|
//
|
||||||
property json: TJSONObject read fJson;
|
property json: TJSONObject read fJSON;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// these 9 built types always exist
|
// these 9 built types always exist
|
||||||
|
@ -76,6 +80,7 @@ begin
|
||||||
fProjectSubject := TCEProjectSubject.Create;
|
fProjectSubject := TCEProjectSubject.Create;
|
||||||
fBuildTypes := TStringList.Create;
|
fBuildTypes := TStringList.Create;
|
||||||
fConfigs := TStringList.Create;
|
fConfigs := TStringList.Create;
|
||||||
|
fSrcs := TStringList.Create;
|
||||||
//
|
//
|
||||||
subjProjNew(fProjectSubject, self);
|
subjProjNew(fProjectSubject, self);
|
||||||
subjProjChanged(fProjectSubject, self);
|
subjProjChanged(fProjectSubject, self);
|
||||||
|
@ -86,9 +91,10 @@ begin
|
||||||
subjProjClosing(fProjectSubject, self);
|
subjProjClosing(fProjectSubject, self);
|
||||||
fProjectSubject.free;
|
fProjectSubject.free;
|
||||||
//
|
//
|
||||||
fJSon.Free;
|
fJSON.Free;
|
||||||
fBuildTypes.Free;
|
fBuildTypes.Free;
|
||||||
fConfigs.Free;
|
fConfigs.Free;
|
||||||
|
fSrcs.Free;
|
||||||
inherited;
|
inherited;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -139,11 +145,9 @@ begin
|
||||||
// builtype1 - config0, builtype1 - config1, ... , builtype1 - configN, etc
|
// builtype1 - config0, builtype1 - config1, ... , builtype1 - configN, etc
|
||||||
|
|
||||||
|
|
||||||
//fConfigs.Add('(dub default)'); // default
|
if fJSON.Find('configurations') <> nil then
|
||||||
|
|
||||||
if fJson.Find('configurations') <> nil then
|
|
||||||
begin
|
begin
|
||||||
configs := fJson.Arrays['configurations'];
|
configs := fJSON.Arrays['configurations'];
|
||||||
for i:= 0 to configs.Count-1 do
|
for i:= 0 to configs.Count-1 do
|
||||||
begin
|
begin
|
||||||
item := TJSONObject(configs.Items[i]);
|
item := TJSONObject(configs.Items[i]);
|
||||||
|
@ -157,9 +161,9 @@ begin
|
||||||
end;
|
end;
|
||||||
|
|
||||||
fBuildTypes.AddStrings(DubBuiltTypeName);
|
fBuildTypes.AddStrings(DubBuiltTypeName);
|
||||||
if fJson.Find('buildTypes') <> nil then
|
if fJSON.Find('buildTypes') <> nil then
|
||||||
begin
|
begin
|
||||||
builtTypes := fJson.Arrays['buildTypes'];
|
builtTypes := fJSON.Arrays['buildTypes'];
|
||||||
for i := 0 to builtTypes.Count-1 do
|
for i := 0 to builtTypes.Count-1 do
|
||||||
begin
|
begin
|
||||||
item := TJSONObject(builtTypes.Items[i]);
|
item := TJSONObject(builtTypes.Items[i]);
|
||||||
|
@ -177,16 +181,65 @@ begin
|
||||||
//TODO-cDUB: update the source files for the current configuration
|
//TODO-cDUB: update the source files for the current configuration
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TCEDubProject.findTargetKindIn(value: TJSONObject): boolean;
|
||||||
|
var
|
||||||
|
tt: TJSONData;
|
||||||
|
begin
|
||||||
|
result := true;
|
||||||
|
tt := value.Find('targetType');
|
||||||
|
if tt <> nil then
|
||||||
|
begin
|
||||||
|
case tt.AsString of
|
||||||
|
'executable': fBinKind := executable;
|
||||||
|
'staticLibrary' : fBinKind := staticlib;
|
||||||
|
'dynamicLibrary' : fBinKind := sharedlib;
|
||||||
|
'autodetect': result := false;
|
||||||
|
else fBinKind := executable;
|
||||||
|
end;
|
||||||
|
end else result := false;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TCEDubProject.updateTargetKindFromJson;
|
||||||
|
var
|
||||||
|
guess: boolean = false;
|
||||||
|
item: TJSONData;
|
||||||
|
confs: TJSONArray;
|
||||||
|
i: integer;
|
||||||
|
begin
|
||||||
|
fBinKind := executable;
|
||||||
|
if fJSON = nil then exit;
|
||||||
|
|
||||||
|
// actually for a DUB project this is only used to known if output can be
|
||||||
|
// ran from the 'project' menu
|
||||||
|
guess := not findTargetKindIn(fJSON);
|
||||||
|
if fConfigIx <> 0 then
|
||||||
|
begin
|
||||||
|
item := fJSON.Find('configurations');
|
||||||
|
if item <> nil then
|
||||||
|
begin
|
||||||
|
confs := TJSONArray(item);
|
||||||
|
for i := 0 to confs.Count-1 do
|
||||||
|
if TJSONObject(confs.Objects[i]).Find('name') <> nil then
|
||||||
|
guess := guess and findTargetKindIn(confs.Objects[i]);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
if guess then
|
||||||
|
begin
|
||||||
|
// TODO-cDUB: guess target kind
|
||||||
|
// app.d in source ? exe : lib
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TCEDubProject.updateFields;
|
procedure TCEDubProject.updateFields;
|
||||||
begin
|
begin
|
||||||
udpateConfigsFromJson;
|
udpateConfigsFromJson;
|
||||||
updateSourcesFromJson;
|
updateSourcesFromJson;
|
||||||
|
updateTargetKindFromJson;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCEDubProject.getBinaryKind: TProjectBinaryKind;
|
function TCEDubProject.getBinaryKind: TProjectBinaryKind;
|
||||||
begin
|
begin
|
||||||
//TODO-cDUB: implement
|
exit(fBinKind);
|
||||||
exit(executable);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCEDubProject.loadFromFile(const aFilename: string);
|
procedure TCEDubProject.loadFromFile(const aFilename: string);
|
||||||
|
@ -198,10 +251,10 @@ begin
|
||||||
try
|
try
|
||||||
fFilename:= aFilename;
|
fFilename:= aFilename;
|
||||||
loader.LoadFromFile(fFilename);
|
loader.LoadFromFile(fFilename);
|
||||||
fJSon.Free;
|
fJSON.Free;
|
||||||
parser := TJSONParser.Create(loader);
|
parser := TJSONParser.Create(loader);
|
||||||
try
|
try
|
||||||
fJSon := parser.Parse as TJSONObject;
|
fJSON := parser.Parse as TJSONObject;
|
||||||
finally
|
finally
|
||||||
parser.Free;
|
parser.Free;
|
||||||
end;
|
end;
|
||||||
|
@ -221,7 +274,7 @@ begin
|
||||||
saver := TMemoryStream.Create;
|
saver := TMemoryStream.Create;
|
||||||
try
|
try
|
||||||
fFilename := aFilename;
|
fFilename := aFilename;
|
||||||
str := fJson.FormatJSON;
|
str := fJSON.FormatJSON;
|
||||||
saver.Write(str[1], length(str));
|
saver.Write(str[1], length(str));
|
||||||
saver.SaveToFile(fFilename);
|
saver.SaveToFile(fFilename);
|
||||||
finally
|
finally
|
||||||
|
|
Loading…
Reference in New Issue