From c488460c716b4cce4ab795d8f9f772c21fcb99e0 Mon Sep 17 00:00:00 2001 From: Marc Durdin Date: Mon, 13 Nov 2023 12:12:11 +0700 Subject: [PATCH] chore(developer): manage SourcePath in project upgrade Relates to #9948. When upgrading a project to v2.0, it is important that all source files are in the same folder. This change makes the upgrade process verify that this is the case and blocks the upgrade if there are source files in multiple folders. Source files are .kmn, .xml (ldml keyboard), .kps, and .model.ts. --- ...n.Developer.System.Project.ProjectFile.pas | 35 +++++++++++++++---- ...oper.System.Project.xmlLdmlProjectFile.pas | 4 --- ...eloper.UI.Project.xmlLdmlProjectFileUI.pas | 10 ------ 3 files changed, 29 insertions(+), 20 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 3dae6bf319d..9b7b0da5f7a 100644 --- a/developer/src/tike/project/Keyman.Developer.System.Project.ProjectFile.pas +++ b/developer/src/tike/project/Keyman.Developer.System.Project.ProjectFile.pas @@ -617,8 +617,6 @@ function TProjectFile.IsSourceFile: Boolean; end; procedure TProjectFile.Load(node: IXMLNode); // I4698 -var - i: Integer; begin if node.ChildNodes.IndexOf('ID') >= 0 then FID := CleanID(VarToWideStr(node.ChildValues['ID'])); @@ -651,8 +649,6 @@ procedure TProjectFile.RemoveFreeNotification( end; procedure TProjectFile.Save(node: IXMLNode); // I4698 -var - I: Integer; begin node.AddChild('ID').NodeValue := FID; node.AddChild('Filename').NodeValue := ExtractFileName(FFileName); @@ -1019,6 +1015,7 @@ function TProject.CanUpgrade: Boolean; var i: Integer; Path: string; + SourcePath: string; begin if FOptions.Version = pv20 then begin @@ -1043,6 +1040,8 @@ function TProject.CanUpgrade: Boolean; FUpgradeMessages.Add('The BuildPath project setting contains the "$VERSION" tag, which is no longer supported'); end; + SourcePath := '?'; + for i := 0 to Files.Count - 1 do begin if Assigned(Files[i].Parent) then @@ -1051,6 +1050,21 @@ function TProject.CanUpgrade: Boolean; end; Path := ExtractRelativePath(FileName, Files[i].FileName); + + // Ensure all compileable files + if Files[i].IsCompilable then + begin + if SourcePath = '?' then + begin + SourcePath := ExtractFileDir(Path) + end + else if not SameFileName(SourcePath, ExtractFileDir(Path)) then + begin + FUpgradeMessages.Add('File '+Files[i].FileName+' is not in the same folder as at least one other source file. All primary source files must be in the same folder.'); + Result := False; + end; + end; + if IsRelativePath(Path) and not Path.StartsWith('..') then begin // Path is in same folder or a subfolder of the project @@ -1074,8 +1088,17 @@ function TProject.Upgrade: Boolean; Options.Version := pv20; - if DirectoryExists(ExtractFilePath(FileName) + 'source') then - Options.SourcePath := '$PROJECTPATH\source'; + // Set location of all source files, default to 'source' if no source files + // are present in the project + Options.SourcePath := '$PROJECTPATH\source'; + for i := 0 to Files.Count - 1 do + begin + if Files[i].IsCompilable then + begin + Options.SourcePath := '$PROJECTPATH\' + ExtractFileDir(ExtractRelativePath(FFileName, Files[i].FileName)); + Break; + end; + end; for i := Files.Count - 1 downto 0 do begin diff --git a/developer/src/tike/project/Keyman.Developer.System.Project.xmlLdmlProjectFile.pas b/developer/src/tike/project/Keyman.Developer.System.Project.xmlLdmlProjectFile.pas index 11d6d25c88d..9609b899282 100644 --- a/developer/src/tike/project/Keyman.Developer.System.Project.xmlLdmlProjectFile.pas +++ b/developer/src/tike/project/Keyman.Developer.System.Project.xmlLdmlProjectFile.pas @@ -145,10 +145,6 @@ function TxmlLdmlProjectFile.GetTargetFilename: string; end; procedure TxmlLdmlProjectFile.GetFileParameters; -var - j: Integer; - value: WideString; - FVersion: string; // I4701 begin FHeader_Name := ''; FKVKFileName := ''; diff --git a/developer/src/tike/project/Keyman.Developer.UI.Project.xmlLdmlProjectFileUI.pas b/developer/src/tike/project/Keyman.Developer.UI.Project.xmlLdmlProjectFileUI.pas index 793c12dff6d..e4abe152010 100644 --- a/developer/src/tike/project/Keyman.Developer.UI.Project.xmlLdmlProjectFileUI.pas +++ b/developer/src/tike/project/Keyman.Developer.UI.Project.xmlLdmlProjectFileUI.pas @@ -21,7 +21,6 @@ interface TxmlLdmlProjectFileUI = class(TOpenableProjectFileUI) private function TestKeymanWeb(FSilent: Boolean): Boolean; - function DebugKeyboard(FSilent: Boolean): Boolean; function InstallKeyboard: Boolean; function UninstallKeyboard: Boolean; function GetProjectFile: TxmlLdmlProjectFileAction; @@ -234,15 +233,6 @@ function TxmlLdmlProjectFileUI.UninstallKeyboard: Boolean; Result := KeymanDeveloperUtils.UninstallKeyboard(ChangeFileExt(ExtractFileName(ProjectFile.FileName), '')); end; -function TxmlLdmlProjectFileUI.DebugKeyboard(FSilent: Boolean): Boolean; -var - editor: TfrmLdmlKeyboardEditor; -begin - editor := frmKeymanDeveloper.OpenEditor(ProjectFile.FileName, TfrmLdmlKeyboardEditor) as TfrmLdmlKeyboardEditor; -// editor.StartDebugging; - Result := True; -end; - function TxmlLdmlProjectFileUI.TestKeyboardState(FCompiledName: string; FSilent: Boolean): Boolean; var ftxml, ftkmx: TDateTime;