1package main 2 3import ( 4 "flag" 5 "fmt" 6 "os" 7 8 rc_lib "android/soong/cmd/release_config/release_config_lib" 9 rc_proto "android/soong/cmd/release_config/release_config_proto" 10) 11 12type Flags struct { 13 // The path to the top of the workspace. Default: ".". 14 top string 15 16 // Output file. 17 output string 18 19 // Format for output file 20 format string 21 22 // List of flag_declaration files to add. 23 decls rc_lib.StringList 24 25 // List of flag_artifacts files to merge. 26 intermediates rc_lib.StringList 27 28 // Disable warning messages 29 quiet bool 30 31 // Panic on errors. 32 debug bool 33} 34 35func main() { 36 var flags Flags 37 topDir, err := rc_lib.GetTopDir() 38 39 // Handle the common arguments 40 flag.StringVar(&flags.top, "top", topDir, "path to top of workspace") 41 flag.Var(&flags.decls, "decl", "path to a flag_declaration file. May be repeated") 42 flag.Var(&flags.intermediates, "intermediate", "path to a flag_artifacts file (output from a prior run). May be repeated") 43 flag.StringVar(&flags.format, "format", "pb", "output file format") 44 flag.StringVar(&flags.output, "output", "build_flags.pb", "output file") 45 flag.BoolVar(&flags.debug, "debug", false, "turn on debugging output for errors") 46 flag.BoolVar(&flags.quiet, "quiet", false, "disable warning messages") 47 flag.Parse() 48 49 errorExit := func(err error) { 50 if flags.debug { 51 panic(err) 52 } 53 fmt.Fprintf(os.Stderr, "%s\n", err) 54 os.Exit(1) 55 } 56 57 if flags.quiet { 58 rc_lib.DisableWarnings() 59 } 60 61 if err = os.Chdir(flags.top); err != nil { 62 errorExit(err) 63 } 64 65 flagArtifacts := rc_lib.FlagArtifactsFactory("") 66 intermediates := []*rc_proto.FlagDeclarationArtifacts{} 67 for _, intermediate := range flags.intermediates { 68 fda := rc_lib.FlagDeclarationArtifactsFactory(intermediate) 69 intermediates = append(intermediates, fda) 70 } 71 for _, decl := range flags.decls { 72 fa := rc_lib.FlagArtifactFactory(decl) 73 (*flagArtifacts)[*fa.FlagDeclaration.Name] = fa 74 } 75 76 message := flagArtifacts.GenerateFlagDeclarationArtifacts(intermediates) 77 err = rc_lib.WriteFormattedMessage(flags.output, flags.format, message) 78 if err != nil { 79 errorExit(err) 80 } 81} 82