blob: cc750cbbe2ac56bce6914f58a4abee868cd9e32b [file] [log] [blame]
// Copyright 2018 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.
package main
import (
type stringsFlag []string
func (s *stringsFlag) String() string {
return strings.Join(*s, ", ")
func (s *stringsFlag) Set(value string) error {
*s = append(*s, value)
return nil
var (
keyArgs stringsFlag
inputFiles stringsFlag
outFile string
sourcesFile string
func init() {
flag.Var(&keyArgs, "key", "a label for output")
flag.Var(&inputFiles, "in", "path to an input file")
flag.StringVar(&outFile, "out", "", "path to output file (default stdout)")
flag.StringVar(&sourcesFile, "s", "", "path to json file generated by Jiri projects")
func main() {
if flag.NArg() != 0 {
// sources is no longer used since the URL generated for remotes is can be wrong
// due to the path within the Fuchsia tree not matching the path from the root
// of the remote project.
// Also, it appears some files in third_party are being generated from Bazel
// builds, so the link is not accurate.
// TODO(fxb/119650): Remove sourcemap all together.
ctx := context.Background()
argMap := gndoc.NewArgMap()
args, errs := gndoc.ParseGNArgs(ctx, inputFiles, keyArgs)
if err := <-errs; err != nil {
log.Fatalf("Error: %s\n", err)
var out io.Writer
if outFile != "" {
var err error
if dirErr := os.MkdirAll(filepath.Dir(outFile), os.ModePerm); dirErr != nil {
log.Fatalf("Error creating directories: %s", dirErr)
out, err = os.Create(outFile)
if err != nil {
log.Fatalf("Error opening file: %s", err)
} else {
out = os.Stdout