aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--scripts/ci/bootstrap.json1
-rw-r--r--src/BUILD1
-rw-r--r--src/tools/benchmark/BUILD12
-rw-r--r--src/tools/benchmark/README.md20
-rw-r--r--src/tools/benchmark/java/com/google/devtools/build/benchmark/BUILD50
-rw-r--r--src/tools/benchmark/java/com/google/devtools/build/benchmark/BazelBuildCase.java138
-rw-r--r--src/tools/benchmark/java/com/google/devtools/build/benchmark/BazelBuilder.java203
-rw-r--r--src/tools/benchmark/java/com/google/devtools/build/benchmark/BenchmarkOptions.java83
-rw-r--r--src/tools/benchmark/java/com/google/devtools/build/benchmark/BuildCase.java44
-rw-r--r--src/tools/benchmark/java/com/google/devtools/build/benchmark/BuildGroupRunner.java189
-rw-r--r--src/tools/benchmark/java/com/google/devtools/build/benchmark/Builder.java57
-rw-r--r--src/tools/benchmark/java/com/google/devtools/build/benchmark/DateFilter.java43
-rw-r--r--src/tools/benchmark/java/com/google/devtools/build/benchmark/DateFilterConverter.java67
-rw-r--r--src/tools/benchmark/java/com/google/devtools/build/benchmark/Main.java109
-rw-r--r--src/tools/benchmark/java/com/google/devtools/build/benchmark/VersionFilter.java31
-rw-r--r--src/tools/benchmark/java/com/google/devtools/build/benchmark/VersionFilterConverter.java56
-rw-r--r--src/tools/benchmark/java/com/google/devtools/build/benchmark/build_data.proto58
-rw-r--r--src/tools/benchmark/java/com/google/devtools/build/benchmark/codegenerator/BUILD27
-rw-r--r--src/tools/benchmark/java/com/google/devtools/build/benchmark/codegenerator/CodeGenerator.java92
-rw-r--r--src/tools/benchmark/java/com/google/devtools/build/benchmark/codegenerator/CppCodeGenerator.java204
-rw-r--r--src/tools/benchmark/java/com/google/devtools/build/benchmark/codegenerator/CppCodeGeneratorHelper.java209
-rw-r--r--src/tools/benchmark/java/com/google/devtools/build/benchmark/codegenerator/GeneratorOptions.java59
-rw-r--r--src/tools/benchmark/java/com/google/devtools/build/benchmark/codegenerator/JavaCodeGenerator.java212
-rw-r--r--src/tools/benchmark/java/com/google/devtools/build/benchmark/codegenerator/JavaCodeGeneratorHelper.java227
-rw-r--r--src/tools/benchmark/java/com/google/devtools/build/benchmark/codegenerator/Main.java92
-rw-r--r--src/tools/benchmark/javatests/com/google/devtools/build/benchmark/BUILD46
-rw-r--r--src/tools/benchmark/javatests/com/google/devtools/build/benchmark/BazelBuildCaseTest.java101
-rw-r--r--src/tools/benchmark/javatests/com/google/devtools/build/benchmark/BazelBuilderTest.java112
-rw-r--r--src/tools/benchmark/javatests/com/google/devtools/build/benchmark/MainTest.java126
-rw-r--r--src/tools/benchmark/javatests/com/google/devtools/build/benchmark/codegenerator/BUILD61
-rw-r--r--src/tools/benchmark/javatests/com/google/devtools/build/benchmark/codegenerator/CppCodeGeneratorHelperTest.java283
-rw-r--r--src/tools/benchmark/javatests/com/google/devtools/build/benchmark/codegenerator/CppCodeGeneratorTest.java112
-rw-r--r--src/tools/benchmark/javatests/com/google/devtools/build/benchmark/codegenerator/JavaCodeGeneratorHelperTest.java254
-rw-r--r--src/tools/benchmark/javatests/com/google/devtools/build/benchmark/codegenerator/JavaCodeGeneratorTest.java129
-rw-r--r--src/tools/benchmark/javatests/com/google/devtools/build/benchmark/codegenerator/MainTest.java92
-rw-r--r--src/tools/benchmark/webapp/404.html6
-rw-r--r--src/tools/benchmark/webapp/BUILD16
-rw-r--r--src/tools/benchmark/webapp/draw_chart.js290
-rw-r--r--src/tools/benchmark/webapp/index.html52
39 files changed, 0 insertions, 3964 deletions
diff --git a/scripts/ci/bootstrap.json b/scripts/ci/bootstrap.json
index bdad87b16f..b6fdc73c36 100644
--- a/scripts/ci/bootstrap.json
+++ b/scripts/ci/bootstrap.json
@@ -16,7 +16,6 @@
"bazel-genfiles/scripts/packages/debian/bazel.dsc": "bazel.dsc",
"bazel-genfiles/scripts/packages/debian/bazel.tar.gz": "bazel.tar.gz",
"bazel-genfiles/site/jekyll-tree.tar": "docs.bazel.build.tar",
- "bazel-bin/src/tools/benchmark/webapp/site.tar": "perf.bazel.build.tar.nobuild"
},
"targets": [
"//scripts/packages",
diff --git a/src/BUILD b/src/BUILD
index a5f025ccc7..ef7f35695e 100644
--- a/src/BUILD
+++ b/src/BUILD
@@ -421,7 +421,6 @@ filegroup(
"//src/test/py/bazel:srcs",
"//src/test/shell:srcs",
"//src/tools/android/java/com/google/devtools/build/android:srcs",
- "//src/tools/benchmark:srcs",
"//src/tools/launcher:srcs",
"//src/tools/runfiles:srcs",
"//src/tools/skylark/java/com/google/devtools/skylark/skylint:srcs",
diff --git a/src/tools/benchmark/BUILD b/src/tools/benchmark/BUILD
deleted file mode 100644
index a4409eb8e3..0000000000
--- a/src/tools/benchmark/BUILD
+++ /dev/null
@@ -1,12 +0,0 @@
-package(default_visibility = ["//src:__subpackages__"])
-
-filegroup(
- name = "srcs",
- srcs = glob(["**"]) + [
- "//src/tools/benchmark/java/com/google/devtools/build/benchmark:srcs",
- "//src/tools/benchmark/java/com/google/devtools/build/benchmark/codegenerator:srcs",
- "//src/tools/benchmark/javatests/com/google/devtools/build/benchmark:srcs",
- "//src/tools/benchmark/javatests/com/google/devtools/build/benchmark/codegenerator:srcs",
- "//src/tools/benchmark/webapp:srcs",
- ],
-)
diff --git a/src/tools/benchmark/README.md b/src/tools/benchmark/README.md
deleted file mode 100644
index b370915a7c..0000000000
--- a/src/tools/benchmark/README.md
+++ /dev/null
@@ -1,20 +0,0 @@
-# Build Performance Benchmark
-
-This benchmark is used to measure and compare Bazel's performance (elapsed time
-of builds) between several commits. It requires bazel and git to be installed.
-
-To run the benchmark:
-
-1. `bazel build //src/tools/benchmark/java/com/google/devtools/build/benchmark:benchmark`
-2. Run the built binary and follow the instructions.
-3. Put the benchmark result file as `<name>.json` into the directory
- `src/tools/benchmark/webapp/data`.
-4. Put the string `<name>.json` into the file
- `src/tools/benchmark/webapp/file_list`.
-5. Start an HTTP server there and open `/index.html`.
- - Hint: You can start a simple HTTP server by running
- `python -m SimpleHTTPServer` (Python 2) or
- `python3 -m http.server` (Python 3).
-
-A hosted version of the benchmark that is kept up to date by our CI system is
-available here: https://perf.bazel.build/.
diff --git a/src/tools/benchmark/java/com/google/devtools/build/benchmark/BUILD b/src/tools/benchmark/java/com/google/devtools/build/benchmark/BUILD
deleted file mode 100644
index 48cd2c080d..0000000000
--- a/src/tools/benchmark/java/com/google/devtools/build/benchmark/BUILD
+++ /dev/null
@@ -1,50 +0,0 @@
-package(default_visibility = ["//src:__subpackages__"])
-
-proto_library(
- name = "build_data_proto",
- srcs = ["build_data.proto"],
-)
-
-java_proto_library(
- name = "build_data_java_proto",
- deps = [":build_data_proto"],
-)
-
-java_binary(
- name = "benchmark",
- srcs = glob(["*.java"]),
- main_class = "com.google.devtools.build.benchmark.Main",
- deps = [
- ":build_data_java_proto",
- "//src/main/java/com/google/devtools/build/lib/shell",
- "//src/main/java/com/google/devtools/build/lib/vfs",
- "//src/main/java/com/google/devtools/common/options",
- "//src/tools/benchmark/java/com/google/devtools/build/benchmark/codegenerator:codegenerator_lib",
- "//third_party:auto_value",
- "//third_party:guava",
- "//third_party/protobuf:protobuf_java",
- "//third_party/protobuf:protobuf_java_util",
- ],
-)
-
-java_library(
- name = "benchmark_lib",
- testonly = 1,
- srcs = glob(["*.java"]),
- deps = [
- ":build_data_java_proto",
- "//src/main/java/com/google/devtools/build/lib/shell",
- "//src/main/java/com/google/devtools/build/lib/vfs",
- "//src/main/java/com/google/devtools/common/options",
- "//src/tools/benchmark/java/com/google/devtools/build/benchmark/codegenerator:codegenerator_lib",
- "//third_party:auto_value",
- "//third_party:guava",
- "//third_party/protobuf:protobuf_java",
- "//third_party/protobuf:protobuf_java_util",
- ],
-)
-
-filegroup(
- name = "srcs",
- srcs = glob(["*"]),
-)
diff --git a/src/tools/benchmark/java/com/google/devtools/build/benchmark/BazelBuildCase.java b/src/tools/benchmark/java/com/google/devtools/build/benchmark/BazelBuildCase.java
deleted file mode 100644
index 8b59c079af..0000000000
--- a/src/tools/benchmark/java/com/google/devtools/build/benchmark/BazelBuildCase.java
+++ /dev/null
@@ -1,138 +0,0 @@
-// Copyright 2017 The Bazel Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package com.google.devtools.build.benchmark;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
-import com.google.devtools.build.benchmark.codegenerator.CodeGenerator;
-import com.google.devtools.build.benchmark.codegenerator.CppCodeGenerator;
-import com.google.devtools.build.benchmark.codegenerator.JavaCodeGenerator;
-import com.google.devtools.build.lib.shell.CommandException;
-import com.google.devtools.build.lib.vfs.FileSystem;
-import com.google.devtools.build.lib.vfs.FileSystemUtils;
-import com.google.devtools.build.lib.vfs.JavaIoFileSystem;
-import com.google.devtools.build.lib.vfs.Symlinks;
-import java.io.IOException;
-import java.nio.file.Path;
-
-/** Provides all build target information for Bazel. */
-final class BazelBuildCase implements BuildCase {
-
- private static final ImmutableMap<String, String> BUILD_TARGET_NAME_TO_DESCRIPTION =
- ImmutableMap.<String, String>builder()
- .put("java/AFewFiles", "Java Target: A Few Files")
- .put("java/ManyFiles", "Java Target: Many Files")
- .put("java/LongChainedDeps", "Java Target: Long Chained Deps")
- .put("java/ParallelDeps", "Java Target: Parallel Deps")
- .put("cpp/AFewFiles", "Cpp Target: A Few Files")
- .put("cpp/ManyFiles", "Cpp Target: Many Files")
- .put("cpp/LongChainedDeps", "Cpp Target: Long Chained Deps")
- .put("cpp/ParallelDeps", "Cpp Target: Parallel Deps")
- .build();
- private static final ImmutableSet<String> ALL_TARGET_NAMES = ImmutableSet.<String>of(
- "AFewFiles", "ManyFiles", "LongChainedDeps", "ParallelDeps");
- private static final String WORKSPACE_FILE_NAME = "WORKSPACE";
- private static final ImmutableList<BuildTargetConfig> defaultBuildTargetConfigs =
- getDefaultBuildTargetConfigs();
-
- private static final BuildEnvConfig FULL_CLEAN_BUILD_CONFIG =
- BuildEnvConfig.newBuilder()
- .setDescription("Full clean build")
- .setCleanBeforeBuild(true)
- .setIncremental(false)
- .build();
- private static final BuildEnvConfig INCREMENTAL_BUILD_CONFIG =
- BuildEnvConfig.newBuilder()
- .setDescription("Incremental build")
- .setCleanBeforeBuild(false)
- .setIncremental(true)
- .build();
- private static final ImmutableList<BuildEnvConfig> BUILD_ENV_CONFIGS =
- ImmutableList.of(FULL_CLEAN_BUILD_CONFIG, INCREMENTAL_BUILD_CONFIG);
-
- private static final FileSystem fileSystem = new JavaIoFileSystem();
-
- @Override
- public ImmutableList<BuildTargetConfig> getBuildTargetConfigs() {
- return defaultBuildTargetConfigs;
- }
-
- @Override
- public ImmutableList<String> getCodeVersions(Builder builder, BenchmarkOptions options)
- throws IOException, CommandException {
- if (options.versionFilter != null) {
- return builder.getCodeVersionsBetweenVersions(options.versionFilter);
- }
- if (options.dateFilter != null) {
- return builder.getCodeVersionsBetweenDates(options.dateFilter);
- }
- return ImmutableList.copyOf(options.versions);
- }
-
- @Override
- public ImmutableList<BuildEnvConfig> getBuildEnvConfigs() {
- return BUILD_ENV_CONFIGS;
- }
-
- // TODO(yueg): configurable target, we may not want to run benchmark for all kinds of target
- @Override
- public void prepareGeneratedCode(Path copyDir, Path generatedCodePath) throws IOException {
- // Prepare generated code for copy
- if (!copyDir.toFile().exists()) {
- CodeGenerator codeGenerator = new JavaCodeGenerator();
- codeGenerator.generateNewProject(copyDir + codeGenerator.getDirSuffix(), ALL_TARGET_NAMES);
-
- codeGenerator = new CppCodeGenerator();
- codeGenerator.generateNewProject(copyDir + codeGenerator.getDirSuffix(), ALL_TARGET_NAMES);
- }
-
- // Clean generated code path
- if (generatedCodePath.toFile().exists()) {
- try {
- FileSystemUtils.deleteTreesBelow(fileSystem.getPath(generatedCodePath.toString()));
- } catch (IOException e) {
- throw new IOException("Failed to clean directory for generated code", e);
- }
- } else {
- generatedCodePath.toFile().mkdirs();
- }
-
- // Copy
- try {
- FileSystemUtils.copyTreesBelow(
- fileSystem.getPath(copyDir.toString()),
- fileSystem.getPath(generatedCodePath.toString()),
- Symlinks.FOLLOW);
- } catch (IOException e) {
- throw new IOException("Failed to copy generated code", e);
- }
- if (!generatedCodePath.resolve(WORKSPACE_FILE_NAME).toFile().createNewFile()) {
- throw new IOException("Failed to create workspace file");
- }
- }
-
- private static ImmutableList<BuildTargetConfig> getDefaultBuildTargetConfigs() {
- ImmutableList.Builder<BuildTargetConfig> builder = ImmutableList.builder();
- for (ImmutableMap.Entry<String, String> entry : BUILD_TARGET_NAME_TO_DESCRIPTION.entrySet()) {
- builder.add(
- BuildTargetConfig.newBuilder()
- .setBuildTarget(entry.getKey())
- .setDescription(entry.getValue())
- .build());
- }
- return builder.build();
- }
-}
diff --git a/src/tools/benchmark/java/com/google/devtools/build/benchmark/BazelBuilder.java b/src/tools/benchmark/java/com/google/devtools/build/benchmark/BazelBuilder.java
deleted file mode 100644
index 71890b24c7..0000000000
--- a/src/tools/benchmark/java/com/google/devtools/build/benchmark/BazelBuilder.java
+++ /dev/null
@@ -1,203 +0,0 @@
-// Copyright 2017 The Bazel Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package com.google.devtools.build.benchmark;
-
-import static java.nio.charset.StandardCharsets.UTF_8;
-
-import com.google.common.collect.ImmutableList;
-import com.google.devtools.build.lib.shell.Command;
-import com.google.devtools.build.lib.shell.CommandException;
-import com.google.devtools.build.lib.shell.CommandResult;
-import com.google.devtools.build.lib.vfs.FileSystem;
-import com.google.devtools.build.lib.vfs.FileSystemUtils;
-import com.google.devtools.build.lib.vfs.JavaIoFileSystem;
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-/** Class that provides all needed feature of Bazel for benchmark. */
-class BazelBuilder implements Builder {
-
- private static final Logger logger = Logger.getLogger(BazelBuilder.class.getName());
- private static final FileSystem fileSystem = new JavaIoFileSystem();
-
- private static final String BAZEL_BINARY_PATH = "bazel-bin/src/bazel";
- private static final Pattern ELAPSED_TIME_PATTERN = Pattern.compile("(?<=Elapsed time: )[0-9.]+");
- private static final String DEFAULT_GIT_REPO = "https://github.com/bazelbuild/bazel.git";
-
- private final Path generatedCodeDir;
- private final Path builderDir;
- private Path buildBinary = null;
- private String currentCodeVersion = "";
-
- BazelBuilder(Path generatedCodeDir, Path builderDir) {
- this.generatedCodeDir = generatedCodeDir;
- this.builderDir = builderDir;
- }
-
- @Override
- public Path getBuildBinary(String codeVersion) throws IOException, CommandException {
- if (buildBinary != null && currentCodeVersion.equals(codeVersion)) {
- return buildBinary;
- }
-
- // git checkout codeVersion
- String[] checkoutCommand = {"git", "checkout", codeVersion};
- Command cmd = new Command(checkoutCommand, null, builderDir.toFile());
- cmd.execute();
-
- // bazel build src:bazel
- String[] buildBazelCommand = {"bazel", "build", "src:bazel"};
- cmd = new Command(buildBazelCommand, null, builderDir.toFile());
- CommandResult result = cmd.execute();
-
- // Get binary path, bazel output is in stderr
- String output = new String(result.getStderr(), UTF_8).trim();
- if (!output.contains(BAZEL_BINARY_PATH)) {
- throw new IOException("Bazel binary " + BAZEL_BINARY_PATH + " is not in output of build.");
- }
- buildBinary = builderDir.resolve(BAZEL_BINARY_PATH);
- currentCodeVersion = codeVersion;
- return buildBinary;
- }
-
- @Override
- public ImmutableList<String> getCommandFromConfig(
- BuildTargetConfig targetConfig, BuildEnvConfig envConfig) {
- return ImmutableList.<String>builder()
- .add("build")
- .add(targetConfig.getBuildTarget())
- .addAll(envConfig.getBuildArgsList())
- .build();
- }
-
- @Override
- public double buildAndGetElapsedTime(Path buildBinary, ImmutableList<String> args)
- throws CommandException {
- List<String> cmdList = new ArrayList<>();
- cmdList.add(buildBinary.toString());
- cmdList.addAll(args);
- String[] cmdArr = new String[cmdList.size()];
- cmdArr = cmdList.toArray(cmdArr);
-
- // Run build command
- Command cmd = new Command(cmdArr, null, generatedCodeDir.toFile());
- CommandResult result = cmd.execute();
-
- // Get elapsed time from output
- String output = new String(result.getStderr(), UTF_8).trim();
- Matcher m = ELAPSED_TIME_PATTERN.matcher(output);
-
- if (m.find()) {
- try {
- return (Double.parseDouble(m.group(0)));
- } catch (NumberFormatException e) {
- // Should not be here since we look for [0-9.]+
- logger.log(Level.SEVERE, "Cannot parse " + m.group(0));
- }
- }
- throw new CommandException(cmd, "Command didn't provide parsable output.");
- }
-
- @Override
- public void clean() throws CommandException {
- String[] cleanCommand = {"bazel", "clean", "--expunge"};
- Command cmd = new Command(cleanCommand, null, generatedCodeDir.toFile());
- cmd.execute();
- }
-
- @Override
- public void prepare() throws IOException, CommandException {
- prepareFromGitRepo(DEFAULT_GIT_REPO);
- }
-
- @Override
- public ImmutableList<String> getCodeVersionsBetweenVersions(VersionFilter versionFilter)
- throws CommandException {
- return getListOfOutputFromCommand(
- "git", "log",
- versionFilter.getFrom() + ".." + versionFilter.getTo(), "--pretty=format:%H", "--reverse");
- }
-
- @Override
- public ImmutableList<String> getCodeVersionsBetweenDates(DateFilter dateFilter)
- throws CommandException {
- return getListOfOutputFromCommand(
- "git", "log",
- "--after", dateFilter.getFromString(),
- "--before", dateFilter.getToString(), "--pretty=format:%H", "--reverse");
- }
-
- @Override
- public ImmutableList<String> getDatetimeForCodeVersions(ImmutableList<String> codeVersions)
- throws CommandException {
- return getListOfOutputFromCommandWithAdditionalParam(codeVersions,
- "git", "show", "-s",
- "--date=iso", "--pretty=format:%cd", "--date=format:%Y-%m-%d %H:%M:%S");
- }
-
- void prepareFromGitRepo(String gitRepo) throws IOException, CommandException {
- // Try to pull git repo first, delete directory if failed.
- if (builderDir.toFile().isDirectory()) {
- try {
- pullGitRepo();
- } catch (CommandException e) {
- FileSystemUtils.deleteTree(fileSystem.getPath(builderDir.toString()));
- }
- }
-
- if (Files.notExists(builderDir)) {
- try {
- Files.createDirectories(builderDir);
- } catch (IOException e) {
- throw new IOException("Failed to create directory for bazel", e);
- }
-
- String[] gitCloneCommand = {"git", "clone", gitRepo, "."};
- Command cmd = new Command(gitCloneCommand, null, builderDir.toFile());
- cmd.execute();
- }
- // Assume the directory is what we need if not empty
- }
-
- private void pullGitRepo() throws CommandException {
- String[] gitCloneCommand = {"git", "pull"};
- Command cmd = new Command(gitCloneCommand, null, builderDir.toFile());
- cmd.execute();
- }
-
- private ImmutableList<String> getListOfOutputFromCommand(String... command)
- throws CommandException{
- Command cmd = new Command(command, null, builderDir.toFile());
- CommandResult result = cmd.execute();
- String output = new String(result.getStdout(), UTF_8).trim();
- return ImmutableList.copyOf(output.split("\n"));
- }
-
- private ImmutableList<String> getListOfOutputFromCommandWithAdditionalParam(
- ImmutableList<String> additionalParam, String... command) throws CommandException{
- ImmutableList<String> commandList =
- ImmutableList.<String>builder().add(command).addAll(additionalParam).build();
- String[] finalCommand = commandList.toArray(new String[0]);
-
- return getListOfOutputFromCommand(finalCommand);
- }
-}
diff --git a/src/tools/benchmark/java/com/google/devtools/build/benchmark/BenchmarkOptions.java b/src/tools/benchmark/java/com/google/devtools/build/benchmark/BenchmarkOptions.java
deleted file mode 100644
index 3865b1c3c5..0000000000
--- a/src/tools/benchmark/java/com/google/devtools/build/benchmark/BenchmarkOptions.java
+++ /dev/null
@@ -1,83 +0,0 @@
-// Copyright 2017 The Bazel Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package com.google.devtools.build.benchmark;
-
-import com.google.devtools.common.options.Option;
-import com.google.devtools.common.options.OptionDocumentationCategory;
-import com.google.devtools.common.options.OptionEffectTag;
-import com.google.devtools.common.options.OptionsBase;
-import java.util.List;
-
-/** Class that contains arguments for running the benchmark. */
-public class BenchmarkOptions extends OptionsBase {
-
- @Option(
- name = "workspace",
- defaultValue = "",
- category = "benchmark",
- documentationCategory = OptionDocumentationCategory.UNCATEGORIZED,
- effectTags = {OptionEffectTag.UNKNOWN},
- valueHelp = "path",
- help = "Directory where we put all the code and results."
- )
- public String workspace;
-
- @Option(
- name = "output",
- defaultValue = "",
- category = "benchmark",
- documentationCategory = OptionDocumentationCategory.UNCATEGORIZED,
- effectTags = {OptionEffectTag.UNKNOWN},
- valueHelp = "path",
- help = "Path to put benchmark result (json format)."
- )
- public String output;
-
- @Option(
- name = "version_between",
- defaultValue = "",
- category = "version filter",
- documentationCategory = OptionDocumentationCategory.UNCATEGORIZED,
- effectTags = {OptionEffectTag.UNKNOWN},
- valueHelp = "string",
- help = "Use code versions between two versions, eg. 'abcedf..uvwxyz'.",
- converter = VersionFilterConverter.class
- )
- public VersionFilter versionFilter;
-
- @Option(
- name = "time_between",
- defaultValue = "",
- category = "time filter",
- documentationCategory = OptionDocumentationCategory.UNCATEGORIZED,
- effectTags = {OptionEffectTag.UNKNOWN},
- valueHelp = "string",
- help = "Use code versions between two time, eg. '2017-01-01 13:00..2017-01-02 08:00'.",
- converter = DateFilterConverter.class
- )
- public DateFilter dateFilter;
-
- @Option(
- name = "versions",
- defaultValue = "",
- category = "version",
- documentationCategory = OptionDocumentationCategory.UNCATEGORIZED,
- effectTags = {OptionEffectTag.UNKNOWN},
- valueHelp = "list of strings",
- allowMultiple = true,
- help = "Use code versions as listed."
- )
- public List<String> versions;
-}
diff --git a/src/tools/benchmark/java/com/google/devtools/build/benchmark/BuildCase.java b/src/tools/benchmark/java/com/google/devtools/build/benchmark/BuildCase.java
deleted file mode 100644
index 1397a82dfe..0000000000
--- a/src/tools/benchmark/java/com/google/devtools/build/benchmark/BuildCase.java
+++ /dev/null
@@ -1,44 +0,0 @@
-// Copyright 2017 The Bazel Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package com.google.devtools.build.benchmark;
-
-import com.google.common.collect.ImmutableList;
-import com.google.devtools.build.lib.shell.CommandException;
-import java.io.IOException;
-import java.nio.file.Path;
-
-/** Interface that includes methods for a build case including all build target information. */
-interface BuildCase {
-
- /** Returns a list of build environment configs. */
- ImmutableList<BuildEnvConfig> getBuildEnvConfigs();
-
- /** Returns a list of build target configs. */
- ImmutableList<BuildTargetConfig> getBuildTargetConfigs();
-
- /**
- * Returns a list of code versions (can be anything you specified) of {@code builder}.
- */
- ImmutableList<String> getCodeVersions(Builder builder, BenchmarkOptions options)
- throws IOException, CommandException;
-
- /**
- * Prepares generated code for build.
- *
- * @param copyDir the source code path for copy
- * @param generatedCodePath the path to put generated code
- */
- void prepareGeneratedCode(Path copyDir, Path generatedCodePath) throws IOException;
-}
diff --git a/src/tools/benchmark/java/com/google/devtools/build/benchmark/BuildGroupRunner.java b/src/tools/benchmark/java/com/google/devtools/build/benchmark/BuildGroupRunner.java
deleted file mode 100644
index 071a4b8686..0000000000
--- a/src/tools/benchmark/java/com/google/devtools/build/benchmark/BuildGroupRunner.java
+++ /dev/null
@@ -1,189 +0,0 @@
-// Copyright 2017 The Bazel Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package com.google.devtools.build.benchmark;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableSet;
-import com.google.devtools.build.benchmark.codegenerator.CodeGenerator;
-import com.google.devtools.build.benchmark.codegenerator.CppCodeGenerator;
-import com.google.devtools.build.benchmark.codegenerator.JavaCodeGenerator;
-import com.google.devtools.build.lib.shell.CommandException;
-import java.io.IOException;
-import java.nio.file.Path;
-
-/** Class for running a build group with all build targets and getting performance results. */
-class BuildGroupRunner {
-
- private static final String GENERATED_CODE_FOR_COPY_DIR = "GeneratedCodeForCopy";
- private static final String GENERATED_CODE_DIR = "GeneratedCode";
- private static final String BUILDER_DIR = "BuilderBazel";
- private static final int REPEAT_TIMES = 3;
-
- private final Path workspace;
- private Builder builder = null;
-
- BuildGroupRunner(Path workspace) {
- this.workspace = workspace;
- }
-
- BuildGroupResult run(BenchmarkOptions opt)
- throws IOException, CommandException {
- BuildCase buildCase = new BazelBuildCase();
- ImmutableList<BuildTargetConfig> buildTargetConfigs = buildCase.getBuildTargetConfigs();
- ImmutableList<BuildEnvConfig> buildEnvConfigs = buildCase.getBuildEnvConfigs();
-
- // Prepare builder (Bazel)
- prepareBuilder();
- System.out.println("Done preparing builder.");
-
- // Get code versions (commit hashtag for Bazel) and datetimes
- ImmutableList<String> codeVersions = buildCase.getCodeVersions(builder, opt);
- ImmutableList<String> datetimes = builder.getDatetimeForCodeVersions(codeVersions);
- System.out.println("Ready to run benchmark for the following versions:");
- for (String version : codeVersions) {
- System.out.println(version);
- }
-
- BuildGroupResult.Builder buildGroupResultBuilder =
- getBuildGroupResultBuilder(buildTargetConfigs, buildEnvConfigs, codeVersions, datetimes);
-
- for (int versionIndex = 0; versionIndex < codeVersions.size(); ++versionIndex) {
- String version = codeVersions.get(versionIndex);
- System.out.format("Benchmark for version %s started.\n", version);
-
- // Get builder binary (build Bazel binary)
- Path buildBinary = builder.getBuildBinary(version);
-
- // Repeat several times to calculate average result
- for (int t = 0; t < REPEAT_TIMES; ++t) {
- // Prepare generated code for build
- buildCase.prepareGeneratedCode(
- workspace.resolve(GENERATED_CODE_FOR_COPY_DIR),
- workspace.resolve(GENERATED_CODE_DIR));
-
- // Target config
- for (int targetIndex = 0; targetIndex < buildTargetConfigs.size(); ++targetIndex) {
- System.out.println(
- "Started target: " + buildTargetConfigs.get(targetIndex).getDescription());
-
- // Environment config
- for (int envIndex = 0; envIndex < buildEnvConfigs.size(); ++envIndex) {
- System.out.println("Started config: " + buildEnvConfigs.get(envIndex).getDescription());
-
- double elapsedTime = buildSingleTargetAndGetElapsedTime(
- buildTargetConfigs, buildEnvConfigs, buildBinary, targetIndex, envIndex);
-
- // Store result
- buildGroupResultBuilder
- .getBuildTargetResultsBuilder(targetIndex)
- .getBuildEnvResultsBuilder(envIndex)
- .getResultsBuilder(versionIndex)
- .addResults(elapsedTime);
- }
- }
- }
- }
-
- return buildGroupResultBuilder.build();
- }
-
- private double buildSingleTargetAndGetElapsedTime(
- ImmutableList<BuildTargetConfig> buildTargetConfigs,
- ImmutableList<BuildEnvConfig> buildEnvConfigs,
- Path buildBinary, int targetIndex, int envIndex) throws CommandException {
-
- BuildTargetConfig targetConfig = buildTargetConfigs.get(targetIndex);
- BuildEnvConfig envConfig = buildEnvConfigs.get(envIndex);
-
- // Clean if should
- if (envConfig.getCleanBeforeBuild()) {
- builder.clean();
- }
-
- // Modify generated code if should (only this target)
- if (envConfig.getIncremental()) {
- String targetName = targetConfig.getBuildTarget();
- targetName = targetName.substring(targetName.lastIndexOf('/') + 1, targetName.length());
-
- CodeGenerator codeGenerator = new JavaCodeGenerator();
- codeGenerator.modifyExistingProject(
- workspace.resolve(GENERATED_CODE_DIR) + codeGenerator.getDirSuffix(),
- ImmutableSet.of(targetName));
-
- codeGenerator = new CppCodeGenerator();
- codeGenerator.modifyExistingProject(
- workspace.resolve(GENERATED_CODE_DIR) + codeGenerator.getDirSuffix(),
- ImmutableSet.of(targetName));
- }
-
- // Remove the first target since it's slow
- if (targetIndex == 0 && envIndex == 0) {
- buildTargetAndGetElapsedTime(buildBinary, envConfig, targetConfig);
- builder.clean();
- }
- return buildTargetAndGetElapsedTime(buildBinary, envConfig, targetConfig);
- }
-
- private double buildTargetAndGetElapsedTime(
- Path buildBinary, BuildEnvConfig envConfig, BuildTargetConfig targetConfig)
- throws CommandException {
- // Run build
- double elapsedTime =
- builder.buildAndGetElapsedTime(
- buildBinary, builder.getCommandFromConfig(targetConfig, envConfig));
- System.out.println(elapsedTime);
- return elapsedTime;
- }
-
- private static BuildGroupResult.Builder getBuildGroupResultBuilder(
- ImmutableList<BuildTargetConfig> buildTargetConfigs,
- ImmutableList<BuildEnvConfig> buildEnvConfigs,
- ImmutableList<String> codeVersions,
- ImmutableList<String> datetimes) {
- // Initialize a BuildGroupResult object to preserve array length
- BuildGroupResult.Builder buildGroupResultBuilder = BuildGroupResult.newBuilder();
- for (BuildTargetConfig targetConfig : buildTargetConfigs) {
- BuildTargetResult.Builder targetBuilder =
- BuildTargetResult.newBuilder().setBuildTargetConfig(targetConfig);
- prepareBuildEnvConfigs(buildEnvConfigs, targetBuilder, codeVersions, datetimes);
- buildGroupResultBuilder.addBuildTargetResults(targetBuilder.build());
- }
- return buildGroupResultBuilder;
- }
-
- private static void prepareBuildEnvConfigs(
- ImmutableList<BuildEnvConfig> buildEnvConfigs,
- BuildTargetResult.Builder targetBuilder,
- ImmutableList<String> codeVersions,
- ImmutableList<String> datetimes) {
- for (BuildEnvConfig envConfig : buildEnvConfigs) {
- BuildEnvResult.Builder envBuilder = BuildEnvResult.newBuilder().setConfig(envConfig);
- for (int i = 0; i < codeVersions.size(); ++i) {
- envBuilder.addResults(
- SingleBuildResult.newBuilder()
- .setCodeVersion(codeVersions.get(i))
- .setDatetime(datetimes.get(i))
- .build());
- }
- targetBuilder.addBuildEnvResults(envBuilder.build());
- }
- }
-
- private void prepareBuilder() throws IOException, CommandException {
- builder =
- new BazelBuilder(workspace.resolve(GENERATED_CODE_DIR), workspace.resolve(BUILDER_DIR));
- builder.prepare();
- }
-}
diff --git a/src/tools/benchmark/java/com/google/devtools/build/benchmark/Builder.java b/src/tools/benchmark/java/com/google/devtools/build/benchmark/Builder.java
deleted file mode 100644
index 8409a2c97e..0000000000
--- a/src/tools/benchmark/java/com/google/devtools/build/benchmark/Builder.java
+++ /dev/null
@@ -1,57 +0,0 @@
-// Copyright 2017 The Bazel Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package com.google.devtools.build.benchmark;
-
-import com.google.common.collect.ImmutableList;
-import com.google.devtools.build.lib.shell.CommandException;
-import java.io.IOException;
-import java.nio.file.Path;
-
-/** Interface that includes methods for a building tool. */
-interface Builder {
-
- /** Prepare anything the build needs. */
- void prepare() throws IOException, CommandException;
-
- /** Returns the binary path of the build tool of a specific {@code codeVersion}. */
- Path getBuildBinary(String codeVersion) throws IOException, CommandException;
-
- /** Returns the code versions of the build tool between versions {@code (from, to]}. */
- ImmutableList<String> getCodeVersionsBetweenVersions(VersionFilter versionFilter)
- throws CommandException;
-
- /** Returns the code versions of the build tool between dates {@code [from, to]}. */
- ImmutableList<String> getCodeVersionsBetweenDates(DateFilter dateFilter)
- throws CommandException;
-
- /** Return the datetime of all {@code codeVersions} */
- ImmutableList<String> getDatetimeForCodeVersions(ImmutableList<String> codeVersions)
- throws CommandException;
-
- /** Returns a command for build under specific config. */
- ImmutableList<String> getCommandFromConfig(
- BuildTargetConfig targetConfig, BuildEnvConfig envConfig);
-
- /**
- * Build the given buildConfig using the given binary.
- *
- * @return elapsed time of the build
- */
- double buildAndGetElapsedTime(Path buildBinary, ImmutableList<String> args)
- throws CommandException;
-
- /** Clean the previous build results. */
- void clean() throws CommandException;
-}
diff --git a/src/tools/benchmark/java/com/google/devtools/build/benchmark/DateFilter.java b/src/tools/benchmark/java/com/google/devtools/build/benchmark/DateFilter.java
deleted file mode 100644
index e8affca853..0000000000
--- a/src/tools/benchmark/java/com/google/devtools/build/benchmark/DateFilter.java
+++ /dev/null
@@ -1,43 +0,0 @@
-// Copyright 2017 The Bazel Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package com.google.devtools.build.benchmark;
-
-import java.text.SimpleDateFormat;
-import java.util.Date;
-
-/**
- * Contains start date and end date.
- */
-class DateFilter {
-
- static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
-
- private final Date from;
- private final Date to;
-
- public DateFilter(Date from, Date to) {
- this.from = from;
- this.to = to;
- }
-
- public String getFromString() {
- return DATE_FORMAT.format(from);
- }
-
- public String getToString() {
- return DATE_FORMAT.format(to);
- }
-
-}
diff --git a/src/tools/benchmark/java/com/google/devtools/build/benchmark/DateFilterConverter.java b/src/tools/benchmark/java/com/google/devtools/build/benchmark/DateFilterConverter.java
deleted file mode 100644
index 077f8ae0bd..0000000000
--- a/src/tools/benchmark/java/com/google/devtools/build/benchmark/DateFilterConverter.java
+++ /dev/null
@@ -1,67 +0,0 @@
-// Copyright 2017 The Bazel Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package com.google.devtools.build.benchmark;
-
-import com.google.devtools.common.options.Converter;
-import com.google.devtools.common.options.OptionsParsingException;
-
-import java.text.ParseException;
-import java.util.Date;
-
-/**
- * A converter class that convert an input string to a {@link DateFilter} object.
- */
-public class DateFilterConverter implements Converter<DateFilter> {
-
- public DateFilterConverter() {
- super();
- }
-
- @Override
- public DateFilter convert(String input) throws OptionsParsingException {
- if (input.isEmpty()) {
- return null;
- }
-
- String[] parts = input.split("\\.\\.");
- if (parts.length != 2) {
- throw new OptionsParsingException("Error parsing time_between option: no '..' found.");
- }
- if (parts[0].isEmpty()) {
- throw new OptionsParsingException(
- "Error parsing time_between option: start date not found");
- }
- if (parts[1].isEmpty()) {
- throw new OptionsParsingException(
- "Error parsing time_between option: end date not found");
- }
-
- // TODO(yueg): support more date formats
- try {
- Date from = DateFilter.DATE_FORMAT.parse(parts[0]);
- Date to = DateFilter.DATE_FORMAT.parse(parts[1]);
- return new DateFilter(from, to);
- } catch (ParseException e) {
- throw new OptionsParsingException(
- "Error parsing datetime, format should be: yyyy-MM-ddTHH:mm:ss");
- }
- }
-
- @Override
- public String getTypeDescription() {
- return "A date filter in format: <start date(time)>..<end date(time)>";
- }
-
-} \ No newline at end of file
diff --git a/src/tools/benchmark/java/com/google/devtools/build/benchmark/Main.java b/src/tools/benchmark/java/com/google/devtools/build/benchmark/Main.java
deleted file mode 100644
index 463bb5f419..0000000000
--- a/src/tools/benchmark/java/com/google/devtools/build/benchmark/Main.java
+++ /dev/null
@@ -1,109 +0,0 @@
-// Copyright 2017 The Bazel Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package com.google.devtools.build.benchmark;
-
-import static java.nio.charset.StandardCharsets.UTF_8;
-
-import com.google.devtools.common.options.Options;
-import com.google.devtools.common.options.OptionsParsingException;
-import com.google.protobuf.InvalidProtocolBufferException;
-import com.google.protobuf.util.JsonFormat;
-import java.io.File;
-import java.io.IOException;
-import java.io.Writer;
-import java.nio.file.Files;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/** Main class for running benchmark. */
-public class Main {
-
- private static final Logger logger = Logger.getLogger(Main.class.getName());
-
- public static void main(String[] args) {
-
- BenchmarkOptions opt = null;
- try {
- opt = parseArgs(args);
- } catch (Exception e) {
- if (!e.getMessage().isEmpty()) {
- logger.log(Level.SEVERE, e.getMessage());
- }
- System.exit(1);
- }
-
- // Prepare paths
- File workspace = new File(opt.workspace);
- if (workspace.isFile()) {
- logger.log(Level.SEVERE, "Workspace directory is an existing file: " + opt.workspace);
- System.exit(1);
- }
- if (!workspace.exists() && !workspace.mkdirs()) {
- logger.log(Level.SEVERE, "Failed to create workspace directory: " + opt.workspace);
- System.exit(1);
- }
- File outputFile = new File(opt.output);
- if (outputFile.exists()) {
- logger.log(Level.SEVERE, "Output file already exists: " + opt.output);
- System.exit(1);
- }
-
- BuildGroupRunner runner = new BuildGroupRunner(workspace.toPath());
- BuildGroupResult result = null;
- try {
- result = runner.run(opt);
- } catch (Exception e) {
- logger.log(Level.SEVERE, e.getMessage());
- System.exit(1);
- }
-
- // Store data
- try {
- Writer writer = Files.newBufferedWriter(outputFile.toPath(), UTF_8);
- JsonFormat.printer().appendTo(result, writer);
- writer.flush();
- } catch (InvalidProtocolBufferException e) {
- logger.log(Level.SEVERE, "Invalid protobuf: " + e.getMessage());
- System.exit(1);
- } catch (IOException e) {
- logger.log(Level.SEVERE, "Failed to write to output file: " + e.getMessage());
- System.exit(1);
- }
- }
-
- public static BenchmarkOptions parseArgs(String[] args) throws OptionsParsingException {
- BenchmarkOptions opt = Options.parse(BenchmarkOptions.class, args).getOptions();
-
- // Missing options
- if (opt.workspace.isEmpty() || opt.output.isEmpty()) {
- System.err.println(Options.getUsage(BenchmarkOptions.class));
- throw new IllegalArgumentException("Argument --workspace and --output should not be empty.");
- }
- // Should use exact one argument between from/to, after/before and versions
- int emptyNum = booleanToInt(opt.versionFilter == null)
- + booleanToInt(opt.dateFilter == null)
- + booleanToInt(opt.versions.isEmpty());
- if (emptyNum != 2) {
- System.err.println(Options.getUsage(BenchmarkOptions.class));
- throw new IllegalArgumentException("Please use exact one type of version filter at a time.");
- }
-
- return opt;
- }
-
- private static int booleanToInt(boolean b) {
- return b ? 1 : 0;
- }
-}
diff --git a/src/tools/benchmark/java/com/google/devtools/build/benchmark/VersionFilter.java b/src/tools/benchmark/java/com/google/devtools/build/benchmark/VersionFilter.java
deleted file mode 100644
index 0932fa6fd4..0000000000
--- a/src/tools/benchmark/java/com/google/devtools/build/benchmark/VersionFilter.java
+++ /dev/null
@@ -1,31 +0,0 @@
-// Copyright 2017 The Bazel Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package com.google.devtools.build.benchmark;
-
-import com.google.auto.value.AutoValue;
-
-@AutoValue
-/**
- * Contains start version and end version.
- */
-abstract class VersionFilter {
-
- static VersionFilter create(String from, String to) {
- return new AutoValue_VersionFilter(from, to);
- }
-
- abstract String getFrom();
- abstract String getTo();
-} \ No newline at end of file
diff --git a/src/tools/benchmark/java/com/google/devtools/build/benchmark/VersionFilterConverter.java b/src/tools/benchmark/java/com/google/devtools/build/benchmark/VersionFilterConverter.java
deleted file mode 100644
index 09dd8f8385..0000000000
--- a/src/tools/benchmark/java/com/google/devtools/build/benchmark/VersionFilterConverter.java
+++ /dev/null
@@ -1,56 +0,0 @@
-// Copyright 2017 The Bazel Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package com.google.devtools.build.benchmark;
-
-import com.google.devtools.common.options.Converter;
-import com.google.devtools.common.options.OptionsParsingException;
-
-/**
- * A converter class that convert an input string to a {@link VersionFilter} object.
- */
-public class VersionFilterConverter implements Converter<VersionFilter> {
-
- public VersionFilterConverter() {
- super();
- }
-
- @Override
- public VersionFilter convert(String input) throws OptionsParsingException {
- if (input.isEmpty()) {
- return null;
- }
-
- String[] parts = input.split("\\.\\.");
- if (parts.length != 2) {
- throw new OptionsParsingException("Error parsing version_filter option: no '..' found.");
- }
- if (parts[0].isEmpty()) {
- throw new OptionsParsingException(
- "Error parsing version_filter option: start version not found");
- }
- if (parts[1].isEmpty()) {
- throw new OptionsParsingException(
- "Error parsing version_filter option: end version not found");
- }
-
- return VersionFilter.create(parts[0], parts[1]);
- }
-
- @Override
- public String getTypeDescription() {
- return "A version filter in format: <start version>..<end version>";
- }
-
-} \ No newline at end of file
diff --git a/src/tools/benchmark/java/com/google/devtools/build/benchmark/build_data.proto b/src/tools/benchmark/java/com/google/devtools/build/benchmark/build_data.proto
deleted file mode 100644
index 97e35702f4..0000000000
--- a/src/tools/benchmark/java/com/google/devtools/build/benchmark/build_data.proto
+++ /dev/null
@@ -1,58 +0,0 @@
-// Copyright 2017 The Bazel Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-syntax = "proto3";
-
-package benchmark;
-
-option java_package = "com.google.devtools.build.benchmark";
-option java_multiple_files = true;
-
-// Environment config for a build (how we build a target)
-message BuildEnvConfig {
- string description = 1;
- repeated string build_args = 2;
- bool clean_before_build = 3;
- bool incremental = 4;
-}
-
-// Build results (elapsed time) for a specific code version
-// results are used for running benchmark for several times for now
-message SingleBuildResult {
- string code_version = 1;
- string datetime = 2;
- repeated double results = 3;
-}
-
-// Build results for a specific environment config
-message BuildEnvResult {
- BuildEnvConfig config = 1;
- repeated SingleBuildResult results = 2;
-}
-
-// Target config for a build (what to build)
-message BuildTargetConfig {
- string description = 1;
- string build_target = 2;
-}
-
-// Build results for a specific target config
-message BuildTargetResult {
- BuildTargetConfig build_target_config = 1;
- repeated BuildEnvResult build_env_results = 2;
-}
-
-// Build results for a group (environment * target)
-message BuildGroupResult {
- repeated BuildTargetResult build_target_results = 1;
-}
diff --git a/src/tools/benchmark/java/com/google/devtools/build/benchmark/codegenerator/BUILD b/src/tools/benchmark/java/com/google/devtools/build/benchmark/codegenerator/BUILD
deleted file mode 100644
index 9f2a920b58..0000000000
--- a/src/tools/benchmark/java/com/google/devtools/build/benchmark/codegenerator/BUILD
+++ /dev/null
@@ -1,27 +0,0 @@
-package(default_visibility = ["//src:__subpackages__"])
-
-filegroup(
- name = "srcs",
- srcs = glob(["*"]),
-)
-
-java_binary(
- name = "codegenerator",
- srcs = glob(["*.java"]),
- main_class = "com.google.devtools.build.benchmark.codegenerator.Main",
- deps = [
- "//src/main/java/com/google/devtools/common/options",
- "//third_party:guava",
- "//third_party/java/javapoet",
- ],
-)
-
-java_library(
- name = "codegenerator_lib",
- srcs = glob(["*.java"]),
- deps = [
- "//src/main/java/com/google/devtools/common/options",
- "//third_party:guava",
- "//third_party/java/javapoet",
- ],
-)
diff --git a/src/tools/benchmark/java/com/google/devtools/build/benchmark/codegenerator/CodeGenerator.java b/src/tools/benchmark/java/com/google/devtools/build/benchmark/codegenerator/CodeGenerator.java
deleted file mode 100644
index 6d2ef8f833..0000000000
--- a/src/tools/benchmark/java/com/google/devtools/build/benchmark/codegenerator/CodeGenerator.java
+++ /dev/null
@@ -1,92 +0,0 @@
-// Copyright 2017 The Bazel Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package com.google.devtools.build.benchmark.codegenerator;
-
-import com.google.common.annotations.VisibleForTesting;
-import com.google.common.collect.ImmutableSet;
-
-import java.nio.file.Path;
-import java.nio.file.Paths;
-
-/**
- * Abstract base class for creating 4 types of project, or modify existing ones.
- * Subclasses are for different languages.
- */
-public abstract class CodeGenerator {
-
- @VisibleForTesting static final String TARGET_A_FEW_FILES = "AFewFiles";
- @VisibleForTesting static final String TARGET_MANY_FILES = "ManyFiles";
- @VisibleForTesting static final String TARGET_LONG_CHAINED_DEPS = "LongChainedDeps";
- @VisibleForTesting static final String TARGET_PARALLEL_DEPS = "ParallelDeps";
-
- public void generateNewProject(String outputDir, ImmutableSet<String> projectNames) {
- Path dir = Paths.get(outputDir);
- for (String projectName : projectNames) {
- switch (projectName) {
- case TARGET_A_FEW_FILES:
- createTargetWithSomeFiles(dir.resolve(TARGET_A_FEW_FILES), getSizeAFewFiles());
- break;
- case TARGET_MANY_FILES:
- createTargetWithSomeFiles(dir.resolve(TARGET_MANY_FILES), getSizeManyFiles());
- break;
- case TARGET_LONG_CHAINED_DEPS:
- createTargetWithLongChainedDeps(dir.resolve(TARGET_LONG_CHAINED_DEPS));
- break;
- case TARGET_PARALLEL_DEPS:
- createTargetWithParallelDeps(dir.resolve(TARGET_PARALLEL_DEPS));
- break;
- default:
- // Do nothing
- }
- }
- }
-
- public void modifyExistingProject(String outputDir, ImmutableSet<String> projectNames) {
- Path dir = Paths.get(outputDir);
- for (String projectName : projectNames) {
- switch (projectName) {
- case TARGET_A_FEW_FILES:
- modifyTargetWithSomeFiles(dir.resolve(TARGET_A_FEW_FILES));
- break;
- case TARGET_MANY_FILES:
- modifyTargetWithSomeFiles(dir.resolve(TARGET_MANY_FILES));
- break;
- case TARGET_LONG_CHAINED_DEPS:
- modifyTargetWithLongChainedDeps(dir.resolve(TARGET_LONG_CHAINED_DEPS));
- break;
- case TARGET_PARALLEL_DEPS:
- modifyTargetWithParallelDeps(dir.resolve(TARGET_PARALLEL_DEPS));
- break;
- default:
- // Do nothing
- }
- }
- }
-
- abstract void createTargetWithSomeFiles(Path projectPath, int numberOfFiles);
- abstract void modifyTargetWithSomeFiles(Path projectPath);
-
- abstract void createTargetWithLongChainedDeps(Path projectPath);
- abstract void modifyTargetWithLongChainedDeps(Path projectPath);
-
- abstract void createTargetWithParallelDeps(Path projectPath);
- abstract void modifyTargetWithParallelDeps(Path projectPath);
-
- public abstract String getDirSuffix();
- public abstract int getSizeAFewFiles();
- public abstract int getSizeManyFiles();
- public abstract int getSizeLongChainedDeps();
- public abstract int getSizeParallelDeps();
-} \ No newline at end of file
diff --git a/src/tools/benchmark/java/com/google/devtools/build/benchmark/codegenerator/CppCodeGenerator.java b/src/tools/benchmark/java/com/google/devtools/build/benchmark/codegenerator/CppCodeGenerator.java
deleted file mode 100644
index 6f1ff0cc85..0000000000
--- a/src/tools/benchmark/java/com/google/devtools/build/benchmark/codegenerator/CppCodeGenerator.java
+++ /dev/null
@@ -1,204 +0,0 @@
-// Copyright 2017 The Bazel Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package com.google.devtools.build.benchmark.codegenerator;
-
-import java.io.File;
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Path;
-
-/** Create 4 types of Cpp project, or modify existing ones. */
-public class CppCodeGenerator extends CodeGenerator {
-
- private static final int SIZE_A_FEW_FILES = 10;
- private static final int SIZE_MANY_FILES = 200;
- private static final int SIZE_LONG_CHAINED_DEPS = 20;
- private static final int SIZE_PARALLEL_DEPS = 20;
-
- private static final String DIR_SUFFIX = "/cpp";
-
- @Override
- public String getDirSuffix() {
- return DIR_SUFFIX;
- }
-
- @Override
- public int getSizeAFewFiles() {
- return SIZE_A_FEW_FILES;
- }
-
- @Override
- public int getSizeManyFiles() {
- return SIZE_MANY_FILES;
- }
-
- @Override
- public int getSizeLongChainedDeps() {
- return SIZE_LONG_CHAINED_DEPS;
- }
-
- @Override
- public int getSizeParallelDeps() {
- return SIZE_PARALLEL_DEPS;
- }
-
- /** Target type 1/2: Create targets with some files */
- @Override
- void createTargetWithSomeFiles(Path projectPath, int numberOfFiles) {
- if (pathExists(projectPath)) {
- return;
- }
-
- try {
- Files.createDirectories(projectPath);
- for (int i = 0; i < numberOfFiles; ++i) {
- CppCodeGeneratorHelper.createRandomClass("RandomClass" + i, projectPath);
- }
- CppCodeGeneratorHelper.writeBuildFileWithAllFilesToDir(
- projectPath.getFileName().toString(), projectPath);
- } catch (IOException e) {
- System.err.println("Error creating target with some files: " + e.getMessage());
- }
- }
-
- /** Target type 1/2: Modify targets with some files */
- @Override
- void modifyTargetWithSomeFiles(Path projectPath) {
- File dir = projectPath.toFile();
- if (directoryNotExists(dir)) {
- System.err.format(
- "Project dir (%s) does not contain code for modification.\n", projectPath.toString());
- return;
- }
-
- try {
- CppCodeGeneratorHelper.createRandomClassExtra("RandomClass0", projectPath);
- } catch (IOException e) {
- System.err.println("Error modifying targets some files: " + e.getMessage());
- }
- }
-
- /** Target type 3: Create targets with a few long chained dependencies (A -> B -> C -> … -> Z) */
- @Override
- void createTargetWithLongChainedDeps(Path projectPath) {
- if (pathExists(projectPath)) {
- return;
- }
-
- try {
- Files.createDirectories(projectPath);
-
- int count = SIZE_LONG_CHAINED_DEPS;
-
- // Call next one for 1..(count-2)
- for (int i = 1; i < count - 1; ++i) {
- CppCodeGeneratorHelper.createClassAndBuildFileWithDepsNext(i, projectPath);
- }
- // Don't call next one for (count-1)
- CppCodeGeneratorHelper.createRandomClass("Deps" + (count - 1), projectPath);
- CppCodeGeneratorHelper.appendTargetToBuildFile("Deps" + (count - 1), projectPath);
-
- // Main
- String deps = " deps=[ ':Deps1' ],";
- CppCodeGeneratorHelper.createMainClassAndBuildFileWithDeps(
- TARGET_LONG_CHAINED_DEPS, deps, projectPath);
- } catch (IOException e) {
- System.err.println(
- "Error creating targets with a few long chained dependencies: " + e.getMessage());
- }
- }
-
- /** Target type 3: Modify targets with a few long chained dependencies (A -> B -> C -> … -> Z) */
- @Override
- void modifyTargetWithLongChainedDeps(Path projectPath) {
- File dir = projectPath.toFile();
- if (directoryNotExists(dir)) {
- System.err.format(
- "Project dir (%s) does not contain code for modification.\n", projectPath.toString());
- return;
- }
-
- try {
- CppCodeGeneratorHelper.createClassWithDepsNextExtra(
- (SIZE_LONG_CHAINED_DEPS + 1) >> 1, projectPath);
- } catch (IOException e) {
- System.err.println(
- "Error modifying targets with a few long chained dependencies: " + e.getMessage());
- }
- }
-
- /** Target type 4: Create targets with lots of parallel dependencies (A -> B, C, D, E, F, G, H) */
- @Override
- void createTargetWithParallelDeps(Path projectPath) {
- if (pathExists(projectPath)) {
- return;
- }
-
- try {
- Files.createDirectories(projectPath);
-
- int count = SIZE_PARALLEL_DEPS;
-
- // parallel dependencies B~Z
- for (int i = 1; i < count; ++i) {
- CppCodeGeneratorHelper.createRandomClass("Deps" + i, projectPath);
- CppCodeGeneratorHelper.appendTargetToBuildFile("Deps" + i, projectPath);
- }
-
- // A(Main)
- String deps = " deps=[ ";
- for (int i = 1; i < count; ++i) {
- deps += "\":Deps" + i + "\", ";
- }
- deps += "],";
- CppCodeGeneratorHelper.createMainClassAndBuildFileWithDeps(
- TARGET_PARALLEL_DEPS, deps, projectPath);
- } catch (IOException e) {
- System.err.println(
- "Error creating targets with lots of parallel dependencies: " + e.getMessage());
- }
- }
-
- /** Target type 4: Modify targets with lots of parallel dependencies (A -> B, C, D, E, F, G, H) */
- @Override
- void modifyTargetWithParallelDeps(Path projectPath) {
- File dir = projectPath.toFile();
- if (directoryNotExists(dir)) {
- System.err.format(
- "Project dir (%s) does not contain code for modification.\n", projectPath.toString());
- return;
- }
- try {
- CppCodeGeneratorHelper.createRandomClassExtra("Deps1", projectPath);
- } catch (IOException e) {
- System.err.println(
- "Error creating targets with lots of parallel dependencies: " + e.getMessage());
- }
- }
-
- private static boolean pathExists(Path path) {
- File dir = path.toFile();
- if (dir.exists()) {
- System.err.println("File or directory exists, not rewriting it: " + path);
- return true;
- }
-
- return false;
- }
-
- private static boolean directoryNotExists(File file) {
- return !(file.exists() && file.isDirectory());
- }
-}
diff --git a/src/tools/benchmark/java/com/google/devtools/build/benchmark/codegenerator/CppCodeGeneratorHelper.java b/src/tools/benchmark/java/com/google/devtools/build/benchmark/codegenerator/CppCodeGeneratorHelper.java
deleted file mode 100644
index e5b8d7cd13..0000000000
--- a/src/tools/benchmark/java/com/google/devtools/build/benchmark/codegenerator/CppCodeGeneratorHelper.java
+++ /dev/null
@@ -1,209 +0,0 @@
-// Copyright 2017 The Bazel Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package com.google.devtools.build.benchmark.codegenerator;
-
-import static java.nio.charset.StandardCharsets.UTF_8;
-import static java.nio.file.StandardOpenOption.APPEND;
-import static java.nio.file.StandardOpenOption.CREATE;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.StandardOpenOption;
-
-/** Helper class of {@link CppCodeGenerator} */
-class CppCodeGeneratorHelper {
-
- private static final String CPP_FILE_SUFFIX = ".cc";
- private static final String CPP_HEADER_FILE_SUFFIX = ".h";
- private static final String BUILD_FILE_NAME = "BUILD";
-
- static void createRandomClass(String className, Path dir) throws IOException {
- writeLinesToFile(dir.resolve(className + CPP_FILE_SUFFIX),
- "#include <random>",
- "#include <iostream>",
- "#include <ctime>",
- "using namespace std;",
- "",
- "class " + className + " {",
- "public:",
- " static void printSth() {",
- " srand(time(NULL));",
- " int n = rand();",
- " cout << \"This is method(printSth) with random number(\" << n << \")\\n\";",
- " }",
- "};");
- writeLinesToFile(dir.resolve(className + CPP_HEADER_FILE_SUFFIX),
- "class " + className + " {",
- "public:",
- " static void printSth();",
- "};");
- }
-
- static void createRandomClassExtra(String className, Path dir) throws IOException {
- writeLinesToFile(dir.resolve(className + CPP_FILE_SUFFIX),
- "#include <random>",
- "#include <iostream>",
- "#include <ctime>",
- "using namespace std;",
- "",
- "class " + className + " {",
- "public:",
- " static void printSth() {",
- " srand(time(NULL));",
- " int n = rand();",
- " cout << \"This is method(printSth) with random number(\" << n << \")\\n\";",
- " }",
- " static void printSthElse() {",
- " srand(time(NULL));",
- " int n = rand();",
- " cout << \"This is method(printSthElse) with random number(\" << n << \")\\n\";",
- " }",
- "};");
- writeLinesToFile(dir.resolve(className + CPP_HEADER_FILE_SUFFIX),
- "class " + className + " {",
- "public:",
- " static void printSth();",
- " static void printSthElse();",
- "};");
- }
-
- static void writeBuildFileWithAllFilesToDir(String targetName, Path dir) throws IOException {
- writeLinesToFile(dir.resolve(BUILD_FILE_NAME),
- "cc_library(",
- " name = '" + targetName + "',",
- " srcs = glob([ '*" + CPP_FILE_SUFFIX + "', '*" + CPP_HEADER_FILE_SUFFIX + "' ]),",
- ")");
- }
-
- static void createClassAndBuildFileWithDepsNext(int index, Path dir) throws IOException {
- writeLinesToFile(dir.resolve("Deps" + index + CPP_HEADER_FILE_SUFFIX),
- "class Deps" + index + " {",
- "public:",
- " static void printSth();",
- " static void callNext();",
- "};");
- writeLinesToFile(dir.resolve("Deps" + index + CPP_FILE_SUFFIX),
- "#include <random>",
- "#include <iostream>",
- "#include <ctime>",
- "#include \"Deps" + (index + 1) + ".h\"",
- "using namespace std;",
- "",
- "class Deps" + index + " {",
- "public:",
- " static void printSth() {",
- " srand(time(NULL));",
- " int n = rand();",
- " cout << \"This is method(printSth) with random number(\" << n << \")\\n\";",
- " }",
- " static void callNext() {",
- " Deps" + (index + 1) + "::printSth();",
- " }",
- "};");
- appendLinesToFile(dir.resolve(BUILD_FILE_NAME),
- "cc_library(",
- " name = 'Deps" + index + "',",
- " srcs = [ 'Deps" + index + ".cc', 'Deps" + index + ".h' ],",
- " deps = [ ':Deps" + (index + 1) + "' ],",
- ")");
- }
-
- static void createClassWithDepsNextExtra(int index, Path dir) throws IOException {
- writeLinesToFile(dir.resolve("Deps" + index + CPP_HEADER_FILE_SUFFIX),
- "class Deps" + index + " {",
- "public:",
- " static void printSth();",
- " static void printSthElse();",
- " static void callNext();",
- "};");
- writeLinesToFile(dir.resolve("Deps" + index + CPP_FILE_SUFFIX),
- "#include <random>",
- "#include <iostream>",
- "#include <ctime>",
- "#include \"Deps" + (index + 1) + ".h\"",
- "using namespace std;",
- "",
- "class Deps" + index + " {",
- "public:",
- " static void printSth() {",
- " srand(time(NULL));",
- " int n = rand();",
- " cout << \"This is method(printSth) with random number(\" << n << \")\\n\";",
- " }",
- " static void printSthElse() {",
- " srand(time(NULL));",
- " int n = rand();",
- " cout << \"This is method(printSthElse) with random number(\" << n << \")\\n\";",
- " }",
- " static void callNext() {",
- " Deps" + (index + 1) + "::printSth();",
- " }",
- "};");
- }
-
- static void appendTargetToBuildFile(String targetName, Path dir) throws IOException {
- appendLinesToFile(dir.resolve(BUILD_FILE_NAME),
- "cc_library(",
- " name = '" + targetName + "',",
- " srcs = [ '" + targetName + ".cc', '" + targetName + ".h' ],",
- ")");
- }
-
- static void createMainClassAndBuildFileWithDeps(String targetName, String deps, Path dir)
- throws IOException {
- writeLinesToFile(dir.resolve("Main" + CPP_FILE_SUFFIX),
- "int main() {",
- " return 0;",
- "}");
- appendLinesToFile(dir.resolve(BUILD_FILE_NAME),
- "cc_binary(",
- " name = '" + targetName + "',",
- " srcs = [ 'Main.cc' ],",
- deps,
- ")");
- }
-
- private static void appendLinesToFile(Path filePath, String... lines) throws IOException {
- writeOrAppendLinesToFile(true, filePath, lines);
- }
-
- private static void writeLinesToFile(Path filePath, String... lines) throws IOException {
- writeOrAppendLinesToFile(false, filePath, lines);
- }
-
- private static void writeOrAppendLinesToFile(boolean append, Path filePath, String... lines)
- throws IOException {
- File file = filePath.toFile();
- if (!file.exists() && !file.createNewFile()) {
- return;
- }
-
- PrintWriter printWriter =
- new PrintWriter(
- Files.newBufferedWriter(
- file.toPath(),
- UTF_8,
- append
- ? new StandardOpenOption[] {CREATE, APPEND}
- : new StandardOpenOption[] {CREATE}));
- for (String line : lines) {
- printWriter.println(line);
- }
- printWriter.close();
- }
-}
diff --git a/src/tools/benchmark/java/com/google/devtools/build/benchmark/codegenerator/GeneratorOptions.java b/src/tools/benchmark/java/com/google/devtools/build/benchmark/codegenerator/GeneratorOptions.java
deleted file mode 100644
index 5f8cdb44e9..0000000000
--- a/src/tools/benchmark/java/com/google/devtools/build/benchmark/codegenerator/GeneratorOptions.java
+++ /dev/null
@@ -1,59 +0,0 @@
-// Copyright 2017 The Bazel Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package com.google.devtools.build.benchmark.codegenerator;
-
-import com.google.devtools.common.options.Option;
-import com.google.devtools.common.options.OptionDocumentationCategory;
-import com.google.devtools.common.options.OptionEffectTag;
-import com.google.devtools.common.options.OptionsBase;
-import java.util.List;
-
-/** Class that contains arguments for the java files generator. */
-public class GeneratorOptions extends OptionsBase {
-
- @Option(
- name = "modify",
- defaultValue = "false",
- category = "generator",
- documentationCategory = OptionDocumentationCategory.UNCATEGORIZED,
- effectTags = {OptionEffectTag.NO_OP},
- help = "if we modify the existing code (or generate new code)."
- )
- public boolean modificationMode;
-
- @Option(
- name = "output_dir",
- defaultValue = "",
- category = "generator",
- documentationCategory = OptionDocumentationCategory.UNCATEGORIZED,
- effectTags = {OptionEffectTag.NO_OP},
- valueHelp = "path",
- help = "directory where we put generated code or modify the existing code."
- )
- public String outputDir;
-
- @Option(
- name = "project_name",
- defaultValue = "",
- category = "generator",
- documentationCategory = OptionDocumentationCategory.UNCATEGORIZED,
- effectTags = {OptionEffectTag.NO_OP},
- allowMultiple = true,
- help =
- "which project we should generate,"
- + " available: AFewFiles, ManyFiles, LongChainedDeps, ParallelDeps"
- )
- public List<String> projectNames;
-}
diff --git a/src/tools/benchmark/java/com/google/devtools/build/benchmark/codegenerator/JavaCodeGenerator.java b/src/tools/benchmark/java/com/google/devtools/build/benchmark/codegenerator/JavaCodeGenerator.java
deleted file mode 100644
index 7f6d774f21..0000000000
--- a/src/tools/benchmark/java/com/google/devtools/build/benchmark/codegenerator/JavaCodeGenerator.java
+++ /dev/null
@@ -1,212 +0,0 @@
-// Copyright 2017 The Bazel Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package com.google.devtools.build.benchmark.codegenerator;
-
-import java.io.File;
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Path;
-
-/** Create 4 types of Java project, or modify existing ones. */
-public class JavaCodeGenerator extends CodeGenerator {
-
- private static final int SIZE_A_FEW_FILES = 10;
- private static final int SIZE_MANY_FILES = 1000;
- private static final int SIZE_LONG_CHAINED_DEPS = 20;
- private static final int SIZE_PARALLEL_DEPS = 20;
-
- private static final String DIR_SUFFIX = "/java";
-
- @Override
- public String getDirSuffix() {
- return DIR_SUFFIX;
- }
-
- @Override
- public int getSizeAFewFiles() {
- return SIZE_A_FEW_FILES;
- }
-
- @Override
- public int getSizeManyFiles() {
- return SIZE_MANY_FILES;
- }
-
- @Override
- public int getSizeLongChainedDeps() {
- return SIZE_LONG_CHAINED_DEPS;
- }
-
- @Override
- public int getSizeParallelDeps() {
- return SIZE_PARALLEL_DEPS;
- }
-
-
- /** Target type 1/2: Create targets with some files */
- @Override
- void createTargetWithSomeFiles(Path projectPath, int numberOfFiles) {
- if (pathExists(projectPath)) {
- return;
- }
-
- try {
- Files.createDirectories(projectPath);
-
- for (int i = 0; i < numberOfFiles; ++i) {
- JavaCodeGeneratorHelper.writeRandomClassToDir(
- /* addExtraMethod = */ false, "RandomClass" + i, "com.example.generated", projectPath);
- }
-
- JavaCodeGeneratorHelper.writeMainClassToDir("com.example.generated", projectPath);
- JavaCodeGeneratorHelper.buildFileWithMainClass(projectPath.getFileName().toString(), "", projectPath);
- } catch (IOException e) {
- System.err.println("Error creating target with some files: " + e.getMessage());
- }
- }
-
- /** Target type 1/2: Modify targets with some files */
- @Override
- void modifyTargetWithSomeFiles(Path projectPath) {
- File dir = projectPath.toFile();
- if (directoryNotExists(dir)) {
- System.err.format(
- "Project dir (%s) does not contain code for modification.\n", projectPath.toString());
- return;
- }
- try {
- JavaCodeGeneratorHelper.writeRandomClassToDir(
- /* addExtraMethod = */ true, "RandomClass0", "com.example.generated", projectPath);
- } catch (IOException e) {
- System.err.println("Error modifying targets some files: " + e.getMessage());
- }
- }
-
- /** Target type 3: Create targets with a few long chained dependencies (A -> B -> C -> … -> Z) */
- @Override
- void createTargetWithLongChainedDeps(Path projectPath) {
- if (pathExists(projectPath)) {
- return;
- }
-
- try {
- Files.createDirectories(projectPath);
-
- int count = SIZE_LONG_CHAINED_DEPS;
-
- // Call next one for 0..(count-2)
- for (int i = 0; i < count - 1; ++i) {
- JavaCodeGeneratorHelper.targetWithNextHelper(i, true, projectPath);
- JavaCodeGeneratorHelper.buildFileWithNextDeps(
- i, " deps=[ \":Deps" + (i + 1) + "\" ],\n", projectPath);
- }
- // Don't call next one for (count-1)
- JavaCodeGeneratorHelper.targetWithNextHelper(count - 1, false, projectPath);
- JavaCodeGeneratorHelper.buildFileWithNextDeps(count - 1, "", projectPath);
-
- JavaCodeGeneratorHelper.writeMainClassToDir("com.example.generated", projectPath);
-
- String deps = " deps=[ \":Deps0\" ],\n";
- JavaCodeGeneratorHelper.buildFileWithMainClass(TARGET_LONG_CHAINED_DEPS, deps, projectPath);
- } catch (IOException e) {
- System.err.println(
- "Error creating targets with a few long chained dependencies: " + e.getMessage());
- }
- }
-
- /** Target type 3: Modify targets with a few long chained dependencies (A -> B -> C -> … -> Z) */
- @Override
- void modifyTargetWithLongChainedDeps(Path projectPath) {
- File dir = projectPath.toFile();
- if (directoryNotExists(dir)) {
- System.err.format(
- "Project dir (%s) does not contain code for modification.\n", projectPath.toString());
- return;
- }
- try {
- JavaCodeGeneratorHelper.targetWithNextExtraHelper(
- (SIZE_LONG_CHAINED_DEPS + 1) >> 1, true, projectPath);
- } catch (IOException e) {
- System.err.println(
- "Error modifying targets with a few long chained dependencies: " + e.getMessage());
- }
- }
-
- /** Target type 4: Create targets with lots of parallel dependencies (A -> B, C, D, E, F, G, H) */
- @Override
- void createTargetWithParallelDeps(Path projectPath) {
- if (pathExists(projectPath)) {
- return;
- }
-
- try {
- Files.createDirectories(projectPath);
-
- int count = SIZE_PARALLEL_DEPS;
-
- // parallel dependencies B~Z
- for (int i = 1; i < count; ++i) {
- JavaCodeGeneratorHelper.writeRandomClassToDir(
- false, "Deps" + i, "com.example.deps" + i, projectPath);
- JavaCodeGeneratorHelper.buildFileWithNextDeps(i, "", projectPath);
- }
-
- // A(Main)
- JavaCodeGeneratorHelper.parallelDepsMainClassHelper(count, projectPath);
-
- String deps = " deps=[ ";
- for (int i = 1; i < count; ++i) {
- deps += "\":Deps" + i + "\", ";
- }
- deps += "], \n";
- JavaCodeGeneratorHelper.buildFileWithMainClass(TARGET_PARALLEL_DEPS, deps, projectPath);
- } catch (IOException e) {
- System.err.println(
- "Error creating targets with lots of parallel dependencies: " + e.getMessage());
- }
- }
-
- /** Target type 4: Modify targets with lots of parallel dependencies (A -> B, C, D, E, F, G, H) */
- @Override
- void modifyTargetWithParallelDeps(Path projectPath) {
- File dir = projectPath.toFile();
- if (directoryNotExists(dir)) {
- System.err.format(
- "Project dir (%s) does not contain code for modification.\n", projectPath.toString());
- return;
- }
- try {
- JavaCodeGeneratorHelper.writeRandomClassToDir(
- true, "Deps1", "com.example.deps1", projectPath);
- } catch (IOException e) {
- System.err.println(
- "Error creating targets with lots of parallel dependencies: " + e.getMessage());
- }
- }
-
- private static boolean pathExists(Path path) {
- File dir = path.toFile();
- if (dir.exists()) {
- System.err.println("File or directory exists, not rewriting it: " + path);
- return true;
- }
-
- return false;
- }
-
- private static boolean directoryNotExists(File file) {
- return !(file.exists() && file.isDirectory());
- }
-}
diff --git a/src/tools/benchmark/java/com/google/devtools/build/benchmark/codegenerator/JavaCodeGeneratorHelper.java b/src/tools/benchmark/java/com/google/devtools/build/benchmark/codegenerator/JavaCodeGeneratorHelper.java
deleted file mode 100644
index b90b480b72..0000000000
--- a/src/tools/benchmark/java/com/google/devtools/build/benchmark/codegenerator/JavaCodeGeneratorHelper.java
+++ /dev/null
@@ -1,227 +0,0 @@
-// Copyright 2017 The Bazel Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package com.google.devtools.build.benchmark.codegenerator;
-
-import static java.nio.charset.StandardCharsets.UTF_8;
-
-import com.google.common.base.Joiner;
-import com.squareup.javapoet.ClassName;
-import com.squareup.javapoet.JavaFile;
-import com.squareup.javapoet.MethodSpec;
-import com.squareup.javapoet.TypeSpec;
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.StandardOpenOption;
-import java.util.Random;
-import javax.lang.model.element.Modifier;
-
-/** Helper class of {@link JavaCodeGenerator} */
-class JavaCodeGeneratorHelper {
-
- private static final Joiner JOINER = Joiner.on("\n");
- private static final MethodSpec randomMethod = genRandomMethod("PrintSth");
- private static final MethodSpec somethingElseMethod = genRandomMethod("PrintSthElse");
-
- /**
- * Writes a class file {@code Deps(index).java} to the directory
- * {@code projectPath/com/example/deps(index)}
- *
- * @param callNext if we should call the method from {@code Deps(index+1).java}
- */
- static void targetWithNextHelper(int index, boolean callNext, Path projectPath)
- throws IOException {
- ClassName nextClass = ClassName.get("com.example.deps" + (index + 1), "Deps" + (index + 1));
-
- MethodSpec callNextMethod =
- MethodSpec.methodBuilder("CallNext")
- .addModifiers(Modifier.PUBLIC, Modifier.STATIC)
- .returns(void.class)
- .addStatement("$T.PrintSth()", nextClass)
- .build();
-
- TypeSpec.Builder klassBuilder =
- TypeSpec.classBuilder("Deps" + index)
- .addModifiers(Modifier.PUBLIC, Modifier.FINAL)
- .addMethod(randomMethod);
- if (callNext) {
- klassBuilder.addMethod(callNextMethod);
- }
- TypeSpec klass = klassBuilder.build();
-
- writeClassToDir(klass, "com.example.deps" + index, projectPath);
- }
-
- /**
- * Writes a class file {@code Deps(index).java} with extra method {@code printSthElse()}
- * to the directory {@code projectPath/com/example/deps(index)}
- *
- * @param callNext if we should call the method from {@code Deps(index+1).java}
- */
- static void targetWithNextExtraHelper(int index, boolean callNext, Path projectPath)
- throws IOException {
- ClassName nextClass = ClassName.get("com.example.deps" + (index + 1), "Deps" + (index + 1));
-
- MethodSpec callNextMethod =
- MethodSpec.methodBuilder("CallNext")
- .addModifiers(Modifier.PUBLIC, Modifier.STATIC)
- .returns(void.class)
- .addStatement("$T.PrintSth()", nextClass)
- .build();
-
- TypeSpec.Builder klassBuilder =
- TypeSpec.classBuilder("Deps" + index)
- .addModifiers(Modifier.PUBLIC, Modifier.FINAL)
- .addMethod(randomMethod)
- .addMethod(somethingElseMethod);
- if (callNext) {
- klassBuilder.addMethod(callNextMethod);
- }
- TypeSpec klass = klassBuilder.build();
-
- writeClassToDir(klass, "com.example.deps" + index, projectPath);
- }
-
- /**
- * Writes {@code count-1} class files to the directory {@code projectPath/com/example/deps(index)}
- * and one main class.
- */
- static void parallelDepsMainClassHelper(int count, Path projectPath) throws IOException {
- MethodSpec.Builder callDepsBuilder =
- MethodSpec.methodBuilder("main")
- .addModifiers(Modifier.PUBLIC, Modifier.STATIC)
- .addParameter(String[].class, "args")
- .returns(void.class);
- for (int i = 1; i < count; ++i) {
- ClassName callingClass = ClassName.get("com.example.deps" + i, "Deps" + i);
- callDepsBuilder.addStatement("$T.PrintSth()", callingClass);
- }
- MethodSpec callDeps = callDepsBuilder.build();
- TypeSpec klass =
- TypeSpec.classBuilder("Main")
- .addModifiers(Modifier.PUBLIC, Modifier.FINAL)
- .addMethod(callDeps)
- .build();
- writeClassToDir(klass, "com.example.generated", projectPath);
- }
-
- static void writeRandomClassToDir(
- boolean addExtraMethod, String className, String packageName, Path projectPath)
- throws IOException {
- TypeSpec klass = genRandomClass(addExtraMethod, className);
- writeClassToDir(klass, packageName, projectPath);
- }
-
- static void writeMainClassToDir(String packageName, Path projectPath) throws IOException {
- TypeSpec main = genMainClass();
- writeClassToDir(main, packageName, projectPath);
- }
-
- static void buildFileWithNextDeps(int index, String deps, Path projectPath) throws IOException {
- Path buildFilePath = projectPath.resolve("BUILD");
-
- String buildFileContent =
- String.format(
- JOINER
- .join(
- "java_library(",
- " name = 'Deps%d',",
- " srcs = glob([ 'com/example/deps%d/*.java' ]),",
- "%s",
- " visibility = [ '//visibility:public' ],",
- ")",
- ""),
- index,
- index,
- deps);
-
- createAndAppendFile(buildFilePath, buildFileContent);
- }
-
- static void buildFileWithMainClass(String targetName, String deps, Path projectPath)
- throws IOException {
- Path buildFilePath = projectPath.resolve("BUILD");
-
- String buildFileContent =
- String.format(
- JOINER
- .join(
- "java_binary(",
- " name = '%s',",
- " srcs = glob([ 'com/example/generated/*.java' ]),",
- " main_class = 'com.example.generated.Main',",
- "%s",
- ")",
- ""),
- targetName,
- deps);
-
- createAndAppendFile(buildFilePath, buildFileContent);
- }
-
- private static MethodSpec genRandomMethod(String methodName) {
- return MethodSpec.methodBuilder(methodName)
- .addModifiers(Modifier.PUBLIC, Modifier.STATIC)
- .returns(void.class)
- .addStatement("$T rand = new Random()", Random.class)
- .addStatement("int n = rand.nextInt(100)")
- .addStatement(
- "$T.out.format($S, $S, $L)",
- System.class,
- "This is method(%s) with random number(%d)\n",
- methodName,
- "n")
- .build();
- }
-
- private static TypeSpec genRandomClass(boolean addExtraMethod, String className) {
-
- TypeSpec.Builder klassBuilder =
- TypeSpec.classBuilder(className)
- .addModifiers(Modifier.PUBLIC, Modifier.FINAL)
- .addMethod(randomMethod);
-
- if (addExtraMethod) {
- klassBuilder.addMethod(somethingElseMethod);
- }
-
- return klassBuilder.build();
- }
-
- private static TypeSpec genMainClass() {
- MethodSpec method =
- MethodSpec.methodBuilder("main")
- .addModifiers(Modifier.PUBLIC, Modifier.STATIC)
- .returns(void.class)
- .addParameter(String[].class, "args")
- .build();
-
- return TypeSpec.classBuilder("Main").addModifiers(Modifier.PUBLIC).addMethod(method).build();
- }
-
- private static void writeClassToDir(TypeSpec klass, String packageName, Path path)
- throws IOException {
- JavaFile javaFile = JavaFile.builder(packageName, klass).build();
- javaFile.writeTo(path);
- }
-
- private static void createAndAppendFile(Path path, String content) throws IOException {
- if (!Files.exists(path)) {
- Files.createFile(path);
- }
- Files.write(path, content.getBytes(UTF_8), StandardOpenOption.APPEND);
- }
-
-}
diff --git a/src/tools/benchmark/java/com/google/devtools/build/benchmark/codegenerator/Main.java b/src/tools/benchmark/java/com/google/devtools/build/benchmark/codegenerator/Main.java
deleted file mode 100644
index f0d823175a..0000000000
--- a/src/tools/benchmark/java/com/google/devtools/build/benchmark/codegenerator/Main.java
+++ /dev/null
@@ -1,92 +0,0 @@
-// Copyright 2017 The Bazel Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package com.google.devtools.build.benchmark.codegenerator;
-
-import com.google.common.collect.ImmutableSet;
-import com.google.devtools.common.options.Options;
-import com.google.devtools.common.options.OptionsParsingException;
-import java.io.File;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/** Main class for generating code. */
-public class Main {
-
- private static final ImmutableSet<String> allowedProjectNames = ImmutableSet.of(
- CodeGenerator.TARGET_A_FEW_FILES,
- CodeGenerator.TARGET_MANY_FILES,
- CodeGenerator.TARGET_LONG_CHAINED_DEPS,
- CodeGenerator.TARGET_PARALLEL_DEPS);
-
- private static final Logger logger = Logger.getLogger(Main.class.getName());
-
- public static void main(String[] args) {
- GeneratorOptions opt = null;
- try {
- opt = parseArgs(args);
- } catch (Exception e) {
- if (!e.getMessage().isEmpty()) {
- logger.log(Level.SEVERE, e.getMessage());
- }
- System.exit(1);
- }
-
- // Generate or modify Java code
- CodeGenerator codeGenerator = new JavaCodeGenerator();
- generateOrModifyProject(opt, codeGenerator);
-
- // Generate or modify Cpp code
- codeGenerator = new CppCodeGenerator();
- generateOrModifyProject(opt, codeGenerator);
- }
-
- public static GeneratorOptions parseArgs(String[] args) throws OptionsParsingException {
- GeneratorOptions opt = Options.parse(GeneratorOptions.class, args).getOptions();
-
- // Check output_dir argument
- if (opt.outputDir.isEmpty()) {
- throw new IllegalArgumentException("--output_dir should not be empty.");
- }
- if (opt.modificationMode) {
- File dir = new File(opt.outputDir);
- if (!(dir.exists() && dir.isDirectory())) {
- throw new IllegalArgumentException(
- "--output_dir (" + opt.outputDir + ") does not contain code for modification.");
- }
- }
- // Check at least one type of package will be generated
- if (opt.projectNames.isEmpty()) {
- System.err.println(Options.getUsage(GeneratorOptions.class));
- throw new IllegalArgumentException("No type of package is specified.");
- }
- for (String projectName : opt.projectNames) {
- if (!allowedProjectNames.contains(projectName)) {
- throw new IllegalArgumentException("Project name " + projectName + " is not allowed.");
- }
- }
-
- return opt;
- }
-
- private static void generateOrModifyProject(GeneratorOptions opt, CodeGenerator codeGenerator) {
- if (opt.modificationMode) {
- codeGenerator.modifyExistingProject(
- opt.outputDir + codeGenerator.getDirSuffix(), ImmutableSet.copyOf(opt.projectNames));
- } else {
- codeGenerator.generateNewProject(
- opt.outputDir + codeGenerator.getDirSuffix(), ImmutableSet.copyOf(opt.projectNames));
- }
- }
-}
diff --git a/src/tools/benchmark/javatests/com/google/devtools/build/benchmark/BUILD b/src/tools/benchmark/javatests/com/google/devtools/build/benchmark/BUILD
deleted file mode 100644
index 105abbef42..0000000000
--- a/src/tools/benchmark/javatests/com/google/devtools/build/benchmark/BUILD
+++ /dev/null
@@ -1,46 +0,0 @@
-package(default_visibility = ["//src:__subpackages__"])
-
-filegroup(
- name = "srcs",
- srcs = glob(["*"]),
-)
-
-java_test(
- name = "MainTest",
- srcs = ["MainTest.java"],
- deps = [
- "//src/main/java/com/google/devtools/common/options",
- "//src/tools/benchmark/java/com/google/devtools/build/benchmark:benchmark_lib",
- "//third_party:junit4",
- "//third_party:truth",
- ],
-)
-
-java_test(
- name = "BazelBuildCaseTest",
- srcs = ["BazelBuildCaseTest.java"],
- deps = [
- "//src/tools/benchmark/java/com/google/devtools/build/benchmark:benchmark_lib",
- "//src/tools/benchmark/java/com/google/devtools/build/benchmark:build_data_java_proto",
- "//third_party:guava",
- "//third_party:junit4",
- "//third_party:truth",
- ],
-)
-
-java_test(
- name = "BazelBuilderTest",
- srcs = ["BazelBuilderTest.java"],
- # Needs git to run.
- tags = [
- "local",
- ],
- deps = [
- "//src/main/java/com/google/devtools/build/lib/shell",
- "//src/tools/benchmark/java/com/google/devtools/build/benchmark:benchmark_lib",
- "//src/tools/benchmark/java/com/google/devtools/build/benchmark:build_data_java_proto",
- "//third_party:guava",
- "//third_party:junit4",
- "//third_party:truth",
- ],
-)
diff --git a/src/tools/benchmark/javatests/com/google/devtools/build/benchmark/BazelBuildCaseTest.java b/src/tools/benchmark/javatests/com/google/devtools/build/benchmark/BazelBuildCaseTest.java
deleted file mode 100644
index ef7526a5d2..0000000000
--- a/src/tools/benchmark/javatests/com/google/devtools/build/benchmark/BazelBuildCaseTest.java
+++ /dev/null
@@ -1,101 +0,0 @@
-// Copyright 2017 The Bazel Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package com.google.devtools.build.benchmark;
-
-import static com.google.common.truth.Truth.assertThat;
-import static java.nio.charset.StandardCharsets.UTF_8;
-
-import com.google.common.collect.ImmutableSet;
-import java.io.File;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.nio.file.Path;
-import java.util.Scanner;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
-@RunWith(JUnit4.class)
-public class BazelBuildCaseTest {
-
- @Rule public TemporaryFolder folder = new TemporaryFolder();
-
- @Test
- public void testPrepareGeneratedCode_Copy() throws IOException {
- Path root = folder.newFolder("PrepareGeneratedCodeCopy").toPath();
- // Prepare source
- Path source = root.resolve("source");
- source.toFile().mkdir();
- try (PrintWriter writer = new PrintWriter(source.resolve("file").toFile(), UTF_8.name())) {
- writer.println("content");
- }
- // Prepare destination
- Path destination = root.resolve("destination");
- destination.toFile().mkdir();
-
- new BazelBuildCase().prepareGeneratedCode(source, destination);
-
- ImmutableSet<String> filenames = fileArrayToImmutableSet(destination.toFile().listFiles());
- assertThat(filenames).containsExactly("WORKSPACE", "file");
- assertThat(
- new Scanner(destination.resolve("file")).useDelimiter("\\Z").next()).isEqualTo("content");
- }
-
- @Test
- public void testPrepareGeneratedCode_Generate() throws IOException {
- Path root = folder.newFolder("PrepareGeneratedCodeGenerate").toPath();
- // Prepare source, don't mkdir
- Path source = root.resolve("source");
- // Prepare destination
- Path destination = root.resolve("destination");
- destination.toFile().mkdir();
-
- new BazelBuildCase().prepareGeneratedCode(source, destination);
-
- // Check both source and destination directory include generated code
- ImmutableSet<String> sourceList = fileArrayToImmutableSet(source.toFile().listFiles());
- ImmutableSet<String> destinationList =
- fileArrayToImmutableSet(destination.toFile().listFiles());
- assertThat(sourceList)
- .containsExactly("cpp", "java");
- assertThat(destinationList)
- .containsExactly("cpp", "java", "WORKSPACE");
-
- ImmutableSet<String> targets = ImmutableSet.of(
- "AFewFiles", "LongChainedDeps", "ManyFiles", "ParallelDeps");
- ImmutableSet<String> sourceCppList =
- fileArrayToImmutableSet(source.resolve("cpp").toFile().listFiles());
- ImmutableSet<String> sourceJavaList =
- fileArrayToImmutableSet(source.resolve("java").toFile().listFiles());
- ImmutableSet<String> destinationCppList =
- fileArrayToImmutableSet(destination.resolve("cpp").toFile().listFiles());
- ImmutableSet<String> destinationJavaList =
- fileArrayToImmutableSet(destination.resolve("java").toFile().listFiles());
- assertThat(sourceCppList).containsExactlyElementsIn(targets);
- assertThat(sourceJavaList).containsExactlyElementsIn(targets);
- assertThat(destinationCppList).containsExactlyElementsIn(targets);
- assertThat(destinationJavaList).containsExactlyElementsIn(targets);
- }
-
- private static ImmutableSet<String> fileArrayToImmutableSet(File[] files) {
- ImmutableSet.Builder<String> fileNames = ImmutableSet.builder();
- for (File file : files) {
- fileNames.add(file.getName());
- }
- return fileNames.build();
- }
-}
diff --git a/src/tools/benchmark/javatests/com/google/devtools/build/benchmark/BazelBuilderTest.java b/src/tools/benchmark/javatests/com/google/devtools/build/benchmark/BazelBuilderTest.java
deleted file mode 100644
index 33c53bef42..0000000000
--- a/src/tools/benchmark/javatests/com/google/devtools/build/benchmark/BazelBuilderTest.java
+++ /dev/null
@@ -1,112 +0,0 @@
-// Copyright 2017 The Bazel Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package com.google.devtools.build.benchmark;
-
-import static com.google.common.truth.Truth.assertThat;
-import static org.junit.Assert.fail;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableSet;
-import com.google.devtools.build.lib.shell.Command;
-import com.google.devtools.build.lib.shell.CommandException;
-import java.io.File;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
-@RunWith(JUnit4.class)
-public class BazelBuilderTest {
-
- private static final double EPSILON = 1e-4;
-
- @Rule public TemporaryFolder folder = new TemporaryFolder();
-
- @Test
- public void testGetCommandFromConfig() {
- BuildTargetConfig targetConfig = BuildTargetConfig.newBuilder().setBuildTarget("foo").build();
- BuildEnvConfig envConfig =
- BuildEnvConfig.newBuilder().addBuildArgs("apple").addBuildArgs("mango").build();
-
- ImmutableList<String> command =
- new BazelBuilder(null, null).getCommandFromConfig(targetConfig, envConfig);
-
- assertThat(command).containsExactly("build", "foo", "apple", "mango");
- }
-
- @Test
- public void testBuildAndGetElapsedTime() throws IOException, CommandException {
- Path root = folder.newFolder("BuildAndGetElapsedTime").toPath();
- Path generatedCode = root.resolve("GeneratedCode");
- Files.createDirectories(generatedCode);
- // Prepare binary
- Path buildBinary = root.resolve("binary.sh");
- Files.createFile(buildBinary);
- if (!buildBinary.toFile().setExecutable(true)) {
- fail("Failed to set executable");
- }
- double expectedValue = 10.42;
- try (PrintWriter writer = new PrintWriter(buildBinary.toFile())) {
- writer.format(
- "#!/bin/bash\n>&2 echo 'blah blah Elapsed time: %.2f blah blah'", expectedValue);
- }
-
- double result =
- new BazelBuilder(generatedCode, null)
- .buildAndGetElapsedTime(buildBinary, ImmutableList.<String>of());
-
- assertThat(result).isWithin(EPSILON).of(expectedValue);
- }
-
- @Test
- public void testPrepareFromGitRepo() throws IOException, CommandException {
- Path root = folder.newFolder("Prepare").toPath();
- // Create a git repo for clone
- Path repo = root.resolve("SimpleRepo");
- Files.createDirectories(repo);
- Files.createFile(repo.resolve("BUILD"));
- Files.createFile(repo.resolve("WORKSPACE"));
-
- ImmutableList<String[]> gitCommands = ImmutableList.of(
- new String[]{"git", "init"},
- new String[]{"git", "add", "."},
- new String[]{"git", "config", "user.email", "you@example.com"},
- new String[]{"git", "config", "user.name", "Your Name"},
- new String[]{"git", "commit", "-m", "empty"});
- for (String[] gitCommand : gitCommands) {
- (new Command(gitCommand, null, repo.toFile())).execute();
- }
-
- BazelBuilder builder = new BazelBuilder(root.resolve("GeneratedCode"), root.resolve("Builder"));
- builder.prepareFromGitRepo(repo.toString());
-
- ImmutableSet<String> fileList =
- fileArrayToImmutableSet(root.resolve("Builder").toFile().listFiles());
- assertThat(fileList).containsExactly(".git", "BUILD", "WORKSPACE");
- }
-
- private static ImmutableSet<String> fileArrayToImmutableSet(File[] files) {
- ImmutableSet.Builder<String> fileNames = ImmutableSet.builder();
- for (File file : files) {
- fileNames.add(file.getName());
- }
- return fileNames.build();
- }
-}
diff --git a/src/tools/benchmark/javatests/com/google/devtools/build/benchmark/MainTest.java b/src/tools/benchmark/javatests/com/google/devtools/build/benchmark/MainTest.java
deleted file mode 100644
index 4cf8216437..0000000000
--- a/src/tools/benchmark/javatests/com/google/devtools/build/benchmark/MainTest.java
+++ /dev/null
@@ -1,126 +0,0 @@
-// Copyright 2017 The Bazel Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package com.google.devtools.build.benchmark;
-
-import static com.google.common.truth.Truth.assertThat;
-import static org.junit.Assert.fail;
-
-import com.google.devtools.common.options.OptionsParsingException;
-import java.io.IOException;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
-/** Test for {@link Main}. */
-@RunWith(JUnit4.class)
-public class MainTest {
-
- private static final String TIME_FROM = "2017-02-06T18:00:00";
- private static final String TIME_TO = "2017-02-07T15:00:00";
- private static final String TIME_BETWEEN = TIME_FROM + ".." + TIME_TO;
- private static final String TIME_BETWEEN_WRONG_FORMAT = "2017-02-06T18:00..2017-02-07T15:00";
-
- @Test
- public void testParseArgs_MissingArgs() throws OptionsParsingException, IOException {
- try {
- Main.parseArgs(new String[] {"--workspace=workspace", "--version_between=1..2"});
- fail("Should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- assertThat(e)
- .hasMessageThat()
- .isEqualTo("Argument --workspace and --output should not be empty.");
- }
- }
-
- @Test
- public void testParseArgs_MultipleFilter() throws OptionsParsingException, IOException {
- try {
- Main.parseArgs(new String[] {
- "--output=output", "--workspace=workspace",
- "--version_between=1..2", "--time_between=" + TIME_BETWEEN});
- fail("Should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- assertThat(e)
- .hasMessageThat()
- .isEqualTo("Please use exact one type of version filter at a time.");
- }
- }
-
- @Test
- public void testParseArgs_WrongVersionBetween() throws OptionsParsingException, IOException {
- try {
- Main.parseArgs(
- new String[]{"--output=output", "--workspace=workspace", "--version_between=1.3"});
- fail("Should throw OptionsParsingException");
- } catch (OptionsParsingException e) {
- assertThat(e)
- .hasMessageThat()
- .isEqualTo(
- "While parsing option --version_between=1.3: "
- + "Error parsing version_filter option: no '..' found.");
- }
- }
-
- @Test
- public void testParseArgs_CorrectVersionBetween() throws OptionsParsingException, IOException {
- BenchmarkOptions opt =
- Main.parseArgs(
- new String[] {"--output=output", "--workspace=workspace", "--version_between=1..3"});
- assertThat(opt.output).isEqualTo("output");
- assertThat(opt.workspace).isEqualTo("workspace");
- assertThat(opt.versionFilter.getFrom()).isEqualTo("1");
- assertThat(opt.versionFilter.getTo()).isEqualTo("3");
- }
-
- @Test
- public void testParseArgs_WrongTimeBetween() throws OptionsParsingException, IOException {
- try {
- Main.parseArgs(
- new String[]{"--output=output", "--workspace=workspace",
- "--time_between=" + TIME_BETWEEN_WRONG_FORMAT});
- fail("Should throw OptionsParsingException");
- } catch (OptionsParsingException e) {
- assertThat(e)
- .hasMessageThat()
- .isEqualTo(
- "While parsing option --time_between="
- + TIME_BETWEEN_WRONG_FORMAT
- + ": Error parsing datetime, format should be: yyyy-MM-ddTHH:mm:ss");
- }
- }
-
- @Test
- public void testParseArgs_CorrectTimeBetween() throws OptionsParsingException, IOException {
- BenchmarkOptions opt =
- Main.parseArgs(
- new String[] {"--output=output", "--workspace=workspace",
- "--time_between=" + TIME_BETWEEN});
- assertThat(opt.output).isEqualTo("output");
- assertThat(opt.workspace).isEqualTo("workspace");
- assertThat(opt.dateFilter.getFromString()).isEqualTo(TIME_FROM);
- assertThat(opt.dateFilter.getToString()).isEqualTo(TIME_TO);
- }
-
- @Test
- public void testParseArgs_CorrectVersions() throws OptionsParsingException, IOException {
- BenchmarkOptions opt =
- Main.parseArgs(
- new String[] {"--output=output", "--workspace=workspace",
- "--versions=v1", "--versions=v2", "--versions=v4"});
- assertThat(opt.output).isEqualTo("output");
- assertThat(opt.workspace).isEqualTo("workspace");
- assertThat(opt.versions).containsExactly("v1", "v2", "v4");
- }
-}
diff --git a/src/tools/benchmark/javatests/com/google/devtools/build/benchmark/codegenerator/BUILD b/src/tools/benchmark/javatests/com/google/devtools/build/benchmark/codegenerator/BUILD
deleted file mode 100644
index 6098e7ce53..0000000000
--- a/src/tools/benchmark/javatests/com/google/devtools/build/benchmark/codegenerator/BUILD
+++ /dev/null
@@ -1,61 +0,0 @@
-package(default_visibility = ["//src:__subpackages__"])
-
-filegroup(
- name = "srcs",
- srcs = glob(["*"]),
-)
-
-java_test(
- name = "JavaCodeGeneratorHelperTest",
- srcs = ["JavaCodeGeneratorHelperTest.java"],
- deps = [
- "//src/tools/benchmark/java/com/google/devtools/build/benchmark/codegenerator:codegenerator_lib",
- "//third_party:guava",
- "//third_party:junit4",
- "//third_party:truth",
- ],
-)
-
-java_test(
- name = "JavaCodeGeneratorTest",
- srcs = ["JavaCodeGeneratorTest.java"],
- deps = [
- "//src/tools/benchmark/java/com/google/devtools/build/benchmark/codegenerator:codegenerator_lib",
- "//third_party:guava",
- "//third_party:junit4",
- "//third_party:truth",
- ],
-)
-
-java_test(
- name = "CppCodeGeneratorHelperTest",
- srcs = ["CppCodeGeneratorHelperTest.java"],
- deps = [
- "//src/tools/benchmark/java/com/google/devtools/build/benchmark/codegenerator:codegenerator_lib",
- "//third_party:guava",
- "//third_party:junit4",
- "//third_party:truth",
- ],
-)
-
-java_test(
- name = "CppCodeGeneratorTest",
- srcs = ["CppCodeGeneratorTest.java"],
- deps = [
- "//src/tools/benchmark/java/com/google/devtools/build/benchmark/codegenerator:codegenerator_lib",
- "//third_party:guava",
- "//third_party:junit4",
- "//third_party:truth",
- ],
-)
-
-java_test(
- name = "MainTest",
- srcs = ["MainTest.java"],
- deps = [
- "//src/main/java/com/google/devtools/common/options",
- "//src/tools/benchmark/java/com/google/devtools/build/benchmark/codegenerator:codegenerator_lib",
- "//third_party:junit4",
- "//third_party:truth",
- ],
-)
diff --git a/src/tools/benchmark/javatests/com/google/devtools/build/benchmark/codegenerator/CppCodeGeneratorHelperTest.java b/src/tools/benchmark/javatests/com/google/devtools/build/benchmark/codegenerator/CppCodeGeneratorHelperTest.java
deleted file mode 100644
index aea46ff88c..0000000000
--- a/src/tools/benchmark/javatests/com/google/devtools/build/benchmark/codegenerator/CppCodeGeneratorHelperTest.java
+++ /dev/null
@@ -1,283 +0,0 @@
-// Copyright 2017 The Bazel Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package com.google.devtools.build.benchmark.codegenerator;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import com.google.common.base.Joiner;
-import java.io.IOException;
-import java.nio.file.Path;
-import java.util.Scanner;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
-/** Test for {@link CppCodeGeneratorHelper}. */
-@RunWith(JUnit4.class)
-public class CppCodeGeneratorHelperTest {
-
- private static final String RANDOM_CLASS_HEADER_CONTENT = joinLines(
- "class ClassName {",
- "public:",
- " static void printSth();",
- "};");
-
- private static final String RANDOM_CLASS_CONTENT = joinLines(
- "#include <random>",
- "#include <iostream>",
- "#include <ctime>",
- "using namespace std;",
- "",
- "class ClassName {",
- "public:",
- " static void printSth() {",
- " srand(time(NULL));",
- " int n = rand();",
- " cout << \"This is method(printSth) with random number(\" << n << \")\\n\";",
- " }",
- "};");
-
- private static final String RANDOM_CLASS_HEADER_EXTRA_CONTENT = joinLines(
- "class ClassName {",
- "public:",
- " static void printSth();",
- " static void printSthElse();",
- "};");
-
- private static final String RANDOM_CLASS_EXTRA_CONTENT = joinLines(
- "#include <random>",
- "#include <iostream>",
- "#include <ctime>",
- "using namespace std;",
- "",
- "class ClassName {",
- "public:",
- " static void printSth() {",
- " srand(time(NULL));",
- " int n = rand();",
- " cout << \"This is method(printSth) with random number(\" << n << \")\\n\";",
- " }",
- " static void printSthElse() {",
- " srand(time(NULL));",
- " int n = rand();",
- " cout << \"This is method(printSthElse) with random number(\" << n << \")\\n\";",
- " }",
- "};");
-
- private static final String ALL_FILES_BUILD_FILE_CONTENT = joinLines(
- "cc_library(",
- " name = 'target',",
- " srcs = glob([ '*.cc', '*.h' ]),",
- ")");
-
- private static final String RANDOM_CLASS_HEADER_NEXT_CONTENT = joinLines(
- "class Deps42 {",
- "public:",
- " static void printSth();",
- " static void callNext();",
- "};");
-
- private static final String RANDOM_CLASS_NEXT_CONTENT = joinLines(
- "#include <random>",
- "#include <iostream>",
- "#include <ctime>",
- "#include \"Deps43.h\"",
- "using namespace std;",
- "",
- "class Deps42 {",
- "public:",
- " static void printSth() {",
- " srand(time(NULL));",
- " int n = rand();",
- " cout << \"This is method(printSth) with random number(\" << n << \")\\n\";",
- " }",
- " static void callNext() {",
- " Deps43::printSth();",
- " }",
- "};");
-
- private static final String BUILD_FILE_NEXT_CONTENT = joinLines(
- "cc_library(",
- " name = 'Deps42',",
- " srcs = [ 'Deps42.cc', 'Deps42.h' ],",
- " deps = [ ':Deps43' ],",
- ")");
-
- private static final String RANDOM_CLASS_HEADER_NEXT_EXTRA_CONTENT = joinLines(
- "class Deps42 {",
- "public:",
- " static void printSth();",
- " static void printSthElse();",
- " static void callNext();",
- "};");
-
- private static final String RANDOM_CLASS_NEXT_EXTRA_CONTENT = joinLines(
- "#include <random>",
- "#include <iostream>",
- "#include <ctime>",
- "#include \"Deps43.h\"",
- "using namespace std;",
- "",
- "class Deps42 {",
- "public:",
- " static void printSth() {",
- " srand(time(NULL));",
- " int n = rand();",
- " cout << \"This is method(printSth) with random number(\" << n << \")\\n\";",
- " }",
- " static void printSthElse() {",
- " srand(time(NULL));",
- " int n = rand();",
- " cout << \"This is method(printSthElse) with random number(\" << n << \")\\n\";",
- " }",
- " static void callNext() {",
- " Deps43::printSth();",
- " }",
- "};");
-
- private static final String BUILD_FILE_CONTENT = joinLines(
- "cc_library(",
- " name = 'target',",
- " srcs = [ 'target.cc', 'target.h' ],",
- ")");
-
- private static final String MAIN_CLASS_CONTENT = joinLines(
- "int main() {",
- " return 0;",
- "}");
-
- private static final String MAIN_CLASS_BUILD_FILE_CONTENT = joinLines(
- "cc_binary(",
- " name = 'target',",
- " srcs = [ 'Main.cc' ],",
- "This is deps",
- ")");
-
- @Rule
- public TemporaryFolder folder = new TemporaryFolder();
-
- @Test
- public void testCreateRandomClass() throws IOException {
- Path dir = folder.newFolder("CreateRandomClass").toPath();
- CppCodeGeneratorHelper.createRandomClass("ClassName", dir);
-
- Path cppFile = dir.resolve("ClassName.h");
- assertThat(cppFile.toFile().exists()).isTrue();
- String content = new Scanner(cppFile).useDelimiter("\\Z").next();
- assertThat(content).isEqualTo(RANDOM_CLASS_HEADER_CONTENT);
-
- cppFile = dir.resolve("ClassName.cc");
- assertThat(cppFile.toFile().exists()).isTrue();
- content = new Scanner(cppFile).useDelimiter("\\Z").next();
- assertThat(content).isEqualTo(RANDOM_CLASS_CONTENT);
- }
-
- @Test
- public void testCreateRandomClassExtra() throws IOException {
- Path dir = folder.newFolder("CreateRandomClassExtra").toPath();
- CppCodeGeneratorHelper.createRandomClassExtra("ClassName", dir);
-
- Path cppFile = dir.resolve("ClassName.h");
- assertThat(cppFile.toFile().exists()).isTrue();
- String content = new Scanner(cppFile).useDelimiter("\\Z").next();
- assertThat(content).isEqualTo(RANDOM_CLASS_HEADER_EXTRA_CONTENT);
-
- cppFile = dir.resolve("ClassName.cc");
- assertThat(cppFile.toFile().exists()).isTrue();
- content = new Scanner(cppFile).useDelimiter("\\Z").next();
- assertThat(content).isEqualTo(RANDOM_CLASS_EXTRA_CONTENT);
- }
-
- @Test
- public void testWriteBuildFileWithAllFilesToDir() throws IOException {
- Path dir = folder.newFolder("WriteBuildFileWithAllFilesToDir").toPath();
- CppCodeGeneratorHelper.writeBuildFileWithAllFilesToDir("target", dir);
-
- Path buildFile = dir.resolve("BUILD");
- assertThat(buildFile.toFile().exists()).isTrue();
- String content = new Scanner(buildFile).useDelimiter("\\Z").next();
- assertThat(content).isEqualTo(ALL_FILES_BUILD_FILE_CONTENT);
- }
-
- @Test
- public void testCreateClassAndBuildFileWithDepsNext() throws IOException {
- Path dir = folder.newFolder("CreateClassAndBuildFileWithDepsNext").toPath();
- CppCodeGeneratorHelper.createClassAndBuildFileWithDepsNext(42, dir);
-
- Path file = dir.resolve("Deps42.h");
- assertThat(file.toFile().exists()).isTrue();
- String content = new Scanner(file).useDelimiter("\\Z").next();
- assertThat(content).isEqualTo(RANDOM_CLASS_HEADER_NEXT_CONTENT);
-
- file = dir.resolve("Deps42.cc");
- assertThat(file.toFile().exists()).isTrue();
- content = new Scanner(file).useDelimiter("\\Z").next();
- assertThat(content).isEqualTo(RANDOM_CLASS_NEXT_CONTENT);
-
- file = dir.resolve("BUILD");
- assertThat(file.toFile().exists()).isTrue();
- content = new Scanner(file).useDelimiter("\\Z").next();
- assertThat(content).isEqualTo(BUILD_FILE_NEXT_CONTENT);
- }
-
- @Test
- public void testCreateClassWithDepsNextExtra() throws IOException {
- Path dir = folder.newFolder("CreateClassWithDepsNextExtra").toPath();
- CppCodeGeneratorHelper.createClassWithDepsNextExtra(42, dir);
-
- Path file = dir.resolve("Deps42.h");
- assertThat(file.toFile().exists()).isTrue();
- String content = new Scanner(file).useDelimiter("\\Z").next();
- assertThat(content).isEqualTo(RANDOM_CLASS_HEADER_NEXT_EXTRA_CONTENT);
-
- file = dir.resolve("Deps42.cc");
- assertThat(file.toFile().exists()).isTrue();
- content = new Scanner(file).useDelimiter("\\Z").next();
- assertThat(content).isEqualTo(RANDOM_CLASS_NEXT_EXTRA_CONTENT);
- }
-
- @Test
- public void testAppendTargetToBuildFile() throws IOException {
- Path dir = folder.newFolder("AppendTargetToBuildFile").toPath();
- CppCodeGeneratorHelper.appendTargetToBuildFile("target", dir);
-
- Path file = dir.resolve("BUILD");
- assertThat(file.toFile().exists()).isTrue();
- String content = new Scanner(file).useDelimiter("\\Z").next();
- assertThat(content).isEqualTo(BUILD_FILE_CONTENT);
- }
-
- @Test
- public void testCreateMainClassAndBuildFileWithDeps() throws IOException {
- Path dir = folder.newFolder("CreateMainClassAndBuildFileWithDeps").toPath();
- CppCodeGeneratorHelper.createMainClassAndBuildFileWithDeps("target", "This is deps", dir);
-
- Path file = dir.resolve("Main.cc");
- assertThat(file.toFile().exists()).isTrue();
- String content = new Scanner(file).useDelimiter("\\Z").next();
- assertThat(content).isEqualTo(MAIN_CLASS_CONTENT);
-
- file = dir.resolve("BUILD");
- assertThat(file.toFile().exists()).isTrue();
- content = new Scanner(file).useDelimiter("\\Z").next();
- assertThat(content).isEqualTo(MAIN_CLASS_BUILD_FILE_CONTENT);
- }
-
- private static String joinLines(String... lines) {
- return Joiner.on("\n").join(lines);
- }
-}
diff --git a/src/tools/benchmark/javatests/com/google/devtools/build/benchmark/codegenerator/CppCodeGeneratorTest.java b/src/tools/benchmark/javatests/com/google/devtools/build/benchmark/codegenerator/CppCodeGeneratorTest.java
deleted file mode 100644
index 500cf704b8..0000000000
--- a/src/tools/benchmark/javatests/com/google/devtools/build/benchmark/codegenerator/CppCodeGeneratorTest.java
+++ /dev/null
@@ -1,112 +0,0 @@
-// Copyright 2017 The Bazel Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package com.google.devtools.build.benchmark.codegenerator;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import com.google.common.collect.ImmutableSet;
-
-import java.io.File;
-import java.io.IOException;
-import java.nio.file.Path;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
-/** Test for {@link CppCodeGenerator}. */
-@RunWith(JUnit4.class)
-public class CppCodeGeneratorTest {
-
- @Rule public TemporaryFolder folder = new TemporaryFolder();
-
- @Test
- public void testGenerateNewProject() throws IOException {
- File createdFolder = folder.newFolder("GenerateNewProject");
- Path dir = createdFolder.toPath();
- CppCodeGenerator cppCodeGenerator = new CppCodeGenerator();
- cppCodeGenerator.generateNewProject(dir.toString(), ImmutableSet.of(
- CppCodeGenerator.TARGET_A_FEW_FILES,
- CppCodeGenerator.TARGET_LONG_CHAINED_DEPS,
- CppCodeGenerator.TARGET_MANY_FILES,
- CppCodeGenerator.TARGET_PARALLEL_DEPS
- ));
-
- // Check dir contains 4 project directories
- File[] filesList = dir.toFile().listFiles();
- assertThat(filesList).isNotNull();
- ImmutableSet<String> filenames = fileArrayToImmutableSet(filesList);
- assertThat(filenames).containsExactly(
- CppCodeGenerator.TARGET_A_FEW_FILES,
- CppCodeGenerator.TARGET_LONG_CHAINED_DEPS,
- CppCodeGenerator.TARGET_MANY_FILES,
- CppCodeGenerator.TARGET_PARALLEL_DEPS);
-
- // Target 1: a few files
- checkSimpleTarget(
- dir, CppCodeGenerator.TARGET_A_FEW_FILES, cppCodeGenerator.getSizeAFewFiles());
-
- // Target 2: many files
- checkSimpleTarget(dir, CppCodeGenerator.TARGET_MANY_FILES, cppCodeGenerator.getSizeManyFiles());
-
- // Target 3: long chained deps
- checkDepsTarget(
- dir, CppCodeGenerator.TARGET_LONG_CHAINED_DEPS, cppCodeGenerator.getSizeLongChainedDeps());
-
- // Target 4: parallel deps
- checkDepsTarget(
- dir, CppCodeGenerator.TARGET_PARALLEL_DEPS, cppCodeGenerator.getSizeParallelDeps());
- }
-
- private static ImmutableSet<String> fileArrayToImmutableSet(File[] files) {
- ImmutableSet.Builder<String> builder = ImmutableSet.builder();
- for (File file : files) {
- builder.add(file.getName());
- }
- return builder.build();
- }
-
- private static void checkSimpleTarget(Path root, String targetName, int targetSize) {
- // Check all files including BUILD, .cc, .h
- File[] filesList =
- root.resolve(targetName).toFile().listFiles();
- assertThat(filesList).isNotNull();
- ImmutableSet<String> filenames = fileArrayToImmutableSet(filesList);
- ImmutableSet.Builder<String> randomClassNames = ImmutableSet.builder();
- randomClassNames.add("BUILD");
- for (int i = 0; i < targetSize; ++i) {
- randomClassNames.add("RandomClass" + i + ".h");
- randomClassNames.add("RandomClass" + i + ".cc");
- }
- assertThat(filenames).containsExactlyElementsIn(randomClassNames.build());
- }
-
- private static void checkDepsTarget(Path root, String targetName, int targetSize) {
- // Check all files including BUILD, .cc, .h
- File[] filesList =
- root.resolve(targetName).toFile().listFiles();
- assertThat(filesList).isNotNull();
- ImmutableSet<String> filenames = fileArrayToImmutableSet(filesList);
- ImmutableSet.Builder<String> randomClassNames = ImmutableSet.builder();
- randomClassNames.add("BUILD");
- randomClassNames.add("Main.cc");
- for (int i = 1; i < targetSize; ++i) {
- randomClassNames.add("Deps" + i + ".h");
- randomClassNames.add("Deps" + i + ".cc");
- }
- assertThat(filenames).containsExactlyElementsIn(randomClassNames.build());
- }
-} \ No newline at end of file
diff --git a/src/tools/benchmark/javatests/com/google/devtools/build/benchmark/codegenerator/JavaCodeGeneratorHelperTest.java b/src/tools/benchmark/javatests/com/google/devtools/build/benchmark/codegenerator/JavaCodeGeneratorHelperTest.java
deleted file mode 100644
index 1217e962a5..0000000000
--- a/src/tools/benchmark/javatests/com/google/devtools/build/benchmark/codegenerator/JavaCodeGeneratorHelperTest.java
+++ /dev/null
@@ -1,254 +0,0 @@
-// Copyright 2017 The Bazel Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package com.google.devtools.build.benchmark.codegenerator;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import com.google.common.base.Joiner;
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.util.Scanner;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
-/** Test for {@link JavaCodeGeneratorHelper}. */
-@RunWith(JUnit4.class)
-public class JavaCodeGeneratorHelperTest {
-
- private static final String RANDOM_CLASS_CONTENT = joinLines(
- "package com.package.name;",
- "",
- "import java.lang.System;",
- "import java.util.Random;",
- "",
- "public final class ClassName {",
- " public static void PrintSth() {",
- " Random rand = new Random();",
- " int n = rand.nextInt(100);",
- " System.out.format(\"This is method(%s) with random number(%d)\\n\", \"PrintSth\", n);",
- " }",
- "}");
-
- private static final String RANDOM_CLASS_EXTRA_CONTENT = joinLines(
- "package com.package.name;",
- "",
- "import java.lang.System;",
- "import java.util.Random;",
- "",
- "public final class ClassNameExtra {",
- " public static void PrintSth() {",
- " Random rand = new Random();",
- " int n = rand.nextInt(100);",
- " System.out.format(\"This is method(%s) with random number(%d)\\n\", \"PrintSth\", n);",
- " }",
- "",
- " public static void PrintSthElse() {",
- " Random rand = new Random();",
- " int n = rand.nextInt(100);",
- " System.out.format(\"This is method(%s) with random number(%d)\\n\","
- + " \"PrintSthElse\", n);",
- " }",
- "}");
-
- private static final String MAIN_CLASS_CONTENT = joinLines(
- "package com.package.name;",
- "",
- "import java.lang.String;",
- "",
- "public class Main {",
- " public static void main(String[] args) {",
- " }",
- "}");
-
- private static final String DEPS_BUILD_FILE_CONTENT = joinLines(
- "java_library(",
- " name = 'Deps42',",
- " srcs = glob([ 'com/example/deps42/*.java' ]),",
- "<this is deps>",
- " visibility = [ '//visibility:public' ],",
- ")");
-
- private static final String TARGET_BUILD_FILE_CONTENT = joinLines(
- "java_binary(",
- " name = 'Target',",
- " srcs = glob([ 'com/example/generated/*.java' ]),",
- " main_class = 'com.example.generated.Main',",
- "<this is deps>",
- ")");
-
- private static final String DEPS_CLASS_CONTENT = joinLines(
- "package com.example.deps42;",
- "",
- "import com.example.deps43.Deps43;",
- "import java.lang.System;",
- "import java.util.Random;",
- "",
- "public final class Deps42 {",
- " public static void PrintSth() {",
- " Random rand = new Random();",
- " int n = rand.nextInt(100);",
- " System.out.format(\"This is method(%s) with random number(%d)\\n\", \"PrintSth\", n);",
- " }",
- "",
- " public static void CallNext() {",
- " Deps43.PrintSth();",
- " }",
- "}");
-
- private static final String DEPS_CLASS_EXTRA_CONTENT = joinLines(
- "package com.example.deps42;",
- "",
- "import java.lang.System;",
- "import java.util.Random;",
- "",
- "public final class Deps42 {",
- " public static void PrintSth() {",
- " Random rand = new Random();",
- " int n = rand.nextInt(100);",
- " System.out.format(\"This is method(%s) with random number(%d)\\n\", \"PrintSth\", n);",
- " }",
- "",
- " public static void PrintSthElse() {",
- " Random rand = new Random();",
- " int n = rand.nextInt(100);",
- " System.out.format(\"This is method(%s) with random number(%d)\\n\","
- + " \"PrintSthElse\", n);",
- " }",
- "}");
-
- private static final String MAIN_CLASS_WITH_DEPS_CONTENT = joinLines(
- "package com.example.generated;",
- "",
- "import com.example.deps1.Deps1;",
- "import com.example.deps2.Deps2;",
- "import com.example.deps3.Deps3;",
- "import java.lang.String;",
- "",
- "public final class Main {",
- " public static void main(String[] args) {",
- " Deps1.PrintSth();",
- " Deps2.PrintSth();",
- " Deps3.PrintSth();",
- " }",
- "}");
-
- @Rule public TemporaryFolder folder = new TemporaryFolder();
-
- @Test
- public void testWriteRandomClassToDir() throws IOException {
- Path dir = folder.newFolder("WriteRandomClassToDir").toPath();
- JavaCodeGeneratorHelper.writeRandomClassToDir(false, "ClassName", "com.package.name", dir);
-
- Path javaFile = dir.resolve("com/package/name/ClassName.java");
- assertThat(javaFile.toFile().exists()).isTrue();
-
- String content = new Scanner(javaFile).useDelimiter("\\Z").next();
- assertThat(content).isEqualTo(RANDOM_CLASS_CONTENT);
- }
-
- @Test
- public void testWriteRandomClassToDirExtraMethod() throws IOException {
- Path dir = folder.newFolder("WriteRandomClassToDirExtraMethod").toPath();
- JavaCodeGeneratorHelper.writeRandomClassToDir(true, "ClassNameExtra", "com.package.name", dir);
-
- Path javaFile = dir.resolve("com/package/name/ClassNameExtra.java");
- assertThat(javaFile.toFile().exists()).isTrue();
-
- String content = new Scanner(javaFile).useDelimiter("\\Z").next();
- assertThat(content).isEqualTo(RANDOM_CLASS_EXTRA_CONTENT);
- }
-
- @Test
- public void testWriteMainClassToDir() throws IOException {
- Path dir = folder.newFolder("WriteMainClassToDir").toPath();
- JavaCodeGeneratorHelper.writeMainClassToDir("com.package.name", dir);
-
- Path javaFile = dir.resolve("com/package/name/Main.java");
- assertThat(javaFile.toFile().exists()).isTrue();
-
- String content = new Scanner(javaFile).useDelimiter("\\Z").next();
- assertThat(content).isEqualTo(MAIN_CLASS_CONTENT);
- }
-
- @Test
- public void testBuildFileWithNextDeps() throws IOException {
- Path dir = folder.newFolder("BuildFileWithNextDeps").toPath();
- Files.createDirectories(dir);
- JavaCodeGeneratorHelper.buildFileWithNextDeps(42, "<this is deps>", dir);
-
- Path buildFile = dir.resolve("BUILD");
- assertThat(buildFile.toFile().exists()).isTrue();
-
- String content = new Scanner(buildFile).useDelimiter("\\Z").next();
- assertThat(content).isEqualTo(DEPS_BUILD_FILE_CONTENT);
- }
-
- @Test
- public void testBuildFileWithMainClass() throws IOException {
- Path dir = folder.newFolder("BuildFileWithMainClass").toPath();
- Files.createDirectories(dir);
- JavaCodeGeneratorHelper.buildFileWithMainClass("Target", "<this is deps>", dir);
-
- Path buildFile = dir.resolve("BUILD");
- assertThat(buildFile.toFile().exists()).isTrue();
-
- String content = new Scanner(buildFile).useDelimiter("\\Z").next();
- assertThat(content).isEqualTo(TARGET_BUILD_FILE_CONTENT);
- }
-
- @Test
- public void testTargetWithNextHelper() throws IOException {
- Path dir = folder.newFolder("TargetWithNextHelper").toPath();
- JavaCodeGeneratorHelper.targetWithNextHelper(42, true, dir);
-
- Path javaFile = dir.resolve("com/example/deps42/Deps42.java");
- assertThat(javaFile.toFile().exists()).isTrue();
-
- String content = new Scanner(javaFile).useDelimiter("\\Z").next();
- assertThat(content).isEqualTo(DEPS_CLASS_CONTENT);
- }
-
- @Test
- public void testTargetWithNextExtraHelper() throws IOException {
- Path dir = folder.newFolder("TargetWithNextHelperExtra").toPath();
- JavaCodeGeneratorHelper.targetWithNextExtraHelper(42, false, dir);
-
- Path javaFile = dir.resolve("com/example/deps42/Deps42.java");
- assertThat(javaFile.toFile().exists()).isTrue();
-
- String content = new Scanner(javaFile).useDelimiter("\\Z").next();
- assertThat(content).isEqualTo(DEPS_CLASS_EXTRA_CONTENT);
- }
-
- @Test
- public void testParallelDepsMainClassHelper() throws IOException {
- Path dir = folder.newFolder("ParallelDepsMainClassHelper").toPath();
- JavaCodeGeneratorHelper.parallelDepsMainClassHelper(4, dir);
-
- Path javaFile = dir.resolve("com/example/generated/Main.java");
- assertThat(javaFile.toFile().exists()).isTrue();
-
- String content = new Scanner(javaFile).useDelimiter("\\Z").next();
- assertThat(content).isEqualTo(MAIN_CLASS_WITH_DEPS_CONTENT);
- }
-
- private static String joinLines(String... lines) {
- return Joiner.on("\n").join(lines);
- }
-}
diff --git a/src/tools/benchmark/javatests/com/google/devtools/build/benchmark/codegenerator/JavaCodeGeneratorTest.java b/src/tools/benchmark/javatests/com/google/devtools/build/benchmark/codegenerator/JavaCodeGeneratorTest.java
deleted file mode 100644
index 6472772216..0000000000
--- a/src/tools/benchmark/javatests/com/google/devtools/build/benchmark/codegenerator/JavaCodeGeneratorTest.java
+++ /dev/null
@@ -1,129 +0,0 @@
-// Copyright 2017 The Bazel Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package com.google.devtools.build.benchmark.codegenerator;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import com.google.common.collect.ImmutableSet;
-import java.io.File;
-import java.io.IOException;
-import java.nio.file.Path;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
-/** Test for {@link JavaCodeGenerator}. */
-@RunWith(JUnit4.class)
-public class JavaCodeGeneratorTest {
-
- @Rule public TemporaryFolder folder = new TemporaryFolder();
-
- @Test
- public void testGenerateNewProject() throws IOException {
- File createdFolder = folder.newFolder("GenerateNewProject");
- Path dir = createdFolder.toPath();
- JavaCodeGenerator javaCodeGenerator = new JavaCodeGenerator();
- javaCodeGenerator.generateNewProject(dir.toString(), ImmutableSet.of(
- JavaCodeGenerator.TARGET_A_FEW_FILES,
- JavaCodeGenerator.TARGET_LONG_CHAINED_DEPS,
- JavaCodeGenerator.TARGET_MANY_FILES,
- JavaCodeGenerator.TARGET_PARALLEL_DEPS));
-
- // Check dir contains 4 project directories
- File[] filesList = dir.toFile().listFiles();
- assertThat(filesList).isNotNull();
- ImmutableSet<String> filenames = fileArrayToImmutableSet(filesList);
- assertThat(filenames).containsExactly(
- JavaCodeGenerator.TARGET_A_FEW_FILES,
- JavaCodeGenerator.TARGET_LONG_CHAINED_DEPS,
- JavaCodeGenerator.TARGET_MANY_FILES,
- JavaCodeGenerator.TARGET_PARALLEL_DEPS);
-
- // Target 1: a few files
- checkProjectPathContains(dir, JavaCodeGenerator.TARGET_A_FEW_FILES);
- checkSimpleTarget(
- dir, JavaCodeGenerator.TARGET_A_FEW_FILES, javaCodeGenerator.getSizeAFewFiles());
-
- // Target 2: many files
- checkProjectPathContains(dir, JavaCodeGenerator.TARGET_MANY_FILES);
- checkSimpleTarget(
- dir, JavaCodeGenerator.TARGET_MANY_FILES, javaCodeGenerator.getSizeManyFiles());
-
- // Target 3: long chained deps
- checkProjectPathContains(dir, JavaCodeGenerator.TARGET_LONG_CHAINED_DEPS);
- checkDepsTarget(
- dir, JavaCodeGenerator.TARGET_LONG_CHAINED_DEPS,
- javaCodeGenerator.getSizeLongChainedDeps());
-
- // Target 4: parallel deps
- checkProjectPathContains(dir, JavaCodeGenerator.TARGET_PARALLEL_DEPS);
- checkDepsTarget(
- dir, JavaCodeGenerator.TARGET_PARALLEL_DEPS, javaCodeGenerator.getSizeParallelDeps());
- }
-
- private static ImmutableSet<String> fileArrayToImmutableSet(File[] files) {
- ImmutableSet.Builder<String> builder = ImmutableSet.builder();
- for (File file : files) {
- builder.add(file.getName());
- }
- return builder.build();
- }
-
- private static void checkProjectPathContains(Path root, String targetName) {
- // Check project dir contains BUILD and com
- File[] filesList = root.resolve(targetName).toFile().listFiles();
- assertThat(filesList).isNotNull();
- ImmutableSet<String> filenames = fileArrayToImmutableSet(filesList);
- assertThat(filenames).containsExactly("BUILD", "com");
-
- // Check project dir contains com/example
- filesList = root.resolve(targetName).resolve("com").toFile().listFiles();
- assertThat(filesList).isNotNull();
- filenames = fileArrayToImmutableSet(filesList);
- assertThat(filenames).containsExactly("example");
- }
-
- private static void checkSimpleTarget(Path root, String targetName, int targetSize) {
- // Check Java files
- File[] filesList =
- root.resolve(targetName).resolve("com/example/generated").toFile().listFiles();
- assertThat(filesList).isNotNull();
- ImmutableSet<String> filenames = fileArrayToImmutableSet(filesList);
- ImmutableSet.Builder<String> randomClassNames = ImmutableSet.builder();
- randomClassNames.add("Main.java");
- for (int i = 0; i < targetSize; ++i) {
- randomClassNames.add("RandomClass" + i + ".java");
- }
- assertThat(filenames).containsExactlyElementsIn(randomClassNames.build());
- }
-
- private static void checkDepsTarget(Path root, String targetName, int targetSize) {
- // Check Java files
- for (int i = 1; i < targetSize; ++i) {
- File[] filesList =
- root.resolve(targetName).resolve("com/example/deps" + i).toFile().listFiles();
- assertThat(filesList).isNotNull();
- ImmutableSet<String> filenames = fileArrayToImmutableSet(filesList);
- assertThat(filenames).containsExactly("Deps" + i + ".java");
- }
- File[] filesList =
- root.resolve(targetName).resolve("com/example/generated").toFile().listFiles();
- assertThat(filesList).isNotNull();
- ImmutableSet<String> filenames = fileArrayToImmutableSet(filesList);
- assertThat(filenames).containsExactly("Main.java");
- }
-}
diff --git a/src/tools/benchmark/javatests/com/google/devtools/build/benchmark/codegenerator/MainTest.java b/src/tools/benchmark/javatests/com/google/devtools/build/benchmark/codegenerator/MainTest.java
deleted file mode 100644
index 5d46a7f054..0000000000
--- a/src/tools/benchmark/javatests/com/google/devtools/build/benchmark/codegenerator/MainTest.java
+++ /dev/null
@@ -1,92 +0,0 @@
-// Copyright 2017 The Bazel Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package com.google.devtools.build.benchmark.codegenerator;
-
-import static com.google.common.truth.Truth.assertThat;
-import static org.junit.Assert.fail;
-
-import com.google.devtools.common.options.OptionsParsingException;
-import java.io.IOException;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
-/** Test for {@link Main}. */
-@RunWith(JUnit4.class)
-public class MainTest {
-
- @Test
- public void testParseArgsEmpty() throws OptionsParsingException, IOException {
- try {
- Main.parseArgs(new String[]{});
- fail("Should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- assertThat(e).hasMessage("--output_dir should not be empty.");
- }
- }
-
- @Test
- public void testParseArgsWrongMode() throws IOException {
- try {
- Main.parseArgs(new String[]{"--modify=mango"});
- fail("Should throw OptionsParsingException");
- } catch (OptionsParsingException e) {
- assertThat(e).hasMessage("While parsing option --modify=mango: 'mango' is not a boolean");
- }
- }
-
- @Test
- public void testParseArgsNoOutputDir() throws OptionsParsingException, IOException {
- try {
- Main.parseArgs(new String[]{"--modify"});
- fail("Should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- assertThat(e).hasMessage("--output_dir should not be empty.");
- }
- }
-
- @Test
- public void testParseArgsOutputDirNonExists() throws OptionsParsingException, IOException {
- try {
- Main.parseArgs(new String[]{"--modify", "--output_dir=mango"});
- fail("Should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- assertThat(e).hasMessage("--output_dir (mango) does not contain code for modification.");
- }
- }
-
- @Test
- public void testParseArgsNoType() throws OptionsParsingException, IOException {
- try {
- Main.parseArgs(new String[]{"--output_dir=mango"});
- fail("Should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- assertThat(e).hasMessage("No type of package is specified.");
- }
- }
-
- @Test
- public void testParseArgsCorrect() throws OptionsParsingException, IOException {
- GeneratorOptions opt = Main.parseArgs(
- new String[]{
- "--modify=false",
- "--output_dir=mango",
- "--project_name=AFewFiles",
- "--project_name=ParallelDeps"});
- assertThat(opt.modificationMode).isFalse();
- assertThat(opt.outputDir).isEqualTo("mango");
- assertThat(opt.projectNames).containsExactly("AFewFiles", "ParallelDeps");
- }
-}
diff --git a/src/tools/benchmark/webapp/404.html b/src/tools/benchmark/webapp/404.html
deleted file mode 100644
index 2971495fe6..0000000000
--- a/src/tools/benchmark/webapp/404.html
+++ /dev/null
@@ -1,6 +0,0 @@
-<!DOCTYPE html>
-<html>
- <body>
- <p>404 - Page not found</p>
- </body>
-</html>
diff --git a/src/tools/benchmark/webapp/BUILD b/src/tools/benchmark/webapp/BUILD
deleted file mode 100644
index f6ad7b4b08..0000000000
--- a/src/tools/benchmark/webapp/BUILD
+++ /dev/null
@@ -1,16 +0,0 @@
-package(default_visibility = ["//src:__subpackages__"])
-
-load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar")
-
-filegroup(
- name = "srcs",
- srcs = glob(["*"]),
-)
-
-pkg_tar(
- name = "site",
- srcs = [
- "draw_chart.js",
- "index.html",
- ],
-)
diff --git a/src/tools/benchmark/webapp/draw_chart.js b/src/tools/benchmark/webapp/draw_chart.js
deleted file mode 100644
index 222aff8434..0000000000
--- a/src/tools/benchmark/webapp/draw_chart.js
+++ /dev/null
@@ -1,290 +0,0 @@
-google.charts.load('current', {packages: ['corechart', 'controls', 'table']});
-google.charts.setOnLoadCallback(drawAllChart);
-
-/**
- * Get data from /data/*.json and draw charts from it.
- */
-function drawAllChart() {
- $.get('file_list?v=' + Date.now(), function(data) {
- /** @type {!Array<Dashboard>} */
- const dashboard = [];
- /** @type {!Array<ControlWrapper>} */
- const control = [];
- /** @type {!Array<LineChart>} */
- const chart = [];
- const options = [];
- /** @type {!Array<DataTable>} */
- const tableData = [];
- /** @type {!Array<Column>} */
- const columns = [];
- /** @type {!boolean} */
- let chartInit = false;
- /** @type {!number} */
- let targetNum = 0;
-
- /** @type {!Array<string>} */
- const filenames = data.trim().split('\n');
-
- // Make sure the length of the deffered object array is always > 1
- $.when.apply($, [0].concat(filenames.map(function(filename) {
- return $.getJSON("data/" + filename);
- }))).then(function(){
- /** @type {!Array<Object>} */
- let responses = [].slice.call(arguments, 1);
- for (let response of responses) {
- let data = response[0];
- targetNum = data.buildTargetResults.length;
-
- if (!chartInit) {
- initChartData(data.buildTargetResults, dashboard, control, chart, tableData, options);
- chartInit = true;
- }
-
- // Add rows for chart (including data)
- for (let i = 0; i < targetNum; ++i) {
- addRowsFromData(tableData[i], data.buildTargetResults[i].buildEnvResults);
- }
- }
- afterChartData(targetNum, dashboard, control, chart, columns, tableData, options);
- });
- });
-}
-
-/**
- * Initialize all the chart data (columns, options, divs and chart objects)
- * @param {!Array<Object>} buildTargetResults results for all build targets
- * @param {!Array<Dashboard>} dashboard all dashboards
- * @param {!Array<Control>} control all controls
- * @param {!Array<LineChart>} chart all charts
- * @param {!Array<DataTable>} tableData data for all charts
- * @param {!Array<Object>} options options for all charts
- */
-function initChartData (buildTargetResults, dashboard, control, chart, tableData, options) {
- for (let i = 0; i < buildTargetResults.length; ++i) {
- const buildEnvResults = buildTargetResults[i].buildEnvResults;
-
- // add divs to #content
- $('<div id="target' + i + '" style="width: 100%; height: 600px"></div>')
- .appendTo('#content');
- $('<div id="control' + i + '" style="width: 100%; height: 100px"></div>')
- .appendTo('#content');
-
- // Dashboard
- dashboard[i] = new google.visualization.Dashboard(
- document.getElementById('target' + i));
-
- // Control
- control[i] = new google.visualization.ControlWrapper({
- 'controlType': 'ChartRangeFilter',
- 'containerId': 'control' + i,
- 'options': {
- // Filter by the date axis.
- 'filterColumnIndex': 1,
- 'ui': {
- 'chartType': 'LineChart',
- 'chartOptions': {
- 'chartArea': {'width': '70%'},
- 'hAxis': {'baselineColor': 'none'}
- },
- 'chartView': {
- 'columns': [0, 2, 6]
- }
- }
- }
- });
-
- // Options for each chart (including title)
- options[i] = {
- title: buildTargetResults[i].buildTargetConfig.description,
- vAxis: { title: 'Elapsed time (s)' },
- hAxis: { title: 'Changes with pushed time' },
- tooltip: { isHtml: true, trigger: 'both' },
- intervals: { style: 'bars' },
- chartArea: { width: '70%' }
- };
-
- // Create data table & add columns(line options)
- tableData[i] = new google.visualization.DataTable();
- addColumnsFromBuildEnv(tableData[i], buildEnvResults);
-
- // Create chart objects
- chart[i] = new google.visualization.ChartWrapper({
- 'chartType': 'LineChart',
- 'containerId': 'target' + i,
- 'options': options[i],
- 'view': { columns: [0, 2, 3, 4, 5, 6, 7, 8, 9] }
- });
- }
-}
-
-/**
- * Called after getting and filling chart data, draw all charts
- * @param {!number} targetNum number of target configs (charts)
- * @param {!Array<Dashboard>} dashboard all dashboards
- * @param {!Array<Control>} control all controls
- * @param {!Array<LineChart>} chart all charts
- * @param {!Array<Column>} columns columns of all charts
- * @param {!Array<DataTable>} tableData data for all charts
- * @param {!Array<Object>} options options for all charts
- */
-function afterChartData (targetNum, dashboard, control, chart, columns, tableData, options) {
- // final steps to draw charts
- for (let i = 0; i < targetNum; ++i) {
- dashboard[i].bind(control[i], chart[i]);
- dashboard[i].draw(tableData[i]);
-
- // event
- columns[i] = [];
- for (let j = 0; j < tableData[i].getNumberOfColumns(); j++) {
- columns[i].push(j);
- }
-
- google.visualization.events.addListener(
- chart[i], 'select', (function (x) {
- return function () {
- hideOrShow(dashboard[x], chart[x], columns[x], tableData[x], options[x]);
- };
- })(i));
- }
-}
-
-/**
- * Add columns for each buildEnvResults/line.
- * @param {!LineChart} lineChart
- * @param {!Array<Object>} buildEnvResults build results
- */
-function addColumnsFromBuildEnv (lineChart, buildEnvResults) {
- // Using datetime value as hAxis label makes intervals different,
- // so we use number instead.
- lineChart.addColumn('string', 'label index');
- lineChart.addColumn('number', 'numeric index');
- for (let buildEnvResult of buildEnvResults) {
- lineChart.addColumn(
- 'number', buildEnvResult.config.description);
- lineChart.addColumn({type:'number', role:'interval'});
- lineChart.addColumn({type:'number', role:'interval'});
- lineChart.addColumn(
- {'type': 'string', 'role': 'tooltip', 'p': {'html': true}});
- }
-}
-
-/**
- * Add rows for each code version.
- * @param {!LineChart} lineChart
- * @param {!Array<Object>} buildEnvResults build results
- */
-function addRowsFromData (lineChart, buildEnvResults) {
- const rowNum = lineChart.getNumberOfRows();
- for (let j = 0; j < buildEnvResults[0].results.length; ++j) {
- const row = [buildEnvResults[0].results[j].datetime, rowNum + j];
-
- for (let buildEnvResult of buildEnvResults) {
- const singleBuildResult = buildEnvResult.results[j];
-
- const ave = getAverage(singleBuildResult.results);
- const sd = getStandardDeviation(singleBuildResult.results, ave);
- row.push(ave);
- row.push(ave - sd);
- row.push(ave + sd);
- row.push(
- createCustomHTMLContent(
- singleBuildResult.results, singleBuildResult.codeVersion));
- }
- lineChart.addRow(row);
- }
-}
-
-/**
- * Get average of an array.
- * @param {!Array<number>} arr
- * @return {!number} the average
- */
-function getAverage(arr) {
- let ave = arr.reduce(function(a, b) { return a + b; });
- ave /= arr.length;
- return ave;
-}
-
-/**
- * Get standard deviation of an array.
- * @param {!Array<number>} arr
- * @param {!number} ave average of the array
- * @return {!number} the standard deviation
- */
-function getStandardDeviation(arr, ave) {
- let sd = 0;
- for (let item of arr) {
- const diff = ave - item;
- sd += diff * diff;
- }
- sd = Math.sqrt(sd);
- return sd;
-}
-
-/**
- * Create html content as tooltip.
- * @param {!Array<number>} arr array of build results
- * @param {!string} codeVersion current code version
- * @return {!string} the html content
- */
-function createCustomHTMLContent(arr, codeVersion) {
- let str = '<div style="padding:10px 10px 10px 10px;">';
- for (let i = 0; i < arr.length; ++i) {
- str += (i+1) + '-th run: ' + arr[i] + '<br>';
- }
- str += '<a href="https://github.com/bazelbuild/bazel/commit/' + codeVersion
- + '">commit</a></div>';
- return str;
-}
-
-/**
- * Hide or show one column/line in a chart.
- * @param {!Dashboard} dashboard the dashboard to operate
- * @param {!LineChart} chart the chart to operate
- * @param {!Column} columns columns of current chart
- * @param {!DataTable} tableData data for current chart
- * @param {!Object} options options for current chart
- */
-function hideOrShow(dashboard, chart, columns, tableData, options) {
- const sel = chart.getChart().getSelection();
- // If selection length is 0, we deselected an element
- if (sel.length <= 0 || sel[0].row !== null) {
- return;
- }
-
- // Since real col[1] is hidden (numeric index),
- // the col that we are looking for should +1
- const col = sel[0].column + 1;
- if (columns[col] == col) {
- // Hide the data series
- columns[col] = {
- label: tableData.getColumnLabel(col),
- type: tableData.getColumnType(col),
- calc: function () {
- return null;
- }
- };
- } else {
- // Show the data series
- columns[col] = col;
- }
- const view = new google.visualization.DataView(tableData);
- view.setColumns(columns);
- dashboard.draw(view);
-}
-
-/** @type {!Array<string>} */
-const chartDivList = ['java', 'cpp'];
-/**
- * Only show the specific div
- * @param {!string} divId the id of the div that needs to be shown
- */
-function showChartDiv(divId) {
- for (let id of chartDivList) {
- if (id === divId) {
- $('#' + id).show();
- } else {
- $('#' + id).hide();
- }
- }
-}
diff --git a/src/tools/benchmark/webapp/index.html b/src/tools/benchmark/webapp/index.html
deleted file mode 100644
index 5a1318f553..0000000000
--- a/src/tools/benchmark/webapp/index.html
+++ /dev/null
@@ -1,52 +0,0 @@
-<!DOCTYPE html>
-<html>
- <head>
- <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
- <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
- <script type="text/javascript" src="draw_chart.js"></script>
- <style type="text/css">
- span {
- cursor: pointer;
- }
- #bar {
- text-align:center;
- font-weight:bold;
- font-size:30px;
- }
- </style>
- <title>Continuous Build Performance Benchmark</title>
- </head>
- <body>
- <div>
- <p>Note:</p>
- <p>Click the legend (eg. "Full clean build", "Incremental build") to hide or show corresponding line.</p>
- <p>Drag the control buttons under the charts to filter data.</p>
- <p>This benchmark is generated by the code in <a href="https://github.com/bazelbuild/bazel/tree/master/src/tools/benchmark">bazel/src/tools/benchmark</a>. You can also try it locally.</p>
- <p>Our <a href="http://ci.bazel.io">CI system</a> automatically builds Bazel at each Git commit. The performance of each version is then assessed by building various kinds of <a href="https://github.com/bazelbuild/bazel/tree/master/src/tools/benchmark/java/com/google/devtools/build/benchmark/codegenerator">generated Java code</a> (e.g. Java libraries with few files, with many files, with many parallel deps, with a long chain of deps). The time it took to build each kind of code is measured and used to generate these charts.</p>
- </div>
- <div id="bar">
- <span onclick="showChartDiv('java');">Java</span> | <span onclick="showChartDiv('cpp');">C++</span></div>
- <div id="content">
- <div id="java">
- <div id="target0" style="width: 100%; height: 600px"></div>
- <div id="control0" style="width: 100%; height: 100px"></div>
- <div id="target1" style="width: 100%; height: 600px"></div>
- <div id="control1" style="width: 100%; height: 100px"></div>
- <div id="target2" style="width: 100%; height: 600px"></div>
- <div id="control2" style="width: 100%; height: 100px"></div>
- <div id="target3" style="width: 100%; height: 600px"></div>
- <div id="control3" style="width: 100%; height: 100px"></div>
- </div>
- <div id="cpp">
- <div id="target4" style="width: 100%; height: 600px"></div>
- <div id="control4" style="width: 100%; height: 100px"></div>
- <div id="target5" style="width: 100%; height: 600px"></div>
- <div id="control5" style="width: 100%; height: 100px"></div>
- <div id="target6" style="width: 100%; height: 600px"></div>
- <div id="control6" style="width: 100%; height: 100px"></div>
- <div id="target7" style="width: 100%; height: 600px"></div>
- <div id="control7" style="width: 100%; height: 100px"></div>
- </div>
- </div>
- </body>
-</html> \ No newline at end of file