Skip to content

Commit ebdd4af

Browse files
committed
Improve s11n.
1 parent 5cd3eb0 commit ebdd4af

16 files changed

Lines changed: 246 additions & 112 deletions

File tree

src/sw/builder/execution_plan.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,8 +399,12 @@ void ExecutionPlan::prepare(USet &cmds)
399399

400400
// some commands get its i/o deps in wrong order,
401401
// so we explicitly call this once more
402-
//for (auto &c : cmds)
403-
//c->addInputOutputDeps();
402+
// do not remove!
403+
for (auto &c : cmds)
404+
{
405+
if (auto c1 = dynamic_cast<builder::Command*>(c))
406+
c1->addInputOutputDeps();
407+
}
404408

405409
// separate loop for additional deps tracking (programs, inputs, outputs etc.)
406410
auto cmds2 = cmds;

src/sw/builder/execution_plan_serialization.cpp

Lines changed: 52 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,29 @@
66

77
#include "execution_plan.h"
88

9+
#include <sw/support/serialization.h>
10+
11+
#include <boost/serialization/access.hpp>
12+
#include <boost/archive/binary_iarchive.hpp>
13+
#include <boost/archive/binary_oarchive.hpp>
14+
#include <boost/archive/text_iarchive.hpp>
15+
#include <boost/archive/text_oarchive.hpp>
916
#include <primitives/exceptions.h>
1017

1118
#include <fstream>
1219

1320
#include "execution_plan_serialization_boost.h"
1421

22+
static const int serialization_version = 2;
23+
1524
namespace sw
1625
{
1726

27+
namespace driver
28+
{
29+
struct Command;
30+
}
31+
1832
enum SerializationType
1933
{
2034
BoostSerializationBinaryArchive,
@@ -26,18 +40,36 @@ ExecutionPlan ExecutionPlan::load(const path &p, const SwBuilderContext &swctx,
2640
// TODO: memory leak
2741
auto &commands = *new std::unordered_set<std::shared_ptr<builder::Command>>;
2842

29-
type = 1;
43+
auto load = [&commands](auto &ar)
44+
{
45+
int version;
46+
ar >> version;
47+
if (version != serialization_version)
48+
{
49+
throw SW_RUNTIME_ERROR("Incorrect archive version (" + std::to_string(version) + "), expected (" +
50+
std::to_string(serialization_version) + "), run configure command again");
51+
}
52+
path cp;
53+
ar >> cp;
54+
fs::current_path(cp);
55+
ar >> commands;
56+
};
57+
3058
if (type == 0)
3159
{
32-
std::ifstream ifs(p, std::ios_base::in | std::ios_base::binary);
60+
std::ifstream ifs(p, std::ios_base::in | std::ios_base::binary);
61+
if (!ifs)
62+
throw SW_RUNTIME_ERROR("Cannot read file: " + normalize_path(p));
3363
boost::archive::binary_iarchive ia(ifs);
34-
ia >> commands;
64+
load(ia);
3565
}
3666
else if (type == 1)
3767
{
38-
std::ifstream ifs(p);
68+
std::ifstream ifs(p);
69+
if (!ifs)
70+
throw SW_RUNTIME_ERROR("Cannot read file: " + normalize_path(p));
3971
boost::archive::text_iarchive ia(ifs);
40-
ia >> commands;
72+
load(ia);
4173
}
4274

4375
// some setup
@@ -52,18 +84,28 @@ void ExecutionPlan::save(const path &p, int type) const
5284
{
5385
fs::create_directories(p.parent_path());
5486

55-
type = 1;
87+
auto save = [this](auto &ar)
88+
{
89+
ar << serialization_version;
90+
ar << fs::current_path();
91+
ar << commands;
92+
};
93+
5694
if (type == 0)
5795
{
58-
std::ofstream ofs(p, std::ios_base::out | std::ios_base::binary);
96+
std::ofstream ofs(p, std::ios_base::out | std::ios_base::binary);
97+
if (!ofs)
98+
throw SW_RUNTIME_ERROR("Cannot write file: " + normalize_path(p));
5999
boost::archive::binary_oarchive oa(ofs);
60-
oa << commands;
100+
save(oa);
61101
}
62102
else if (type == 1)
63103
{
64-
std::ofstream ofs(p);
104+
std::ofstream ofs(p);
105+
if (!ofs)
106+
throw SW_RUNTIME_ERROR("Cannot write file: " + normalize_path(p));
65107
boost::archive::text_oarchive oa(ofs);
66-
oa << commands;
108+
save(oa);
67109
}
68110
}
69111

src/sw/builder/execution_plan_serialization_boost.h

Lines changed: 70 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@
44
// License, v. 2.0. If a copy of the MPL was not distributed with this
55
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
66

7-
#include <boost/serialization/access.hpp>
8-
#include <boost/archive/binary_iarchive.hpp>
9-
#include <boost/archive/binary_oarchive.hpp>
10-
#include <boost/archive/text_iarchive.hpp>
11-
#include <boost/archive/text_oarchive.hpp>
12-
137
#ifdef _MSC_VER
148
#pragma warning(push)
159
#pragma warning(disable : 4005) // warning C4005: 'XXX': macro redefinition
@@ -19,35 +13,13 @@
1913

2014
////////////////////////////////////////////////////////////////////////////////
2115

22-
#define SERIALIZATION_BEGIN_LOAD(t) \
23-
template <class Archive> \
24-
void load(Archive &ar, t &v, const unsigned)
25-
26-
#define SERIALIZATION_BEGIN_SAVE(t) \
27-
template <class Archive> \
28-
void save(Archive &ar, const t &v, const unsigned)
29-
30-
#define SERIALIZATION_BEGIN_SPLIT \
31-
BOOST_SERIALIZATION_SPLIT_FREE(SERIALIZATION_TYPE) \
32-
namespace boost::serialization \
33-
{ \
34-
SERIALIZATION_BEGIN_LOAD(SERIALIZATION_TYPE) \
35-
{
36-
37-
#define SERIALIZATION_END }
38-
#define SERIALIZATION_SPLIT_CONTINUE } SERIALIZATION_BEGIN_SAVE(SERIALIZATION_TYPE) {
39-
#define SERIALIZATION_SPLIT_END } SERIALIZATION_END
40-
41-
////////////////////////////////////////////////////////////////////////////////
42-
4316
#define SERIALIZATION_TYPE ::path
4417
SERIALIZATION_BEGIN_SPLIT
4518
String s;
4619
ar >> s;
4720
v = fs::u8path(s);
48-
SERIALIZATION_SPLIT_CONTINUE
49-
String s = v.u8string();
50-
ar << s;
21+
SERIALIZATION_SPLIT_CONTINUE
22+
ar << v.u8string();
5123
SERIALIZATION_SPLIT_END
5224

5325
////////////////////////////////////////
@@ -87,41 +59,35 @@ SERIALIZATION_SPLIT_CONTINUE
8759
SERIALIZATION_SPLIT_END
8860

8961
////////////////////////////////////////
90-
91-
namespace boost::serialization
92-
{
93-
94-
template<class Archive>
95-
void serialize(Archive &ar, ::sw::builder::Command::Argument &a, const unsigned)
96-
{
97-
ar << a.toString();
98-
}
99-
100-
} // namespace boost::serialization
101-
102-
/*StringHashMap<int> gatherStrings() const
103-
{
104-
for (auto &c : commands)
105-
{
106-
insert(c->in.file.u8string());
107-
insert(c->out.file.u8string());
108-
insert(c->err.file.u8string());
109-
}
110-
}*/
62+
63+
#define SERIALIZATION_TYPE ::sw::builder::Command::Argument
64+
SERIALIZATION_BEGIN_UNIFIED
65+
ar & a.toString();
66+
SERIALIZATION_UNIFIED_END
11167

11268
////////////////////////////////////////
11369

114-
#define SERIALIZATION_TYPE ::sw::builder::Command
70+
#define SERIALIZATION_TYPE ::primitives::Command::Stream
71+
SERIALIZATION_BEGIN_UNIFIED
72+
ar & v.text;
73+
ar & v.file;
74+
ar & v.append;
75+
SERIALIZATION_UNIFIED_END
76+
77+
////////////////////////////////////////
78+
79+
#define SERIALIZATION_TYPE ::primitives::Command
11580
SERIALIZATION_BEGIN_SPLIT
116-
ar >> v.name;
117-
ar >> v.command_storage;
118-
ar >> v.working_directory;
119-
ar >> v.environment;
120-
ar >> v.first_response_file_argument;
121-
ar >> v.always;
122-
ar >> v.remove_outputs_before_execution;
123-
ar >> v.strict_order;
124-
ar >> v.output_dirs;
81+
ar & v.working_directory;
82+
ar & v.environment;
83+
84+
ar & v.in;
85+
ar & v.out;
86+
ar & v.err;
87+
88+
/*if (v.next)
89+
throw SW_RUNTIME_ERROR("Some error");
90+
ar & v.prev;*/
12591

12692
size_t sz;
12793
ar >> sz;
@@ -133,25 +99,51 @@ SERIALIZATION_BEGIN_SPLIT
13399
{
134100
ar >> s;
135101
v.push_back(s);
136-
}
137-
ar >> v.inputs;
138-
ar >> v.outputs;
102+
}
139103
SERIALIZATION_SPLIT_CONTINUE
140-
ar << v.getName();
141-
ar << v.command_storage;
142-
ar << v.working_directory;
143-
ar << v.environment;
144-
ar << v.first_response_file_argument;
145-
ar << v.always;
146-
ar << v.remove_outputs_before_execution;
147-
ar << v.strict_order;
148-
ar << v.output_dirs;
104+
ar & v.working_directory;
105+
ar & v.environment;
106+
107+
ar & v.in;
108+
ar & v.out;
109+
ar & v.err;
110+
111+
//ar & v.prev;
149112

150113
ar << v.arguments.size();
151114
for (auto &a : v.arguments)
152-
ar << a->toString();
153-
ar << v.inputs;
154-
ar << v.outputs;
115+
ar << a->toString();
116+
SERIALIZATION_SPLIT_END
117+
118+
////////////////////////////////////////
119+
120+
#define SERIALIZATION_TYPE ::sw::builder::Command
121+
SERIALIZATION_BEGIN_SPLIT
122+
ar & base_object<::primitives::Command>(v);
123+
124+
ar & v.name;
125+
ar & v.command_storage;
126+
ar & v.first_response_file_argument;
127+
ar & v.always;
128+
ar & v.remove_outputs_before_execution;
129+
ar & v.strict_order;
130+
ar & v.output_dirs;
131+
132+
ar & v.inputs;
133+
ar & v.outputs;
134+
SERIALIZATION_SPLIT_CONTINUE
135+
ar & base_object<::primitives::Command>(v);
136+
137+
ar & v.getName();
138+
ar & v.command_storage;
139+
ar & v.first_response_file_argument;
140+
ar & v.always;
141+
ar & v.remove_outputs_before_execution;
142+
ar & v.strict_order;
143+
ar & v.output_dirs;
144+
145+
ar & v.inputs;
146+
ar & v.outputs;
155147
SERIALIZATION_SPLIT_END
156148

157149
////////////////////////////////////////
@@ -167,14 +159,14 @@ SERIALIZATION_BEGIN_SPLIT
167159
ar >> *c;
168160
}
169161
SERIALIZATION_SPLIT_CONTINUE
170-
SW_UNIMPLEMENTED;
162+
SW_UNREACHABLE;
171163
SERIALIZATION_SPLIT_END
172164

173165
////////////////////////////////////////
174166

175167
#define SERIALIZATION_TYPE ::std::vector<::sw::ExecutionPlan::PtrT>
176168
SERIALIZATION_BEGIN_SPLIT
177-
SW_UNIMPLEMENTED;
169+
SW_UNREACHABLE;
178170
SERIALIZATION_SPLIT_CONTINUE
179171
ar << v.size();
180172
for (auto c : v)

src/sw/client/command/update.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@
1818

1919
#include "commands.h"
2020

21-
extern ::cl::opt<bool> dry_run;
21+
//extern ::cl::opt<bool> dry_run;
2222
::cl::opt<String> build_arg_update(::cl::Positional, ::cl::desc("Update lock"), ::cl::init("."), ::cl::sub(subcommand_update));
2323

2424
SUBCOMMAND_DECL(update)
2525
{
2626
SW_UNIMPLEMENTED;
2727

2828
auto swctx = createSwContext();
29-
dry_run = true;
29+
//dry_run = true;
3030
/*((Strings&)build_arg).clear();
3131
build_arg.push_back(build_arg_update.getValue());
3232
cli_build(*swctx);*/

0 commit comments

Comments
 (0)