Skip to content

Commit

Permalink
chore(developer): manage SourcePath in project upgrade
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mcdurdin committed Nov 13, 2023
1 parent d39af4e commit c488460
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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']));
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -1019,6 +1015,7 @@ function TProject.CanUpgrade: Boolean;
var
i: Integer;
Path: string;
SourcePath: string;
begin
if FOptions.Version = pv20 then
begin
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,6 @@ function TxmlLdmlProjectFile.GetTargetFilename: string;
end;

procedure TxmlLdmlProjectFile.GetFileParameters;
var
j: Integer;
value: WideString;
FVersion: string; // I4701
begin
FHeader_Name := '';
FKVKFileName := '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit c488460

Please sign in to comment.