Skip to content

Commit 5cd3eb0

Browse files
committed
Fix program version storage. Cleanups in Command. Improve its s11n.
1 parent a601cb4 commit 5cd3eb0

File tree

18 files changed

+71
-96
lines changed

18 files changed

+71
-96
lines changed

src/sw/builder/command.cpp

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -75,19 +75,6 @@ Command::Command(const SwBuilderContext &swctx)
7575
{
7676
}
7777

78-
/*Command::Command(const Command &rhs)
79-
: Base(rhs)
80-
, swctx(rhs.swctx)
81-
{
82-
SW_UNIMPLEMENTED;
83-
}
84-
85-
Command &Command::operator=(const Command &rhs)
86-
{
87-
SW_UNIMPLEMENTED;
88-
return *this;
89-
}*/
90-
9178
Command::~Command()
9279
{
9380
}
@@ -274,19 +261,6 @@ void Command::addImplicitInput(const Files &files)
274261
addImplicitInput(f);
275262
}
276263

277-
/*void Command::addIntermediate(const path &p)
278-
{
279-
if (p.empty())
280-
return;
281-
intermediate.insert(p);
282-
}
283-
284-
void Command::addIntermediate(const Files &files)
285-
{
286-
for (auto &f : files)
287-
addIntermediate(f);
288-
}*/
289-
290264
void Command::addOutput(const path &p)
291265
{
292266
if (p.empty())
@@ -1059,16 +1033,6 @@ void Command::onEnd() noexcept
10591033
t_end = Clock::now();
10601034
}
10611035

1062-
/*void Command::load(BinaryContext &bctx)
1063-
{
1064-
1065-
}
1066-
1067-
void Command::save(BinaryContext &bctx)
1068-
{
1069-
1070-
}*/
1071-
10721036
Command &Command::operator|(Command &c2)
10731037
{
10741038
Base::operator|(c2);

src/sw/builder/command.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,6 @@ struct SW_BUILDER_API Command : ICastable, CommandNode, detail::ResolvableComman
193193

194194
Command() = default;
195195
Command(const SwBuilderContext &swctx);
196-
//Command(const Command &);
197-
//Command &operator=(const Command &);
198196
virtual ~Command();
199197

200198
void prepare() override;
@@ -215,8 +213,6 @@ struct SW_BUILDER_API Command : ICastable, CommandNode, detail::ResolvableComman
215213
void addInput(const Files &p);
216214
void addImplicitInput(const path &p);
217215
void addImplicitInput(const Files &p);
218-
//void addIntermediate(const path &p);
219-
//void addIntermediate(const Files &p);
220216
void addOutput(const path &p);
221217
void addOutput(const Files &p);
222218
path redirectStdin(const path &p);
@@ -231,9 +227,6 @@ struct SW_BUILDER_API Command : ICastable, CommandNode, detail::ResolvableComman
231227

232228
bool lessDuringExecution(const CommandNode &rhs) const override;
233229

234-
//void load(BinaryContext &bctx);
235-
//void save(BinaryContext &bctx);
236-
237230
void onBeforeRun() noexcept override;
238231
void onEnd() noexcept override;
239232

@@ -312,11 +305,6 @@ struct SW_BUILDER_API ExecuteBuiltinCommand : Command
312305
ExecuteBuiltinCommand(const SwBuilderContext &swctx, const String &cmd_name, void *f, int version = 0);
313306
virtual ~ExecuteBuiltinCommand() = default;
314307

315-
//path getProgram() const override { return "ExecuteBuiltinCommand"; };
316-
317-
//template <class T>
318-
//auto push_back(T &&v) { args.push_back(v); }
319-
320308
using Command::push_back;
321309
void push_back(const Strings &strings);
322310
void push_back(const Files &files);

src/sw/builder/execution_plan_serialization.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ enum SerializationType
2424
ExecutionPlan ExecutionPlan::load(const path &p, const SwBuilderContext &swctx, int type)
2525
{
2626
// TODO: memory leak
27-
auto commands = new std::unordered_set<std::shared_ptr<builder::Command>>;
27+
auto &commands = *new std::unordered_set<std::shared_ptr<builder::Command>>;
28+
29+
type = 1;
2830
if (type == 0)
2931
{
3032
std::ifstream ifs(p, std::ios_base::in | std::ios_base::binary);
@@ -37,15 +39,20 @@ ExecutionPlan ExecutionPlan::load(const path &p, const SwBuilderContext &swctx,
3739
boost::archive::text_iarchive ia(ifs);
3840
ia >> commands;
3941
}
40-
for (auto &c : *commands)
42+
43+
// some setup
44+
for (auto &c : commands)
45+
{
4146
c->setContext(swctx);
42-
return createExecutionPlan(*commands);
47+
}
48+
return createExecutionPlan(commands);
4349
}
4450

4551
void ExecutionPlan::save(const path &p, int type) const
4652
{
4753
fs::create_directories(p.parent_path());
4854

55+
type = 1;
4956
if (type == 0)
5057
{
5158
std::ofstream ofs(p, std::ios_base::out | std::ios_base::binary);

src/sw/builder/execution_plan_serialization_boost.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,20 @@ SERIALIZATION_BEGIN_SPLIT
117117
ar >> v.command_storage;
118118
ar >> v.working_directory;
119119
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;
125+
120126
size_t sz;
121127
ar >> sz;
128+
String s;
129+
ar >> s;
130+
sz--;
131+
v.setProgram(s);
122132
while (sz--)
123133
{
124-
String s;
125134
ar >> s;
126135
v.push_back(s);
127136
}
@@ -132,6 +141,12 @@ SERIALIZATION_SPLIT_CONTINUE
132141
ar << v.command_storage;
133142
ar << v.working_directory;
134143
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;
149+
135150
ar << v.arguments.size();
136151
for (auto &a : v.arguments)
137152
ar << a->toString();

src/sw/builder/program.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
#include "command.h"
1010
#include "file_storage.h"
11-
//#include "program_version_storage.h"
1211
#include "sw_context.h"
1312

1413
#include <sw/manager/storage.h>

src/sw/builder/program_version_storage.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,27 @@ ProgramVersionStorage::ProgramVersionStorage(const path &fn)
1717
: fn(fn)
1818
{
1919
path p;
20-
String s;
20+
String v;
21+
time_t t;
2122
std::ifstream ifile(fn);
22-
while (ifile)
23+
while (1)
2324
{
2425
ifile >> p;
2526
if (!ifile)
2627
break;
27-
ifile >> s;
28-
//if (!File(p, service_fs).isChanged())
29-
//versions[p] = s;
28+
ifile >> v;
29+
ifile >> t;
30+
auto lwt = fs::last_write_time(p).time_since_epoch().count();
31+
if (t && lwt <= t)
32+
versions[p] = {v,lwt};
3033
}
3134
}
3235

3336
ProgramVersionStorage::~ProgramVersionStorage()
3437
{
3538
std::ofstream ofile(fn);
3639
for (auto &[p, v] : std::map{ versions.begin(), versions.end() })
37-
ofile << p << " " << v.toString() << "\n";
40+
ofile << p << " " << v.v.toString() << " " << v.t << "\n";
3841
}
3942

4043
}

src/sw/builder/program_version_storage.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,24 @@ struct FileStorage;
1515

1616
struct ProgramVersionStorage
1717
{
18+
struct ProgramInfo
19+
{
20+
Version v;
21+
time_t t;
22+
23+
operator Version&() { return v; }
24+
};
25+
1826
path fn;
19-
std::unordered_map<path, Version> versions;
27+
std::unordered_map<path, ProgramInfo> versions;
2028

2129
ProgramVersionStorage(const path &fn);
2230
~ProgramVersionStorage();
31+
32+
void addVersion(const path &p, const Version &v)
33+
{
34+
versions[p] = {v,fs::last_write_time(p).time_since_epoch().count()};
35+
}
2336
};
2437

2538
}

src/sw/builder/sw_context.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ Version getVersion(const SwBuilderContext &swctx, builder::detail::ResolvableCom
133133

134134
boost::upgrade_to_unique_lock lk2(lk);
135135

136-
vs.versions[program] = gatherVersion1(c, in_regex);
136+
vs.addVersion(program, gatherVersion1(c, in_regex));
137137
return vs.versions[program];
138138
}
139139

@@ -149,7 +149,7 @@ Version getVersion(const SwBuilderContext &swctx, const path &program, const Str
149149

150150
boost::upgrade_to_unique_lock lk2(lk);
151151

152-
vs.versions[program] = gatherVersion(program, arg, in_regex);
152+
vs.addVersion(program, gatherVersion(program, arg, in_regex));
153153
return vs.versions[program];
154154
}
155155

src/sw/client/command/build.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,8 +413,7 @@ SUBCOMMAND_DECL2(build)
413413
{
414414
auto b = swctx.createBuild();
415415
b->overrideBuildState(sw::BuildState::Prepared);
416-
sw::ExecutionPlan p;
417-
p.load(build_explan, swctx);
416+
auto p = sw::ExecutionPlan::load(build_explan, swctx);
418417
b->execute(p);
419418
return;
420419
}
@@ -444,6 +443,7 @@ SUBCOMMAND_DECL2(build)
444443
if (build_default_explan)
445444
{
446445
b->load();
446+
swctx.clearFileStorages();
447447
b->runSavedExecutionPlan();
448448
return;
449449
}

src/sw/core/build.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ namespace sw
4949
SwBuild::SwBuild(SwContext &swctx)
5050
: swctx(swctx)
5151
{
52+
binary_dir = fs::current_path() / SW_BINARY_DIR;
5253
}
5354

5455
SwBuild::~SwBuild()
@@ -315,7 +316,7 @@ void SwBuild::execute(ExecutionPlan &p) const
315316
LOG_INFO(logger, "Build time: " << t2 << " s.");*/
316317

317318
if (time_trace)
318-
p.saveChromeTrace(swctx.source_dir / SW_BINARY_DIR / "misc" / "time_trace.json");
319+
p.saveChromeTrace(getBinaryDirectory() / "misc" / "time_trace.json");
319320
}
320321

321322
Commands SwBuild::getCommands() const
@@ -471,7 +472,7 @@ Input &SwBuild::addInput(const PackageId &i)
471472
template <class I>
472473
Input &SwBuild::addInput1(const I &i)
473474
{
474-
auto input = std::make_unique<Input>(i, swctx);
475+
auto input = std::make_unique<Input>(i, getContext());
475476
auto it = std::find_if(inputs.begin(), inputs.end(), [&i = *input](const auto &p)
476477
{
477478
return *p == i;
@@ -484,7 +485,7 @@ Input &SwBuild::addInput1(const I &i)
484485

485486
path SwBuild::getExecutionPlanPath() const
486487
{
487-
return swctx.source_dir / SW_BINARY_DIR / "ep" / getHash() += ".ep";
488+
return getBinaryDirectory() / "ep" / getHash() += ".ep";
488489
}
489490

490491
void SwBuild::saveExecutionPlan() const
@@ -499,8 +500,7 @@ void SwBuild::runSavedExecutionPlan() const
499500
{
500501
CHECK_STATE(BuildState::InputsLoaded);
501502

502-
ExecutionPlan p;
503-
p.load(getExecutionPlanPath(), getContext());
503+
auto p = ExecutionPlan::load(getExecutionPlanPath(), getContext());
504504

505505
// change state
506506
overrideBuildState(BuildState::Prepared);

0 commit comments

Comments
 (0)