• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "gn/pool.h"
6 
7 #include <sstream>
8 
9 #include "base/logging.h"
10 
11 Pool::~Pool() = default;
12 
AsPool()13 Pool* Pool::AsPool() {
14   return this;
15 }
16 
AsPool() const17 const Pool* Pool::AsPool() const {
18   return this;
19 }
20 
GetNinjaName(const Label & default_toolchain) const21 std::string Pool::GetNinjaName(const Label& default_toolchain) const {
22   bool include_toolchain = label().toolchain_dir() != default_toolchain.dir() ||
23                            label().toolchain_name() != default_toolchain.name();
24   return GetNinjaName(include_toolchain);
25 }
26 
GetNinjaName(bool include_toolchain) const27 std::string Pool::GetNinjaName(bool include_toolchain) const {
28   std::ostringstream buffer;
29   if (include_toolchain) {
30     DCHECK(label().toolchain_dir().is_source_absolute());
31     std::string toolchain_dir = label().toolchain_dir().value();
32     for (std::string::size_type i = 2; i < toolchain_dir.size(); ++i) {
33       buffer << (toolchain_dir[i] == '/' ? '_' : toolchain_dir[i]);
34     }
35     buffer << label().toolchain_name() << "_";
36   }
37 
38   DCHECK(label().dir().is_source_absolute());
39   std::string label_dir = label().dir().value();
40   for (std::string::size_type i = 2; i < label_dir.size(); ++i) {
41     buffer << (label_dir[i] == '/' ? '_' : label_dir[i]);
42   }
43   buffer << label().name();
44   return buffer.str();
45 }
46