1 // Copyright 2018 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 #ifndef TOOLS_GN_GENERATED_FILE_TARGET_GENERATOR_H_ 6 #define TOOLS_GN_GENERATED_FILE_TARGET_GENERATOR_H_ 7 8 #include <string_view> 9 10 #include "gn/target.h" 11 #include "gn/target_generator.h" 12 13 // Collects and writes specified data. 14 class GeneratedFileTargetGenerator : public TargetGenerator { 15 public: 16 GeneratedFileTargetGenerator(Target* target, 17 Scope* scope, 18 const FunctionCallNode* function_call, 19 Target::OutputType type, 20 Err* err); 21 ~GeneratedFileTargetGenerator() override; 22 23 protected: 24 void DoRun() override; 25 26 private: 27 bool FillGeneratedFileOutput(); 28 bool FillOutputConversion(); 29 bool FillContents(); 30 bool FillDataKeys(); 31 bool FillWalkKeys(); 32 bool FillRebase(); 33 34 // Returns false if `contents` is defined (i.e. if this target was provided 35 // with explicit contents to write). Returns false otherwise, indicating that 36 // it is okay to set metadata collection variables on this target. 37 // 38 // Should be called before FillContents(). 39 bool IsMetadataCollectionTarget(std::string_view variable, 40 const ParseNode* origin); 41 42 bool contents_defined_ = false; 43 bool data_keys_defined_ = false; 44 45 Target::OutputType output_type_; 46 47 GeneratedFileTargetGenerator(const GeneratedFileTargetGenerator&) = delete; 48 GeneratedFileTargetGenerator& operator=(const GeneratedFileTargetGenerator&) = 49 delete; 50 }; 51 52 #endif // TOOLS_GN_GENERATED_FILE_TARGET_GENERATOR_H_ 53