From d39af4edc5d4b5967a59c277448aa0dfda30c964 Mon Sep 17 00:00:00 2001 From: Marc Durdin Date: Sun, 12 Nov 2023 06:41:37 +0700 Subject: [PATCH] chore(developer): only build source files For batch builds (e.g. project/compile all) of v2.0 projects, we only want to build files that are listed in the project's $SOURCEPATH, so that the project can contain extra folders with source file types that won't break a project-level build. Any source file types in extra folders can still be built one-by-one, which is helpful for investigation and test for keyboard authors, but will not be built if project build is selected. This commit also formalizes the source/ SourcePath for upgraded projects which contain a source/ folder. If the project to be upgraded does not contain the source/ folder, then no SourcePath is assigned, and any source file in any folder will be built. --- ...n.Developer.System.Project.ProjectFile.pas | 42 +++++++++++++++++-- ...eyman.Developer.UI.Project.UfrmProject.pas | 19 +++++++++ 2 files changed, 57 insertions(+), 4 deletions(-) diff --git a/developer/src/tike/project/Keyman.Developer.System.Project.ProjectFile.pas b/developer/src/tike/project/Keyman.Developer.System.Project.ProjectFile.pas index 1d13591347e..3dae6bf319d 100644 --- a/developer/src/tike/project/Keyman.Developer.System.Project.ProjectFile.pas +++ b/developer/src/tike/project/Keyman.Developer.System.Project.ProjectFile.pas @@ -266,6 +266,7 @@ TProjectFile = class destructor Destroy; override; function IsCompilable: Boolean; virtual; + function IsSourceFile: Boolean; virtual; class function IsFileTypeSupported(const Filename: string): Boolean; virtual; procedure Load(node: IXMLNode); virtual; // I4698 @@ -587,6 +588,34 @@ class function TProjectFile.IsFileTypeSupported( Result := True; end; +function TProjectFile.IsSourceFile: Boolean; +var + FilePath, SourcePath: string; +begin + // An file that is a sub-file of another one is never a source file + if Assigned(FParent) then + Exit(False); + + // If no project is assigned, this is an unsupported mode (loading without + // project is no longer supported in 17.0+) but we don't want to crash so + // we'll just treat this as a source file + if not Assigned(FProject) then + Exit(True); + + // We don't restrict builds to sourcepath files for v1.0 projects + if FProject.Options.Version = pv10 then + Exit(True); + + // If no sourcepath is defined, then we'll build any files + if FProject.Options.SourcePath = '' then + Exit(True); + + // Only return true if the file is directly in the ProjectOptions.SourcePath folder + SourcePath := ReplaceStr(IncludeTrailingPathDelimiter(FProject.ResolveProjectPath(FProject.Options.SourcePath)), '/', '\'); + FilePath := ReplaceStr(ExtractFilePath(FFileName), '/', '\'); + Result := SameFileName(SourcePath, FilePath); +end; + procedure TProjectFile.Load(node: IXMLNode); // I4698 var i: Integer; @@ -943,16 +972,18 @@ function TProject.IsDefaultProject(Version: TProjectVersion): Boolean; /// function TProject.PopulateFiles: Boolean; var - SourcePath: string; + ProjectPath: string; begin if FOptions.Version <> pv20 then raise EProjectLoader.Create('PopulateFiles can only be called on a v2.0 project'); - SourcePath := ExtractFilePath(FileName); - if not DirectoryExists(SourcePath) then + FFiles.Clear; + + ProjectPath := ExtractFilePath(FileName); + if not DirectoryExists(ProjectPath) then Exit(False); - PopulateFolder(SourcePath); + PopulateFolder(ProjectPath); Result := True; end; @@ -1043,6 +1074,9 @@ function TProject.Upgrade: Boolean; Options.Version := pv20; + if DirectoryExists(ExtractFilePath(FileName) + 'source') then + Options.SourcePath := '$PROJECTPATH\source'; + for i := Files.Count - 1 downto 0 do begin if Assigned(Files[i].Parent) then diff --git a/developer/src/tike/project/Keyman.Developer.UI.Project.UfrmProject.pas b/developer/src/tike/project/Keyman.Developer.UI.Project.UfrmProject.pas index c9b3f9ba14b..ba73eaf68cf 100644 --- a/developer/src/tike/project/Keyman.Developer.UI.Project.UfrmProject.pas +++ b/developer/src/tike/project/Keyman.Developer.UI.Project.UfrmProject.pas @@ -288,6 +288,8 @@ procedure TfrmProject.CompileAll; ClearMessages; for i := 0 to FGlobalProject.Files.Count - 1 do begin + if not FGlobalProject.Files[i].IsSourceFile then + Continue; if FGlobalProject.Files[i].IsCompilable and not (FGlobalProject.Files[i] is TkpsProjectFile) then begin @@ -296,6 +298,8 @@ procedure TfrmProject.CompileAll; end; for i := 0 to FGlobalProject.Files.Count - 1 do begin + if not FGlobalProject.Files[i].IsSourceFile then + Continue; if FGlobalProject.Files[i] is TkpsProjectFile then if not (FGlobalProject.Files[i].UI as TProjectFileUI).DoAction(pfaCompile, False) then Exit; // I4687 end; @@ -509,6 +513,8 @@ procedure TfrmProject.WebCommandProject(Command: WideString; Params: TStringList ClearMessages; for i := 0 to FGlobalProject.Files.Count - 1 do begin + if not FGlobalProject.Files[i].IsSourceFile then + Continue; (FGlobalProject.Files[i].UI as TProjectFileUI).DoAction(pfaClean, False); // I4687 end; end @@ -517,6 +523,9 @@ procedure TfrmProject.WebCommandProject(Command: WideString; Params: TStringList ClearMessages; for i := 0 to FGlobalProject.Files.Count - 1 do begin + if not FGlobalProject.Files[i].IsSourceFile then + Continue; + if (FGlobalProject.Files[i] is TkmnProjectFile) or (FGlobalProject.Files[i] is TxmlLdmlProjectFile) then (FGlobalProject.Files[i].UI as TProjectFileUI).DoAction(pfaCompile, False); // I4687 @@ -527,6 +536,8 @@ procedure TfrmProject.WebCommandProject(Command: WideString; Params: TStringList ClearMessages; for i := 0 to FGlobalProject.Files.Count - 1 do begin + if not FGlobalProject.Files[i].IsSourceFile then + Continue; if (FGlobalProject.Files[i] is TkmnProjectFile) or (FGlobalProject.Files[i] is TxmlLdmlProjectFile) then (FGlobalProject.Files[i].UI as TProjectFileUI).DoAction(pfaClean, False); @@ -537,6 +548,8 @@ procedure TfrmProject.WebCommandProject(Command: WideString; Params: TStringList ClearMessages; for i := 0 to FGlobalProject.Files.Count - 1 do begin + if not FGlobalProject.Files[i].IsSourceFile then + Continue; if FGlobalProject.Files[i] is TmodelTsProjectFile then (FGlobalProject.Files[i].UI as TProjectFileUI).DoAction(pfaCompile, False); // I4687 end; @@ -546,6 +559,8 @@ procedure TfrmProject.WebCommandProject(Command: WideString; Params: TStringList ClearMessages; for i := 0 to FGlobalProject.Files.Count - 1 do begin + if not FGlobalProject.Files[i].IsSourceFile then + Continue; if FGlobalProject.Files[i] is TmodelTsProjectFile then (FGlobalProject.Files[i].UI as TProjectFileUI).DoAction(pfaClean, False); end; @@ -556,6 +571,8 @@ procedure TfrmProject.WebCommandProject(Command: WideString; Params: TStringList ClearMessages; for i := 0 to FGlobalProject.Files.Count - 1 do begin + if not FGlobalProject.Files[i].IsSourceFile then + Continue; if FGlobalProject.Files[i] is TkpsProjectFile then (FGlobalProject.Files[i].UI as TProjectFileUI).DoAction(pfaCompile, False); end; @@ -565,6 +582,8 @@ procedure TfrmProject.WebCommandProject(Command: WideString; Params: TStringList ClearMessages; for i := 0 to FGlobalProject.Files.Count - 1 do begin + if not FGlobalProject.Files[i].IsSourceFile then + Continue; if FGlobalProject.Files[i] is TkpsProjectFile then (FGlobalProject.Files[i].UI as TProjectFileUI).DoAction(pfaClean, False); end;