Skip to content

Commit

Permalink
Open-source command-line options specific to protocol buffer.
Browse files Browse the repository at this point in the history
--
MOS_MIGRATED_REVID=109897602
  • Loading branch information
cgrushko authored and kchodorow committed Dec 10, 2015
1 parent 02269df commit e8a8624
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/main/java/com/google/devtools/build/lib/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,7 @@ java_library(
":util",
":vfs",
"//src/main/java/com/google/devtools/build/lib/actions",
"//src/main/java/com/google/devtools/common/options",
"//third_party:auto_value",
"//third_party:guava",
"//third_party:jsr305",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// Copyright 2015 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.lib.rules.proto;

import com.google.common.collect.ImmutableSet;
import com.google.devtools.build.lib.analysis.config.BuildConfiguration.Fragment;
import com.google.devtools.build.lib.analysis.config.BuildOptions;
import com.google.devtools.build.lib.analysis.config.ConfigurationEnvironment;
import com.google.devtools.build.lib.analysis.config.ConfigurationFragmentFactory;
import com.google.devtools.build.lib.analysis.config.FragmentOptions;
import com.google.devtools.build.lib.analysis.config.InvalidConfigurationException;
import com.google.devtools.common.options.Option;

import java.util.List;

/**
* Configuration for Protocol Buffer Libraries.
*/
public class ProtoConfiguration extends Fragment {

/**
* Command line options.
*/
public static class Options extends FragmentOptions {
@Option(name = "protocopt",
allowMultiple = true,
defaultValue = "",
category = "flags",
help = "Additional options to pass to the protobuf compiler.")
public List<String> protocOpts;
}

/**
* Loader class for proto.
*/
public static class Loader implements ConfigurationFragmentFactory {
@Override
public Fragment create(ConfigurationEnvironment env, BuildOptions buildOptions)
throws InvalidConfigurationException {
return new ProtoConfiguration(buildOptions.get(Options.class));
}

@Override
public Class<? extends Fragment> creates() {
return ProtoConfiguration.class;
}

@Override
public ImmutableSet<Class<? extends FragmentOptions>> requiredOptions() {
return ImmutableSet.<Class<? extends FragmentOptions>>of(Options.class);
}
}

private final Options options;

public ProtoConfiguration(Options options) {
this.options = options;
}

public List<String> protocOpts() {
return options.protocOpts;
}
}

0 comments on commit e8a8624

Please sign in to comment.