1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431
|
{ /***************************************************************************
showcompileropts.pas - Lazarus IDE unit
-----------------------------------------
***************************************************************************/
***************************************************************************
* *
* This source is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This code is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* General Public License for more details. *
* *
* A copy of the GNU General Public License is available on the World *
* Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also *
* obtain it by writing to the Free Software Foundation, *
* Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1335, USA. *
* *
***************************************************************************
Author: Mattias Gaertner
Abstract:
Dialog for showing the compiler options as command line parameters.
}
unit ShowCompilerOpts;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils,
// LCL
Forms, Controls, Buttons, StdCtrls, ComCtrls, ExtCtrls,
// LazUtils
LazFileUtils, LazUTF8, LazStringUtils,
// CodeTools
CodeToolsCfgScript,
// IdeIntf
BaseIDEIntf, LazIDEIntf, IDEImagesIntf, CompOptsIntf, ProjectIntf, PackageIntf,
// IDE
LazarusIDEStrConsts, Project, PackageDefs,
CompilerOptions, ModeMatrixOpts, MiscOptions;
type
{ TShowCompilerOptionsDlg }
TShowCompilerOptionsDlg = class(TForm)
CloseButton: TBitBtn;
CmdLineMemo: TMEMO;
CmdLineParamsTabSheet: TTabSheet;
InheritedParamsTabSheet: TTabSheet;
InhItemMemo: TMemo;
InhSplitter: TSplitter;
InhTreeView: TTreeView;
MultilineCheckBox: TCheckBox;
PageControl1: TPageControl;
RelativePathsCheckBox: TCheckBox;
procedure FormClose(Sender: TObject; var {%H-}CloseAction: TCloseAction);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure InhTreeViewSelectionChanged(Sender: TObject);
procedure MultilineCheckBoxChange(Sender: TObject);
procedure RelativePathsCheckBoxChange(Sender: TObject);
private
FCompilerOpts: TBaseCompilerOptions;
ImageIndexInherited: Integer;
ImageIndexRequired: Integer;
ImageIndexPackage: Integer;
InheritedChildDatas: TFPList; // list of PInheritedNodeData
procedure ClearInheritedTree;
procedure SetCompilerOpts(const AValue: TBaseCompilerOptions);
procedure UpdateMemo;
procedure UpdateInheritedTree;
public
property CompilerOpts: TBaseCompilerOptions read FCompilerOpts write SetCompilerOpts;
end;
function ShowCompilerOptionsDialog(OwnerForm: TCustomForm;
CompilerOpts: TBaseCompilerOptions): TModalResult;
implementation
{$R *.lfm}
type
TInheritedNodeData = record
FullText: string;
Option: TInheritedCompilerOption;
end;
PInheritedNodeData = ^TInheritedNodeData;
function ShowCompilerOptionsDialog(OwnerForm: TCustomForm;
CompilerOpts: TBaseCompilerOptions): TModalResult;
var
ShowCompilerOptionsDlg: TShowCompilerOptionsDlg;
begin
Result:=mrOk;
LazarusIDE.PrepareBuildTarget(false,smsfsBackground);
ShowCompilerOptionsDlg:=TShowCompilerOptionsDlg.Create(OwnerForm);
try
ShowCompilerOptionsDlg.CompilerOpts:=CompilerOpts;
Result:=ShowCompilerOptionsDlg.ShowModal;
finally
ShowCompilerOptionsDlg.Free;
end;
end;
{ TShowCompilerOptionsDlg }
procedure TShowCompilerOptionsDlg.RelativePathsCheckBoxChange(Sender: TObject);
begin
UpdateMemo;
end;
procedure TShowCompilerOptionsDlg.ClearInheritedTree;
var
i: integer;
ChildData: PInheritedNodeData;
begin
if InhTreeView = nil then
exit;
InhTreeView.BeginUpdate;
// dispose all child data
if InheritedChildDatas <> nil then
begin
for i := 0 to InheritedChildDatas.Count - 1 do
begin
ChildData := PInheritedNodeData(InheritedChildDatas[i]);
Dispose(ChildData);
end;
InheritedChildDatas.Free;
InheritedChildDatas := nil;
end;
InhTreeView.Items.Clear;
InhTreeView.EndUpdate;
end;
procedure TShowCompilerOptionsDlg.InhTreeViewSelectionChanged(Sender: TObject);
var
ANode: TTreeNode;
ChildData: PInheritedNodeData;
sl: TStrings;
begin
ANode := InhTreeView.Selected;
if (ANode = nil) or (ANode.Data = nil) then
begin
InhItemMemo.Lines.Text := lisSelectANode;
end
else
begin
ChildData := PInheritedNodeData(ANode.Data);
if ChildData^.Option in icoAllSearchPaths then
begin
sl := SplitString(ChildData^.FullText, ';');
InhItemMemo.Lines.Assign(sl);
sl.Free;
end
else
InhItemMemo.Lines.Text := ChildData^.FullText;
end;
end;
procedure TShowCompilerOptionsDlg.MultilineCheckBoxChange(Sender: TObject);
begin
UpdateMemo;
end;
procedure TShowCompilerOptionsDlg.FormCreate(Sender: TObject);
begin
ImageIndexPackage := IDEImages.LoadImage('item_package');
ImageIndexRequired := IDEImages.LoadImage('pkg_required');
ImageIndexInherited := IDEImages.LoadImage('pkg_inherited');
Caption:=dlgCompilerOptions;
PageControl1.ActivePage:=CmdLineParamsTabSheet;
CmdLineParamsTabSheet.Caption:=lisCommandLineParameters;
RelativePathsCheckBox.Caption:=lisShowRelativePaths;
RelativePathsCheckBox.Checked:=not MiscellaneousOptions.ShowCompOptFullFilenames;
MultilineCheckBox.Caption:=lisShowMultipleLines;
MultilineCheckBox.Checked:=not MiscellaneousOptions.ShowCompOptMultiLine;
InheritedParamsTabSheet.Caption:=lisInheritedParameters;
InhTreeView.Images := IDEImages.Images_16;
InhItemMemo.Text := lisSelectANode;
CloseButton.Caption:=lisBtnClose;
end;
procedure TShowCompilerOptionsDlg.FormClose(Sender: TObject;
var CloseAction: TCloseAction);
begin
MiscellaneousOptions.ShowCompOptFullFilenames:=not RelativePathsCheckBox.Checked;
MiscellaneousOptions.ShowCompOptMultiLine:=MultilineCheckBox.Checked;
MiscellaneousOptions.Save;
end;
procedure TShowCompilerOptionsDlg.FormDestroy(Sender: TObject);
begin
ClearInheritedTree;
end;
procedure TShowCompilerOptionsDlg.SetCompilerOpts(
const AValue: TBaseCompilerOptions);
begin
if FCompilerOpts=AValue then exit;
FCompilerOpts:=AValue;
UpdateMemo;
UpdateInheritedTree;
end;
procedure TShowCompilerOptionsDlg.UpdateMemo;
var
Flags: TCompilerCmdLineOptions;
CurOptions: String;
ParamList: TStrings;
begin
if CompilerOpts=nil then exit;
Flags:=CompilerOpts.DefaultMakeOptionsFlags+[ccloAddCompilerPath];
if not RelativePathsCheckBox.Checked then
Include(Flags,ccloAbsolutePaths);
CurOptions := CompilerOpts.MakeOptionsString(Flags);
if MultilineCheckBox.Checked then begin
ParamList:=TStringList.Create;
try
SplitCmdLineParams(CurOptions,ParamList);
CurOptions:=ParamList.Text;
finally
ParamList.Free;
end;
CmdLineMemo.ScrollBars:=ssAutoBoth;
end else
CmdLineMemo.ScrollBars:=ssAutoVertical;
CmdLineMemo.Lines.Text:=CurOptions;
end;
procedure TShowCompilerOptionsDlg.UpdateInheritedTree;
var
OptionsList: TFPList;
i: integer;
AncestorOptions: TAdditionalCompilerOptions;
AncestorNode: TTreeNode;
AncestorBaseOpts: TBaseCompilerOptions;
Vars: TCTCfgScriptVariables;
Macro: TLazBuildMacro;
j: Integer;
procedure AddChildNode(const NewNodeName, Value: string;
Option: TInheritedCompilerOption);
var
VisibleValue: string;
ChildNode: TTreeNode;
ChildData: PInheritedNodeData;
begin
if Value = '' then
exit;
New(ChildData);
ChildData^.FullText := Value;
ChildData^.Option := Option;
if InheritedChildDatas = nil then
InheritedChildDatas := TFPList.Create;
InheritedChildDatas.Add(ChildData);
if UTF8Length(Value) > 100 then
VisibleValue := UTF8Copy(Value, 1, 100) + '[...]'
else
VisibleValue := Value;
ChildNode := InhTreeView.Items.AddChildObject(AncestorNode,
NewNodeName + ' = "' + VisibleValue + '"', ChildData);
ChildNode.ImageIndex := ImageIndexRequired;
ChildNode.SelectedIndex := ChildNode.ImageIndex;
end;
var
SkippedPkgList: TFPList;
AProject: TProject;
Pkg: TLazPackage;
t: TBuildMatrixGroupType;
procedure AddMatrixGroupNode(Grp: TBuildMatrixGroupType);
begin
if AncestorNode<>nil then exit;
AncestorNode := InhTreeView.Items.Add(nil, '');
case Grp of
bmgtEnvironment: AncestorNode.Text:=dlgGroupEnvironment;
bmgtProject: AncestorNode.Text:=dlgProject;
bmgtSession: AncestorNode.Text:=lisProjectSession;
end;
AncestorNode.ImageIndex := ImageIndexPackage;
AncestorNode.SelectedIndex := AncestorNode.ImageIndex;
end;
procedure AddMatrixGroup(Grp: TBuildMatrixGroupType);
var
CustomOptions: String;
OutDir: String;
begin
AncestorNode := nil;
CustomOptions:='';
OnAppendCustomOption(CompilerOpts,CustomOptions,[Grp]);
if CustomOptions<>'' then begin
AddMatrixGroupNode(Grp);
AddChildNode(liscustomOptions, CustomOptions, icoCustomOptions);
end;
OutDir:='.*';
OnGetOutputDirectoryOverride(CompilerOpts,OutDir,[Grp]);
if OutDir<>'.*' then begin
AddMatrixGroupNode(Grp);
AddChildNode('Output directory', OutDir, icoNone);
end;
if AncestorNode<>nil then
AncestorNode.Expand(true);
end;
begin
if CompilerOpts=nil then exit;
OptionsList := nil;
//debugln(['TCompilerInheritedOptionsFrame.UpdateInheritedTree START CompilerOpts=',DbgSName(CompilerOpts)]);
CompilerOpts.GetInheritedCompilerOptions(OptionsList);
SkippedPkgList:=nil;
try
if CompilerOpts is TProjectCompilerOptions then begin
AProject:=TProjectCompilerOptions(CompilerOpts).LazProject;
AProject.GetAllRequiredPackages(SkippedPkgList);
if (SkippedPkgList<>nil)
and (not (pfUseDesignTimePackages in AProject.Flags)) then begin
// keep design time only packages
for i:=SkippedPkgList.Count-1 downto 0 do
if TLazPackage(SkippedPkgList[i]).PackageType<>lptDesignTime then
SkippedPkgList.Delete(i);
end;
end;
//debugln(['TCompilerInheritedOptionsFrame.UpdateInheritedTree END']);
InhTreeView.BeginUpdate;
ClearInheritedTree;
if OptionsList <> nil then
begin
Vars:=GetBuildMacroValues(CompilerOpts,false);
// add All node
AncestorNode := InhTreeView.Items.Add(nil, lisAllInheritedOptions);
AncestorNode.ImageIndex := ImageIndexInherited;
AncestorNode.SelectedIndex := AncestorNode.ImageIndex;
with CompilerOpts do
begin
AddChildNode(lisunitPath,
GetInheritedOption(icoUnitPath, True), icoUnitPath);
AddChildNode(lisincludePath,
GetInheritedOption(icoIncludePath, True), icoIncludePath);
AddChildNode(lisobjectPath,
GetInheritedOption(icoObjectPath, True), icoObjectPath);
AddChildNode(lislibraryPath,
GetInheritedOption(icoLibraryPath, True), icoLibraryPath);
AddChildNode(lislinkerOptions, GetInheritedOption(icoLinkerOptions, True),
icoLinkerOptions);
AddChildNode(liscustomOptions, GetInheritedOption(icoCustomOptions, True),
icoCustomOptions);
end;
AncestorNode.Expanded := True;
// add detail nodes
for i := 0 to OptionsList.Count - 1 do
begin
AncestorOptions := TAdditionalCompilerOptions(OptionsList[i]);
AncestorNode := InhTreeView.Items.Add(nil, '');
AncestorNode.Text := AncestorOptions.GetOwnerName;
AncestorNode.ImageIndex := ImageIndexPackage;
AncestorNode.SelectedIndex := AncestorNode.ImageIndex;
AncestorBaseOpts:=AncestorOptions.GetBaseCompilerOptions;
with AncestorOptions.ParsedOpts do
begin
AddChildNode(lisunitPath,
CreateRelativeSearchPath(GetParsedValue(pcosUnitPath),CompilerOpts.BaseDirectory),
icoUnitPath);
AddChildNode(lisincludePath,
CreateRelativeSearchPath(GetParsedValue(pcosIncludePath),CompilerOpts.BaseDirectory),
icoIncludePath);
AddChildNode(lisobjectPath,
CreateRelativeSearchPath(GetParsedValue(pcosObjectPath),CompilerOpts.BaseDirectory),
icoObjectPath);
AddChildNode(lislibraryPath,
CreateRelativeSearchPath(GetParsedValue(pcosLibraryPath),CompilerOpts.BaseDirectory),
icoLibraryPath);
AddChildNode(lislinkerOptions, GetParsedValue(pcosLinkerOptions),
icoLinkerOptions);
AddChildNode(liscustomOptions, GetParsedValue(pcosCustomOptions),
icoCustomOptions);
end;
if (AncestorBaseOpts<>nil) and (Vars<>nil) then begin
for j:=0 to AncestorBaseOpts.BuildMacros.Count-1 do
begin
Macro:=AncestorBaseOpts.BuildMacros[j];
AddChildNode(Macro.Identifier,Vars.Values[Macro.Identifier],icoNone);
end;
end;
AncestorNode.Expanded := True;
end;
OptionsList.Free;
end else
begin
InhTreeView.Items.Add(nil, lisNoCompilerOptionsInherited);
end;
if SkippedPkgList<>nil then begin
for i:=0 to SkippedPkgList.Count-1 do begin
Pkg:=TLazPackage(SkippedPkgList[i]);
AncestorNode := InhTreeView.Items.Add(nil, '');
AncestorNode.Text := Format(lisExcludedAtRunTime, [Pkg.Name]);
AncestorNode.ImageIndex := ImageIndexPackage;
AncestorNode.SelectedIndex := AncestorNode.ImageIndex;
end;
end;
// add matrix options
for t:=low(TBuildMatrixGroupType) to high(TBuildMatrixGroupType) do
AddMatrixGroup(t);
InhTreeView.EndUpdate;
finally
SkippedPkgList.Free;
end;
end;
end.
|