3
0
Fork 0
forked from mirrors/nixpkgs

bazel: remove dependence on buildFHSUserEnv

This commit is contained in:
Itai Zukerman 2017-02-15 07:40:27 -08:00
parent 183eeb3c0f
commit 59bb3d1f3f
3 changed files with 252 additions and 65 deletions

View file

@ -0,0 +1,207 @@
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());
}

View file

@ -1,7 +1,6 @@
{ stdenv, fetchurl, buildFHSUserEnv, writeScript, jdk, zip, unzip,
which, makeWrapper, binutils }:
{ stdenv, fetchurl, jdk, zip, unzip, which, bash, binutils, perl }:
let
stdenv.mkDerivation rec {
version = "0.4.4";
@ -13,60 +12,57 @@ let
platforms = platforms.linux;
};
bootstrapEnv = buildFHSUserEnv {
name = "bazel-bootstrap-env";
name = "bazel-${version}";
targetPkgs = pkgs: [ ];
inherit meta;
src = fetchurl {
url = "https://github.com/bazelbuild/bazel/releases/download/${version}/bazel-${version}-dist.zip";
sha256 = "1fwfahkqi680zyxmdriqj603lpacyh6cg6ff25bn9bkilbfj2anm";
};
bazelBinary = stdenv.mkDerivation rec {
sourceRoot = ".";
name = "bazel-${version}";
patches = [ ./bin_to_env.patch ];
src = fetchurl {
url = "https://github.com/bazelbuild/bazel/releases/download/${version}/bazel-${version}-dist.zip";
sha256 = "1fwfahkqi680zyxmdriqj603lpacyh6cg6ff25bn9bkilbfj2anm";
};
postPatch = ''
patchShebangs ./compile.sh
for d in scripts src/java_tools src/test src/tools third_party/ijar/test tools; do
patchShebangs $d
done
'';
sourceRoot = ".";
buildInputs = [
stdenv.cc
stdenv.cc.cc.lib
bash
jdk
zip
unzip
which
binutils
];
patches = [ ./java_stub_template.patch ];
# 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.
packagesNotFromEnv = [
stdenv.cc stdenv.cc.cc.lib jdk which zip unzip binutils ];
buildInputs = packagesNotFromEnv ++ [ bootstrapEnv makeWrapper ];
buildPhase = ''
export TMPDIR=/tmp
./compile.sh
'';
buildTimeBinPath = stdenv.lib.makeBinPath packagesNotFromEnv;
buildTimeLibPath = stdenv.lib.makeLibraryPath packagesNotFromEnv;
# Build the CPP and Java examples to verify that Bazel works.
doCheck = true;
checkPhase = ''
export TEST_TMPDIR=$(pwd)
./output/bazel test examples/cpp:hello-success_test
./output/bazel test examples/java-native/src/test/java/com/example/myproject:hello
'';
runTimeBinPath = stdenv.lib.makeBinPath [ jdk stdenv.cc.cc ];
runTimeLibPath = stdenv.lib.makeLibraryPath [ stdenv.cc.cc.lib ];
installPhase = ''
mkdir -p $out/bin
mv output/bazel $out/bin
'';
buildWrapper = writeScript "build-wrapper.sh" ''
#! ${stdenv.shell} -e
export PATH="${buildTimeBinPath}:$PATH"
export LD_LIBRARY_PATH="${buildTimeLibPath}:$LD_LIBRARY_PATH"
./compile.sh
'';
buildPhase = ''
bazel-bootstrap-env ${buildWrapper}
'';
installPhase = ''
mkdir -p $out/bin
cp output/bazel $out/bin/
wrapProgram $out/bin/bazel \
--suffix PATH ":" "${runTimeBinPath}" \
--suffix LD_LIBRARY_PATH ":" "${runTimeLibPath}"
'';
dontStrip = true;
dontPatchELF = true;
inherit meta;
};
in bazelBinary
dontStrip = true;
dontPatchELF = true;
}

View file

@ -1,16 +0,0 @@
commit 5525326e3287243e0e7417de96bf7d58d04b4c8b
Author: Irene Knapp <ireneista@google.com>
Date: Sat Oct 8 19:36:12 2016 -0700
Change #!/bin/bash to #!/usr/bin/env bash.
diff --git 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
index f77051f..fbf367a 100644
--- 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
@@ -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");