Recent

Author Topic: SetAlternativeCompile "for after"  (Read 8313 times)

Mathias

  • Jr. Member
  • **
  • Posts: 88
SetAlternativeCompile "for after"
« on: September 05, 2018, 11:04:10 pm »
I'm a build an IDE component for AVR.
There I want to make a presetting at "Execute after".

With SetAlternativeCompile I can only write something in "Execute before". How can I write in "Execute after"?

Code: Pascal  [Select][+][-]
  1. type
  2.   { TProjectAVRApp }
  3.  
  4.   TProjectAVRApp = class(TProjectDescriptor)
  5. .........
  6.  
  7. function TProjectAVRApp.InitProject(AProject: TLazProject): TModalResult;
  8. const
  9.   ProjectText = 'program Project1;' + LineEnding +
  10.     LineEnding +
  11.     '{$H-}' + LineEnding +
  12.     '{$O-}' + LineEnding +
  13.     LineEnding +
  14.     'uses' + LineEnding +
  15.     '  intrinsics;' + LineEnding +
  16.     LineEnding +
  17.     'begin' + LineEnding +
  18.     '  // Setup' + LineEnding +
  19.     '  repeat' + LineEnding +
  20.     '    // Loop;' + LineEnding +
  21.     '  until 1 = 2;' + LineEnding +
  22.     'end;' + LineEnding +
  23.     LineEnding +
  24.     'end.';
  25.  
  26. var
  27.   MainFile: TLazProjectFile;
  28.   CompOpts: TLazCompilerOptions;
  29.  
  30. begin
  31.   inherited InitProject(AProject);
  32.  
  33.   MainFile := AProject.CreateProjectFile('Project1.lpr');
  34.   MainFile.IsPartOfProject := True;
  35.  
  36.   //  AProject.AddPackageDependency('AVRLaz');
  37.   AProject.AddFile(MainFile, False);
  38.   AProject.MainFileID := 0;
  39.  
  40.   AProject.LazCompilerOptions.TargetCPU := 'avr';
  41.   AProject.LazCompilerOptions.TargetOS := 'embedded';
  42.   AProject.LazCompilerOptions.TargetProcessor := 'avr5';
  43.  
  44.   AProject.LazCompilerOptions.CompilerPath:=''path';
  45.  AProject.LazCompilerOptions.SetAlternativeCompile('vorher', True); // ????
  46.  

Does anyone have a tip?

See also: http://www.lazarusforum.de/viewtopic.php?f=18&t=11760&p=105520#p105520

One more thing, I can not find a GetAlternativeCompile, either.

balazsszekely

  • Guest
Re: SetAlternativeCompile "for after"
« Reply #1 on: September 05, 2018, 11:15:09 pm »
It looks like only ExecuteBefore is implemented. Just open $(Lazarus)/IDE/compileroptions.pp, search for SetAlternativeCompile:
Code: Pascal  [Select][+][-]
  1. procedure TBaseCompilerOptions.SetAlternativeCompile(const Command: string;
  2.   ScanFPCMsgs: boolean);
  3. begin
  4.   CompilerPath:='';
  5.   ExecuteBefore.Command:=Command;
  6.   if ScanFPCMsgs then
  7.     ExecuteBefore.Parsers.Text:=SubToolFPC+LineEnding+SubToolMake
  8.   else
  9.     ExecuteBefore.Parsers.Clear;
  10. end;  
You can add a new param CommandAfter, then make the necessary adjustments. Alternatively you can file a bugreport with a new feature request.

PS: You can also directly edit the lpi file.

balazsszekely

  • Guest
Re: SetAlternativeCompile "for after"
« Reply #2 on: September 05, 2018, 11:26:11 pm »
Quote
PS: You can also directly edit the lpi file.
Something like this:
Code: Pascal  [Select][+][-]
  1. uses Laz2_XMLCfg;
  2.  
  3. function UpdateLPI(const APathToLPI, ACommand: string): Boolean;
  4. var
  5.   XML: TXMLConfig;
  6. begin
  7.   Result := False;
  8.   if not FileExists(APathToLPI) then
  9.     Exit;
  10.   XML := TXMLConfig.Create(APathToLPI);
  11.   try
  12.     try
  13.       XML.SetValue('Other/ExecuteAfter/Value', ACommand);
  14.       XML.Flush;
  15.       Result := True;
  16.     except
  17.     end;
  18.   finally
  19.     XML.Free;
  20.   end;
  21. end;
  22.  
  23. procedure TForm1.Button1Click(Sender: TObject);
  24. begin
  25.   if UpdateLPI('PathToYourLPI', 'this is a test') then
  26.     ShowMessage('success')
  27. end;

Mathias

  • Jr. Member
  • **
  • Posts: 88
Re: SetAlternativeCompile "for after"
« Reply #3 on: September 06, 2018, 08:03:00 pm »
Writing directly to the XML (lpi) would work in principle. As soon as I call UpdateLPI, the * .lpi on the disk is changed, looked at with an external editor. But as soon as I press F9 or save Project, the * .lpi is overwritten immediately.
In that sense, this does not help me.

I also tried your first variant, I tried to write a descendant of TLazProject.
But there he does not find CompilerPath + ExecuteBefore.

Too bad that afterwards is not not implemented, that is the most important thing for the AVR programming with Lazarus, which is called there AVRdude with different parameters.

Code: Pascal  [Select][+][-]
  1. uses
  2.   IDEExternToolIntf;
  3. ......
  4. procedure TNewLazProject(const Command: string;  ScanFPCMsgs: boolean);
  5. begin
  6.   CompilerPath:='';
  7.   ExecuteBefore.Command:=Command;
  8.   if ScanFPCMsgs then
  9.     ExecuteBefore.Parsers.Text:=SubToolFPC+LineEnding+SubToolMake
  10.   else
  11.     ExecuteBefore.Parsers.Clear;
  12. end;  
« Last Edit: September 06, 2018, 10:51:21 pm by Mathias »

kupferstecher

  • Hero Member
  • *****
  • Posts: 583
Re: SetAlternativeCompile "for after"
« Reply #4 on: September 10, 2018, 06:16:21 pm »
Would it be possible to access the CompilerOptions through TProject?
When I tried to access TProject, see below, then I need to add the package "ide" to the "required packages". But then an error occurs, "ide" is a "run time only" package.

Is it possible to use TProject in a package/plugin?

Code: Pascal  [Select][+][-]
  1. uses Project;
  2.  
  3. function TMyApplicationDescriptor.InitProject(AProject: TLazProject): TModalResult;
  4. var vProject: TProject;
  5. begin
  6.   inherited InitProject(AProject);
  7.  
  8.   vProject:= AProject as TProject;
  9.   ...
  10. end;
  11.  

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4459
  • I like bugs.
Re: SetAlternativeCompile "for after"
« Reply #5 on: September 11, 2018, 09:58:55 am »
Would it be possible to access the CompilerOptions through TProject?
You can access LazCompilerOptions from its base class. That is what TProject does, too, and then typecast it.
Code: Pascal  [Select][+][-]
  1. function TProject.GetCompilerOptions: TProjectCompilerOptions;
  2. begin
  3.   Result := TProjectCompilerOptions(FLazCompilerOptions);
  4. end;

Quote
When I tried to access TProject, see below, then I need to add the package "ide" to the "required packages". But then an error occurs, "ide" is a "run time only" package.
There is no package called "ide". There are only unit files in "ide" directory included in Lazarus project. What do you mean?

Quote
Is it possible to use TProject in a package/plugin?
No but the interface in package IdeIntf can be extended as needed.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

kupferstecher

  • Hero Member
  • *****
  • Posts: 583
Re: SetAlternativeCompile "for after"
« Reply #6 on: September 11, 2018, 01:10:02 pm »
You can access LazCompilerOptions from its base class. That is what TProject does, too, and then typecast it.
Actually thats what I tried to do, but if I can't use the unit Project, then I can't typecast to a type defined in unit Project.

Quote
There is no package called "ide". There are only unit files in "ide" directory included in Lazarus project. What do you mean?
Attached a screenshot.

Quote
Quote
Is it possible to use TProject in a package/plugin?
No but the interface in package IdeIntf can be extended as needed.
Yes, but I wanted to avoid editing Lazarus units. On the one hand I'm not a pro, on the other hand it may take a long time until the changes get into the next stable release, this means my package wouldn't be easily usable by others in the meantime.

I'll look further if I find any other way, e.g. using a project template.

ccrause

  • Hero Member
  • *****
  • Posts: 845
Re: SetAlternativeCompile "for after"
« Reply #7 on: September 11, 2018, 01:51:18 pm »
Quote
No but the interface in package IdeIntf can be extended as needed.
Yes, but I wanted to avoid editing Lazarus units. On the one hand I'm not a pro, on the other hand it may take a long time until the changes get into the next stable release, this means my package wouldn't be easily usable by others in the meantime.
If the "correct" way is to extend IdeIntf then so be it. I don't mind compiling Lazarus trunk to get support for creating AVR projects.  To get new functionality into a stable release takes time anyway, so doing it now may result in this functionality getting into the new Lazarus release which will hopefully follow shortly after FPC 3.2 is released (which will be the first stable FPC release with proper AVR support in my opinion).

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4459
  • I like bugs.
Re: SetAlternativeCompile "for after"
« Reply #8 on: September 11, 2018, 01:53:17 pm »
Attached a screenshot.
Ok, the package "ide" must be specific to AVR. It is not part of Lazarus sources.

Quote
Yes, but I wanted to avoid editing Lazarus units. On the one hand I'm not a pro, on the other hand it may take a long time until the changes get into the next stable release, this means my package wouldn't be easily usable by others in the meantime.
Changes can get into Lazarus trunk quickly if you provide a patch. Then you and others interested could use it right away.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

kupferstecher

  • Hero Member
  • *****
  • Posts: 583
Re: SetAlternativeCompile "for after"
« Reply #9 on: September 11, 2018, 05:50:01 pm »
If the "correct" way is to extend IdeIntf then so be it.
I think I understand now, its not intended to use the ide internal units/classes directly, as they could change by time.

Ok, the package "ide" must be specific to AVR. It is not part of Lazarus sources.
The ide extension is for dektop computers (i368/amd64), so its not directly related to AVR. You can find it in the menu under package/open loaded package (I use Lazarus 1.8.0). I didn't install it.

Regards
« Last Edit: September 11, 2018, 07:46:51 pm by kupferstecher »

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4459
  • I like bugs.
Re: SetAlternativeCompile "for after"
« Reply #10 on: September 11, 2018, 07:34:41 pm »
I think I understand now, its not intended to use the ide internal units/classes directly, as they could change by time.
The IDE internals would be linked into every plugin/package if they were part of the interface. Not a good idea. It is an API, an interface, not an implementation.

Quote
The ide extension is for dektop computers (i368/amd64), so its not directly related to AVR. You can find it in the menu under package/open loaded package (I use Lazarus 1.8).
No I can't. I believe you can find it there because you have it installed but I don't.
IDE extensions are typically pure Pascal and can be compiled for any CPU but that is another thing.

Quote
I didn't install it.
Somehow you did. I searched the whole Lazarus sources for "ide.lpk" but there is no such thing.
I went to year 2010 in revision control (yes, time travelling) and it is not there either.
I am interested where you got it from. Can you please tell the exact path for your "ide.lpk" and maybe contents. A screenshot of the package editor would reveal many things.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

kupferstecher

  • Hero Member
  • *****
  • Posts: 583
Re: SetAlternativeCompile "for after"
« Reply #11 on: September 11, 2018, 07:57:27 pm »
Quote
The ide extension is for dektop computers (i368/amd64), so its not directly related to AVR. You can find it in the menu under package/open loaded package (I use Lazarus 1.8).
No I can't. I believe you can find it there because you have it installed but I don't.
IDE extensions are typically pure Pascal and can be compiled for any CPU but that is another thing.
I just tried again and can't now, as well. Because I removed the package "ide" from the "required packages" in my package. If I try to add it there, then it still is available.

Quote
Quote
I didn't install it.
Somehow you did. I searched the whole Lazarus sources for "ide.lpk" but there is no such thing.
I went to year 2010 in revision control (yes, time travelling) and it is not there either.
I am interested where you got it from. Can you please tell the exact path for your "ide.lpk" and maybe contents. A screenshot of the package editor would reveal many things.
See attached screenshots, also the package path can be seen. Its not in the Lazarus installation path, but in a random folder with lazarus sources. I remember that I placed the sources there when I was new to Lazarus. But no idea, how the current installation still finds that folder...

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4459
  • I like bugs.
Re: SetAlternativeCompile "for after"
« Reply #12 on: September 11, 2018, 10:04:14 pm »
See attached screenshots, also the package path can be seen. Its not in the Lazarus installation path, but in a random folder with lazarus sources. I remember that I placed the sources there when I was new to Lazarus. But no idea, how the current installation still finds that folder...
The path hints to Lazarus 1.2.6 but it was released well after the year 2010 which I checked.
Your current IDE remembers all packages which were opened even once. Their paths are saved in local configuration.
To prevent the IDE remembering those old packages, you must either rename their path or delete the relevant configuration file.
I have been involved in Lazarus development since 2009, some 9 years. I don't remember that package. It must come from earlier days. Mattias Gärtner could tell about it for sure.
Anyway, please get rid of that old stuff now, get Lazarus trunk from SVN, improve IdeIntf and provide patches. Easy peasy!
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

kupferstecher

  • Hero Member
  • *****
  • Posts: 583
Re: SetAlternativeCompile "for after"
« Reply #13 on: September 11, 2018, 11:10:09 pm »
Yes, I'll do it the right way.
Thanks for the help!

Easy peasy!
;)

Mathias

  • Jr. Member
  • **
  • Posts: 88
Re: SetAlternativeCompile "for after"
« Reply #14 on: September 12, 2018, 10:47:03 pm »
I have slightly modified the Lazarus IDE and the package to IDE, see patch attached. This makes it possible to write and read the ExecuteBefore and ExecuteAfter command parameters.

What I have not managed yet are the Reasons parameters.

A sample code which accesses the command.

Would it be possible that the Lazarus team would install that?  :)

Write:
Code: Pascal  [Select][+][-]
  1. function TProjectAVRApp.InitProject(AProject: TLazProject): TModalResult;
  2. const
  3.   ProjectText = 'program Project1;' + LineEnding + LineEnding +
  4.     '{$H-}' + LineEnding + '{$O-}' + LineEnding + LineEnding +
  5.     'uses' + LineEnding + '  intrinsics;' + LineEnding + LineEnding +
  6.     'begin' + LineEnding + '  // Setup' + LineEnding + '  repeat' +
  7.     LineEnding + '    // Loop;' + LineEnding + '  until 1 = 2;' +
  8.     LineEnding + 'end;' + LineEnding + LineEnding + 'end.';
  9.  
  10. var
  11.   MainFile: TLazProjectFile;
  12.   CompOpts: TLazCompilerOptions;
  13.  
  14. begin
  15.   inherited InitProject(AProject);
  16.  
  17.   MainFile := AProject.CreateProjectFile('Project1.lpr');
  18.   MainFile.IsPartOfProject := True;
  19.  
  20.   //  AProject.AddPackageDependency('AVRLaz');
  21.   AProject.AddFile(MainFile, False);
  22.   AProject.MainFileID := 0;
  23.  
  24.   AProject.LazCompilerOptions.Win32GraphicApp := False;
  25.   AProject.LazCompilerOptions.UnitOutputDirectory :=
  26.     'lib' + PathDelim + '$(TargetCPU)-$(TargetOS)';
  27.  
  28.   AProject.LazCompilerOptions.TargetCPU := 'avr';
  29.   AProject.LazCompilerOptions.TargetOS := 'embedded';
  30.   AProject.LazCompilerOptions.TargetProcessor := 'avr5';
  31.  
  32.   AProject.LazCompilerOptions.ExecuteBeforeCommand := 'Vorher....';
  33.   AProject.LazCompilerOptions.ExecuteAfterCommand:='avrdude -v -patmega328p -carduino -P/dev/ttyUSB0 -b57600 -D -Uflash:w:Project1.hex:i';    

Read:
Code: Pascal  [Select][+][-]
  1. procedure ShowAVRDialog(Sender: TObject);
  2. var
  3.   LazProject: TLazProject;
  4.   f: TProjectOptionsForm;
  5. begin
  6.   f := TProjectOptionsForm.Create(nil);
  7.   f.Show;
  8.  
  9.   LazProject := LazarusIDE.ActiveProject;
  10.  
  11.   f.AVR_Project_Options_Frame1.Label3.Caption:= LazProject.LazCompilerOptions.ExecuteBeforeCommand +
  12.     LineEnding + LazProject.LazCompilerOptions.ExecuteAfterCommand;
« Last Edit: September 12, 2018, 10:49:52 pm by Mathias »

 

TinyPortal © 2005-2018