Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[CRTP] Target Deps API #154

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions buildcc/lib/target/cmake/mock_target.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ add_library(mock_target STATIC
src/api/lib_api.cpp
src/api/pch_api.cpp
src/api/flag_api.cpp
src/api/deps_api.cpp

# Generator
src/generator/generator_loader.cpp
Expand All @@ -33,8 +34,6 @@ add_library(mock_target STATIC
src/target/target_loader.cpp
src/target/target_storer.cpp

src/target/additional_deps.cpp

src/target/build.cpp

# Target mocks
Expand Down
4 changes: 2 additions & 2 deletions buildcc/lib/target/cmake/target.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ set(TARGET_SRCS
src/api/lib_api.cpp
src/api/pch_api.cpp
src/api/flag_api.cpp
src/api/deps_api.cpp
include/target/api/copy_api.h
include/target/api/source_api.h
include/target/api/include_api.h
include/target/api/lib_api.h
include/target/api/pch_api.h
include/target/api/flag_api.h
include/target/api/deps_api.h

# Generator
src/generator/generator_loader.cpp
Expand All @@ -56,8 +58,6 @@ set(TARGET_SRCS
include/target/target_storer.h
include/target/target.h

src/target/additional_deps.cpp

src/target/recheck_states.cpp

src/target/build.cpp
Expand Down
40 changes: 40 additions & 0 deletions buildcc/lib/target/include/target/api/deps_api.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2021 Niket Naidu. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef TARGET_API_DEPS_API_H_
#define TARGET_API_DEPS_API_H_

#include <filesystem>

namespace fs = std::filesystem;

namespace buildcc::base {

// Requires
// - TargetStorer
// - TargetState
// - TargetEnv
template <typename T> class DepsApi {
public:
void AddCompileDependency(const fs::path &relative_path);
void AddCompileDependencyAbsolute(const fs::path &absolute_path);
void AddLinkDependency(const fs::path &relative_path);
void AddLinkDependencyAbsolute(const fs::path &absolute_path);
};

} // namespace buildcc::base

#endif
3 changes: 3 additions & 0 deletions buildcc/lib/target/include/target/api/flag_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@

namespace buildcc::base {

// Requires
// - TargetStorer
// - TargetState
template <typename T> class FlagApi {
public:
void AddPreprocessorFlag(const std::string &flag);
Expand Down
13 changes: 4 additions & 9 deletions buildcc/lib/target/include/target/target.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

// API
#include "target/api/copy_api.h"
#include "target/api/deps_api.h"
#include "target/api/flag_api.h"
#include "target/api/include_api.h"
#include "target/api/lib_api.h"
Expand Down Expand Up @@ -75,7 +76,8 @@ class Target : public BuilderInterface,
public IncludeApi<Target>,
public LibApi<Target>,
public PchApi<Target>,
public FlagApi<Target> {
public FlagApi<Target>,
public DepsApi<Target> {

public:
explicit Target(const std::string &name, TargetType type,
Expand All @@ -95,14 +97,6 @@ class Target : public BuilderInterface,
// Builders
void Build() override;

// Setters

// * Rebuild
void AddCompileDependency(const fs::path &relative_path);
void AddCompileDependencyAbsolute(const fs::path &absolute_path);
void AddLinkDependency(const fs::path &relative_path);
void AddLinkDependencyAbsolute(const fs::path &absolute_path);

// TODO, Add more setters

//
Expand Down Expand Up @@ -222,6 +216,7 @@ class Target : public BuilderInterface,
friend class LibApi<Target>;
friend class PchApi<Target>;
friend class FlagApi<Target>;
friend class DepsApi<Target>;

private:
void Initialize();
Expand Down
56 changes: 56 additions & 0 deletions buildcc/lib/target/src/api/deps_api.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright 2021 Niket Naidu. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "target/api/deps_api.h"

#include "target/target.h"

namespace buildcc::base {

template <typename T>
void DepsApi<T>::AddCompileDependencyAbsolute(const fs::path &absolute_path) {
T &t = static_cast<T &>(*this);

t.state_.ExpectsUnlock();
t.storer_.current_compile_dependencies.user.insert(absolute_path);
}
template <typename T>
void DepsApi<T>::AddLinkDependencyAbsolute(const fs::path &absolute_path) {
T &t = static_cast<T &>(*this);

t.state_.ExpectsUnlock();
t.storer_.current_link_dependencies.user.insert(absolute_path);
}

template <typename T>
void DepsApi<T>::AddCompileDependency(const fs::path &relative_path) {
T &t = static_cast<T &>(*this);

fs::path absolute_path = t.env_.GetTargetRootDir() / relative_path;
AddCompileDependencyAbsolute(absolute_path);
}

template <typename T>
void DepsApi<T>::AddLinkDependency(const fs::path &relative_path) {
T &t = static_cast<T &>(*this);

fs::path absolute_path = t.env_.GetTargetRootDir() / relative_path;
AddLinkDependencyAbsolute(absolute_path);
}

template class DepsApi<Target>;

} // namespace buildcc::base
39 changes: 0 additions & 39 deletions buildcc/lib/target/src/target/additional_deps.cpp

This file was deleted.