diff --git a/mkspecs/features/functions.prf b/mkspecs/features/functions.prf
index ac84ad32131fc57979d7d922b251b137a44c58f3..a26f1258d8c394042c77cbd7d6e8121cca1b5aa9 100644
--- a/mkspecs/features/functions.prf
+++ b/mkspecs/features/functions.prf
@@ -70,7 +70,7 @@ defineReplace(ninjaPath) {
 
 defineReplace(gnPath) {
     src_3rd_party_dir = $$absolute_path("$${getChromiumSrcDir()}/../", "$$QTWEBENGINE_ROOT")
-    out = $$shadowed($$absolute_path(chromium/tools/gn/out/Release/gn, $$src_3rd_party_dir))
+    out = $$shadowed($$absolute_path(gn/out/Release/gn, $$src_3rd_party_dir))
 
     win32: out = $${out}.exe
     return($$out)
diff --git a/src/buildtools/gn.pro b/src/buildtools/gn.pro
index d8f57aee12a7e2f251c1b47fce271b9adc36d016..559cdf183b9952fa35f37224de085f862bcf3304 100644
--- a/src/buildtools/gn.pro
+++ b/src/buildtools/gn.pro
@@ -9,24 +9,20 @@ QT_FOR_CONFIG += webenginecore-private
 build_pass|!debug_and_release {
     !qtConfig(webengine-system-gn): CONFIG(release, debug|release) {
         buildgn.target = build_gn
-        gn_args = $$gnArgs()
         out = $$gnPath()
-        !qtConfig(webengine-system-ninja): ninja_path = "--path $$ninjaPath()"
+        out_path = $$dirname(out)
+        !qtConfig(webengine-system-ninja): ninja_path = $$ninjaPath()
+        else: ninja_path="ninja"
         # check if it is not already build
         !exists($$out) {
-            mkpath($$dirname(out))
             src_3rd_party_dir = $$absolute_path("$${getChromiumSrcDir()}/../", "$$QTWEBENGINE_ROOT")
-            gn_bootstrap = $$system_path($$absolute_path(chromium/tools/gn/bootstrap/bootstrap.py, $$src_3rd_party_dir))
+            gn_bootstrap = $$system_path($$absolute_path(gn/build/gen.py, $$src_3rd_party_dir))
 
-            gn_args = $$system_quote($$gn_args)
-            win32:isDeveloperBuild() {
-              # GN is always built in release mode, which conflicts with incremental linking when
-              # doing a developer build of WebEngine.
-              gn_args = $$replace(gn_args, "use_incremental_linking=true ", "")
+            gn_configure = $$system_quote($$gn_bootstrap) --no-last-commit-position --out-path $$out_path
+            !system("$$pythonPathForSystem() $$gn_configure") {
+                error("GN generation error!")
             }
-
-            gn_configure = $$system_quote($$gn_bootstrap) --shadow --gn-gen-args=$$gn_args $$ninja_path
-            !system("cd $$system_quote($$system_path($$dirname(out))) && $$pythonPathForSystem() $$gn_configure") {
+            !system("cd $$system_quote($$system_path($$out_path)) && $$ninja_path $$basename(out)" ) {
                 error("GN build error!")
             }
         }
diff --git a/tools/scripts/init-repository.py b/tools/scripts/init-repository.py
index a5bef10c36d72112b149cc2e19c930f7d446404b..221f74a65f25a3fcc2a28a39fae110ba67a04437 100755
--- a/tools/scripts/init-repository.py
+++ b/tools/scripts/init-repository.py
@@ -42,6 +42,7 @@ import version_resolver as resolver
 
 chromium_src = os.environ.get('CHROMIUM_SRC_DIR')
 ninja_src = os.path.join(qtwebengine_root, 'src/3rdparty_upstream/ninja')
+gn_src = os.path.join(qtwebengine_root, 'src/3rdparty_upstream/gn')
 use_external_chromium = False
 
 parser = argparse.ArgumentParser(description='Initialize QtWebEngine repository.')
@@ -63,6 +64,7 @@ if not chromium_src or not os.path.isdir(chromium_src):
     if args.snapshot or not chromium_src:
         chromium_src = os.path.join(qtwebengine_root, 'src/3rdparty/chromium')
         ninja_src = os.path.join(qtwebengine_root, 'src/3rdparty/ninja')
+        gn_src = os.path.join(qtwebengine_root, 'src/3rdparty/gn')
         args.snapshot = True
     print 'CHROMIUM_SRC_DIR not set, using Chromium in' + chromium_src
 
@@ -84,6 +86,7 @@ def updateLastChange():
     os.chdir(currentDir)
 
 def initUpstreamSubmodules():
+    gn_url = 'https://gn.googlesource.com/gn'
     ninja_url = 'https://github.com/martine/ninja.git'
     chromium_url = 'https://chromium.googlesource.com/chromium/src.git'
     ninja_shasum = 'refs/tags/' + resolver.currentNinjaVersion()
@@ -91,6 +94,8 @@ def initUpstreamSubmodules():
     os.chdir(qtwebengine_root)
 
     current_submodules = subprocess.check_output(['git', 'submodule'])
+    if not 'src/3rdparty_upstream/gn' in current_submodules:
+        subprocess.call(['git', 'submodule', 'add', gn_url, 'src/3rdparty_upstream/gn'])
     if not 'src/3rdparty_upstream/ninja' in current_submodules:
         subprocess.call(['git', 'submodule', 'add', ninja_url, 'src/3rdparty_upstream/ninja'])
     if not use_external_chromium and not 'src/3rdparty_upstream/chromium' in current_submodules:
@@ -103,6 +108,13 @@ def initUpstreamSubmodules():
     ninjaSubmodule.os = 'all'
     ninjaSubmodule.initialize()
 
+    gnSubmodule = GitSubmodule.Submodule()
+    gnSubmodule.path = 'src/3rdparty_upstream/gn'
+    gnSubmodule.ref = 'master'
+    gnSubmodule.url = gn_url
+    gnSubmodule.os = 'all'
+    gnSubmodule.initialize()
+
     if not use_external_chromium:
         chromiumSubmodule = GitSubmodule.Submodule()
         chromiumSubmodule.path = 'src/3rdparty_upstream/chromium'
@@ -113,6 +125,7 @@ def initUpstreamSubmodules():
         chromiumSubmodule.initSubmodules()
 
     # Unstage repositories so we do not accidentally commit them.
+    subprocess.call(['git', 'reset', '-q', 'HEAD', 'src/3rdparty_upstream/gn'])
     subprocess.call(['git', 'reset', '-q', 'HEAD', 'src/3rdparty_upstream/ninja'])
     subprocess.call(['git', 'reset', '-q', 'HEAD', 'src/3rdparty_upstream/chromium'])
 
diff --git a/tools/scripts/take_snapshot.py b/tools/scripts/take_snapshot.py
index 0373f391bd0446d49f9d30973fe3f6ab8e7e65ee..8f841b9eb4888f35c8010e0420e09ec79a92e045 100755
--- a/tools/scripts/take_snapshot.py
+++ b/tools/scripts/take_snapshot.py
@@ -299,6 +299,21 @@ def listFilesInCurrentRepository():
             files.append(os.path.join(submodule.pathRelativeToTopMostSupermodule(), submodule_file))
     return files
 
+def exportGn():
+    third_party_upstream_gn = os.path.join(third_party_upstream, 'gn')
+    third_party_gn = os.path.join(third_party, 'gn')
+    os.makedirs(third_party_gn);
+    print 'exporting contents of:' + third_party_upstream_gn
+    os.chdir(third_party_upstream_gn)
+    files = listFilesInCurrentRepository()
+    print 'copying files to ' + third_party_gn
+    for i in xrange(len(files)):
+        printProgress(i+1, len(files))
+        f = files[i]
+        if not isInGitBlacklist(f):
+            copyFile(f, os.path.join(third_party_gn, f))
+    print("")
+
 def exportNinja():
     third_party_upstream_ninja = os.path.join(third_party_upstream, 'ninja')
     third_party_ninja = os.path.join(third_party, 'ninja')
@@ -352,6 +367,7 @@ if 'true' in ignore_case_setting:
 
 clearDirectory(third_party)
 
+exportGn()
 exportNinja()
 exportChromium()