// 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. #ifndef TOOLS_GN_TARGET_H_ #define TOOLS_GN_TARGET_H_ #include #include #include #include "base/gtest_prod_util.h" #include "base/logging.h" #include "base/macros.h" #include "tools/gn/action_values.h" #include "tools/gn/bundle_data.h" #include "tools/gn/config_values.h" #include "tools/gn/inherited_libraries.h" #include "tools/gn/item.h" #include "tools/gn/label_pattern.h" #include "tools/gn/label_ptr.h" #include "tools/gn/lib_file.h" #include "tools/gn/ordered_set.h" #include "tools/gn/output_file.h" #include "tools/gn/source_file.h" #include "tools/gn/toolchain.h" #include "tools/gn/unique_vector.h" class DepsIteratorRange; class Settings; class Toolchain; class Target : public Item { public: enum OutputType { UNKNOWN, GROUP, EXECUTABLE, SHARED_LIBRARY, LOADABLE_MODULE, STATIC_LIBRARY, SOURCE_SET, COPY_FILES, ACTION, ACTION_FOREACH, BUNDLE_DATA, CREATE_BUNDLE, }; enum DepsIterationType { DEPS_ALL, // Iterates through all public, private, and data deps. DEPS_LINKED, // Iterates through all non-data dependencies. }; typedef std::vector FileList; typedef std::vector StringVector; Target(const Settings* settings, const Label& label); ~Target() override; // Returns a string naming the output type. static const char* GetStringForOutputType(OutputType type); // Item overrides. Target* AsTarget() override; const Target* AsTarget() const override; bool OnResolved(Err* err) override; OutputType output_type() const { return output_type_; } void set_output_type(OutputType t) { output_type_ = t; } // True for targets that compile source code (all types of libaries and // executables). bool IsBinary() const; // Can be linked into other targets. bool IsLinkable() const; // True if the target links dependencies rather than propogated up the graph. // This is also true of action and copy steps even though they don't link // dependencies, because they also don't propogate libraries up. bool IsFinal() const; // Will be the empty string to use the target label as the output name. // See GetComputedOutputName(). const std::string& output_name() const { return output_name_; } void set_output_name(const std::string& name) { output_name_ = name; } // Returns the output name for this target, which is the output_name if // specified, or the target label if not. // // Because this depends on the tool for this target, the toolchain must // have been set before calling. std::string GetComputedOutputName() const; bool output_prefix_override() const { return output_prefix_override_; } void set_output_prefix_override(bool prefix_override) { output_prefix_override_ = prefix_override; } // Desired output directory for the final output. This will be used for // the {{output_dir}} substitution in the tool if it is specified. If // is_null, the tool default will be used. const SourceDir& output_dir() const { return output_dir_; } void set_output_dir(const SourceDir& dir) { output_dir_ = dir; } // The output extension is really a tri-state: unset (output_extension_set // is false and the string is empty, meaning the default extension should be // used), the output extension is set but empty (output should have no // extension) and the output extension is set but nonempty (use the given // extension). const std::string& output_extension() const { return output_extension_; } void set_output_extension(const std::string& extension) { output_extension_ = extension; output_extension_set_ = true; } bool output_extension_set() const { return output_extension_set_; } const FileList& sources() const { return sources_; } FileList& sources() { return sources_; } // Set to true when all sources are public. This is the default. In this case // the public headers list should be empty. bool all_headers_public() const { return all_headers_public_; } void set_all_headers_public(bool p) { all_headers_public_ = p; } // When all_headers_public is false, this is the list of public headers. It // could be empty which would mean no headers are public. const FileList& public_headers() const { return public_headers_; } FileList& public_headers() { return public_headers_; } // Whether this target's includes should be checked by "gn check". bool check_includes() const { return check_includes_; } void set_check_includes(bool ci) { check_includes_ = ci; } // Whether this static_library target should have code linked in. bool complete_static_lib() const { return complete_static_lib_; } void set_complete_static_lib(bool complete) { DCHECK_EQ(STATIC_LIBRARY, output_type_); complete_static_lib_ = complete; } bool testonly() const { return testonly_; } void set_testonly(bool value) { testonly_ = value; } OutputFile write_runtime_deps_output() const { return write_runtime_deps_output_; } void set_write_runtime_deps_output(const OutputFile& value) { write_runtime_deps_output_ = value; } // Compile-time extra dependencies. const FileList& inputs() const { return inputs_; } FileList& inputs() { return inputs_; } // Runtime dependencies. These are "file-like things" that can either be // directories or files. They do not need to exist, these are just passed as // runtime dependencies to external test systems as necessary. const std::vector& data() const { return data_; } std::vector& data() { return data_; } // Information about the bundle. Only valid for CREATE_BUNDLE target after // they have been resolved. const BundleData& bundle_data() const { return bundle_data_; } BundleData& bundle_data() { return bundle_data_; } // Returns true if targets depending on this one should have an order // dependency. bool hard_dep() const { return output_type_ == ACTION || output_type_ == ACTION_FOREACH || output_type_ == COPY_FILES || output_type_ == CREATE_BUNDLE; } // Returns the iterator range which can be used in range-based for loops // to iterate over multiple types of deps in one loop: // for (const auto& pair : target->GetDeps(Target::DEPS_ALL)) ... DepsIteratorRange GetDeps(DepsIterationType type) const; // Linked private dependencies. const LabelTargetVector& private_deps() const { return private_deps_; } LabelTargetVector& private_deps() { return private_deps_; } // Linked public dependencies. const LabelTargetVector& public_deps() const { return public_deps_; } LabelTargetVector& public_deps() { return public_deps_; } // Non-linked dependencies. const LabelTargetVector& data_deps() const { return data_deps_; } LabelTargetVector& data_deps() { return data_deps_; } // List of configs that this class inherits settings from. Once a target is // resolved, this will also list all-dependent and public configs. const UniqueVector& configs() const { return configs_; } UniqueVector& configs() { return configs_; } // List of configs that all dependencies (direct and indirect) of this // target get. These configs are not added to this target. Note that due // to the way this is computed, there may be duplicates in this list. const UniqueVector& all_dependent_configs() const { return all_dependent_configs_; } UniqueVector& all_dependent_configs() { return all_dependent_configs_; } // List of configs that targets depending directly on this one get. These // configs are also added to this target. const UniqueVector& public_configs() const { return public_configs_; } UniqueVector& public_configs() { return public_configs_; } // Dependencies that can include files from this target. const std::set