From b216dbf9d812a42b74aa43a06c13de3f75c690df Mon Sep 17 00:00:00 2001
From: BenceJanosSzabo <bence.janos.szabo@ericsson.com>
Date: Mon, 23 Jan 2017 16:17:19 +0100
Subject: [PATCH] makefilegen TPD buildconfig error fixed (Bug 510868)

Change-Id: I409bc83af2aa5c77dd5dbec4c220c12bbeb9b659
Signed-off-by: BenceJanosSzabo <bence.janos.szabo@ericsson.com>
---
 compiler2/xpather.cc                          | 14 +++--
 .../mfgen-tpd/required_config/58/Makefile     | 60 +++++++++++++++++++
 .../mfgen-tpd/required_config/58/a.tpd        | 45 ++++++++++++++
 .../mfgen-tpd/required_config/58/b.tpd        | 45 ++++++++++++++
 .../mfgen-tpd/required_config/58/c.tpd        | 38 ++++++++++++
 .../mfgen-tpd/required_config/Makefile        |  2 +-
 6 files changed, 198 insertions(+), 6 deletions(-)
 create mode 100644 regression_test/compileonly/mfgen-tpd/required_config/58/Makefile
 create mode 100644 regression_test/compileonly/mfgen-tpd/required_config/58/a.tpd
 create mode 100644 regression_test/compileonly/mfgen-tpd/required_config/58/b.tpd
 create mode 100644 regression_test/compileonly/mfgen-tpd/required_config/58/c.tpd

diff --git a/compiler2/xpather.cc b/compiler2/xpather.cc
index 4b3e96340..bddf069ce 100644
--- a/compiler2/xpather.cc
+++ b/compiler2/xpather.cc
@@ -1068,6 +1068,8 @@ static boolean analyse_child(struct config_struct* const all_configs, const char
             // Go to the next required config
             req_config = req_config->next;
             continue;
+          } else {
+            found = TRUE;
           }
           
           // Get the project_name's act_config config_struct (tmp holds it)
@@ -1090,7 +1092,7 @@ static boolean analyse_child(struct config_struct* const all_configs, const char
           }
           insert_to_tmp_config(tmp_configs, project_name, act_config, is_active);
           
-          // Analyse referenced project's of project_name project
+          // Analyze referenced projects of project_name project
           struct string_list* last_child = tmp->children;
           while (last_child && last_child->str != NULL) {
             result = analyse_child(all_configs, last_child->str, NULL, required_configs, tmp_configs);
@@ -1103,8 +1105,8 @@ static boolean analyse_child(struct config_struct* const all_configs, const char
       }
       last = last->next;
     }
-    
-    if (found == FALSE) { // No one said anything about this project's configuration
+     // No one said anything about this project's configuration or we still don't know the configuration
+    if (found == FALSE || get_act_config(required_configs, project_name) == NULL) {
       //Get the active configuration of this project
       last = all_configs;
       while (last && last->project_name != NULL && last->project_conf != NULL) {
@@ -1218,13 +1220,14 @@ static tpd_result config_struct_get_required_configs(struct config_struct* const
         if (result == FALSE) return TPD_FAILED;
         insert_to_tmp_config(*tmp_configs, last->project_name, last->project_conf, TRUE);
         
-        // last variable holds the top level project's active configuration which needed to be analysed
+        // last variable holds the top level project's active configuration which needed to be analyzed
         // Insert every required config of the top level project active configuration
         struct string2_list* last_proj_config = last->requirements;
         while (last_proj_config && last_proj_config->str1 != NULL && last_proj_config->str2 != NULL) { // todo ezek a null cuccok mindenhova, every param should not be null
           struct string_list* children = last->children;
           // This if allows that a top level project can require an other project's configuration
           // without referencing it.
+          
           if (children->str != NULL || strcmp(last_proj_config->str1, last->project_name) == 0) {
             result = insert_to_required_config(all_configs, last_proj_config->str1, last_proj_config->str2, required_configs);
             if (result == FALSE) return TPD_FAILED;
@@ -1233,7 +1236,7 @@ static tpd_result config_struct_get_required_configs(struct config_struct* const
         }
         last->processed = TRUE;
         
-        //Analyse the referenced project of the top level project
+        //Analyze the referenced project of the top level project
         struct string_list* last_child = last->children;
         while (last_child && last_child->str != NULL) {
           result = analyse_child(all_configs, last_child->str, NULL, required_configs, *tmp_configs); // todo check if everywhere is handled
@@ -2925,6 +2928,7 @@ static tpd_result process_tpd_internal(const char *p_tpd_name, char *tpdName, co
                 next_child->next = NULL;
                 last_child->next = next_child;
                 last_child = next_child;
+                //break; needed???
               }
             }
             tmp = tmp->next;
diff --git a/regression_test/compileonly/mfgen-tpd/required_config/58/Makefile b/regression_test/compileonly/mfgen-tpd/required_config/58/Makefile
new file mode 100644
index 000000000..8b872c38e
--- /dev/null
+++ b/regression_test/compileonly/mfgen-tpd/required_config/58/Makefile
@@ -0,0 +1,60 @@
+##############################################################################
+# Copyright (c) 2000-2016 Ericsson Telecom AB
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+#   Szabo, Bence Janos
+#
+##############################################################################
+TOPDIR := ../../../..
+include $(TOPDIR)/Makefile.regression
+
+ifdef LCOV
+COVERAGE_FLAG := -C
+endif
+
+# ${MAKEPROG} has the same content as the built-in ${MAKE},
+# except the special handling of ${MAKE} does not apply.
+# If we used ${MAKE} in the rules below, 'make -n' would succeed once,
+# then fail on every subsequent invocation until a 'make clean' is done. 
+
+#This tests that 'a' references 'b' and 'b' references 'c' and 'b' requires
+#'c''s '1' configuration. The extra is that 'a' has some configs which requires
+# 'b''s other config, but the 'a''s defualt config does not require anything.
+#      a
+#      |
+#      |
+#      |
+#      b
+#      |
+#      |c:1
+#      |
+#      c
+
+MAKEPROG := ${MAKE}
+
+all: CheckTpd 
+
+BuildTpd:
+	$(TTCN3_DIR)/bin/ttcn3_makefilegen -F $(MFGEN_FLAGS) $(COVERAGE_FLAG) \
+	-t a.tpd -r -c -W -g
+
+CheckTpd: BuildTpd
+	if [ ! -f "./a_binDefault/Makefile" ] || [ `grep -c "EXECUTABLE = binDefault" ./a_binDefault/Makefile` -ne 1 ]; \
+	then echo "Makefilegen required config test 58 failed: Overall verdict: fail" && exit 1; fi
+	if [ ! -f "./b_binDefault/Makefile" ] || [ `grep -c "EXECUTABLE = binDefault" ./b_bin1/Makefile` -ne 1 ]; \
+	then echo "Makefilegen required config test 58 failed: Overall verdict: fail" && exit 1; fi
+	if [ ! -f "./c_bin1/Makefile" ] || [ `grep -c "EXECUTABLE = bin1" ./c_bin1/Makefile` -ne 1 ]; \
+	then echo "Makefilegen required config test 58 failed: Overall verdict: fail" && exit 1; fi
+
+clean:
+	-rm -rf a_binDefault b_binDefault c_bin1
+
+distclean: clean
+	-rm -f *.out
+
+.PHONY: all clean distclean BuildTpd CheckTpd
+
diff --git a/regression_test/compileonly/mfgen-tpd/required_config/58/a.tpd b/regression_test/compileonly/mfgen-tpd/required_config/58/a.tpd
new file mode 100644
index 000000000..c0b913611
--- /dev/null
+++ b/regression_test/compileonly/mfgen-tpd/required_config/58/a.tpd
@@ -0,0 +1,45 @@
+<!--
+ Copyright (c) 2000-2016 Ericsson Telecom AB
+ All rights reserved. This program and the accompanying materials
+ are made available under the terms of the Eclipse Public License v1.0
+ which accompanies this distribution, and is available at
+ http://www.eclipse.org/legal/epl-v10.html
+
+ Contributors:
+  Szabo, Bence Janos – initial implementation
+-->
+<TITAN_Project_File_Information version="1.0">
+  <ProjectName>a</ProjectName>
+  <ReferencedProjects>
+    <ReferencedProject name="b" projectLocationURI="b.tpd"/>
+  </ReferencedProjects>
+  <ActiveConfiguration>Default</ActiveConfiguration>
+  <Configurations>
+    <Configuration name="Default">
+      <ProjectProperties>
+        <MakefileSettings>
+          <targetExecutable>binDefault</targetExecutable>
+        </MakefileSettings>
+        <LocalBuildSettings>
+          <workingDirectory>binDefault</workingDirectory>
+        </LocalBuildSettings>
+      </ProjectProperties>
+    </Configuration>
+    <Configuration name="a">
+      <ProjectProperties>
+        <MakefileSettings>
+          <targetExecutable>binDefault</targetExecutable>
+        </MakefileSettings>
+        <LocalBuildSettings>
+          <workingDirectory>binDefault</workingDirectory>
+        </LocalBuildSettings>
+        <ConfigurationRequirements>
+          <configurationRequirement>
+            <projectName>b</projectName>
+            <requiredConfiguration>1</requiredConfiguration>
+          </configurationRequirement>
+        </ConfigurationRequirements>
+      </ProjectProperties>
+    </Configuration>
+  </Configurations>
+</TITAN_Project_File_Information>
diff --git a/regression_test/compileonly/mfgen-tpd/required_config/58/b.tpd b/regression_test/compileonly/mfgen-tpd/required_config/58/b.tpd
new file mode 100644
index 000000000..0d43262dd
--- /dev/null
+++ b/regression_test/compileonly/mfgen-tpd/required_config/58/b.tpd
@@ -0,0 +1,45 @@
+<!--
+ Copyright (c) 2000-2016 Ericsson Telecom AB
+ All rights reserved. This program and the accompanying materials
+ are made available under the terms of the Eclipse Public License v1.0
+ which accompanies this distribution, and is available at
+ http://www.eclipse.org/legal/epl-v10.html
+
+ Contributors:
+  Szabo, Bence Janos – initial implementation
+-->
+<TITAN_Project_File_Information version="1.0">
+  <ProjectName>b</ProjectName>
+  <ReferencedProjects>
+    <ReferencedProject name="c" projectLocationURI="c.tpd"/>
+  </ReferencedProjects>
+  <ActiveConfiguration>Default</ActiveConfiguration>
+  <Configurations>
+    <Configuration name="Default">
+      <ProjectProperties>
+        <MakefileSettings>
+          <targetExecutable>binDefault</targetExecutable>
+        </MakefileSettings>
+        <LocalBuildSettings>
+          <workingDirectory>binDefault</workingDirectory>
+        </LocalBuildSettings>
+         <ConfigurationRequirements>
+          <configurationRequirement>
+            <projectName>c</projectName>
+            <requiredConfiguration>1</requiredConfiguration>
+          </configurationRequirement>
+        </ConfigurationRequirements>
+      </ProjectProperties>
+    </Configuration>
+  <Configuration name="1">
+      <ProjectProperties>
+        <MakefileSettings>
+          <targetExecutable>bin1</targetExecutable>
+        </MakefileSettings>
+        <LocalBuildSettings>
+          <workingDirectory>bin1</workingDirectory>
+        </LocalBuildSettings>
+      </ProjectProperties>
+    </Configuration>
+  </Configurations>
+</TITAN_Project_File_Information>
diff --git a/regression_test/compileonly/mfgen-tpd/required_config/58/c.tpd b/regression_test/compileonly/mfgen-tpd/required_config/58/c.tpd
new file mode 100644
index 000000000..00ce28721
--- /dev/null
+++ b/regression_test/compileonly/mfgen-tpd/required_config/58/c.tpd
@@ -0,0 +1,38 @@
+<!--
+ Copyright (c) 2000-2016 Ericsson Telecom AB
+ All rights reserved. This program and the accompanying materials
+ are made available under the terms of the Eclipse Public License v1.0
+ which accompanies this distribution, and is available at
+ http://www.eclipse.org/legal/epl-v10.html
+
+ Contributors:
+  Szabo, Bence Janos – initial implementation
+-->
+<TITAN_Project_File_Information version="1.0">
+  <ProjectName>c</ProjectName>
+  <ReferencedProjects>
+  </ReferencedProjects>
+  <ActiveConfiguration>Default</ActiveConfiguration>
+  <Configurations>
+    <Configuration name="Default">
+      <ProjectProperties>
+        <MakefileSettings>
+          <targetExecutable>binDefault</targetExecutable>
+        </MakefileSettings>
+        <LocalBuildSettings>
+          <workingDirectory>binDefault</workingDirectory>
+        </LocalBuildSettings>
+      </ProjectProperties>
+    </Configuration>
+  <Configuration name="1">
+      <ProjectProperties>
+        <MakefileSettings>
+          <targetExecutable>bin1</targetExecutable>
+        </MakefileSettings>
+        <LocalBuildSettings>
+          <workingDirectory>bin1</workingDirectory>
+        </LocalBuildSettings>
+      </ProjectProperties>
+    </Configuration>
+  </Configurations>
+</TITAN_Project_File_Information>
diff --git a/regression_test/compileonly/mfgen-tpd/required_config/Makefile b/regression_test/compileonly/mfgen-tpd/required_config/Makefile
index 13490173a..7517fed9b 100644
--- a/regression_test/compileonly/mfgen-tpd/required_config/Makefile
+++ b/regression_test/compileonly/mfgen-tpd/required_config/Makefile
@@ -14,7 +14,7 @@ include $(TOPDIR)/Makefile.regression
 
 CODIRS := 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
+	  48 49 50 51 52 53 54 55 56 57 58
 
 
 #The configurations of the TPD files only differ in the name of the working
-- 
GitLab