-
Notifications
You must be signed in to change notification settings - Fork 298
/
mm_check_interface.in.mos
87 lines (67 loc) · 2.68 KB
/
mm_check_interface.in.mos
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
echo(false);
mm_src_file := "@MM_INPUT_SOURCE_DIR@/@MM_PACKAGE_NAME@.mo";
tmp_interface_file := "@MM_OUTPUT_DIR@/@MM_PACKAGE_NAME@.interface.mo.stamp";
interface_file := "@MM_OUTPUT_DIR@/@MM_PACKAGE_NAME@.interface.mo";
depends_file := "@MM_OUTPUT_DIR@/@MM_PACKAGE_NAME@.depends";
public_imports_file := "@MM_OUTPUT_DIR@/@MM_PACKAGE_NAME@.public.imports";
class_typename := $TypeName(@MM_PACKAGE_NAME@);
setCommandLineOptions("-g=MetaModelica");
setCommandLineOptions("-d=skipInputOutputSyntacticSugar");
if not loadFile(mm_src_file) then
print("Failed to load file: " + mm_src_file + "\n" + getErrorString());
exit(1);
end if;
if not checkInterfaceOfPackages(class_typename, {
{"backendInterface", "backend", "frontend", "util", "susan"},
{"backend", "frontend", "util", "susan", "backendInterface"},
{"frontend", "util", "susan", "backendInterface", ""},
{"susan", "util", "", "", ""},
{"util", "", "", "", ""}
}) then
print(getErrorString());
exit(1);
end if;
if classAnnotationExists(class_typename, __OpenModelica_isBaseClass) then
new_interface_string := OpenModelica.Scripting.readFile(mm_src_file);
else
new_interface_string := OpenModelica.Scripting.list(exportKind=OpenModelica.Scripting.ExportKind.MetaModelicaInterface);
end if;
success := OpenModelica.Scripting.writeFile(tmp_interface_file, new_interface_string);
if not success then
print("Failed to write file: " + tmp_interface_file + "\n" + getErrorString());
exit(1);
end if;
isSame := OpenModelica.Scripting.compareFiles(tmp_interface_file, interface_file);
if isSame then
// print("Interface is the same\n");
else
// print("Interface has changed. Updating. Dependents will be recompiled.\n");
success := OpenModelica.Scripting.copy(tmp_interface_file, interface_file);
if not success then
print("Failed to rename file: " + tmp_interface_file + "\n" + getErrorString());
exit(1);
end if;
end if;
(pub_imported_names, pro_imported_names) := getImportedNames(class_typename);
getErrorString();
public_imports_string := "";
for dep in pub_imported_names loop
public_imports_string := public_imports_string + dep + ";";
end for;
success := OpenModelica.Scripting.writeFile(public_imports_file, public_imports_string);
if not success then
print("Failed to write file: " + public_imports_file + "\n" + getErrorString());
exit(1);
end if;
dep_string := "";
for dep in pub_imported_names loop
dep_string := dep_string + dep + " ";
end for;
for dep in pro_imported_names loop
dep_string := dep_string + dep + " ";
end for;
success := OpenModelica.Scripting.writeFile(depends_file, dep_string);
if not success then
print("Failed to write file: " + depends_file + "\n" + getErrorString());
exit(1);
end if;