16d528ed9Sopenharmony_ci// Copyright 2018 The Chromium Authors. All rights reserved.
26d528ed9Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be
36d528ed9Sopenharmony_ci// found in the LICENSE file.
46d528ed9Sopenharmony_ci
56d528ed9Sopenharmony_ci#ifndef TOOLS_GN_GENERATED_FILE_TARGET_GENERATOR_H_
66d528ed9Sopenharmony_ci#define TOOLS_GN_GENERATED_FILE_TARGET_GENERATOR_H_
76d528ed9Sopenharmony_ci
86d528ed9Sopenharmony_ci#include <string_view>
96d528ed9Sopenharmony_ci
106d528ed9Sopenharmony_ci#include "gn/target.h"
116d528ed9Sopenharmony_ci#include "gn/target_generator.h"
126d528ed9Sopenharmony_ci
136d528ed9Sopenharmony_ci// Collects and writes specified data.
146d528ed9Sopenharmony_ciclass GeneratedFileTargetGenerator : public TargetGenerator {
156d528ed9Sopenharmony_ci public:
166d528ed9Sopenharmony_ci  GeneratedFileTargetGenerator(Target* target,
176d528ed9Sopenharmony_ci                               Scope* scope,
186d528ed9Sopenharmony_ci                               const FunctionCallNode* function_call,
196d528ed9Sopenharmony_ci                               Target::OutputType type,
206d528ed9Sopenharmony_ci                               Err* err);
216d528ed9Sopenharmony_ci  ~GeneratedFileTargetGenerator() override;
226d528ed9Sopenharmony_ci
236d528ed9Sopenharmony_ci protected:
246d528ed9Sopenharmony_ci  void DoRun() override;
256d528ed9Sopenharmony_ci
266d528ed9Sopenharmony_ci private:
276d528ed9Sopenharmony_ci  bool FillGeneratedFileOutput();
286d528ed9Sopenharmony_ci  bool FillOutputConversion();
296d528ed9Sopenharmony_ci  bool FillContents();
306d528ed9Sopenharmony_ci  bool FillDataKeys();
316d528ed9Sopenharmony_ci  bool FillWalkKeys();
326d528ed9Sopenharmony_ci  bool FillRebase();
336d528ed9Sopenharmony_ci
346d528ed9Sopenharmony_ci  // Returns false if `contents` is defined (i.e. if this target was provided
356d528ed9Sopenharmony_ci  // with explicit contents to write). Returns false otherwise, indicating that
366d528ed9Sopenharmony_ci  // it is okay to set metadata collection variables on this target.
376d528ed9Sopenharmony_ci  //
386d528ed9Sopenharmony_ci  // Should be called before FillContents().
396d528ed9Sopenharmony_ci  bool IsMetadataCollectionTarget(std::string_view variable,
406d528ed9Sopenharmony_ci                                  const ParseNode* origin);
416d528ed9Sopenharmony_ci
426d528ed9Sopenharmony_ci  bool contents_defined_ = false;
436d528ed9Sopenharmony_ci  bool data_keys_defined_ = false;
446d528ed9Sopenharmony_ci
456d528ed9Sopenharmony_ci  Target::OutputType output_type_;
466d528ed9Sopenharmony_ci
476d528ed9Sopenharmony_ci  GeneratedFileTargetGenerator(const GeneratedFileTargetGenerator&) = delete;
486d528ed9Sopenharmony_ci  GeneratedFileTargetGenerator& operator=(const GeneratedFileTargetGenerator&) =
496d528ed9Sopenharmony_ci      delete;
506d528ed9Sopenharmony_ci};
516d528ed9Sopenharmony_ci
526d528ed9Sopenharmony_ci#endif  // TOOLS_GN_GENERATED_FILE_TARGET_GENERATOR_H_
53