<p dir="auto">During compilation of TF, <code class="notranslate">tensorflow_framework</code> target (<code class="notranslate">libtensorflow_framework.so</code>) will end up with multiple definitions of zlib. The reason is that <code class="notranslate">protobuf</code> will bring <code class="notranslate">zlib</code></p>
<p dir="auto">whereas the rest of the system is using <code class="notranslate">zlib_archive</code>. There is a patch <code class="notranslate">//third_party/protobuf/protobuf.patch</code> to force the <code class="notranslate">protobuf</code> to use <code class="notranslate">zlib_archive</code> but it is not working because the logic introduced in <code class="notranslate">thrid_party/repo.bzl</code> to use <code class="notranslate">git apply</code> command instead of <code class="notranslate">patch -p1</code> on Unix machine is not working.</p>
<p dir="auto"><strong>System information</strong></p>
<ul dir="auto">
<li>OS Platform and Distribution: Linux Ubuntu 18.04.2 LTS</li>
<li>TensorFlow: Branch # master, Commit # <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/tensorflow/tensorflow/commit/7ab1171547f9c52b7f467604a5c13c98947dac1c/hovercard" href="https://github.com/tensorflow/tensorflow/commit/7ab1171547f9c52b7f467604a5c13c98947dac1c"><tt>7ab1171</tt></a></li>
<li>Python version: python3.6</li>
<li>Bazel version: 0.24.1</li>
<li>GCC/Compiler version: 7.3.1</li>
</ul>
<p dir="auto"><strong>Diff view</strong></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="diff --git a/third_party/repo.bzl b/third_party/repo.bzl
index a7506b4efe..083ebf9d6a 100644
--- a/third_party/repo.bzl
+++ b/third_party/repo.bzl
@@ -62,13 +62,15 @@ def _repos_are_siblings():
     return Label(&quot;@foo//bar&quot;).workspace_root.startswith(&quot;../&quot;)
 
 # Apply a patch_file to the repository root directory
-# Runs 'git apply' on Unix, 'patch -p1' on Windows.
+# Runs 'patch -p1'
 def _apply_patch(ctx, patch_file):
-    if _is_windows(ctx):
-        patch_command = [&quot;patch&quot;, &quot;-p1&quot;, &quot;-d&quot;, ctx.path(&quot;.&quot;), &quot;-i&quot;, ctx.path(patch_file)]
-    else:
-        patch_command = [&quot;git&quot;, &quot;apply&quot;, &quot;-v&quot;, ctx.path(patch_file)]
-    cmd = _wrap_bash_cmd(ctx, patch_command)
+    # Don't check patch on Windows, because patch is only available under bash.
+    if not _is_windows(ctx) and not ctx.which(&quot;patch&quot;):
+        fail(&quot;patch command is not found, please install it&quot;)
+    cmd = _wrap_bash_cmd(
+        ctx,
+        [&quot;patch&quot;, &quot;-p1&quot;, &quot;-d&quot;, ctx.path(&quot;.&quot;), &quot;-i&quot;, ctx.path(patch_file)],
+    )
     _execute_and_check_ret_code(ctx, cmd)
 
 def _apply_delete(ctx, paths):"><pre class="notranslate"><code class="notranslate">diff --git a/third_party/repo.bzl b/third_party/repo.bzl
index a7506b4efe..083ebf9d6a 100644
--- a/third_party/repo.bzl
+++ b/third_party/repo.bzl
@@ -62,13 +62,15 @@ def _repos_are_siblings():
     return Label("@foo//bar").workspace_root.startswith("../")
 
 # Apply a patch_file to the repository root directory
-# Runs 'git apply' on Unix, 'patch -p1' on Windows.
+# Runs 'patch -p1'
 def _apply_patch(ctx, patch_file):
-    if _is_windows(ctx):
-        patch_command = ["patch", "-p1", "-d", ctx.path("."), "-i", ctx.path(patch_file)]
-    else:
-        patch_command = ["git", "apply", "-v", ctx.path(patch_file)]
-    cmd = _wrap_bash_cmd(ctx, patch_command)
+    # Don't check patch on Windows, because patch is only available under bash.
+    if not _is_windows(ctx) and not ctx.which("patch"):
+        fail("patch command is not found, please install it")
+    cmd = _wrap_bash_cmd(
+        ctx,
+        ["patch", "-p1", "-d", ctx.path("."), "-i", ctx.path(patch_file)],
+    )
     _execute_and_check_ret_code(ctx, cmd)
 
 def _apply_delete(ctx, paths):
</code></pre></div>
<p dir="auto">During compilation of TF, <code class="notranslate">tensorflow_framework</code> target (<code class="notranslate">libtensorflow_framework.so</code>) will end up with multiple definitions of zlib. The reason is that <code class="notranslate">protobuf</code> will bring <code class="notranslate">zlib</code></p>
<p dir="auto">whereas the rest of the system is using <code class="notranslate">zlib_archive</code>. There is a patch <code class="notranslate">//third_party/protobuf/protobuf.patch</code> to force the <code class="notranslate">protobuf</code> to use <code class="notranslate">zlib_archive</code> but it is not working because the logic introduced in <code class="notranslate">thrid_party/repo.bzl</code> to use <code class="notranslate">git apply</code> command instead of <code class="notranslate">patch -p1</code> on Unix machine is not working.</p>
<p dir="auto"><strong>System information</strong></p>
<ul dir="auto">
<li>OS Platform and Distribution: Linux Ubuntu 18.04.2 LTS</li>
<li>TensorFlow: Branch # master, Commit # <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/tensorflow/tensorflow/commit/7ab1171547f9c52b7f467604a5c13c98947dac1c/hovercard" href="https://github.com/tensorflow/tensorflow/commit/7ab1171547f9c52b7f467604a5c13c98947dac1c"><tt>7ab1171</tt></a></li>
<li>Python version: python3.6</li>
<li>Bazel version: 0.24.1</li>
<li>GCC/Compiler version: 7.3.1</li>
</ul>
<p dir="auto"><strong>Diff view</strong></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="diff --git a/third_party/repo.bzl b/third_party/repo.bzl
index a7506b4efe..083ebf9d6a 100644
--- a/third_party/repo.bzl
+++ b/third_party/repo.bzl
@@ -62,13 +62,15 @@ def _repos_are_siblings():
     return Label(&quot;@foo//bar&quot;).workspace_root.startswith(&quot;../&quot;)
 
 # Apply a patch_file to the repository root directory
-# Runs 'git apply' on Unix, 'patch -p1' on Windows.
+# Runs 'patch -p1'
 def _apply_patch(ctx, patch_file):
-    if _is_windows(ctx):
-        patch_command = [&quot;patch&quot;, &quot;-p1&quot;, &quot;-d&quot;, ctx.path(&quot;.&quot;), &quot;-i&quot;, ctx.path(patch_file)]
-    else:
-        patch_command = [&quot;git&quot;, &quot;apply&quot;, &quot;-v&quot;, ctx.path(patch_file)]
-    cmd = _wrap_bash_cmd(ctx, patch_command)
+    # Don't check patch on Windows, because patch is only available under bash.
+    if not _is_windows(ctx) and not ctx.which(&quot;patch&quot;):
+        fail(&quot;patch command is not found, please install it&quot;)
+    cmd = _wrap_bash_cmd(
+        ctx,
+        [&quot;patch&quot;, &quot;-p1&quot;, &quot;-d&quot;, ctx.path(&quot;.&quot;), &quot;-i&quot;, ctx.path(patch_file)],
+    )
     _execute_and_check_ret_code(ctx, cmd)
 
 def _apply_delete(ctx, paths):"><pre class="notranslate"><code class="notranslate">diff --git a/third_party/repo.bzl b/third_party/repo.bzl
index a7506b4efe..083ebf9d6a 100644
--- a/third_party/repo.bzl
+++ b/third_party/repo.bzl
@@ -62,13 +62,15 @@ def _repos_are_siblings():
     return Label("@foo//bar").workspace_root.startswith("../")
 
 # Apply a patch_file to the repository root directory
-# Runs 'git apply' on Unix, 'patch -p1' on Windows.
+# Runs 'patch -p1'
 def _apply_patch(ctx, patch_file):
-    if _is_windows(ctx):
-        patch_command = ["patch", "-p1", "-d", ctx.path("."), "-i", ctx.path(patch_file)]
-    else:
-        patch_command = ["git", "apply", "-v", ctx.path(patch_file)]
-    cmd = _wrap_bash_cmd(ctx, patch_command)
+    # Don't check patch on Windows, because patch is only available under bash.
+    if not _is_windows(ctx) and not ctx.which("patch"):
+        fail("patch command is not found, please install it")
+    cmd = _wrap_bash_cmd(
+        ctx,
+        ["patch", "-p1", "-d", ctx.path("."), "-i", ctx.path(patch_file)],
+    )
     _execute_and_check_ret_code(ctx, cmd)
 
 def _apply_delete(ctx, paths):
</code></pre></div>