Skip to content
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

feat: add order to pack upg supported targets #335

Merged
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
194ec29
feat: add order to pack upg supported targets
magi-arun Jun 26, 2023
d02209f
resolve review comments
magi-arun Jun 26, 2023
117063c
refactor: resolved review comments
magi-arun Jul 6, 2023
e4f52ce
refactor: resolved review comments
magi-arun Jul 6, 2023
0ab6e10
style: fix build
magi-arun Jul 6, 2023
b17413f
Merge branch 'main' into feature/add_order_for_pack_builder_supported…
magi-arun Jul 6, 2023
1ce4516
refactor: resolved review comments
magi-arun Jul 10, 2023
00b7fb2
Merge branch 'feature/add_order_for_pack_builder_supported_targets' o…
magi-arun Jul 10, 2023
86a7083
Update upgrade/pack_builder_instantiations/UpgradePackBuilderFacade.cpp
magi-arun Jul 10, 2023
4a1285a
review comments resolved
magi-arun Jul 18, 2023
6fe0cb2
Merge branch 'main' into feature/add_order_for_pack_builder_supported…
magi-arun Jul 18, 2023
9582f91
build(deps): bump github/codeql-action from 2.21.6 to 2.21.7 (#417)
dependabot[bot] Sep 19, 2023
228d645
ci: consolidate configurations (#411)
richardapeters Sep 20, 2023
1b8d421
build(deps): bump actions/checkout from 4.0.0 to 4.1.0 (#420)
dependabot[bot] Sep 26, 2023
1ac21b1
build(deps): bump actions/first-interaction from 1.1.1 to 1.2.0 (#421)
dependabot[bot] Sep 28, 2023
e55a9d6
build(deps): bump github/codeql-action from 2.21.7 to 2.21.9 (#422)
dependabot[bot] Sep 28, 2023
c249b3e
chore: switch static analysis to container (#423)
rjaegers Sep 28, 2023
7b2ada0
build(deps): bump oxsecurity/megalinter from 7.3.0 to 7.4.0 (#419)
dependabot[bot] Sep 28, 2023
f5260dd
feat: add protobuf/echo/ProtoMessageBuilder (#416)
richardapeters Sep 28, 2023
6e05bb7
build(deps): bump google-github-actions/release-please-action from 3.…
dependabot[bot] Sep 29, 2023
45eb746
build(deps): bump oss-fuzz-base/base-builder from `5e1404d` to `6c61e…
dependabot[bot] Oct 3, 2023
19d14bf
build: add emil_install to emil_build_for.cmake which only installs t…
richardapeters Oct 3, 2023
fd73c78
build(deps): bump seanmiddleditch/gha-setup-ninja from 3 to 4 (#430)
dependabot[bot] Oct 10, 2023
536bf6d
build(deps): bump ossf/scorecard-action from 2.2.0 to 2.3.0 (#432)
dependabot[bot] Oct 10, 2023
48b1127
build(deps): bump github/codeql-action from 2.21.9 to 2.22.1 (#433)
dependabot[bot] Oct 10, 2023
83d39fd
chore: make services/util/MessageCommunicationSecured compliant with …
richardapeters Oct 11, 2023
ef29941
build(deps): bump github/codeql-action from 2.22.1 to 2.22.3 (#437)
dependabot[bot] Oct 17, 2023
a9070a4
build(deps): bump actions/checkout from 4.1.0 to 4.1.1 (#438)
dependabot[bot] Oct 19, 2023
4b52156
feat: removed Dac.hpp (#439)
daantimmer Oct 19, 2023
2c87dfb
feat: added SerialCommunicationLoopback (#440)
daantimmer Oct 20, 2023
063b595
fix: added workaround mbedtls and clang-cl incomatibility (#441)
daantimmer Oct 23, 2023
21f640d
build(deps): bump Namchee/conventional-pr from 0.14.0 to 0.14.1 (#443)
dependabot[bot] Oct 24, 2023
d6de535
build(deps): bump ossf/scorecard-action from 2.3.0 to 2.3.1 (#444)
dependabot[bot] Oct 24, 2023
8039f73
build(deps): bump github/codeql-action from 2.22.3 to 2.22.4 (#442)
dependabot[bot] Oct 25, 2023
3358e45
build: only build and install protobuf echo compilers when EMIL_BUILD…
richardapeters Oct 26, 2023
40958dc
build(deps): bump oxsecurity/megalinter from 7.4.0 to 7.5.0 (#446)
dependabot[bot] Oct 31, 2023
049ff32
build(deps): bump github/codeql-action from 2.22.4 to 2.22.5 (#447)
dependabot[bot] Oct 31, 2023
ec3a2f7
build(deps): bump Namchee/conventional-pr from 0.14.1 to 0.15.1 (#448)
dependabot[bot] Oct 31, 2023
8d5b900
build(deps): bump carlosperate/arm-none-eabi-gcc-action from 1.7.1 to…
dependabot[bot] Oct 31, 2023
1b7c229
Merge branch 'main' into feature/add_order_for_pack_builder_supported…
magi-arun Oct 31, 2023
94d2188
fix review comments
magi-arun Nov 3, 2023
d788f76
Update upgrade/pack_builder_instantiations/UpgradePackBuilderFacade.cpp
magi-arun Nov 16, 2023
23b70c2
Update upgrade/pack_builder_instantiations/UpgradePackBuilderFacade.cpp
magi-arun Nov 16, 2023
bf95231
refactor: fix review comments
magi-arun Nov 17, 2023
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
22 changes: 22 additions & 0 deletions upgrade/pack_builder/SupportedTargets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,38 +14,60 @@ namespace application
return *this;
}

SupportedTargetsBuilder& SupportedTargetsBuilder::Order(uint8_t order)
{
this->order.Emplace(order);
return *this;
}

SupportedTargetsBuilder& SupportedTargetsBuilder::AddCmd(const SupportedTargets::Target& target)
{
AddToMandatoryWhenNecessary(target);
AddInOrder(target);
targets.cmd.emplace_back(target);
return *this;
}

SupportedTargetsBuilder& SupportedTargetsBuilder::AddHex(const SupportedTargets::Target& target)
{
AddToMandatoryWhenNecessary(target);
AddInOrder(target);
targets.hex.emplace_back(target);
return *this;
}

SupportedTargetsBuilder& SupportedTargetsBuilder::AddElf(const SupportedTargets::Target& target, uint32_t offset)
{
AddToMandatoryWhenNecessary(target);
AddInOrder(target);
targets.elf.emplace_back(target, offset);
return *this;
}

SupportedTargetsBuilder& SupportedTargetsBuilder::AddBin(const SupportedTargets::Target& target, uint32_t offset)
{
AddToMandatoryWhenNecessary(target);
AddInOrder(target);
targets.bin.emplace_back(target, offset);
return *this;
}

void SupportedTargetsBuilder::AddToMandatoryWhenNecessary(const SupportedTargets::Target& target)
{
if (mandatory)
{
targets.mandatory.emplace_back(target);
mandatory = false;
}
}

void SupportedTargetsBuilder::AddInOrder(const SupportedTargets::Target& target)
{
if (order)
{
targets.order[*order].emplace_back(target);
order = infra::none;
}
}

SupportedTargetsBuilder SupportedTargets::Create()
Expand Down
11 changes: 11 additions & 0 deletions upgrade/pack_builder/SupportedTargets.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef UPGRADE_SUPPORTED_TARGETS_HPP
#define UPGRADE_SUPPORTED_TARGETS_HPP

#include "infra/util/Optional.hpp"
#include <map>
#include <string>
#include <utility>
#include <vector>
Expand Down Expand Up @@ -43,13 +45,19 @@ namespace application
return mandatory;
}

const auto& OrderOfTargets() const
{
return order;
}

private:
std::vector<Target> cmd;
std::vector<Target> hex;
std::vector<TargetWithOffset> elf;
std::vector<TargetWithOffset> bin;

std::vector<Target> mandatory;
std::map<uint8_t, std::vector<Target>> order;
};

class SupportedTargetsBuilder
Expand All @@ -62,6 +70,7 @@ namespace application

SupportedTargetsBuilder& Mandatory();
SupportedTargetsBuilder& Optional();
SupportedTargetsBuilder& Order(uint8_t order);

SupportedTargetsBuilder& AddCmd(const SupportedTargets::Target& target);
SupportedTargetsBuilder& AddHex(const SupportedTargets::Target& target);
Expand All @@ -70,10 +79,12 @@ namespace application

private:
void AddToMandatoryWhenNecessary(const SupportedTargets::Target& target);
void AddInOrder(const SupportedTargets::Target& target);

private:
SupportedTargets targets;
bool mandatory{ false };
infra::Optional<uint8_t> order;
};
}

Expand Down
35 changes: 35 additions & 0 deletions upgrade/pack_builder/test/TestSupportedTargets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,38 @@ TEST(SupportedTargetsTest, should_add_mandatory_targets)
EXPECT_EQ(2, targets.HexTargets().size());
EXPECT_EQ("application", targets.MandatoryTargets()[0]);
}

TEST(SupportedTargetsTest, should_add_target_to_mandatory_only_if_specified)
{
application::SupportedTargets targets = application::SupportedTargets::Create()
.Mandatory()
.AddHex("application")
.AddHex("data");

EXPECT_EQ(1, targets.MandatoryTargets().size());
EXPECT_EQ("application", targets.MandatoryTargets()[0]);
}

TEST(SupportedTargetsTest, should_add_targets_in_order)
{
application::SupportedTargets targets = application::SupportedTargets::Create()
.Order(2)
.AddHex("application")
.Order(1)
.AddHex("data");

EXPECT_EQ(2, targets.OrderOfTargets().size());
EXPECT_EQ("data", targets.OrderOfTargets()[0][0]);
magi-arun marked this conversation as resolved.
Show resolved Hide resolved
EXPECT_EQ("application", targets.OrderOfTargets()[1][0]);
}

TEST(SupportedTargetsTest, should_add_target_to_order_only_if_specified)
{
application::SupportedTargets targets = application::SupportedTargets::Create()
.Order(1)
.AddHex("data")
.AddHex("application");

EXPECT_EQ(1, targets.OrderOfTargets()[0].size());
EXPECT_EQ("data", targets.OrderOfTargets()[0][0]);
}
41 changes: 41 additions & 0 deletions upgrade/pack_builder_instantiations/UpgradePackBuilderFacade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ namespace main_
{}
};

struct IncorrectOrderOfTargetException
: std::runtime_error
{
explicit IncorrectOrderOfTargetException(const std::string& target)
: std::runtime_error("Incorrect order of target: " + target)
{}
};

UpgradePackBuilderFacade::UpgradePackBuilderFacade(const application::UpgradePackBuilder::HeaderInfo& headerInfo)
: headerInfo(headerInfo)
{}
Expand Down Expand Up @@ -51,12 +59,45 @@ namespace main_
builder.WriteUpgradePack(outputFilename, fileSystem);
}

infra::Optional<uint8_t> UpgradePackBuilderFacade::GetOrder(const std::string& targetName, const std::map<uint8_t, std::vector<std::string>>& orderedTargets) const
{
infra::Optional<uint8_t> order(infra::inPlace, 0);
for (const auto& targets : orderedTargets)
{
++(*order);
const auto targetPos = std::find(targets.second.begin(), targets.second.end(), targetName);

if (targetPos != targets.second.end())
return order;
magi-arun marked this conversation as resolved.
Show resolved Hide resolved
}
return infra::none;
}

bool UpgradePackBuilderFacade::CheckIfTargetIsInOrder(const std::string& target, const application::SupportedTargets& supportedTargets)
magi-arun marked this conversation as resolved.
Show resolved Hide resolved
magi-arun marked this conversation as resolved.
Show resolved Hide resolved
magi-arun marked this conversation as resolved.
Show resolved Hide resolved
{
static uint8_t currentOrderOfTarget = 1;
magi-arun marked this conversation as resolved.
Show resolved Hide resolved
static const auto& orderedTargets = supportedTargets.OrderOfTargets();
magi-arun marked this conversation as resolved.
Show resolved Hide resolved
const auto orderToAdd = GetOrder(target, orderedTargets);
if (orderToAdd)
magi-arun marked this conversation as resolved.
Show resolved Hide resolved
{
if (currentOrderOfTarget > *orderToAdd)
return false;
magi-arun marked this conversation as resolved.
Show resolved Hide resolved
else
currentOrderOfTarget = *orderToAdd;
}
return true;
}

std::vector<std::unique_ptr<application::Input>> UpgradePackBuilderFacade::CreateInputs(const application::SupportedTargets& supportedTargets, const TargetAndFiles& requestedTargets, application::InputFactory& factory)
{
std::vector<std::unique_ptr<application::Input>> inputs;

for (const auto& [target, file, address] : requestedTargets)
{
if (!CheckIfTargetIsInOrder(target, supportedTargets))
throw IncorrectOrderOfTargetException(target);
inputs.push_back(factory.CreateInput(target, file, address));
}

for (const auto& mandatoryTarget : supportedTargets.MandatoryTargets())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ namespace main_
virtual void PostBuilder(application::UpgradePackBuilder& builder, application::ImageSigner& signer, const BuildOptions& buildOptions);

private:
infra::Optional<uint8_t> GetOrder(const std::string& targetName, const std::map<uint8_t, std::vector<std::string>>& orderedTargets) const;
bool CheckIfTargetIsInOrder(const std::string& target, const application::SupportedTargets& supportedTargets);
std::vector<std::unique_ptr<application::Input>> CreateInputs(const application::SupportedTargets& supportedTargets, const TargetAndFiles& requestedTargets, application::InputFactory& factory);

protected:
Expand Down