Skip to content

Commit

Permalink
Refactor rflx execution
Browse files Browse the repository at this point in the history
- Use custom attribute "Object_Dir" for generate output directory
- Create output directory if "Create_Missing_Dirs" is set

Ref. #243
  • Loading branch information
Alexander Senier authored and treiher committed Jul 23, 2020
1 parent 8acac73 commit 383658f
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 27 deletions.
93 changes: 66 additions & 27 deletions ide/gnatstudio/recordflux.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
RecordFlux support for GNAT Studio
"""

import os.path
import os
import re

import GPS
Expand All @@ -15,6 +15,15 @@

XML = r"""<?xml version="1.0"?>
<GNAT_Studio>
<project_attribute
name="Output_Dir"
package="RecordFlux"
editor_page="RecordFlux"
editor_section="Directories"
description="Output directory for files generated by RecordFlux">
</project_attribute>
<Language>
<Name>RecordFlux</Name>
<Spec_Suffix>.rflx</Spec_Suffix>
Expand Down Expand Up @@ -48,51 +57,43 @@
<filter name="RecordFlux" language="RecordFlux"/>
<!-- Actions -->
<action name="check">
<action name="rflx_check">
<filter_and>
<filter id="RecordFlux"/>
<filter id="Source editor"/>
</filter_and>
<shell show-command="false">MDI.save_all</shell>
<shell show-command="false">Locations.remove_category "RecordFlux"</shell>
<external>rflx check %F</external>
<shell lang="python" show-command="false">recordflux.check(&quot;%F&quot;)</shell>
<external>%1</external>
<on-failure>
<shell lang="python" show-command="false">recordflux.parse_output(&quot;&quot;&quot;%1&quot;&quot;&quot;)</shell>
</on-failure>
</action>
<action name="check_all">
<action name="rflx_check_all">
<filter id="File"/>
<shell show-command="false">MDI.save_all</shell>
<shell show-command="false">Locations.remove_category "RecordFlux"</shell>
<shell lang="python" show-command="false">recordflux.get_source_files()</shell>
<external>rflx check %1"</external>
<shell lang="python" show-command="false">recordflux.check_all()</shell>
<external>%1</external>
<on-failure>
<shell lang="python" show-command="false">recordflux.parse_output(&quot;&quot;&quot;%1&quot;&quot;&quot;)</shell>
</on-failure>
</action>
<action name="generate">
<action name="rflx_generate">
<filter_and>
<filter id="RecordFlux"/>
<filter id="Source editor"/>
</filter_and>
<shell show-command="false">MDI.save_all</shell>
<shell show-command="false">Locations.remove_category "RecordFlux"</shell>
<external>rflx generate -d generated %F</external>
<shell lang="python" show-command="false">recordflux.generate(&quot;%F&quot;)</shell>
<external>%1</external>
<on-failure>
<shell lang="python" show-command="false">recordflux.parse_output(&quot;&quot;&quot;%1&quot;&quot;&quot;)</shell>
</on-failure>
</action>
<action name="generate_all">
<filter_and>
<filter id="File"/>
</filter_and>
<shell show-command="false">MDI.save_all</shell>
<shell show-command="false">Locations.remove_category "RecordFlux"</shell>
<shell lang="python" show-command="false">recordflux.get_source_files()</shell>
<external>rflx generate -d generated %1"</external>
<action name="rflx_generate_all">
<filter id="File"/>
<shell lang="python" show-command="false">recordflux.generate_all()</shell>
<external>%1</external>
<on-failure>
<shell lang="python" show-command="false">recordflux.parse_output(&quot;&quot;&quot;%1&quot;&quot;&quot;)</shell>
</on-failure>
Expand All @@ -110,19 +111,19 @@
<submenu before="Window">
<title>RecordFlux</title>
<menu action="check">
<menu action="rflx_check">
<title>Check</title>
</menu>
<menu action="check_all">
<menu action="rflx_check_all">
<title>Check All</title>
</menu>
<menu action="generate">
<menu action="rflx_generate">
<title>Generate</title>
</menu>
<menu action="generate_all">
<menu action="rflx_generate_all">
<title>Generate All</title>
</menu>
</submenu>
Expand Down Expand Up @@ -275,6 +276,44 @@ def get_source_files():
)

if files:
return " ".join([s.name() for s in files if s.language() == "recordflux"])
return [s.name() for s in files if s.language() == "recordflux"]

raise GPS.Exception("No files found")


def run(files, mode, options=None):
assert mode == "check" or mode == "generate"
options = options or []

GPS.MDI.save_all()
GPS.Locations.remove_category("RecordFlux")

return "rflx {mode} {options} {files}".format(
mode=mode, files=" ".join(files), options=" ".join(options)
)


def check_all(filenames=None):
filenames = filenames or get_source_files()
return run(filenames, mode="check")


def check(filename):
return check_all([filename])


def generate_all(filenames=None):
filenames = filenames or get_source_files()
create_missing = GPS.Project.root().get_attribute_as_string("Create_Missing_Dirs")
output_dir = GPS.Project.root().get_attribute_as_string("Output_Dir", "RecordFlux")
assert output_dir, "Output directory not configured"
if create_missing and create_missing.lower() == "true":
if os.path.exists(output_dir):
assert os.path.isdir(output_dir)
else:
os.makedirs(output_dir)
return run(filenames, mode="generate", options=["-d", output_dir])


def generate(filename):
return generate_all([filename])
4 changes: 4 additions & 0 deletions tests/ide/recordflux.gpr
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ project RecordFlux is
for Source_Dirs use (".", "../../specs");
for Languages use ("Ada", "RecordFlux");

package Recordflux is
for Output_Dir use "../../generated";
end Recordflux;

end RecordFlux;

0 comments on commit 383658f

Please sign in to comment.