// -*- c++ -*- // Distributed under the BSD 2-Clause License. // See accompanying file LICENSE for details. #pragma once #include #include #include #include #include #include "ctor.h" enum class State { Unknown, Ready, Running, Done, Error, }; class Task { public: Task(const ctor::build_configuration& config, const ctor::settings& settings, std::string sourceDir); virtual ~Task() = default; int registerDepTasks(const std::vector>& tasks); virtual int registerDepTasksInner([[maybe_unused]]const std::vector>& tasks) { return 0; } bool operator==(const std::string& dep); virtual std::string name() const; bool dirty(); bool ready(); int run(); State state() const; virtual int clean() = 0 ; virtual std::vector depends() const = 0; //! Raw target name as stated in ctor.cc config file or (in case of a derived //! target) the calculated target without builddir prefix. virtual std::string target() const = 0; //! Target file with full path prefix virtual std::filesystem::path targetFile() const = 0; //! Returns true for tasks that are non-target tasks, ie. for example derived //! objects files from target sources. virtual bool derived() const = 0; virtual std::string toJSON() const { return {}; }; //! Returns a reference to the originating build config. //! Note: the build config of a derived task will be that of its parent //! (target) task. const ctor::build_configuration& buildConfig() const; ctor::target_type targetType() const; ctor::language sourceLanguage() const; ctor::output_system outputSystem() const; std::string compiler() const; std::vector> getDependsTasks(); virtual std::string source() const { return {}; } protected: std::atomic task_state{State::Unknown}; virtual int runInner() { return 0; }; virtual bool dirtyInner() { return false; } std::vector dependsStr; std::vector> dependsTasks; const ctor::build_configuration& config; ctor::target_type target_type{ctor::target_type::automatic}; ctor::language source_language{ctor::language::automatic}; ctor::output_system output_system{ctor::output_system::host}; const ctor::settings& settings; std::string sourceDir; };