// 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) { for (const auto& target : setup->builder()->GetAllResolvedTargets()) { for (const auto& dep_pair : target->GetDeps(Target::DEPS_ALL)) dep_map->insert(std::make_pair(dep_pair.ptr, target)); } } // 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 (const auto& cur : results) unique_files.insert(FilePathToUTF8(FilePathForItem(cur))); for (const auto& cur : unique_files) OutputString(cur + "\n"); } else { // Output sorted and uniquified list of labels. The set will sort the // labels. std::set