about summary refs log tree commit diff
path: root/pkgs/development/tools/build-managers
diff options
context:
space:
mode:
authorItai Zukerman <zukerman@math-hat.com>2017-02-27 23:33:48 -0800
committerRobin Gloster <mail@glob.in>2017-02-28 17:41:52 +0100
commit17835f14c52acc0ec80e02eb8379ea81b1c58397 (patch)
treead376e03dcc946e9188e6fbfe09d6dafaaa08fc6 /pkgs/development/tools/build-managers
parent75707b748ce20c80eb78c4235f96c0bd83ca829a (diff)
downloadnixlib-17835f14c52acc0ec80e02eb8379ea81b1c58397.tar
nixlib-17835f14c52acc0ec80e02eb8379ea81b1c58397.tar.gz
nixlib-17835f14c52acc0ec80e02eb8379ea81b1c58397.tar.bz2
nixlib-17835f14c52acc0ec80e02eb8379ea81b1c58397.tar.lz
nixlib-17835f14c52acc0ec80e02eb8379ea81b1c58397.tar.xz
nixlib-17835f14c52acc0ec80e02eb8379ea81b1c58397.tar.zst
nixlib-17835f14c52acc0ec80e02eb8379ea81b1c58397.zip
bazel: replace patch with patchShebangs and substituteInPlace
Diffstat (limited to 'pkgs/development/tools/build-managers')
-rw-r--r--pkgs/development/tools/build-managers/bazel/bin_to_env.patch207
-rw-r--r--pkgs/development/tools/build-managers/bazel/default.nix35
2 files changed, 28 insertions, 214 deletions
diff --git a/pkgs/development/tools/build-managers/bazel/bin_to_env.patch b/pkgs/development/tools/build-managers/bazel/bin_to_env.patch
deleted file mode 100644
index b65bb681f235..000000000000
--- a/pkgs/development/tools/build-managers/bazel/bin_to_env.patch
+++ /dev/null
@@ -1,207 +0,0 @@
-diff -ur a/src/main/java/com/google/devtools/build/lib/analysis/CommandHelper.java b/src/main/java/com/google/devtools/build/lib/analysis/CommandHelper.java
---- a/src/main/java/com/google/devtools/build/lib/analysis/CommandHelper.java	1980-01-01 00:00:00.000000000 -0800
-+++ b/src/main/java/com/google/devtools/build/lib/analysis/CommandHelper.java	2017-02-19 15:37:06.021759347 -0800
-@@ -242,7 +242,7 @@
-   private static Artifact buildCommandLineArtifact(RuleContext ruleContext, String command,
-       String scriptPostFix) {
-     String scriptFileName = ruleContext.getTarget().getName() + scriptPostFix;
--    String scriptFileContents = "#!/bin/bash\n" + command;
-+    String scriptFileContents = "#!/usr/bin/env bash\n" + command;
-     Artifact scriptFileArtifact = FileWriteAction.createFile(
-         ruleContext, scriptFileName, scriptFileContents, /*executable=*/true);
-     return scriptFileArtifact;
-diff -ur a/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelConfiguration.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelConfiguration.java
---- a/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelConfiguration.java	1980-01-01 00:00:00.000000000 -0800
-+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelConfiguration.java	2017-02-19 15:37:06.022759356 -0800
-@@ -73,7 +73,7 @@
-         return new PathFragment("/usr/local/bin/bash");
-       }
-     }
--    return new PathFragment("/bin/bash");
-+    return new PathFragment("bash");
-   }
- 
-   @Override
-diff -ur a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/java_stub_template.txt b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/java_stub_template.txt
---- a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/java_stub_template.txt	1980-01-01 00:00:00.000000000 -0800
-+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/java_stub_template.txt	2017-02-19 15:37:06.022759356 -0800
-@@ -1,4 +1,4 @@
--#!/bin/bash --posix
-+#!/usr/bin/env bash
- # Copyright 2014 The Bazel Authors. All rights reserved.
- #
- # Licensed under the Apache License, Version 2.0 (the "License");
-diff -ur a/src/test/java/com/google/devtools/build/lib/shell/CommandTest.java b/src/test/java/com/google/devtools/build/lib/shell/CommandTest.java
---- a/src/test/java/com/google/devtools/build/lib/shell/CommandTest.java	1980-01-01 00:00:00.000000000 -0800
-+++ b/src/test/java/com/google/devtools/build/lib/shell/CommandTest.java	2017-02-19 15:37:06.022759356 -0800
-@@ -70,7 +70,7 @@
-     }
- 
-     try {
--      new Command(new String[] {"/bin/true", null}).execute();
-+      new Command(new String[] {"/usr/bin/env", "true", null}).execute();
-       fail("Should have thrown NullPointerException");
-     } catch (NullPointerException npe) {
-       // good
-@@ -185,7 +185,7 @@
- 
-   @Test
-   public void testNoStreamingInputForCat() throws Exception {
--    final Command command = new Command(new String[]{"/bin/cat"});
-+    final Command command = new Command(new String[]{"/usr/bin/env", "cat"});
-     ByteArrayInputStream emptyInput = new ByteArrayInputStream(new byte[0]);
-     ByteArrayOutputStream out = new ByteArrayOutputStream();
-     ByteArrayOutputStream err = new ByteArrayOutputStream();
-@@ -198,7 +198,7 @@
- 
-   @Test
-   public void testNoInputForCat() throws Exception {
--    final Command command = new Command(new String[]{"/bin/cat"});
-+    final Command command = new Command(new String[]{"/usr/bin/env", "cat"});
-     CommandResult result = command.execute();
-     assertTrue(result.getTerminationStatus().success());
-     assertThat(new String(result.getStdout(), "UTF-8")).isEmpty();
-@@ -208,7 +208,7 @@
-   @Test
-   public void testProvidedOutputStreamCapturesHelloWorld() throws Exception {
-     String helloWorld = "Hello, world.";
--    final Command command = new Command(new String[]{"/bin/echo", helloWorld});
-+    final Command command = new Command(new String[]{"/usr/bin/env", "echo", helloWorld});
-     ByteArrayOutputStream stdOut = new ByteArrayOutputStream();
-     ByteArrayOutputStream stdErr = new ByteArrayOutputStream();
-     command.execute(Command.NO_INPUT, Command.NO_OBSERVER, stdOut, stdErr);
-@@ -250,7 +250,7 @@
-   public void testAsynchronousWithOutputStreams() throws Exception {
- 
-     final String helloWorld = "Hello, world.";
--    final Command command = new Command(new String[]{"/bin/echo", helloWorld});
-+    final Command command = new Command(new String[]{"/usr/bin/env", "echo", helloWorld});
-     final ByteArrayInputStream emptyInput =
-       new ByteArrayInputStream(new byte[0]);
-     final ByteArrayOutputStream stdOut = new ByteArrayOutputStream();
-@@ -363,12 +363,12 @@
-     for (int exit : new int[] { -1, -2, -3 }) {
-       int expected = 256 + exit;
-       try {
--        String args[] = { "/bin/bash", "-c", "exit " + exit };
-+        String args[] = { "/usr/bin/env", "bash", "-c", "exit " + exit };
-         new Command(args).execute();
-         fail("Should have exited with status " + expected);
-       } catch (BadExitStatusException e) {
-         assertThat(e).hasMessage("Process exited with status " + expected);
--        checkCommandElements(e, "/bin/bash", "-c", "exit " + exit);
-+        checkCommandElements(e, "/usr/bin/env", "bash", "-c", "exit " + exit);
-         TerminationStatus status = e.getResult().getTerminationStatus();
-         assertFalse(status.success());
-         assertTrue(status.exited());
-@@ -471,7 +471,7 @@
-   public void testFlushing() throws Exception {
-     final Command command = new Command(
-         // On darwin, /bin/sh does not support -n for the echo builtin.
--        new String[] {"/bin/bash", "-c", "echo -n Foo; sleep 0.1; echo Bar"});
-+        new String[] {"/usr/bin/env", "bash", "-c", "echo -n Foo; sleep 0.1; echo Bar"});
-     // We run this command, passing in a special output stream
-     // that records when each flush() occurs.
-     // We test that a flush occurs after writing "Foo"
-@@ -541,13 +541,13 @@
-         throw new IOException();
-       }
-     };
--    Command command = new Command(new String[] {"/bin/echo", "foo"});
-+    Command command = new Command(new String[] {"/usr/bin/env", "echo", "foo"});
-     try {
-       command.execute(Command.NO_INPUT, Command.NO_OBSERVER, out, out);
-       fail();
-     } catch (AbnormalTerminationException e) {
-       // Good.
--      checkCommandElements(e, "/bin/echo", "foo");
-+      checkCommandElements(e, "/usr/bin/env", "echo", "foo");
-       assertThat(e).hasMessage("java.io.IOException");
-     }
-   }
-diff -ur a/src/test/java/com/google/devtools/build/lib/shell/InterruptibleTest.java b/src/test/java/com/google/devtools/build/lib/shell/InterruptibleTest.java
---- a/src/test/java/com/google/devtools/build/lib/shell/InterruptibleTest.java	1980-01-01 00:00:00.000000000 -0800
-+++ b/src/test/java/com/google/devtools/build/lib/shell/InterruptibleTest.java	2017-02-19 16:17:42.973071187 -0800
-@@ -60,7 +60,7 @@
- 
-     // We interrupt after 1 sec, so this gives us plenty of time for the library to notice the
-     // subprocess exit.
--    this.command = new Command(new String[] { "/bin/sleep", "20" });
-+    this.command = new Command(new String[] { "/usr/bin/env", "sleep", "20" });
- 
-     interrupter.start();
-   }
-diff -ur a/src/test/java/com/google/devtools/build/lib/shell/LoadTest.java b/src/test/java/com/google/devtools/build/lib/shell/LoadTest.java
---- a/src/test/java/com/google/devtools/build/lib/shell/LoadTest.java	1980-01-01 00:00:00.000000000 -0800
-+++ b/src/test/java/com/google/devtools/build/lib/shell/LoadTest.java	2017-02-19 15:37:06.022759356 -0800
-@@ -66,7 +66,7 @@
- 
-   @Test
-   public void testLoad() throws Throwable {
--    final Command command = new Command(new String[] {"/bin/cat",
-+    final Command command = new Command(new String[] {"/usr/bin/env", "cat",
-                                         tempFile.getAbsolutePath()});
-     Thread[] threads = new Thread[10];
-     List<Throwable> exceptions = Collections.synchronizedList(new ArrayList<Throwable>());
-diff -ur a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleImplementationFunctionsTest.java b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleImplementationFunctionsTest.java
---- a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleImplementationFunctionsTest.java	1980-01-01 00:00:00.000000000 -0800
-+++ b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleImplementationFunctionsTest.java	2017-02-19 15:37:06.022759356 -0800
-@@ -523,7 +523,7 @@
-     @SuppressWarnings("unchecked")
-     List<String> argv = (List<String>) (List<?>) (MutableList) lookup("argv");
-     assertThat(argv).hasSize(3);
--    assertMatches("argv[0]", "^.*/bash" + OsUtils.executableExtension() + "$", argv.get(0));
-+    assertMatches("argv[0]", "^(.*/)?bash" + OsUtils.executableExtension() + "$", argv.get(0));
-     assertThat(argv.get(1)).isEqualTo("-c");
-     assertThat(argv.get(2)).isEqualTo("I got the World on a string");
-   }
-@@ -558,7 +558,7 @@
-     @SuppressWarnings("unchecked")
-     List<String> argv = (List<String>) (List<?>) (MutableList) lookup("argv");
-     assertThat(argv).hasSize(3);
--    assertMatches("argv[0]", "^.*/bash" + OsUtils.executableExtension() + "$", argv.get(0));
-+    assertMatches("argv[0]", "^(.*/)?bash" + OsUtils.executableExtension() + "$", argv.get(0));
-     assertThat(argv.get(1)).isEqualTo("-c");
-     assertMatches("argv[2]", "A.*/mytool .*/mytool.sh B.*file3.dat", argv.get(2));
-   }
-@@ -588,7 +588,7 @@
-     @SuppressWarnings("unchecked")
-     List<String> argv = (List<String>) (List<?>) (MutableList) lookup("argv");
-     assertThat(argv).hasSize(2);
--    assertMatches("argv[0]", "^.*/bash" + OsUtils.executableExtension() + "$", argv.get(0));
-+    assertMatches("argv[0]", "^(.*/)?bash" + OsUtils.executableExtension() + "$", argv.get(0));
-     assertMatches("argv[1]", "^.*/resolve_me[.]script[.]sh$", argv.get(1));
-   }
- 
-diff -ur a/src/test/java/com/google/devtools/build/lib/standalone/StandaloneSpawnStrategyTest.java b/src/test/java/com/google/devtools/build/lib/standalone/StandaloneSpawnStrategyTest.java
---- a/src/test/java/com/google/devtools/build/lib/standalone/StandaloneSpawnStrategyTest.java	1980-01-01 00:00:00.000000000 -0800
-+++ b/src/test/java/com/google/devtools/build/lib/standalone/StandaloneSpawnStrategyTest.java	2017-02-19 16:27:27.851399769 -0800
-@@ -162,16 +162,16 @@
-   }
- 
-   private static String getFalseCommand() {
--    return OS.getCurrent() == OS.DARWIN ? "/usr/bin/false" : "/bin/false";
-+    return OS.getCurrent() == OS.DARWIN ? "/usr/bin/false" : "false";
-   }
- 
-   private static String getTrueCommand() {
--    return OS.getCurrent() == OS.DARWIN ? "/usr/bin/true" : "/bin/true";
-+    return OS.getCurrent() == OS.DARWIN ? "/usr/bin/true" : "true";
-   }
- 
-   @Test
-   public void testBinEchoPrintsArguments() throws Exception {
--    Spawn spawn = createSpawn("/bin/echo", "Hello,", "world.");
-+    Spawn spawn = createSpawn("/usr/bin/env", "echo", "Hello,", "world.");
-     run(spawn);
-     assertEquals("Hello, world.\n", out());
-     assertThat(err()).isEmpty();
-@@ -179,7 +179,7 @@
- 
-   @Test
-   public void testCommandRunsInWorkingDir() throws Exception {
--    Spawn spawn = createSpawn("/bin/pwd");
-+    Spawn spawn = createSpawn("/usr/bin/env", "pwd");
-     run(spawn);
-     assertEquals(executor.getExecRoot() + "\n", out());
-   }
diff --git a/pkgs/development/tools/build-managers/bazel/default.nix b/pkgs/development/tools/build-managers/bazel/default.nix
index 65c9480b114f..25378135d3d9 100644
--- a/pkgs/development/tools/build-managers/bazel/default.nix
+++ b/pkgs/development/tools/build-managers/bazel/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, jdk, zip, unzip, which, bash, binutils, perl }:
+{ stdenv, fetchurl, jdk, zip, unzip, which, bash, binutils, coreutils }:
 
 stdenv.mkDerivation rec {
 
@@ -21,19 +21,31 @@ stdenv.mkDerivation rec {
 
   sourceRoot = ".";
 
-  patches = [ ./bin_to_env.patch ];
-
   postPatch = ''
-    patchShebangs ./compile.sh
-    for d in scripts src/java_tools src/test src/tools third_party/ijar/test tools; do
-      patchShebangs $d
+    patchShebangs .
+    for f in \
+      src/main/java/com/google/devtools/build/lib/analysis/CommandHelper.java \
+      src/main/java/com/google/devtools/build/lib/bazel/rules/BazelConfiguration.java \
+      src/test/java/com/google/devtools/build/lib/shell/CommandTest.java \
+      src/test/java/com/google/devtools/build/lib/shell/InterruptibleTest.java \
+      src/test/java/com/google/devtools/build/lib/shell/LoadTest.java \
+      src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleImplementationFunctionsTest.java \
+      src/test/java/com/google/devtools/build/lib/standalone/StandaloneSpawnStrategyTest.java
+    do
+      substituteInPlace $f \
+        --replace /bin/bash ${bash}/bin/bash \
+        --replace /bin/cat ${coreutils}/bin/cat \
+        --replace /bin/echo ${coreutils}/bin/echo \
+        --replace /bin/false ${coreutils}/bin/false \
+        --replace /bin/pwd ${coreutils}/bin/pwd \
+        --replace /bin/sleep ${coreutils}/bin/sleep \
+        --replace /bin/true ${coreutils}/bin/true
     done
   '';
 
   buildInputs = [
     stdenv.cc
     stdenv.cc.cc.lib
-    bash
     jdk
     zip
     unzip
@@ -41,6 +53,14 @@ stdenv.mkDerivation rec {
     binutils
   ];
 
+  # These must be propagated since the dependency is hidden in a compressed
+  # archive.
+
+  propagatedBuildInputs = [
+    bash
+    coreutils
+  ];
+
   # If TMPDIR is in the unpack dir we run afoul of blaze's infinite symlink
   # detector (see com.google.devtools.build.lib.skyframe.FileFunction).
   # Change this to $(mktemp -d) as soon as we figure out why.
@@ -51,6 +71,7 @@ stdenv.mkDerivation rec {
   '';
 
   # Build the CPP and Java examples to verify that Bazel works.
+
   doCheck = true;
   checkPhase = ''
     export TEST_TMPDIR=$(pwd)