Skip to content

Commit

Permalink
chore(developer): only build source files
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mcdurdin committed Nov 11, 2023
1 parent f9272aa commit d39af4e
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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);
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit d39af4e

Please sign in to comment.