diff --git a/nix/pkgs/copybara.nix b/nix/pkgs/copybara.nix index 49bb17db1f..83ccd5baf9 100644 --- a/nix/pkgs/copybara.nix +++ b/nix/pkgs/copybara.nix @@ -2,11 +2,24 @@ # # SPDX-License-Identifier: Apache-2.0 -{ buildBazelPackage, openjdk11_headless, bazel_4, git, mercurial, makeWrapper, fetchFromGitHub }: +{ buildBazelPackage, buildFHSUserEnv, openjdk11_headless, bazel, git, mercurial, makeWrapper, fetchFromGitHub }: +let + hackedBazelTop = buildFHSUserEnv { + name = "bazel"; + targetPkgs = pkgs: [ + (bazel.override { enableNixHacks = true; }) + openjdk11_headless + git + mercurial + ]; + runScript = "/bin/bazel"; + }; + hackedBazel = hackedBazelTop // { override = x: hackedBazelTop; }; +in buildBazelPackage rec { name = "copybara"; version = "master"; - bazel = bazel_4; + bazel = hackedBazel; src = ../../third_party/copybara; @@ -15,13 +28,17 @@ buildBazelPackage rec { bazelTargets = [ "//java/com/google/copybara:copybara_deploy.jar" ]; removeRulesCC = false; fetchConfigured = true; + dontAddBazelOpts = true; bazelFlags = [ "--javabase=@local_jdk//:jdk" "--host_javabase=@local_jdk//:jdk" + "--java_toolchain=@bazel_tools//tools/jdk:toolchain_hostjdk8" + "--host_java_toolchain=@bazel_tools//tools/jdk:toolchain_hostjdk8" + "--define=EXECUTOR=remote" ]; fetchAttrs = { - sha256 = "sha256:1xahy74my2hr9763sv7ch3safj9mp5a78hg163gsnmqhfzvjh2cj"; + sha256 = "sha256:0r3y4lxwf2kwdfvl5qqqr6kmc0gajsqr24fr7s3ygqjr22vn99qa"; preHook = '' export COURSIER_CACHE="$(echo ''${NIX_BUILD_TOP}/tmp/coursier | sed -e 's,//,/,g')" ''; diff --git a/third_party/copybara/java/com/google/copybara/CheckoutPath.java b/third_party/copybara/java/com/google/copybara/CheckoutPath.java index ef63f754d4..2932e3a84c 100644 --- a/third_party/copybara/java/com/google/copybara/CheckoutPath.java +++ b/third_party/copybara/java/com/google/copybara/CheckoutPath.java @@ -168,7 +168,7 @@ public class CheckoutPath implements Comparable, StarlarkValue { LinkOption.NOFOLLOW_LINKS)); } catch (IOException e) { String msg = "Error getting attributes for " + path + ":" + e; - logger.atSevere().withCause(e).log(msg); + logger.atSevere().withCause(e).log("%s", msg); throw Starlark.errorf("%s", msg); // or IOException? } } @@ -192,7 +192,7 @@ public class CheckoutPath implements Comparable, StarlarkValue { return create(checkoutDir.relativize(resolvedSymlink.getRegularFile())); } catch (IOException e) { String msg = String.format("Cannot resolve symlink %s: %s", path, e); - logger.atSevere().withCause(e).log(msg); + logger.atSevere().withCause(e).log("%s", msg); throw Starlark.errorf("%s", msg); } } diff --git a/third_party/copybara/java/com/google/copybara/Main.java b/third_party/copybara/java/com/google/copybara/Main.java index 06883a3b76..1c96f37e5f 100644 --- a/third_party/copybara/java/com/google/copybara/Main.java +++ b/third_party/copybara/java/com/google/copybara/Main.java @@ -463,7 +463,7 @@ public class Main { generalOptions.getDirFactory().cleanupTempDirs(); // Only for profiling purposes, no need to use the console logger.atInfo() - .log("Cleaned output directory:" + generalOptions.getDirFactory().getTmpRoot()); + .log("Cleaned output directory: %s", generalOptions.getDirFactory().getTmpRoot()); return null; }); } @@ -512,7 +512,7 @@ public class Main { cause = cause.getCause(); } console.error(error.toString()); - logger.at(level).withCause(e).log(formatLogError(e.getMessage(), args)); + logger.at(level).withCause(e).log("%s", formatLogError(e.getMessage(), args)); } private String printException(Throwable t) { @@ -523,7 +523,7 @@ public class Main { } private void handleUnexpectedError(Console console, String msg, String[] args, Throwable e) { - logger.atSevere().withCause(e).log(formatLogError(msg, args)); + logger.atSevere().withCause(e).log("%s", formatLogError(msg, args)); console.error(msg + " (" + e + ")"); } diff --git a/third_party/copybara/java/com/google/copybara/TransformWork.java b/third_party/copybara/java/com/google/copybara/TransformWork.java index f55ad0a197..c40738d7f5 100644 --- a/third_party/copybara/java/com/google/copybara/TransformWork.java +++ b/third_party/copybara/java/com/google/copybara/TransformWork.java @@ -295,7 +295,7 @@ public final class TransformWork implements SkylarkContext, Starl Files.createSymbolicLink(linkFullPath, relativized); } catch (IOException e) { String msg = "Cannot create symlink: " + e.getMessage(); - logger.atSevere().withCause(e).log(msg); + logger.atSevere().withCause(e).log("%s", msg); throw Starlark.errorf("%s", msg); } } diff --git a/third_party/copybara/java/com/google/copybara/buildozer/BuildozerOptions.java b/third_party/copybara/java/com/google/copybara/buildozer/BuildozerOptions.java index 14d6439ce2..67c7715c19 100644 --- a/third_party/copybara/java/com/google/copybara/buildozer/BuildozerOptions.java +++ b/third_party/copybara/java/com/google/copybara/buildozer/BuildozerOptions.java @@ -118,10 +118,10 @@ public final class BuildozerOptions implements Option { .withInput(Joiner.on('\n').join(commands).getBytes(UTF_8)) .execute(); if (!output.getStdout().isEmpty()) { - logger.atInfo().log("buildozer stdout: " + output.getStdout()); + logger.atInfo().log("buildozer stdout: %s", output.getStdout()); } if (!output.getStderr().isEmpty()) { - logger.atInfo().log("buildozer stderr: " + output.getStderr()); + logger.atInfo().log("buildozer stderr: %s", output.getStderr()); } } catch (BadExitStatusWithOutputException e) { // Don't print the output for common/known errors. diff --git a/third_party/copybara/java/com/google/copybara/format/BuildifierFormat.java b/third_party/copybara/java/com/google/copybara/format/BuildifierFormat.java index b5af3b6a88..7d237f0340 100644 --- a/third_party/copybara/java/com/google/copybara/format/BuildifierFormat.java +++ b/third_party/copybara/java/com/google/copybara/format/BuildifierFormat.java @@ -131,10 +131,10 @@ public class BuildifierFormat implements Transformation { .withVerbose(generalOptions.isVerbose()) .execute(); if (!output.getStdout().isEmpty()) { - logger.atInfo().log("buildifier stdout: " + output.getStdout()); + logger.atInfo().log("buildifier stdout: %s", output.getStdout()); } if (!output.getStderr().isEmpty()) { - logger.atInfo().log("buildifier stderr: " + output.getStderr()); + logger.atInfo().log("buildifier stderr: %s", output.getStderr()); } } catch (BadExitStatusWithOutputException e) { log(console, e.getOutput()); diff --git a/third_party/copybara/java/com/google/copybara/git/GitRepository.java b/third_party/copybara/java/com/google/copybara/git/GitRepository.java index 21b1d2e054..6232ed9e13 100644 --- a/third_party/copybara/java/com/google/copybara/git/GitRepository.java +++ b/third_party/copybara/java/com/google/copybara/git/GitRepository.java @@ -313,7 +313,7 @@ public class GitRepository { return simpleCommand("describe", "--", rev.getSha1()).getStdout().trim(); } catch (RepoException e) { logger.atWarning() - .withCause(e).log("Cannot get describe version for commit " + rev.getSha1()); + .withCause(e).log("Cannot get describe version for commit %s", rev.getSha1()); return simpleCommand("describe", "--always", "--", rev.getSha1()).getStdout().trim(); } } diff --git a/third_party/copybara/java/com/google/copybara/git/github/api/GitHubApiTransportImpl.java b/third_party/copybara/java/com/google/copybara/git/github/api/GitHubApiTransportImpl.java index 9985e83fbf..1728f82722 100644 --- a/third_party/copybara/java/com/google/copybara/git/github/api/GitHubApiTransportImpl.java +++ b/third_party/copybara/java/com/google/copybara/git/github/api/GitHubApiTransportImpl.java @@ -127,7 +127,7 @@ public class GitHubApiTransportImpl implements GitHubApiTransport { String msg = String .format("GitHub credentials not found in %s. Assuming the repository is public.", storePath); - logger.atInfo().log(msg); + logger.atInfo().log("%s", msg); console.info(msg); return null; } diff --git a/third_party/copybara/java/com/google/copybara/util/CommandRunner.java b/third_party/copybara/java/com/google/copybara/util/CommandRunner.java index bf96b49309..64cb2797d9 100644 --- a/third_party/copybara/java/com/google/copybara/util/CommandRunner.java +++ b/third_party/copybara/java/com/google/copybara/util/CommandRunner.java @@ -185,10 +185,9 @@ public final class CommandRunner { String startMsg = ShellUtils.prettyPrintArgv(Arrays.asList(cmd.getCommandLineElements())); startMsg = startMsg.length() > MAX_COMMAND_LENGTH ? startMsg.substring(0, MAX_COMMAND_LENGTH) + "..." : startMsg; - String validStartMsg = "Executing [" + startMsg + "] in workdir [" + cmd.getWorkingDirectory() + "]"; - logger.atInfo().log(validStartMsg); + logger.atInfo().log("Executing [%s] in workdir [%s]", startMsg, cmd.getWorkingDirectory()); if (verbose) { - System.err.println(validStartMsg); + System.err.println(String.format("Executing [%s] in workdir [%s]", startMsg, cmd.getWorkingDirectory())); } TerminationStatus exitStatus = null; CombinedKillableObserver cmdMonitor = @@ -248,13 +247,13 @@ public final class CommandRunner { "Command '%s' was killed after timeout. Execution time %s. %s", commandName, formatDuration(stopwatch.elapsed()), exitStatus != null ? exitStatus.toString() : "(No exit status)"); - logger.atSevere().log(finishMsg); + logger.atSevere().log("%s", finishMsg); } else { finishMsg = String.format( "Command '%s' finished in %s. %s", commandName, formatDuration(stopwatch.elapsed()), exitStatus != null ? exitStatus.toString() : "(No exit status)"); - logger.atInfo().log(finishMsg); + logger.atInfo().log("%s", finishMsg); } if (verbose) { System.err.println(finishMsg); @@ -320,7 +319,7 @@ private static class DefaultExecutor implements CommandExecutor { } int lines = 0; for (String line : Splitter.on(System.lineSeparator()).split(string)) { - logger.at(level).log(prefix + line); + logger.at(level).log("%s%s", prefix, line); lines++; if (maxLogLines >= 0 && lines >= maxLogLines) { logger.at(level).log("%s... truncated after %d line(s)", prefix, maxLogLines);