Commit ebf0904d authored by Maxime Perrotin's avatar Maxime Perrotin

Handle paths better in generated gpr files

parent 559123bd
......@@ -135,7 +135,10 @@ The background pattern was downloaded from www.subtlepatterns.com
Changelog
=========
2.0.41 (05/2019)
2.0.43 (05/2019)
- Better handling of path in generated gpr files
2.0.42 (05/2019)
- Fix substring support (can now write var(1,2) := {1,2})
2.0.41 (05/2019)
......
......@@ -265,7 +265,7 @@ end {pr}_Lib;'''.format(pr=process_name.lower(),
ada_gpr = '''project {pr}_Ada is
for Languages use ("Ada");
for Source_Dirs use (".") & External_As_List ("CODE_PATH", ":");
for Object_Dir use "obj";
for Object_Dir use "../obj";
end {pr}_Ada;'''.format(pr=process_name.lower())
simu_script = '''#!/bin/bash -e
......
......@@ -141,7 +141,7 @@ except ImportError:
__all__ = ['opengeode', 'SDL_Scene', 'SDL_View', 'parse']
__version__ = '2.0.42'
__version__ = '2.0.43'
if hasattr(sys, 'frozen'):
# Detect if we are running on Windows (py2exe-generated)
......@@ -1959,14 +1959,18 @@ class SDL_View(QtGui.QGraphicsView, object):
# Need to get the list of .pr (incl e.g. system_structure.pr)
# for the gpr file
pr_names = ['"' + os.path.basename(pr_file) + '"'
for pr_file in sdlSymbols.AST.pr_files]
try:
first_pr = pr_names.pop()
except IndexError:
# case of a new file: use the filename chosen from the file dialog
if len(sdlSymbols.AST.pr_files) > 0:
first = sdlSymbols.AST.pr_files.pop()
source_dir = os.path.dirname(first) or '.'
first_pr = '"' + os.path.basename(first) + '"'
else:
source_dir = os.path.dirname(filename) or "."
first_pr = '"{}"'.format(os.path.basename(filename))
other_pr = ", ".join(pr_names)
# other pr files: use relative path to "code" because gprbuild
# moves to this folder when calling opengeode
other_pr = ", ".join('"' + os.path.relpath(pr_file, 'code') + '"'
for pr_file in sdlSymbols.AST.pr_files)
template_gpr_sdl = '''project {pr} is
for Languages use ("SDL");
......@@ -1990,7 +1994,7 @@ end {pr};'''.format(pr=prj_name,
# ASN1 template to be filled with "Ada" or "c"
template_gpr_asn1 = '''project DataView_{lang} is
for Languages use ("ASN1");
for Source_Dirs use (".");
for Source_Dirs use ("{source_dir}");
for Source_Files use ("{firstAsn}");
for Object_Dir use "code";
......@@ -2091,9 +2095,13 @@ clean:
# Gather list of ASN.1 files (+possibly custom types definitions)
try:
firstAsn1File = ogParser.DV.asn1Files[0]
otherAsn1Files = ogParser.DV.asn1Files[1:]
firstAsn1File = os.path.basename(ogParser.DV.asn1Files[0])
source_dir = os.path.relpath\
(os.path.dirname(ogParser.DV.asn1Files[0]))
otherAsn1Files = [os.path.relpath(path, "code")
for path in ogParser.DV.asn1Files[1:]]
except (AttributeError, IndexError):
source_dir = "."
firstAsn1File, otherAsn1Files = "", []
if ogParser.USER_DEFINED_TYPES:
......@@ -2105,7 +2113,7 @@ clean:
if not firstAsn1File:
firstAsn1File = newtypesAsn
else:
otherAsn1Files.append(newtypesAsn)
otherAsn1Files.append(os.path.relpath(newtypesAsn, "code"))
asn1Quotes = ['"{}"'.format(name) for name in otherAsn1Files]
otherAsn = ", ".join(asn1Quotes)
......@@ -2123,7 +2131,8 @@ clean:
# generate gpr files to compile the ASN.1 models
with open(pr_path + '/dataview_ada.gpr', 'w') as gpr:
gpr.write(template_gpr_asn1
.format(firstAsn=firstAsn1File,
.format(source_dir=source_dir,
firstAsn=firstAsn1File,
otherAsn=", " + otherAsn
if otherAsn else "",
lang='Ada'))
......@@ -2131,7 +2140,8 @@ clean:
# dataview_c.gpr is needed for the simulator
with open(pr_path + '/dataview_c.gpr', 'w') as gpr:
gpr.write(template_gpr_asn1
.format(firstAsn=firstAsn1File,
.format(source_dir=source_dir,
firstAsn=firstAsn1File,
otherAsn=", " + otherAsn
if otherAsn else "",
lang='c'))
......
Datamodel DEFINITIONS ::= BEGIN
-- ./dataview-uniq.asn
T_Int32 ::= INTEGER (-2147483648 .. 2147483647)
-- ./dataview-uniq.asn
T_UInt32 ::= INTEGER (0 .. 4294967295)
-- ./dataview-uniq.asn
T_Int8 ::= INTEGER (-128 .. 127)
-- ./dataview-uniq.asn
T_UInt8 ::= INTEGER (0 .. 255)
-- ./dataview-uniq.asn
T_Boolean ::= BOOLEAN
-- ./dataview-uniq.asn
TASTE_Boolean ::= BOOLEAN
-- ./dataview-uniq.asn
Seq ::= SEQUENCE (SIZE (1 .. 10)) OF T_UInt8
END
include ../shared.mk
ROOT_MODEL=og.pr
all: test-ada test-llvm
edit:
$(OPENGEODE) function2.pr system_structure.pr
test-parse:
$(OPENGEODE) function2.pr system_structure.pr --check
test-qgen-parse:
$(TESTQGEN_PARSE) $(ROOT_MODEL)
test-qgen-ada:
$(TESTQGEN_ADA) $(ROOT_MODEL)
test-qgen-c:
$(TESTQGEN_C) $(ROOT_MODEL)
test-qgen-gt-ada:
$(TESTQGEN_GT_ADA) $(ROOT_MODEL)
test-qgen-gt-c:
$(TESTQGEN_GT_C) $(ROOT_MODEL)
test-ada:
make -f Makefile.function2
test-c:
$(OPENGEODE) function2.pr system_structure.pr --toC
mono $(ASN1SCC) -c -typePrefix asn1Scc -equal dataview-uniq.asn
$(CC) -O$(O) -c *.c
test-llvm:
$(OPENGEODE) function2.pr system_structure.pr --llvm -O$(O)
$(LLC) *.ll
$(CC) -O$(O) -c *.s
coverage:
coverage run -p $(OPENGEODE) function2.pr system_structure.pr --toAda
.PHONY: all edit test-parse test-ada test-llvm coverage
all:
gprbuild -p -P function2.gpr # generate Ada code from the SDL model
gprbuild -p -P dataview_ada.gpr # generate Ada code from the ASN.1 model
gprbuild -p -P code/function2_ada.gpr # build the Ada code
clean:
rm -rf obj code
\ No newline at end of file
TASTE-BasicTypes DEFINITIONS ::=
BEGIN
-- Set of TASTE predefined basic types
T-Int32 ::= INTEGER (-2147483648 .. 2147483647)
T-UInt32 ::= INTEGER (0 .. 4294967295)
T-Int8 ::= INTEGER (-128 .. 127)
T-UInt8 ::= INTEGER (0 .. 255)
T-Boolean ::= BOOLEAN
END
TASTE-Dataview DEFINITIONS ::=
BEGIN
IMPORTS T-Int32, T-UInt32, T-Int8, T-UInt8, T-Boolean FROM TASTE-BasicTypes;
TASTE-Boolean ::= BOOLEAN
Seq ::= SEQUENCE (SIZE (1..10)) OF T-UInt8
-- ASN.1 Type definitions must start with an uppercase
-- Field names in records (SEQUENCE) must start with a lowercase
-- Underscores are not allowed: use dash (hyphen)
-- Simple types:
-- MyInteger ::= INTEGER (0..255)
-- MyReal ::= REAL (0.0 .. 1000.0)
-- MyBool ::= BOOLEAN
-- MyEnum ::= ENUMERATED { hello, world, how-are-you }
-- Complex types:
-- MySeq ::= SEQUENCE {
-- input-data MyInteger,
-- output-data MyInteger,
-- validity ENUMERATED { valid, invalid }
-- }
--
-- MyChoice ::= CHOICE {
-- a BOOLEAN,
-- b MySeq
-- }
--
-- MySeqOf ::= SEQUENCE (SIZE (2)) OF MyEnum
--
-- MyOctStr ::= OCTET STRING (SIZE (3))
--
-- -- You can also declare constants
-- myVar MySeqOf ::= { hello, world }
END
project DataView_Ada is
for Languages use ("ASN1");
for Source_Dirs use (".");
for Source_Files use ("dataview-uniq.asn");
for Object_Dir use "code";
package Naming is
for Body_Suffix ("ASN1") use ".asn";
end Naming;
package Compiler is
for Driver ("ASN1") use "asn1.exe";
for Leading_Required_Switches ("ASN1") use ("-Ada", "-typePrefix", "Asn1Scc");
end Compiler;
end DataView_Ada;
\ No newline at end of file
project DataView_c is
for Languages use ("ASN1");
for Source_Dirs use (".");
for Source_Files use ("dataview-uniq.asn");
for Object_Dir use "code";
package Naming is
for Body_Suffix ("ASN1") use ".asn";
end Naming;
package Compiler is
for Driver ("ASN1") use "asn1.exe";
for Leading_Required_Switches ("ASN1") use ("-c", "-typePrefix", "Asn1Scc");
end Compiler;
end DataView_c;
\ No newline at end of file
project function2 is
for Languages use ("SDL");
for Source_Dirs use (".");
for Object_Dir use "code";
for Source_Files use ("system_structure.pr");
package Naming is
for Body_Suffix ("SDL") use ".pr";
end Naming;
package Compiler is
for Driver ("SDL") use "opengeode";
for Object_File_Suffix ("SDL") use ".adb";
for Leading_Required_Switches ("SDL") use ("--toAda", "../function2.pr");
end Compiler;
end function2;
\ No newline at end of file
/* CIF PROCESS (250, 150), (150, 75) */
process function2;
/* CIF TEXT (743, 581), (292, 248) */
-- Text area for declarations and comments
dcl foo tasTE_Boolean;
/* CIF ENDTEXT */
/* CIF TEXT (622, 68), (290, 130) */
-- Text area for declarations and comments
dcl val1, val2 Seq;
/* CIF ENDTEXT */
/* CIF START (454, 109), (70, 40) */
START;
/* CIF task (399, 169), (179, 40) */
task val1 := {1,2,3, 4, 5, 6, 7, 8},
val2 := {9, 10, 11, 12};
/* CIF NEXTSTATE (454, 227), (70, 35) */
NEXTSTATE Wait;
/* CIF state (450, 10), (70, 35) */
state Wait;
endstate;
/* CIF state (453, 1107), (70, 35) */
state Step4;
/* CIF input (435, 1162), (107, 35) */
input oneStep(foo);
/* CIF output (429, 1217), (119, 35) */
output response (val1);
/* CIF task (407, 1272), (162, 35) */
task val1 (0, 1) := val2 (3, 4);
/* CIF NEXTSTATE (453, 1322), (70, 35) */
NEXTSTATE Wait;
endstate;
/* CIF state (453, 887), (70, 35) */
state Step3;
/* CIF input (435, 942), (107, 35) */
input oneStep(foo);
/* CIF output (429, 997), (119, 35) */
output response (val1);
/* CIF task (425, 1052), (127, 35) */
task val1 := val2 (3, 4);
/* CIF NEXTSTATE (453, 1107), (70, 35) */
NEXTSTATE Step4;
endstate;
/* CIF state (453, 667), (70, 35) */
state Step2;
/* CIF input (435, 722), (107, 35) */
input oneStep(foo);
/* CIF output (429, 777), (119, 35) */
output response (val1);
/* CIF task (411, 832), (155, 35) */
task val1 (0, 1) := {42, 43};
/* CIF NEXTSTATE (453, 887), (70, 35) */
NEXTSTATE Step3;
endstate;
/* CIF state (453, 447), (70, 35) */
state Step1;
/* CIF input (435, 502), (107, 35) */
input oneStep(foo);
/* CIF output (429, 557), (119, 35) */
output response (val1);
/* CIF task (442, 612), (92, 35) */
task val1 := val2;
/* CIF NEXTSTATE (453, 667), (70, 35) */
NEXTSTATE Step2;
endstate;
/* CIF state (454, 227), (70, 35) */
state Wait;
/* CIF input (435, 282), (107, 35) */
input oneStep(foo);
/* CIF output (429, 337), (119, 35) */
output response (val1);
/* CIF task (442, 392), (92, 35) */
task val1 := {42};
/* CIF NEXTSTATE (453, 447), (70, 35) */
NEXTSTATE Step1;
endstate;
endprocess function2;
\ No newline at end of file
/* CIF Keep Specific Geode ASNFilename 'dataview-uniq.asn' */
USE Datamodel;
SYSTEM function2;
/* CIF Keep Specific Geode PARAMNAMES a */
SIGNAL oneStep (TASTE_Boolean);
/* CIF Keep Specific Geode PARAMNAMES a */
SIGNAL response (Seq);
CHANNEL c
FROM ENV TO function2 WITH oneStep;
FROM function2 TO ENV WITH response;
ENDCHANNEL;
BLOCK function2;
SIGNALROUTE r
FROM ENV TO function2 WITH oneStep;
FROM function2 TO ENV WITH response;
CONNECT c and r;
PROCESS function2 REFERENCED;
ENDBLOCK;
ENDSYSTEM;
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment