Przeglądaj źródła

Merge pull request #51 from aws-lumberyard-dev/Atom/garrieta/ATOM-16524/mcpp_new_line_remove_from_comments

MCPP should not add new line characters at the end of comment lines

Modified 'src/support.c' so comment lines do not get a new line
character appended to them. This helps keep the line count of the input
file to match before and after pre-processing.

This marks new version of the MCPP package as:
mcpp-2.7.2_az.2-rev1-

Signed-off-by: garrieta [email protected]
galibzon 4 lat temu
rodzic
commit
f8c2471f12

+ 61 - 8
package-system/mcpp/mcpp_2.7.2_az.patch

@@ -201,7 +201,7 @@ index 6b634fe..6482967 100644
  /* Version message.                 */
  /* Version message.                 */
  /* "MCPP V.2.* (200y/mm) compiled by " precedes VERSION_MSG */
  /* "MCPP V.2.* (200y/mm) compiled by " precedes VERSION_MSG */
 diff --git a/src/support.c b/src/support.c
 diff --git a/src/support.c b/src/support.c
-index c57eaef..909be89 100644
+index c57eaef..ba7c422 100644
 --- a/src/support.c
 --- a/src/support.c
 +++ b/src/support.c
 +++ b/src/support.c
 @@ -364,6 +364,19 @@ void    mcpp_set_out_func(
 @@ -364,6 +364,19 @@ void    mcpp_set_out_func(
@@ -242,15 +242,68 @@ index c57eaef..909be89 100644
              openum = OP_1;
              openum = OP_1;
          }
          }
          break;
          break;
-@@ -1722,6 +1735,7 @@ com_start:
-                     sp -= 2;
-                     while (*sp != '\n')     /* Until end of line    */
-                         mcpp_fputc( *sp++, OUT);
-+                    mcpp_fputc('\n', OUT);
+@@ -1654,6 +1667,28 @@ static char *   parse_line( void)
+     size_t      com_size;
+     int         c;
+ 
++    // By O3DE:
++    // ---- The Goal:
++    // Match the number of lines between the source AZSL files, before preprocessing,
++    // and the AZSL files after preprocessing. Line number matching is important because it helps
++    // providing accurate line numbers when reporting errors either by AZSLc or DXC.
++    // 
++    // ---- The Problem:
++    // MCPP adds a new line after each comment line that starts with '//'
++    // 
++    // ---- Solution:
++    // Do not add the extra line ending character '\n'.
++    // 
++    // ---- How:
++    // We count here the amount of leading spaces before the first
++    // non space character is detected.
++    // This is used to decide whether comments are going to be printed out or
++    // skipped altogether.
++    // If the current line only contains comments, preceded ONLY by whitespaces then
++    // will print the comment in the output WITHOUT line ending character. Otherwise
++    // the comment won't make it into the output.
++    int         NumLeadingSpaces = 0;
++
+     if ((sp = get_line( FALSE)) == NULL)    /* Next logical line    */
+         return  NULL;                       /* End of a file        */
+     if (in_asm) {                           /* In #asm block        */
+@@ -1668,9 +1703,12 @@ static char *   parse_line( void)
+ 
+     while (char_type[ c = *sp++ & UCHARMAX] & HSP) {
+         if (mcpp_mode != POST_STD)
++        { // O3DE
+             /* Preserve line top horizontal white spaces    */
+             /*      as they are for human-readability       */
+             *tp++ = c;
++            ++NumLeadingSpaces; //O3DE
++        } // O3DE
+         /* Else skip the line top spaces    */
+     }
+     sp--;
+@@ -1719,9 +1757,15 @@ com_start:
+                     cwarn( "Parsed \"//\" as comment"       /* _W2_ */
+                             , NULL, 0L, NULL);
+                 if (keep_comments) {
+-                    sp -= 2;
+-                    while (*sp != '\n')     /* Until end of line    */
+-                        mcpp_fputc( *sp++, OUT);
++                    const int numCharactersBeforeComment = (tp - temp);
++                    if (numCharactersBeforeComment == NumLeadingSpaces)
++                    {
++                        // O3DE: It is safe to print the comments
++                        sp -= 2;
++                        while (*sp != '\n')     /* Until end of line    */
++                            mcpp_fputc( *sp++, OUT);
++                        // mcpp_fputc('\n', OUT); // Removed by O3DE. This prevents that each comment line from presenting additional empty lines.
++                    }
                  }
                  }
                  goto  end_line;
                  goto  end_line;
              default:                        /* Not a comment        */
              default:                        /* Not a comment        */
-@@ -1821,7 +1835,7 @@ static char *   read_a_comment(
+@@ -1821,7 +1865,7 @@ static char *   read_a_comment(
      if (keep_spaces) {
      if (keep_spaces) {
          saved_sp = sp - 2;          /* '-2' for beginning / and *   */
          saved_sp = sp - 2;          /* '-2' for beginning / and *   */
          *sizp = 0;
          *sizp = 0;
@@ -259,7 +312,7 @@ index c57eaef..909be89 100644
      if (keep_comments)                      /* If writing comments  */
      if (keep_comments)                      /* If writing comments  */
          mcpp_fputs( "/*", OUT);             /* Write the initializer*/
          mcpp_fputs( "/*", OUT);             /* Write the initializer*/
      c = *sp++;
      c = *sp++;
-@@ -1911,7 +1925,7 @@ static char *   get_line(
+@@ -1911,7 +1955,7 @@ static char *   get_line(
  /*
  /*
   * ANSI (ISO) C: translation phase 1, 2.
   * ANSI (ISO) C: translation phase 1, 2.
   * Get the next logical line from source file.
   * Get the next logical line from source file.

+ 2 - 2
package_build_list_host_darwin.json

@@ -36,7 +36,7 @@
         "DirectXShaderCompilerDxc-1.6.2104-o3de-rev3-mac": "Scripts/extras/pull_and_build_from_git.py ../../package-system/DirectXShaderCompiler --platform-name Mac --package-root ../../package-system --clean",
         "DirectXShaderCompilerDxc-1.6.2104-o3de-rev3-mac": "Scripts/extras/pull_and_build_from_git.py ../../package-system/DirectXShaderCompiler --platform-name Mac --package-root ../../package-system --clean",
         "azslc-1.7.23-rev2-mac": "Scripts/extras/pull_and_build_from_git.py ../../package-system/azslc --platform-name Mac --package-root ../../package-system --clean",
         "azslc-1.7.23-rev2-mac": "Scripts/extras/pull_and_build_from_git.py ../../package-system/azslc --platform-name Mac --package-root ../../package-system --clean",
         "python-3.7.10-rev1-darwin": "package-system/python/build_package_image.py",
         "python-3.7.10-rev1-darwin": "package-system/python/build_package_image.py",
-        "mcpp-2.7.2_az.1-rev1-mac": "package-system/mcpp/get_and_build_mcpp.py mcpp-2.7.2_az.1-rev1",
+        "mcpp-2.7.2_az.2-rev1-mac": "package-system/mcpp/get_and_build_mcpp.py mcpp-2.7.2_az.2-rev1",
         "mikkelsen-1.0.0.4-mac": "package-system/mikkelsen/build_package_image.py --platform mac",
         "mikkelsen-1.0.0.4-mac": "package-system/mikkelsen/build_package_image.py --platform mac",
         "mikkelsen-1.0.0.4-ios": "package-system/mikkelsen/build_package_image.py --platform ios",
         "mikkelsen-1.0.0.4-ios": "package-system/mikkelsen/build_package_image.py --platform ios",
         "zlib-1.2.11-rev2-mac": "Scripts/extras/pull_and_build_from_git.py ../../package-system/zlib --platform-name Mac --package-root ../../package-system --clean",
         "zlib-1.2.11-rev2-mac": "Scripts/extras/pull_and_build_from_git.py ../../package-system/zlib --platform-name Mac --package-root ../../package-system --clean",
@@ -79,7 +79,7 @@
         "mikkelsen-1.0.0.4-ios": "package-system/mikkelsen-ios",
         "mikkelsen-1.0.0.4-ios": "package-system/mikkelsen-ios",
         "poly2tri-7f0487a-rev1-mac": "package-system/poly2tri-mac",
         "poly2tri-7f0487a-rev1-mac": "package-system/poly2tri-mac",
         "v-hacd-2.3-1a49edf-rev1-mac": "package-system/v-hacd-mac",
         "v-hacd-2.3-1a49edf-rev1-mac": "package-system/v-hacd-mac",
-        "mcpp-2.7.2_az.1-rev1-mac": "package-system/mcpp-mac",
+        "mcpp-2.7.2_az.2-rev1-mac": "package-system/mcpp-mac",
         "SPIRVCross-2021.04.29-rev1-mac": "package-system/SPIRVCross-mac",
         "SPIRVCross-2021.04.29-rev1-mac": "package-system/SPIRVCross-mac",
         "squish-ccr-deb557d-rev1-mac": "package-system/squish-ccr-mac",
         "squish-ccr-deb557d-rev1-mac": "package-system/squish-ccr-mac",
         "astc-encoder-3.2-rev1-mac": "package-system/astc-encoder-mac",
         "astc-encoder-3.2-rev1-mac": "package-system/astc-encoder-mac",

+ 2 - 2
package_build_list_host_linux.json

@@ -14,7 +14,7 @@
         "ISPCTexComp-36b80aa-rev1-linux": "package-system/ISPCTexComp/build_package_image.py",
         "ISPCTexComp-36b80aa-rev1-linux": "package-system/ISPCTexComp/build_package_image.py",
         "libpng-1.6.37-rev1-linux": "Scripts/extras/pull_and_build_from_git.py ../../package-system/libpng --platform-name Linux --package-root ../../package-system --clean",
         "libpng-1.6.37-rev1-linux": "Scripts/extras/pull_and_build_from_git.py ../../package-system/libpng --platform-name Linux --package-root ../../package-system --clean",
         "libsamplerate-0.2.1-rev2-linux": "Scripts/extras/pull_and_build_from_git.py ../../package-system/libsamplerate --platform-name Linux --package-root ../../package-system --clean",
         "libsamplerate-0.2.1-rev2-linux": "Scripts/extras/pull_and_build_from_git.py ../../package-system/libsamplerate --platform-name Linux --package-root ../../package-system --clean",
-        "mcpp-2.7.2_az.1-rev1-linux": "package-system/mcpp/get_and_build_mcpp.py mcpp-2.7.2_az.1-rev1",
+        "mcpp-2.7.2_az.2-rev1-linux": "package-system/mcpp/get_and_build_mcpp.py mcpp-2.7.2_az.2-rev1",
         "OpenSSL-1.1.1b-rev2-linux": "package-system/OpenSSL/build_package_image.py",
         "OpenSSL-1.1.1b-rev2-linux": "package-system/OpenSSL/build_package_image.py",
         "ilmbase-2.3.0-rev4-linux": "Scripts/extras/pull_and_build_from_git.py ../../package-system/OpenEXR --platform-name Linux --package-root ../../package-system --clean",
         "ilmbase-2.3.0-rev4-linux": "Scripts/extras/pull_and_build_from_git.py ../../package-system/OpenEXR --platform-name Linux --package-root ../../package-system --clean",
         "PhysX-4.1.2.29882248-rev3-linux": "package-system/PhysX/build_package_image.py --platform-name linux",
         "PhysX-4.1.2.29882248-rev3-linux": "package-system/PhysX/build_package_image.py --platform-name linux",
@@ -44,7 +44,7 @@
         "ISPCTexComp-36b80aa-rev1-linux": "package-system/ISPCTexComp-linux",
         "ISPCTexComp-36b80aa-rev1-linux": "package-system/ISPCTexComp-linux",
         "libpng-1.6.37-rev1-linux": "package-system/libpng-linux",
         "libpng-1.6.37-rev1-linux": "package-system/libpng-linux",
         "libsamplerate-0.2.1-rev2-linux": "package-system/libsamplerate-linux",
         "libsamplerate-0.2.1-rev2-linux": "package-system/libsamplerate-linux",
-        "mcpp-2.7.2_az.1-rev1-linux": "package-system/mcpp-linux",
+        "mcpp-2.7.2_az.2-rev1-linux": "package-system/mcpp-linux",
         "OpenSSL-1.1.1b-rev2-linux": "package-system/OpenSSL-linux",
         "OpenSSL-1.1.1b-rev2-linux": "package-system/OpenSSL-linux",
         "ilmbase-2.3.0-rev4-linux": "package-system/ilmbase-linux",
         "ilmbase-2.3.0-rev4-linux": "package-system/ilmbase-linux",
         "SPIRVCross-2021.04.29-rev1-linux": "package-system/SPIRVCross-linux",
         "SPIRVCross-2021.04.29-rev1-linux": "package-system/SPIRVCross-linux",

+ 2 - 2
package_build_list_host_windows.json

@@ -24,7 +24,7 @@
         "libpng-1.6.37-rev1-android": "Scripts/extras/pull_and_build_from_git.py ../../package-system/libpng --platform-name Android --package-root ../../package-system --clean",
         "libpng-1.6.37-rev1-android": "Scripts/extras/pull_and_build_from_git.py ../../package-system/libpng --platform-name Android --package-root ../../package-system --clean",
         "libsamplerate-0.2.1-rev2-windows": "Scripts/extras/pull_and_build_from_git.py ../../package-system/libsamplerate --platform-name Windows --package-root ../../package-system --clean",
         "libsamplerate-0.2.1-rev2-windows": "Scripts/extras/pull_and_build_from_git.py ../../package-system/libsamplerate --platform-name Windows --package-root ../../package-system --clean",
         "libsamplerate-0.2.1-rev2-android": "Scripts/extras/pull_and_build_from_git.py ../../package-system/libsamplerate --platform-name Android --package-root ../../package-system --custom-toolchain-file ../../Scripts/cmake/Platform/Android/Toolchain_android.cmake --clean",
         "libsamplerate-0.2.1-rev2-android": "Scripts/extras/pull_and_build_from_git.py ../../package-system/libsamplerate --platform-name Android --package-root ../../package-system --custom-toolchain-file ../../Scripts/cmake/Platform/Android/Toolchain_android.cmake --clean",
-        "mcpp-2.7.2_az.1-rev1-windows": "package-system/mcpp/get_and_build_mcpp.py mcpp-2.7.2_az.1-rev1",
+        "mcpp-2.7.2_az.2-rev1-windows": "package-system/mcpp/get_and_build_mcpp.py mcpp-2.7.2_az.2-rev1",
         "OpenSSL-1.1.1b-rev2-windows": "package-system/OpenSSL/build_package_image.py",
         "OpenSSL-1.1.1b-rev2-windows": "package-system/OpenSSL/build_package_image.py",
         "OpenSSL-1.1.1b-rev1-android": "package-system/OpenSSL/build_package_image.py --platform-name android",
         "OpenSSL-1.1.1b-rev1-android": "package-system/OpenSSL/build_package_image.py --platform-name android",
         "ilmbase-2.3.0-rev4-windows": "Scripts/extras/pull_and_build_from_git.py ../../package-system/OpenEXR --platform-name Windows --package-root ../../package-system --clean",
         "ilmbase-2.3.0-rev4-windows": "Scripts/extras/pull_and_build_from_git.py ../../package-system/OpenEXR --platform-name Windows --package-root ../../package-system --clean",
@@ -93,7 +93,7 @@
         "OpenMesh-8.1-rsv1-windows": "package-system/OpenMesh-windows",
         "OpenMesh-8.1-rsv1-windows": "package-system/OpenMesh-windows",
         "pyside2-qt-5.15.1-rev2-windows": "package-system/pyside2-windows",
         "pyside2-qt-5.15.1-rev2-windows": "package-system/pyside2-windows",
         "d3dx12-headers-rev1-windows": "package-system/d3dx12-windows",
         "d3dx12-headers-rev1-windows": "package-system/d3dx12-windows",
-        "mcpp-2.7.2_az.1-rev1-windows": "package-system/mcpp-windows",
+        "mcpp-2.7.2_az.2-rev1-windows": "package-system/mcpp-windows",
         "cityhash-1.1-multiplatform": "package-system/cityhash-multiplatform",
         "cityhash-1.1-multiplatform": "package-system/cityhash-multiplatform",
         "civetweb-1.8-rev1-windows": "package-system/civetweb-windows",
         "civetweb-1.8-rev1-windows": "package-system/civetweb-windows",
         "expat-2.1.0-multiplatform": "package-system/expat-multiplatform",
         "expat-2.1.0-multiplatform": "package-system/expat-multiplatform",