pdfviewer: make pdfviewer compile on mac

Review URL: https://codereview.chromium.org/23163007

git-svn-id: http://skia.googlecode.com/svn/trunk@10721 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/experimental/PdfViewer/SkPdfGraphicsState.h b/experimental/PdfViewer/SkPdfGraphicsState.h
index d00c258..d17dc81 100644
--- a/experimental/PdfViewer/SkPdfGraphicsState.h
+++ b/experimental/PdfViewer/SkPdfGraphicsState.h
@@ -359,11 +359,12 @@
 
 // TODO(edisonn): better class design.
 // TODO(edisonn): rename to SkPdfContext
-struct SkPdfContext {
-    std::stack<SkPdfNativeObject*>        fObjectStack;
+class SkPdfContext {
+public:
+    std::stack<SkPdfNativeObject*>  fObjectStack;
     std::stack<SkPdfGraphicsState>  fStateStack;
     SkPdfGraphicsState              fGraphicsState;
-    SkPdfNativeDoc*              fPdfDoc;
+    SkPdfNativeDoc*                 fPdfDoc;
     // TODO(edisonn): the allocator, could be freed after the page is done drawing.
     SkPdfAllocator*                 fTmpPageAllocator;
     SkMatrix                        fOriginalMatrix;
diff --git a/experimental/PdfViewer/SkPdfRenderer.cpp b/experimental/PdfViewer/SkPdfRenderer.cpp
index 090383e..bd95a98 100644
--- a/experimental/PdfViewer/SkPdfRenderer.cpp
+++ b/experimental/PdfViewer/SkPdfRenderer.cpp
@@ -479,9 +479,9 @@
         return NULL;
     }
 
-    int64_t bpc = image->BitsPerComponent(pdfContext->fPdfDoc);
-    int64_t width = image->Width(pdfContext->fPdfDoc);
-    int64_t height = image->Height(pdfContext->fPdfDoc);
+    int bpc = (int)image->BitsPerComponent(pdfContext->fPdfDoc);
+    int width = (int)image->Width(pdfContext->fPdfDoc);
+    int height = (int)image->Height(pdfContext->fPdfDoc);
     std::string colorSpace = "DeviceRGB";
 
     bool indexed = false;
@@ -500,7 +500,7 @@
                                            ) {
             // TODO(edisonn): suport only DeviceRGB for now.
             indexed = true;
-            cnt = array->objAtAIndex(2)->intValue() + 1;
+            cnt = (int)array->objAtAIndex(2)->intValue() + 1;
             if (cnt > 256) {
                 // TODO(edionn): report NYIs
                 return NULL;
@@ -1041,8 +1041,6 @@
     printf("stack size = %i\n", (int)pdfContext->fObjectStack.size());
 #endif
     double ty = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fObjectStack.pop();
-    SkPdfNativeObject* obj = pdfContext->fObjectStack.top();
-    obj = obj;
     double tx = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fObjectStack.pop();
 
     double array[6] = {1, 0, 0, 1, tx, -ty};
@@ -1445,7 +1443,7 @@
     return kOK_SkPdfResult;
 }
 
-SkPdfResult skpdfGraphicsStateApplyFontCore(SkPdfContext* pdfContext, const SkPdfNativeObject* fontName, double fontSize) {
+static SkPdfResult skpdfGraphicsStateApplyFontCore(SkPdfContext* pdfContext, const SkPdfNativeObject* fontName, double fontSize) {
 #ifdef PDF_TRACE
     printf("font name: %s\n", fontName->nameValue2().c_str());
 #endif
@@ -1799,32 +1797,32 @@
 
 
 // TODO(edisonn): security review here, make sure all parameters are valid, and safe.
-SkPdfResult skpdfGraphicsStateApply_ca(SkPdfContext* pdfContext, double ca) {
+static SkPdfResult skpdfGraphicsStateApply_ca(SkPdfContext* pdfContext, double ca) {
     pdfContext->fGraphicsState.fNonStroking.fOpacity = ca;
     return kOK_SkPdfResult;
 }
 
-SkPdfResult skpdfGraphicsStateApply_CA(SkPdfContext* pdfContext, double CA) {
+static SkPdfResult skpdfGraphicsStateApply_CA(SkPdfContext* pdfContext, double CA) {
     pdfContext->fGraphicsState.fStroking.fOpacity = CA;
     return kOK_SkPdfResult;
 }
 
-SkPdfResult skpdfGraphicsStateApplyLW(SkPdfContext* pdfContext, double lineWidth) {
+static SkPdfResult skpdfGraphicsStateApplyLW(SkPdfContext* pdfContext, double lineWidth) {
     pdfContext->fGraphicsState.fLineWidth = lineWidth;
     return kOK_SkPdfResult;
 }
 
-SkPdfResult skpdfGraphicsStateApplyLC(SkPdfContext* pdfContext, int64_t lineCap) {
+static SkPdfResult skpdfGraphicsStateApplyLC(SkPdfContext* pdfContext, int64_t lineCap) {
     pdfContext->fGraphicsState.fLineCap = (int)lineCap;
     return kOK_SkPdfResult;
 }
 
-SkPdfResult skpdfGraphicsStateApplyLJ(SkPdfContext* pdfContext, int64_t lineJoin) {
+static SkPdfResult skpdfGraphicsStateApplyLJ(SkPdfContext* pdfContext, int64_t lineJoin) {
     pdfContext->fGraphicsState.fLineJoin = (int)lineJoin;
     return kOK_SkPdfResult;
 }
 
-SkPdfResult skpdfGraphicsStateApplyML(SkPdfContext* pdfContext, double miterLimit) {
+static SkPdfResult skpdfGraphicsStateApplyML(SkPdfContext* pdfContext, double miterLimit) {
     pdfContext->fGraphicsState.fMiterLimit = miterLimit;
     return kOK_SkPdfResult;
 }
@@ -1839,7 +1837,7 @@
 6) [2 3] 11 1 on, 3 off, 2 on, 3 off, 2 on, …
  */
 
-SkPdfResult skpdfGraphicsStateApplyD(SkPdfContext* pdfContext, SkPdfArray* intervals, SkPdfNativeObject* phase) {
+static SkPdfResult skpdfGraphicsStateApplyD(SkPdfContext* pdfContext, SkPdfArray* intervals, SkPdfNativeObject* phase) {
     int cnt = intervals->size();
     if (cnt >= 256) {
         // TODO(edisonn): report error/warning, unsuported;
@@ -1877,7 +1875,7 @@
     return kOK_SkPdfResult;
 }
 
-SkPdfResult skpdfGraphicsStateApplyD(SkPdfContext* pdfContext, SkPdfArray* dash) {
+static SkPdfResult skpdfGraphicsStateApplyD(SkPdfContext* pdfContext, SkPdfArray* dash) {
     // TODO(edisonn): verify input
     if (!dash || dash->isArray() || dash->size() != 2 || !dash->objAtAIndex(0)->isArray() || !dash->objAtAIndex(1)->isNumber()) {
         // TODO(edisonn): report error/warning
@@ -1886,7 +1884,7 @@
     return skpdfGraphicsStateApplyD(pdfContext, (SkPdfArray*)dash->objAtAIndex(0), dash->objAtAIndex(1));
 }
 
-void skpdfGraphicsStateApplyFont(SkPdfContext* pdfContext, SkPdfArray* fontAndSize) {
+static void skpdfGraphicsStateApplyFont(SkPdfContext* pdfContext, SkPdfArray* fontAndSize) {
     if (!fontAndSize || fontAndSize->isArray() || fontAndSize->size() != 2 || !fontAndSize->objAtAIndex(0)->isName() || !fontAndSize->objAtAIndex(1)->isNumber()) {
         // TODO(edisonn): report error/warning
         return;
@@ -1978,7 +1976,7 @@
 
 InitBlendModes _gDummyInniter;
 
-SkXfermode::Mode xferModeFromBlendMode(const char* blendMode, size_t len) {
+static SkXfermode::Mode xferModeFromBlendMode(const char* blendMode, size_t len) {
     SkXfermode::Mode mode = (SkXfermode::Mode)(SkXfermode::kLastMode + 1);
     if (gPdfBlendModes.find(blendMode, len, &mode)) {
         return mode;
@@ -1987,7 +1985,7 @@
     return (SkXfermode::Mode)(SkXfermode::kLastMode + 1);
 }
 
-void skpdfGraphicsStateApplyBM_name(SkPdfContext* pdfContext, const std::string& blendMode) {
+static void skpdfGraphicsStateApplyBM_name(SkPdfContext* pdfContext, const std::string& blendMode) {
     SkXfermode::Mode mode = xferModeFromBlendMode(blendMode.c_str(), blendMode.length());
     if (mode <= SkXfermode::kLastMode) {
         pdfContext->fGraphicsState.fBlendModesLength = 1;
@@ -1997,7 +1995,7 @@
     }
 }
 
-void skpdfGraphicsStateApplyBM_array(SkPdfContext* pdfContext, SkPdfArray* blendModes) {
+static void skpdfGraphicsStateApplyBM_array(SkPdfContext* pdfContext, SkPdfArray* blendModes) {
     if (!blendModes || blendModes->isArray() || blendModes->size() == 0 || blendModes->size() > 256) {
         // TODO(edisonn): report error/warning
         return;
@@ -2023,7 +2021,7 @@
     }
 }
 
-void skpdfGraphicsStateApplySMask_dict(SkPdfContext* pdfContext, SkPdfDictionary* sMask) {
+static void skpdfGraphicsStateApplySMask_dict(SkPdfContext* pdfContext, SkPdfDictionary* sMask) {
     // TODO(edisonn): verify input
     if (pdfContext->fPdfDoc->mapper()->mapSoftMaskDictionary(sMask)) {
         pdfContext->fGraphicsState.fSoftMaskDictionary = (SkPdfSoftMaskDictionary*)sMask;
@@ -2035,7 +2033,7 @@
     }
 }
 
-void skpdfGraphicsStateApplySMask_name(SkPdfContext* pdfContext, const std::string& sMask) {
+static void skpdfGraphicsStateApplySMask_name(SkPdfContext* pdfContext, const std::string& sMask) {
     if (sMask == "None") {
         pdfContext->fGraphicsState.fSoftMaskDictionary = NULL;
         pdfContext->fGraphicsState.fSMask = NULL;
@@ -2065,7 +2063,7 @@
     skpdfGraphicsStateApplySMask_dict(pdfContext, obj->asDictionary());
 }
 
-void skpdfGraphicsStateApplyAIS(SkPdfContext* pdfContext, bool alphaSource) {
+static void skpdfGraphicsStateApplyAIS(SkPdfContext* pdfContext, bool alphaSource) {
     pdfContext->fGraphicsState.fAlphaSource = alphaSource;
 }
 
diff --git a/experimental/PdfViewer/SkPdfUtils.cpp b/experimental/PdfViewer/SkPdfUtils.cpp
index 869e633..42cf842 100644
--- a/experimental/PdfViewer/SkPdfUtils.cpp
+++ b/experimental/PdfViewer/SkPdfUtils.cpp
@@ -1,5 +1,4 @@
 #include "SkPdfUtils.h"
-#include "SkPdfConfig.h"
 
 #ifdef PDF_TRACE
 void SkTraceMatrix(const SkMatrix& matrix, const char* sz) {
diff --git a/experimental/PdfViewer/SkPdfUtils.h b/experimental/PdfViewer/SkPdfUtils.h
index 35c2cea..31dfc0b 100644
--- a/experimental/PdfViewer/SkPdfUtils.h
+++ b/experimental/PdfViewer/SkPdfUtils.h
@@ -3,6 +3,7 @@
 
 #include "SkMatrix.h"
 #include "SkRect.h"
+#include "SkPdfConfig.h"
 
 class SkPdfArray;
 class SkPdfContext;
diff --git a/experimental/PdfViewer/chop_transparency_main.cpp b/experimental/PdfViewer/chop_transparency_main.cpp
index c9a199c..f887ab3 100644
--- a/experimental/PdfViewer/chop_transparency_main.cpp
+++ b/experimental/PdfViewer/chop_transparency_main.cpp
@@ -39,7 +39,7 @@
     { SkImageEncoder::kWEBP_Type, SkImageDecoder::kWEBP_Format, ".webp" }
 };
 
-SkISize opaqueSize(const SkBitmap& bm) {
+static SkISize opaqueSize(const SkBitmap& bm) {
     int width = 1;
     int height = 1;
     for (int y = 0 ; y < bm.height(); y++) {
diff --git a/experimental/PdfViewer/copy_files.py b/experimental/PdfViewer/copy_files.py
new file mode 100644
index 0000000..ca04a73
--- /dev/null
+++ b/experimental/PdfViewer/copy_files.py
@@ -0,0 +1,9 @@
+import os
+import shutil
+import sys
+
+dstdir = sys.argv[1]
+
+for i in range(2, len(sys.argv)):
+  shutil.copy(sys.argv[i], dstdir)
+
diff --git a/experimental/PdfViewer/generate_code.py b/experimental/PdfViewer/generate_code.py
index c02f256..66dc41d 100644
--- a/experimental/PdfViewer/generate_code.py
+++ b/experimental/PdfViewer/generate_code.py
@@ -468,12 +468,10 @@
     fileMapperNativeCpp.write('\n')
     
     fileMapperNative.write('class SkPdfMapper {\n')
-
-    fileMapperNative.write('  SkPdfNativeDoc* fParsedDoc;\n')
     
     fileMapperNative.write('public:\n')
     
-    fileMapperNative.write('  SkPdfMapper(SkPdfNativeDoc* doc) : fParsedDoc(doc) {}\n')
+    fileMapperNative.write('  SkPdfMapper() {}\n')
     fileMapperNative.write('\n')
     
     for name in self.fClassesNamesInOrder:
diff --git a/experimental/PdfViewer/pdf_viewer_main.cpp b/experimental/PdfViewer/pdf_viewer_main.cpp
index 2ab88de..8949e7e 100644
--- a/experimental/PdfViewer/pdf_viewer_main.cpp
+++ b/experimental/PdfViewer/pdf_viewer_main.cpp
@@ -83,7 +83,7 @@
     return false;
 }
 
-void make_filepath(SkString* path, const SkString& dir, const SkString& name) {
+static void make_filepath(SkString* path, const SkString& dir, const SkString& name) {
     size_t len = dir.size();
     path->set(dir);
     if (0 < len  && '/' != dir[len - 1]) {
@@ -92,7 +92,7 @@
     path->append(name);
 }
 
-bool is_path_seperator(const char chr) {
+static bool is_path_seperator(const char chr) {
 #if defined(SK_BUILD_FOR_WIN)
     return chr == '\\' || chr == '/';
 #else
@@ -100,7 +100,7 @@
 #endif
 }
 
-void get_basename(SkString* basename, const SkString& path) {
+static void get_basename(SkString* basename, const SkString& path) {
     if (path.size() == 0) {
         basename->reset();
         return;
diff --git a/experimental/PdfViewer/pdfparser/native/SkPdfNativeDoc.cpp b/experimental/PdfViewer/pdfparser/native/SkPdfNativeDoc.cpp
index 3d17fb9..c0156cf 100644
--- a/experimental/PdfViewer/pdfparser/native/SkPdfNativeDoc.cpp
+++ b/experimental/PdfViewer/pdfparser/native/SkPdfNativeDoc.cpp
@@ -7,10 +7,13 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 
-#include "SkPdfFileTrailerDictionary_autogen.h"
-#include "SkPdfCatalogDictionary_autogen.h"
-#include "SkPdfPageObjectDictionary_autogen.h"
-#include "SkPdfPageTreeNodeDictionary_autogen.h"
+// TODO(edisonn): for some reason on mac these files are found here, but are found from headers
+//#include "SkPdfFileTrailerDictionary_autogen.h"
+//#include "SkPdfCatalogDictionary_autogen.h"
+//#include "SkPdfPageObjectDictionary_autogen.h"
+//#include "SkPdfPageTreeNodeDictionary_autogen.h"
+#include "SkPdfHeaders_autogen.h"
+
 #include "SkPdfMapper_autogen.h"
 
 #include "SkStream.h"
@@ -361,7 +364,7 @@
     const unsigned char* current = fFileContent + startOffset;
     const unsigned char* end = fFileContent + fContentLength;
 
-    SkPdfNativeTokenizer tokenizer(current, end - current, fMapper, fAllocator, this);
+    SkPdfNativeTokenizer tokenizer(current, end - current, fAllocator, this);
 
     SkPdfNativeObject idObj;
     SkPdfNativeObject generationObj;
@@ -465,7 +468,7 @@
         return NULL;
     }
 
-    return new SkPdfNativeTokenizer(stream, fMapper, allocator, this);
+    return new SkPdfNativeTokenizer(stream, allocator, this);
 }
 
 // TODO(edisonn): NYI
@@ -473,7 +476,7 @@
                                                            SkPdfAllocator* allocator) {
     // warning does not track two calls in the same buffer! the buffer is updated!
     // make a clean copy if needed!
-    return new SkPdfNativeTokenizer(buffer, len, fMapper, allocator, this);
+    return new SkPdfNativeTokenizer(buffer, len, allocator, this);
 }
 
 size_t SkPdfNativeDoc::objects() const {
diff --git a/experimental/PdfViewer/pdfparser/native/SkPdfNativeObject.cpp b/experimental/PdfViewer/pdfparser/native/SkPdfNativeObject.cpp
index b0f62aa..4b5f59e 100644
--- a/experimental/PdfViewer/pdfparser/native/SkPdfNativeObject.cpp
+++ b/experimental/PdfViewer/pdfparser/native/SkPdfNativeObject.cpp
@@ -1,6 +1,9 @@
 
 #include "SkPdfNativeObject.h"
-#include "SkPdfStreamCommonDictionary_autogen.h"
+
+// TODO(edisonn): mac builder does not find the header ... but from headers is ok
+//#include "SkPdfStreamCommonDictionary_autogen.h"
+#include "SkPdfHeaders_autogen.h"
 
 #include "SkFlate.h"
 #include "SkStream.h"
diff --git a/experimental/PdfViewer/pdfparser/native/SkPdfNativeTokenizer.cpp b/experimental/PdfViewer/pdfparser/native/SkPdfNativeTokenizer.cpp
index 28f3193..178ca6c 100644
--- a/experimental/PdfViewer/pdfparser/native/SkPdfNativeTokenizer.cpp
+++ b/experimental/PdfViewer/pdfparser/native/SkPdfNativeTokenizer.cpp
@@ -3,8 +3,11 @@
 #include "SkPdfNativeObject.h"
 #include "SkPdfConfig.h"
 
-#include "SkPdfStreamCommonDictionary_autogen.h"
-#include "SkPdfImageDictionary_autogen.h"
+// TODO(edisonn): mac builder does not find the header ... but from headers is ok
+//#include "SkPdfStreamCommonDictionary_autogen.h"
+//#include "SkPdfImageDictionary_autogen.h"
+#include "SkPdfHeaders_autogen.h"
+
 
 // TODO(edisonn): perf!!!
 // there could be 0s between start and end! but not in the needle.
@@ -902,7 +905,7 @@
 }
 
 // TODO(edisonn): perf: do no copy the buffers, but use them, and mark cache the result, so there is no need of a second pass
-SkPdfNativeTokenizer::SkPdfNativeTokenizer(SkPdfNativeObject* objWithStream, const SkPdfMapper* mapper, SkPdfAllocator* allocator, SkPdfNativeDoc* doc) : fDoc(doc), fMapper(mapper), fAllocator(allocator), fUncompressedStream(NULL), fUncompressedStreamEnd(NULL), fEmpty(false), fHasPutBack(false) {
+SkPdfNativeTokenizer::SkPdfNativeTokenizer(SkPdfNativeObject* objWithStream, SkPdfAllocator* allocator, SkPdfNativeDoc* doc) : fDoc(doc), fAllocator(allocator), fUncompressedStream(NULL), fUncompressedStreamEnd(NULL), fEmpty(false), fHasPutBack(false) {
     const unsigned char* buffer = NULL;
     size_t len = 0;
     objWithStream->GetFilteredStreamRef(&buffer, &len);
@@ -915,7 +918,7 @@
     fUncompressedStreamEnd = fUncompressedStream + len;
 }
 
-SkPdfNativeTokenizer::SkPdfNativeTokenizer(const unsigned char* buffer, int len, const SkPdfMapper* mapper, SkPdfAllocator* allocator, SkPdfNativeDoc* doc) : fDoc(doc), fMapper(mapper), fAllocator(allocator), fEmpty(false), fHasPutBack(false) {
+SkPdfNativeTokenizer::SkPdfNativeTokenizer(const unsigned char* buffer, int len, SkPdfAllocator* allocator, SkPdfNativeDoc* doc) : fDoc(doc), fAllocator(allocator), fEmpty(false), fHasPutBack(false) {
     // TODO(edisonn): hack, find end of object
     char* endobj = strrstrk((char*)buffer, (char*)buffer + len, "endobj");
     if (endobj) {
diff --git a/experimental/PdfViewer/pdfparser/native/SkPdfNativeTokenizer.h b/experimental/PdfViewer/pdfparser/native/SkPdfNativeTokenizer.h
index a96a002..a67a308 100644
--- a/experimental/PdfViewer/pdfparser/native/SkPdfNativeTokenizer.h
+++ b/experimental/PdfViewer/pdfparser/native/SkPdfNativeTokenizer.h
@@ -6,7 +6,6 @@
 #include <math.h>
 #include <string.h>
 
-class SkPdfMapper;
 class SkPdfDictionary;
 class SkPdfImageDictionary;
 
@@ -128,8 +127,8 @@
 
 class SkPdfNativeTokenizer {
 public:
-    SkPdfNativeTokenizer(SkPdfNativeObject* objWithStream, const SkPdfMapper* mapper, SkPdfAllocator* allocator, SkPdfNativeDoc* doc);
-    SkPdfNativeTokenizer(const unsigned char* buffer, int len, const SkPdfMapper* mapper, SkPdfAllocator* allocator, SkPdfNativeDoc* doc);
+    SkPdfNativeTokenizer(SkPdfNativeObject* objWithStream, SkPdfAllocator* allocator, SkPdfNativeDoc* doc);
+    SkPdfNativeTokenizer(const unsigned char* buffer, int len, SkPdfAllocator* allocator, SkPdfNativeDoc* doc);
 
     virtual ~SkPdfNativeTokenizer();
 
@@ -140,7 +139,6 @@
 
 private:
     SkPdfNativeDoc* fDoc;
-    const SkPdfMapper* fMapper;
     SkPdfAllocator* fAllocator;
 
     const unsigned char* fUncompressedStreamStart;
diff --git a/gyp/pdfviewer.gyp b/gyp/pdfviewer.gyp
index bcb96ea..52e14d1 100644
--- a/gyp/pdfviewer.gyp
+++ b/gyp/pdfviewer.gyp
@@ -7,6 +7,21 @@
   'includes': [
     'apptype_console.gypi',
   ],
+  # TODO(edisonn): Hack! on mack, SHARED_INTERMEDIATE_DIR can't be reliable used in a sources context
+  'conditions' : [
+    [ 'skia_os != "mac"', {
+        'variables': {
+          'GENERATE_DIR%' : '<(SHARED_INTERMEDIATE_DIR)',
+        },
+      },
+    ],
+    [ 'skia_os == "mac"', {
+        'variables': {
+          'GENERATE_DIR%' : '../src/tmp_autogen',
+        },
+      },
+    ],
+  ],
   'targets': [
     {
       'target_name': 'libpdfviewer',
@@ -22,17 +37,8 @@
         '../experimental/PdfViewer/pdfparser/native/SkPdfNativeObject.cpp',
         '../experimental/PdfViewer/pdfparser/native/SkPdfNativeTokenizer.cpp',
         '../experimental/PdfViewer/pdfparser/native/SkPdfNativeDoc.cpp',
-        '<(SHARED_INTERMEDIATE_DIR)/native/autogen/SkPdfMapper_autogen.cpp',
-        '<(SHARED_INTERMEDIATE_DIR)/native/autogen/SkPdfHeaders_autogen.cpp',
-      ],
-      'copies': [
-        {
-          'files': [
-            '../experimental/PdfViewer/datatypes.py',
-            '../experimental/PdfViewer/generate_code.py',
-          ],
-          'destination': '<(SHARED_INTERMEDIATE_DIR)',
-        },
+        '<(GENERATE_DIR)/native/autogen/SkPdfMapper_autogen.cpp',
+        '<(GENERATE_DIR)/native/autogen/SkPdfHeaders_autogen.cpp',
       ],
       'actions': [
         {
@@ -42,34 +48,49 @@
             '../experimental/PdfViewer/PdfReference-okular-1.txt',
           ],
           'outputs': [
-            '<(SHARED_INTERMEDIATE_DIR)/pdfspec_autogen.py',
+            '<(GENERATE_DIR)/pdfspec_autogen.py',
           ],
-          'action': ['python', '../experimental/PdfViewer/spec2def.py', '../experimental/PdfViewer/PdfReference-okular-1.txt', '<(SHARED_INTERMEDIATE_DIR)/pdfspec_autogen.py'],
+          'action': ['python', '../experimental/PdfViewer/spec2def.py', '../experimental/PdfViewer/PdfReference-okular-1.txt', '<(GENERATE_DIR)/pdfspec_autogen.py'],
+        },
+        {
+          'action_name': 'copy_files',
+          'variables': {
+            'sources' : [
+              '../experimental/PdfViewer/datatypes.py',
+              '../experimental/PdfViewer/generate_code.py',
+            ]
+          },
+          'inputs' : ['<(sources)'],
+          'outputs': [
+            '<(GENERATE_DIR)/datatypes.py',
+            '<(GENERATE_DIR)/generate_code.py',
+          ],
+          'action': ['python', '../experimental/PdfViewer/copy_files.py', '<(GENERATE_DIR)', '<@(sources)'],
         },
         {
           'action_name': 'generate_code',
           'inputs': [
-            '<(SHARED_INTERMEDIATE_DIR)/datatypes.py',
-            '<(SHARED_INTERMEDIATE_DIR)/generate_code.py',
-            '<(SHARED_INTERMEDIATE_DIR)/pdfspec_autogen.py',
+            '<(GENERATE_DIR)/datatypes.py',
+            '<(GENERATE_DIR)/generate_code.py',
+            '<(GENERATE_DIR)/pdfspec_autogen.py',
           ],
           'outputs': [
-            '<(SHARED_INTERMEDIATE_DIR)/native/autogen/SkPdfEnums_autogen.h',
-            '<(SHARED_INTERMEDIATE_DIR)/native/autogen/SkPdfMapper_autogen.h',
-            '<(SHARED_INTERMEDIATE_DIR)/native/autogen/SkPdfHeaders_autogen.h',
-            '<(SHARED_INTERMEDIATE_DIR)/native/autogen/SkPdfMapper_autogen.cpp',
-            '<(SHARED_INTERMEDIATE_DIR)/native/autogen/SkPdfHeaders_autogen.cpp',
+            '<(GENERATE_DIR)/native/autogen/SkPdfEnums_autogen.h',
+            '<(GENERATE_DIR)/native/autogen/SkPdfMapper_autogen.h',
+            '<(GENERATE_DIR)/native/autogen/SkPdfHeaders_autogen.h',
+            '<(GENERATE_DIR)/native/autogen/SkPdfMapper_autogen.cpp',
+            '<(GENERATE_DIR)/native/autogen/SkPdfHeaders_autogen.cpp',
             # TODO(edisonn): ok, there are many more files here, which we should list but since
             # any change in the above should trigger a change here, we should be fine normally
           ],
-          'action': ['python', '<(SHARED_INTERMEDIATE_DIR)/generate_code.py', '<(SHARED_INTERMEDIATE_DIR)'],
+          'action': ['python', '<(GENERATE_DIR)/generate_code.py', '<(GENERATE_DIR)'],
         },
       ],
       'include_dirs': [
         '../experimental/PdfViewer',
         '../experimental/PdfViewer/pdfparser',
         '../experimental/PdfViewer/pdfparser/native',
-        '<(SHARED_INTERMEDIATE_DIR)/native/autogen',
+        '<(GENERATE_DIR)/native/autogen',
       ],
       'dependencies': [
         'skia_lib.gyp:skia_lib',