added common project interface funct to get imports paths

This commit is contained in:
Basile Burg 2015-09-18 05:33:41 +02:00
parent e1e86c258f
commit 911a183c0b
3 changed files with 67 additions and 4 deletions

View File

@ -19,6 +19,7 @@ type
fSrcs: TStringList; fSrcs: TStringList;
fProjectSubject: TCEProjectSubject; fProjectSubject: TCEProjectSubject;
fConfigsCount: integer; fConfigsCount: integer;
fImportPaths: TStringList;
fBuildTypes: TStringList; fBuildTypes: TStringList;
fConfigs: TStringList; fConfigs: TStringList;
fBuiltTypeIx: integer; fBuiltTypeIx: integer;
@ -33,6 +34,7 @@ type
procedure udpateConfigsFromJson; procedure udpateConfigsFromJson;
procedure updateSourcesFromJson; procedure updateSourcesFromJson;
procedure updateTargetKindFromJson; procedure updateTargetKindFromJson;
procedure updateImportPathsFromJson;
function findTargetKindInd(value: TJSONObject): boolean; function findTargetKindInd(value: TJSONObject): boolean;
procedure dubProcOutput(proc: TProcess); procedure dubProcOutput(proc: TProcess);
function getCurrentCustomConfig: TJSONObject; function getCurrentCustomConfig: TJSONObject;
@ -54,12 +56,14 @@ type
function modified: boolean; function modified: boolean;
function binaryKind: TProjectBinaryKind; function binaryKind: TProjectBinaryKind;
function getCommandLine: string; function getCommandLine: string;
function outputFilename: string;
// //
function isSource(const aFilename: string): boolean; function isSource(const aFilename: string): boolean;
function sourcesCount: integer; function sourcesCount: integer;
function sourceRelative(index: integer): string; function sourceRelative(index: integer): string;
function sourceAbsolute(index: integer): string; function sourceAbsolute(index: integer): string;
function outputFilename: string; function importsPathCount: integer;
function importPath(index: integer): string;
// //
function configurationCount: integer; function configurationCount: integer;
procedure setActiveConfiguration(index: integer); procedure setActiveConfiguration(index: integer);
@ -95,6 +99,7 @@ begin
fBuildTypes := TStringList.Create; fBuildTypes := TStringList.Create;
fConfigs := TStringList.Create; fConfigs := TStringList.Create;
fSrcs := TStringList.Create; fSrcs := TStringList.Create;
fImportPaths := TStringList.Create;
// //
subjProjNew(fProjectSubject, self); subjProjNew(fProjectSubject, self);
subjProjChanged(fProjectSubject, self); subjProjChanged(fProjectSubject, self);
@ -109,6 +114,7 @@ begin
fBuildTypes.Free; fBuildTypes.Free;
fConfigs.Free; fConfigs.Free;
fSrcs.Free; fSrcs.Free;
fImportPaths.Free;
inherited; inherited;
end; end;
{$ENDREGION --------------------------------------------------------------------} {$ENDREGION --------------------------------------------------------------------}
@ -242,6 +248,16 @@ begin
else else
result := expandFilenameEx(fBasePath, fname); result := expandFilenameEx(fBasePath, fname);
end; end;
function TCEDubProject.importsPathCount: integer;
begin
result := fImportPaths.Count;
end;
function TCEDubProject.importPath(index: integer): string;
begin
result := expandFilenameEx(fBasePath, fImportPaths.Strings[index]);
end;
{$ENDREGION --------------------------------------------------------------------} {$ENDREGION --------------------------------------------------------------------}
{$REGION ICECommonProject: configs ---------------------------------------------} {$REGION ICECommonProject: configs ---------------------------------------------}
@ -555,12 +571,38 @@ begin
end; end;
end; end;
procedure TCEDubProject.updateImportPathsFromJson;
procedure addFrom(obj: TJSONObject);
var
arr: TJSONArray;
item: TJSONData;
i: integer;
begin
item := obj.Find('importPaths');
if assigned(item) then
begin
arr := TJSONArray(item);
for i:= 0 to arr.Count-1 do
fImportPaths.Add(arr.Strings[i]);
end;
end;
var
conf: TJSONObject;
begin
if fJSON = nil then exit;
//
addFrom(fJSON);
conf := getCurrentCustomConfig;
if assigned(conf) then addFrom(conf);
end;
procedure TCEDubProject.updateFields; procedure TCEDubProject.updateFields;
begin begin
updatePackageNameFromJson; updatePackageNameFromJson;
udpateConfigsFromJson; udpateConfigsFromJson;
updateSourcesFromJson; updateSourcesFromJson;
updateTargetKindFromJson; updateTargetKindFromJson;
updateImportPathsFromJson;
end; end;
procedure TCEDubProject.beginModification; procedure TCEDubProject.beginModification;

View File

@ -59,7 +59,7 @@ type
// project sources --------------------------------------------------------- // project sources ---------------------------------------------------------
// returns the count of source file in th e project // returns the count of source files for the current config
function sourcesCount: integer; function sourcesCount: integer;
// returns the source absolute filename. // returns the source absolute filename.
function sourceAbsolute(index: integer): string; function sourceAbsolute(index: integer): string;
@ -67,6 +67,10 @@ type
function sourceRelative(index: integer): string; function sourceRelative(index: integer): string;
// returns true if aFilename is a project source. // returns true if aFilename is a project source.
function isSource(const aFilename: string): boolean; function isSource(const aFilename: string): boolean;
// returns the count of import paths for the current config
function importsPathCount: integer;
// returns the import absolute path
function importPath(index: integer): string;
// sub routines for the actions -------------------------------------------- // sub routines for the actions --------------------------------------------

View File

@ -97,6 +97,8 @@ type
function sourceRelative(index: integer): string; function sourceRelative(index: integer): string;
function sourceAbsolute(index: integer): string; function sourceAbsolute(index: integer): string;
function isSource(const aFilename: string): boolean; function isSource(const aFilename: string): boolean;
function importsPathCount: integer;
function importPath(index: integer): string;
// //
function run(const runArgs: string = ''): Boolean; function run(const runArgs: string = ''): Boolean;
function compile: Boolean; function compile: Boolean;
@ -182,13 +184,16 @@ end;
procedure TCENativeProject.addSource(const aFilename: string); procedure TCENativeProject.addSource(const aFilename: string);
var var
relSrc, absSrc: string; relSrc, absSrc: string;
expand: boolean;
begin begin
if not isDlangCompilable(ExtractFileExt(aFilename)) then if not isDlangCompilable(ExtractFileExt(aFilename)) then
exit; exit;
expand := DirectoryExists(fBasePath);
for relSrc in fSrcs do for relSrc in fSrcs do
begin begin
absSrc := expandFilenameEx(fBasePath,relsrc); if not expand then absSrc := relSrc
if aFilename = absSrc then exit; else absSrc := expandFilenameEx(fBasePath, relsrc);
if SameFileName(aFilename, absSrc) then exit;
end; end;
fSrcs.Add(ExtractRelativepath(fBasePath, aFilename)); fSrcs.Add(ExtractRelativepath(fBasePath, aFilename));
end; end;
@ -900,6 +905,18 @@ begin
result := expandFilenameEx(fBasePath, fname); result := expandFilenameEx(fBasePath, fname);
end; end;
function TCENativeProject.importsPathCount: integer;
begin
result := currentConfiguration.pathsOptions.importModulePaths.Count;
end;
function TCENativeProject.importPath(index: integer): string;
begin
result := currentConfiguration.pathsOptions.importModulePaths.Strings[index];
if DirectoryExists(fBasePath) then
result := expandFilenameEx(fBasePath, result);
end;
function isValidNativeProject(const filename: string): boolean; function isValidNativeProject(const filename: string): boolean;
var var
maybe: TCENativeProject; maybe: TCENativeProject;