| // Copyright 2017 The Fuchsia Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| // This file contains a program that reads cobalt configuration in a YAML format |
| // and outputs it as a CobaltRegistry serialized protocol buffer. |
| |
| package main |
| |
| import ( |
| "config" |
| "config_parser" |
| "config_validator" |
| "flag" |
| "os" |
| "source_generator" |
| |
| "github.com/golang/glog" |
| "google.golang.org/protobuf/proto" |
| ) |
| |
| var ( |
| skipValidation = flag.Bool("skip_validation", false, "Skip validating the config, write it no matter what.") |
| depFile = flag.String("dep_file", "", "Generate a depfile (see gn documentation) that lists all the project configuration files. Requires -output_file and -config_dir.") |
| forClient = flag.Bool("for_client", false, "Filters out the hide_on_client tagged fields") |
| filterCobalt10 = flag.Bool("filter_1_0_metrics", false, "Filters out Cobalt 1.0 metrics.") |
| ) |
| |
| func fail(step string, err error) { |
| glog.Errorf("\n\nFailed to %s:\n%v\n\n", step, err) |
| os.Exit(1) |
| } |
| |
| func main() { |
| flag.Parse() |
| |
| // If the location of a depfile is specified, output the depfile. |
| if *depFile != "" { |
| configFiles, err := config_parser.GetConfigFilesListFromFlags() |
| if err != nil { |
| fail("get config files", err) |
| } |
| if err := source_generator.WriteDepFileFromFlags(configFiles, *depFile); err != nil { |
| fail("write dep file", err) |
| } |
| } |
| |
| // First, we parse the configuration from the specified location. |
| config_datas, err := config_parser.ParseProjectConfigDataFromFlags() |
| if err != nil { |
| fail("parse registry", err) |
| } |
| |
| config_parser.ExpandDefaults(config_datas) |
| |
| // Unless otherwise specified, validate the registry. |
| if !*skipValidation { |
| if err = config_validator.ValidateProjectConfigDatas(config_datas); err != nil { |
| fail("validate registry", err) |
| } |
| } |
| |
| // Compute and write the |prob_bit_flip| and |num_index_points| fields for each Cobalt 1.1 ReportDefinition |
| // in |config_datas|. |
| if err := config_parser.PopulatePrivacyParams(config_datas); err != nil { |
| fail("populate privacy parameters", err) |
| } |
| |
| // Merge the list of project configs in a single config.CobaltRegistry. |
| c := config_parser.MergeConfigs(config_datas) |
| filtered := proto.Clone(&c).(*config.CobaltRegistry) |
| |
| // Filter the fields that are not needed on the client. |
| if *forClient { |
| config_parser.FilterHideOnClient(filtered) |
| } |
| |
| // Filter Cobalt 1.0 metrics. |
| if *filterCobalt10 { |
| config_parser.FilterCobalt10FromCobaltRegistry(filtered) |
| } |
| |
| // Write the registry depending upon the specified flags. |
| if err := source_generator.WriteConfigFromFlags(&c, filtered); err != nil { |
| fail("write generated registry files", err) |
| glog.Exit(err) |
| } |
| |
| os.Exit(0) |
| } |