// Copyright (c) 2013 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include #include #include "base/command_line.h" #include "tools/gn/commands.h" #include "tools/gn/deps_iterator.h" #include "tools/gn/filesystem_utils.h" #include "tools/gn/input_file.h" #include "tools/gn/item.h" #include "tools/gn/setup.h" #include "tools/gn/standard_out.h" #include "tools/gn/target.h" namespace commands { namespace { typedef std::set TargetSet; typedef std::vector TargetVector; // Maps targets to the list of targets that depend on them. typedef std::multimap DepMap; // Populates the reverse dependency map for the targets in the Setup. void FillDepMap(Setup* setup, DepMap* dep_map) { std::vector targets = setup->builder()->GetAllResolvedTargets(); for (size_t target_i = 0; target_i < targets.size(); target_i++) { for (DepsIterator iter(targets[target_i]); !iter.done(); iter.Advance()) dep_map->insert(std::make_pair(iter.target(), targets[target_i])); } } // Returns the file path generating this item. base::FilePath FilePathForItem(const Item* item) { return item->defined_from()->GetRange().begin().file()->physical_name(); } // Prints the targets which are the result of a query. This list is sorted // and, if as_files is set, the unique filenames matching those targets will // be used. void OutputResultSet(const TargetSet& results, bool as_files) { if (results.empty()) return; if (as_files) { // Output the set of unique source files. std::set unique_files; for (TargetSet::const_iterator iter = results.begin(); iter != results.end(); ++iter) unique_files.insert(FilePathToUTF8(FilePathForItem(*iter))); for (std::set::const_iterator iter = unique_files.begin(); iter != unique_files.end(); ++iter) { OutputString(*iter + "\n"); } } else { // Output sorted and uniquified list of labels. The set will sort the // labels. std::set