Prechádzať zdrojové kódy

Merge pull request #7926 from rpastrana/HPCC-14476-AddSupportForImports

HPCC-14476 Add support for dynamic import statements to ESDL tool

Reviewed-By: Anthony Fishbeck <anthony.fishbeck@lexisnexis.com>
Richard Chapman 9 rokov pred
rodič
commit
576ed94ccc

+ 48 - 35
esp/xslt/esdl2ecl.xslt

@@ -17,26 +17,57 @@
 ##############################################################################
 -->
 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
-	<xsl:output method="text" version="1.0" encoding="UTF-8" indent="yes"/>
-	<xsl:param name="sourceFileName" select="'UNKNOWN'"/>
-	<xsl:variable name="docname" select="/expesdl/esxdl/@name"/>
-	<xsl:template match="/">
-		<xsl:apply-templates select="expesdl"/>
-	</xsl:template>
-	<xsl:template name="doNotChangeManuallyComment">
-		<xsl:text>/*** Not to be hand edited (changes will be lost on re-generation) ***/
+    <xsl:output method="text" version="1.0" encoding="UTF-8" indent="yes"/>
+    <xsl:param name="sourceFileName" select="'UNKNOWN'"/>
+    <xsl:param name="importsList" select="''"/>
+    <xsl:variable name="docname" select="/expesdl/esxdl/@name"/>
+    <xsl:template match="/">
+        <xsl:apply-templates select="expesdl"/>
+    </xsl:template>
+    <xsl:template match="text()" name="outputImports">
+    <xsl:param name="import" select="."/>
+        <xsl:if test="string-length($import) > 0">
+            <xsl:text>import </xsl:text><xsl:value-of select="$import"/><xsl:text>;
+</xsl:text>
+        </xsl:if>
+    </xsl:template>
+    <xsl:template match="text()" name="handleImports">
+        <xsl:param name="imports" select="."/>
+
+        <xsl:choose>
+            <xsl:when test="contains($imports, ',')">
+                <xsl:call-template name="outputImports">
+                    <xsl:with-param name="import" select="substring-before($imports, ',')"/>
+                </xsl:call-template>
+                <xsl:call-template name="handleImports">
+                    <xsl:with-param name="imports" select="substring-after($imports, ',')"/>
+                </xsl:call-template>
+            </xsl:when>
+            <xsl:otherwise>
+                <xsl:call-template name="outputImports">
+                    <xsl:with-param name="import" select="$imports"/>
+                </xsl:call-template>
+                <xsl:text>
+</xsl:text>
+            </xsl:otherwise>
+        </xsl:choose>
+    </xsl:template>
+
+    <xsl:template name="doNotChangeManuallyComment">
+        <xsl:text>/*** Not to be hand edited (changes will be lost on re-generation) ***/
 /*** ECL Interface generated by esdl2ecl version 1.0 from </xsl:text><xsl:copy-of select="$sourceFileName"/> <xsl:text>.xml. ***/
 /*===================================================*/
 
-import $.share;
-
 </xsl:text>
-	</xsl:template>
-	<xsl:template match="expesdl">
-			<xsl:apply-templates select="esxdl"/>
-	</xsl:template>
-	<xsl:template match="esxdl">
-	             <xsl:call-template name="doNotChangeManuallyComment"/>
+    </xsl:template>
+    <xsl:template match="expesdl">
+            <xsl:apply-templates select="esxdl"/>
+    </xsl:template>
+    <xsl:template match="esxdl">
+                 <xsl:call-template name="doNotChangeManuallyComment"/>
+                  <xsl:call-template name="handleImports">
+                    <xsl:with-param name="imports" select="$importsList"/>
+                  </xsl:call-template>
 			<xsl:text>export </xsl:text>
 			<xsl:choose>
 				<xsl:when test="starts-with(@name, 'wsm_')"><xsl:value-of select="substring(@name, 5)"/></xsl:when>
@@ -45,17 +76,6 @@ import $.share;
 			<xsl:text> := MODULE
 
 </xsl:text>
-		<xsl:if test="$docname='wsm_share'">
-		<xsl:text>export t_IntegerArrayItem := record
-	integer value { xpath('')};
-end;
-
-export t_StringArrayItem := record
-	string value { xpath(''), MAXLENGTH(8192) };
-end;
-
-</xsl:text>
-		</xsl:if>
 		<xsl:apply-templates select="EsdlStruct"/>
 		<xsl:apply-templates select="EsdlRequest"/>
 		<xsl:apply-templates select="EsdlResponse"/>
@@ -89,7 +109,7 @@ end;
 	</xsl:template>
 	<xsl:template match="EsdlArray[@type='string']">
 		<xsl:if test="not(@ecl_hide) and (@ecl_keep or not(@get_data_from))">
-		<xsl:text>	dataset(</xsl:text><xsl:call-template name="output_arrayitem_ref"/><xsl:text>) </xsl:text><xsl:call-template name="output_ecl_name"/>
+		<xsl:text>	set of string </xsl:text><xsl:call-template name="output_ecl_name"/>
 		<xsl:text> {xpath('</xsl:text>
 		<xsl:if test="not(@flat_array)"><xsl:value-of select="@name"/></xsl:if><xsl:text>/</xsl:text><xsl:call-template name="output_item_tag"/><xsl:text>')</xsl:text>
 		<xsl:choose>
@@ -312,13 +332,6 @@ end;
 	<xsl:text>')</xsl:text>
 </xsl:template>
 
-<xsl:template name="output_arrayitem_ref">
-	<xsl:choose>
-		<xsl:when test="@ecl_item"><xsl:text>t_</xsl:text><xsl:value-of select="@ecl_item"/></xsl:when>
-		<xsl:otherwise><xsl:if test="$sourceFileName!='share'"><xsl:text>share.</xsl:text></xsl:if><xsl:text>t_StringArrayItem</xsl:text></xsl:otherwise>
-	</xsl:choose>
-</xsl:template>
-
 <xsl:template name="output_item_tag">
     <xsl:choose>
          <xsl:when test="@item_tag"><xsl:value-of select="@item_tag"/></xsl:when>

+ 2 - 0
tools/esdlcmd-xml/esdl2xml.hpp

@@ -75,6 +75,8 @@ public:
                    transform(subfile, outdir, out, outputIncludes, true);
                 }
             }
+            if (optVerbose)
+                fprintf(stdout, "Finished processing ESDL definition\n");
         }
         else if (optVerbose)
             fprintf(stdout, "ESDL definition: %s has already been loaded!\n", source);

+ 23 - 8
tools/esdlcmd/esdl2ecl.cpp

@@ -238,11 +238,14 @@ public:
                 continue;
             if (iter.matchFlag(optOutputExpandedXML, ESDL_CONVERT_EXPANDEDXML) || iter.matchFlag(optOutputExpandedXML, ESDL_CONVERT_EXPANDEDXML_x))
                 continue;
-            if (iter.matchFlag(optHPCCCompFilesDir, HPCC_COMPONENT_FILES_DIR) || iter.matchFlag(optHPCCCompFilesDir, HPCC_COMPONENT_FILES_DIR_CDE))
+            if (iter.matchFlag(optHPCCCompFilesDir, HPCC_COMPONENT_FILES_DIR_CDE))
                 continue;
             if (iter.matchFlag(optRollUpEclToSingleFile, ESDL_OPTION_ROLLUP))
                 continue;
-
+            if (iter.matchOption(optECLIncludesList, ESDL_OPTION_ECL_INCLUDE_LIST))
+                continue;
+            if (iter.matchOption(optECLHeaderBlock, ESDL_OPTION_ECL_HEADER_BLOCK))
+                continue;
             if (matchCommandLineOption(iter, true)!=EsdlCmdOptionMatch)
                 return false;
         }
@@ -258,7 +261,11 @@ public:
             return EsdlCmdOptionMatch;
         if (iter.matchFlag(optOutputExpandedXML, ESDL_CONVERT_EXPANDEDXML) || iter.matchFlag(optOutputExpandedXML, ESDL_CONVERT_EXPANDEDXML_x))
             return EsdlCmdOptionMatch;
-        if (iter.matchFlag(optHPCCCompFilesDir, HPCC_COMPONENT_FILES_DIR) || iter.matchFlag(optHPCCCompFilesDir, HPCC_COMPONENT_FILES_DIR_CDE))
+        if (iter.matchFlag(optHPCCCompFilesDir, HPCC_COMPONENT_FILES_DIR_CDE))
+            return EsdlCmdOptionMatch;
+        if (iter.matchOption(optHPCCCompFilesDir, ESDL_OPTION_ECL_INCLUDE_LIST))
+            return EsdlCmdOptionMatch;
+        if (iter.matchOption(optECLHeaderBlock, ESDL_OPTION_ECL_HEADER_BLOCK))
             return EsdlCmdOptionMatch;
 
         return EsdlCmdCommon::matchCommandLineOption(iter, true);
@@ -338,7 +345,7 @@ public:
                 StringBuffer xmlfile;
                 toXML(&file, xmlfile, 0,0);
 
-                outputEcl(srcPath.str(), filename, optOutDirPath.get(), idxxml.str(), xmlfile);
+                outputEcl(srcPath.str(), filename, optOutDirPath.get(), idxxml.str(), xmlfile, optECLIncludesList.str(), optECLHeaderBlock.str());
             }
         }
         else
@@ -352,7 +359,7 @@ public:
                     StringBuffer xmlfile;
                     toXML(file, xmlfile, 0,0);
 
-                    outputEcl(srcPath.str(), srcName.str(), optOutDirPath.get(), idxxml.str(), xmlfile);
+                    outputEcl(srcPath.str(), srcName.str(), optOutDirPath.get(), idxxml.str(), xmlfile, optECLIncludesList.str(), optECLHeaderBlock.str());
                 }
             }
         }
@@ -367,15 +374,19 @@ public:
                 "esdl ecl sourcePath outputPath [options]\n"
                 "\nsourcePath must be absolute path to the ESDL Definition file containing the"
                 "EsdlService definition for the service you want to work with.\n"
-                "outputPath must be the absolute path where the ECL output with be created."
+                "outputPath must be the absolute path where the ECL output with be created.\n"
                 "   Options:\n"
                 "      -x, --expandedxml     Output expanded XML files\n"
                 "      --includes            Process all included files\n"
-                "      --rollup              Roll-up all processed includes to single ecl output file"
+                "      --rollup              Roll-up all processed includes to single ecl output file\n"
+                "      -cde                  HPCC Component files directory (xslt files)\n"
+                "      --ecl-imports         Coma-delimited import list to be attached to output ECL\n"
+                "                            each entry generates a corresponding import *.<entry>\n"
+                "      --ecl-header          Text included in target header (must be valid ECL) \n"
                 ,stdout);
     }
 
-    void outputEcl(const char *srcpath, const char *file, const char *path, const char *types, const char * xml)
+    void outputEcl(const char *srcpath, const char *file, const char *path, const char *types, const char * xml, const char * eclimports, const char * eclheader)
     {
         DBGLOG("Generating ECL file for %s", file);
 
@@ -443,6 +454,8 @@ public:
 
         Owned<IProperties> params = createProperties();
         params->setProp("sourceFileName", finger);
+        params->setProp("importsList", eclimports);
+        params->setProp("eclHeader", eclheader);
         StringBuffer esdl2eclxslt (optHPCCCompFilesDir.get());
         esdl2eclxslt.append("/xslt/esdl2ecl.xslt");
         esdl2eclxsltTransform(expstr.str(), esdl2eclxslt.str(), params, outfile.str());
@@ -488,4 +501,6 @@ public:
     bool optProcessIncludes;
     bool optOutputExpandedXML;
     StringAttr optHPCCCompFilesDir;
+    StringAttr optECLIncludesList;
+    StringAttr optECLHeaderBlock;
 };

+ 3 - 2
tools/esdlcmd/esdlcmd_common.hpp

@@ -57,8 +57,7 @@ typedef IEsdlCommand *(*EsdlCommandFactory)(const char *cmdname);
 #define ESDL_CONVERT_EXPANDEDXML        "--expandedxml"
 #define ESDL_CONVERT_EXPANDEDXML_x      "-x"
 
-#define HPCC_COMPONENT_FILES_DIR        "--compfilesdir"
-#define HPCC_COMPONENT_FILES_DIR_CDE    "--CDE"
+#define HPCC_COMPONENT_FILES_DIR_CDE    "-cde"
 
 #define ESDLOPT_XSLT_PATH               "--xslt"
 
@@ -98,6 +97,8 @@ typedef IEsdlCommand *(*EsdlCommandFactory)(const char *cmdname);
 #define ESDL_OPTION_CONFIG              "--config"
 #define ESDL_OPTION_OVERWRITE           "--overwrite"
 #define ESDL_OPTION_ROLLUP              "--rollup"
+#define ESDL_OPTION_ECL_INCLUDE_LIST    "--ecl-imports"
+#define ESDL_OPTION_ECL_HEADER_BLOCK    "--ecl-header"
 
 
 bool matchVariableOption(ArgvIterator &iter, const char prefix, IArrayOf<IEspNamedValue> &values);