Skip to content

Commit d27d0a5

Browse files
committed
Add simple target aliases.
1 parent 4d13753 commit d27d0a5

11 files changed

Lines changed: 82 additions & 59 deletions

File tree

cppan.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,6 @@ projects:
167167
private:
168168
- name: tools.self_builder
169169
ref: self_builder
170-
- name: pvt.egorpugin.primitives.context
171-
version: master
172-
local: primitives.context
173170
- pvt.cppan.demo.boost.uuid: 1
174171
- name: pvt.egorpugin.primitives.tools.embedder
175172
version: master
@@ -251,6 +248,9 @@ projects:
251248
public:
252249
- manager
253250
- pvt.cppan.demo.preshing.junction: master
251+
- name: pvt.egorpugin.primitives.context
252+
version: master
253+
local: primitives.context
254254

255255
post_sources: |
256256
file(GLOB_RECURSE x "${SDIR}/*")

src/builder/db_file.cpp

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
void save_from_memory_to_file(const path &fn, sqlite3 *db);
1616

17+
#include <primitives/context.h>
1718
#include <primitives/date_time.h>
1819
#include <primitives/debug.h>
1920
#include <primitives/lock.h>
@@ -164,32 +165,27 @@ void FileDb::save(FileStorage &fs, ConcurrentHashMap<path, FileRecord> &files) c
164165
r = sqlite3_open(":memory:", &db);
165166
CHECK_RC(r, SQLITE_OK);
166167

167-
//r = sqlite3_db_config(db, SQLITE_CONFIG_SINGLETHREAD, 1);
168-
//CHECK_RC(r, SQLITE_OK);
169-
170168
r = sqlite3_exec(db, R"xxx(
171169
CREATE TABLE "file" (
172-
"file_id" INTEGER NOT NULL,
170+
"hash" INTEGER,
173171
"path" TEXT,
174172
"last_write_time" INTEGER,
175173
"size" INTEGER,
176-
"hash" INTEGER,
177-
"flags" INTEGER,
178-
PRIMARY KEY ("file_id")
174+
"flags" INTEGER
179175
);
180176
181177
CREATE TABLE "file_dependency" (
182-
"file_id" INTEGER NOT NULL,
183-
"dependency_file_id" INTEGER NOT NULL,
184-
PRIMARY KEY ("file_id", "dependency_file_id"),
185-
FOREIGN KEY ("file_id") REFERENCES "file" ("file_id") ON DELETE CASCADE ON UPDATE CASCADE
186-
--, FOREIGN KEY ("dependency_file_id") REFERENCES "file" ("file_id") ON DELETE CASCADE ON UPDATE CASCADE
178+
"hash" INTEGER,
179+
"dependency_hash" INTEGER
187180
);
188181
)xxx", 0, 0, 0);
189182
CHECK_RC(r, SQLITE_OK);
190183

184+
r = sqlite3_exec(db, "BEGIN", 0, 0, 0);
185+
CHECK_RC(r, SQLITE_OK);
186+
191187
sqlite3_stmt *sf;
192-
r = sqlite3_prepare_v2(db, "INSERT INTO file (path, last_write_time, size, hash) VALUES (?,?,?,?)", -1, &sf, 0);
188+
r = sqlite3_prepare_v2(db, "INSERT INTO file (path, last_write_time, hash) VALUES (?,?,?)", -1, &sf, 0);
193189
CHECK_RC(r, SQLITE_OK);
194190

195191
sqlite3_stmt *sd;
@@ -202,22 +198,22 @@ CREATE TABLE "file_dependency" (
202198
if (!f.data)
203199
continue;
204200

205-
sqlite3_bind_text(sf, 1, normalize_path(f.file).c_str(), -1, 0);
201+
auto h1 = std::hash<path>()(f.file);
202+
auto s = normalize_path(f.file);
203+
sqlite3_bind_text(sf, 1, s.c_str(), s.size() + 1, 0);
206204
sqlite3_bind_int64(sf, 2, f.data->last_write_time.time_since_epoch().count());
207-
sqlite3_bind_int64(sf, 3, f.data->size);
208-
sqlite3_bind_int64(sf, 4, std::hash<path>()(f.file));
205+
//sqlite3_bind_int64(sf, 3, f.data->size);
206+
sqlite3_bind_int64(sf, 3, h1);
209207

210208
r = sqlite3_step(sf);
211209
CHECK_RC(r, SQLITE_DONE);
212210

213211
r = sqlite3_reset(sf);
214212
CHECK_RC(r, SQLITE_OK);
215213

216-
auto rowid = sqlite3_last_insert_rowid(db);
217-
218214
for (auto &[f, d] : f.implicit_dependencies)
219215
{
220-
sqlite3_bind_int64(sd, 1, rowid);
216+
sqlite3_bind_int64(sd, 1, h1);
221217
sqlite3_bind_int64(sd, 2, std::hash<path>()(d->file));
222218

223219
r = sqlite3_step(sd);
@@ -234,12 +230,38 @@ CREATE TABLE "file_dependency" (
234230
r = sqlite3_finalize(sd);
235231
CHECK_RC(r, SQLITE_OK);
236232

233+
r = sqlite3_exec(db, "COMMIT", 0, 0, 0);
234+
CHECK_RC(r, SQLITE_OK);
235+
237236
save_from_memory_to_file(f += ".sqlite", db);
238237

239238
r = sqlite3_close_v2(db);
240239
CHECK_RC(r, SQLITE_OK);
241240
}
242241
LOG_INFO(logger, "save to sqlite db time: " << t2.getTimeFloat() << " s.");
242+
243+
ScopedTime t3;
244+
{
245+
BinaryContext b(10'000'000);
246+
for (auto i = files.getIterator(); i.isValid(); i.next())
247+
{
248+
auto &f = *i.getValue();
249+
if (!f.data)
250+
continue;
251+
252+
auto h1 = std::hash<path>()(f.file);
253+
b.write(h1);
254+
b.write(normalize_path(f.file));
255+
b.write(f.data->last_write_time.time_since_epoch().count());
256+
//b.write(f.data->size);
257+
b.write(f.implicit_dependencies.size());
258+
259+
for (auto &[f, d] : f.implicit_dependencies)
260+
b.write(std::hash<path>()(d->file));
261+
}
262+
b.save(f += ".2");
263+
}
264+
LOG_INFO(logger, "save to file2 time: " << t3.getTimeFloat() << " s.");
243265
}
244266

245267
template <class T>
@@ -266,8 +288,8 @@ void FileDb::write(std::vector<uint8_t> &v, const FileRecord &f) const
266288
write_int(v, std::hash<path>()(f.file));
267289
write_str(v, normalize_path(f.file));
268290
write_int(v, f.data->last_write_time);
269-
write_int(v, f.data->size);
270-
write_int(v, f.data->flags.to_ullong());
291+
//write_int(v, f.data->size);
292+
//write_int(v, f.data->flags.to_ullong());
271293

272294
auto n = f.implicit_dependencies.size();
273295
write_int(v, n);

src/builder/file.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,9 +391,7 @@ void FileRecord::setGenerator(const std::shared_ptr<builder::Command> &g)
391391
!gold->isExecuted() &&
392392
!gold->maybe_unused &&
393393
gold->getHash() != g->getHash()))
394-
;
395-
//throw std::runtime_error("Setting generator twice on file: " + file.u8string());
396-
//generator.reset();
394+
throw std::runtime_error("Setting generator twice on file: " + file.u8string());
397395
generator = g;
398396
generated_ = true;
399397
}

src/builder/file.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
#pragma once
88

9-
#include "node.h"
109
#include <enums.h>
10+
#include <node.h>
1111

1212
#include <primitives/filesystem.h>
1313

@@ -28,7 +28,7 @@ struct Command;
2828
struct FileRecord;
2929
struct FileStorage;
3030

31-
struct SW_BUILDER_API File : Data
31+
struct SW_BUILDER_API File : Node
3232
{
3333
FileStorage *fs = nullptr;
3434
path file;

src/builder/node.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
namespace sw
1212
{
1313

14-
void Executable::execute() const
14+
void detail::Executable::execute() const
1515
{
1616
if (auto c = getCommand())
1717
return c->execute();

src/builder/node.h

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,35 +26,29 @@ struct SW_BUILDER_API Node
2626
virtual ~Node() = default;
2727

2828
template <class T>
29-
T *as() { return dynamic_cast<T*>(this); }
29+
T *as()
30+
{
31+
return dynamic_cast<T *>(this);
32+
}
3033

3134
template <class T>
32-
T *as() const { return dynamic_cast<T*>(this); }
33-
34-
//Cppan *root = nullptr;
35+
T *as() const
36+
{
37+
return dynamic_cast<T *>(this);
38+
}
3539
};
3640

37-
struct SW_BUILDER_API Data : virtual Node
41+
namespace detail
3842
{
39-
virtual ~Data() = default;
40-
};
4143

42-
struct SW_BUILDER_API Executable : virtual Node
44+
struct SW_BUILDER_API Executable : Node
4345
{
4446
virtual ~Executable() = default;
4547

4648
virtual std::shared_ptr<builder::Command> getCommand() const = 0;
4749
virtual void execute() const;
4850
};
4951

50-
struct SW_BUILDER_API Transform : Node
51-
{
52-
virtual ~Transform() = default;
53-
};
54-
55-
struct SW_BUILDER_API Function : Node
56-
{
57-
virtual ~Function() = default;
58-
};
52+
}
5953

6054
}

src/builder/program.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77
#pragma once
88

99
#include "file.h"
10+
#include "node.h"
1011

1112
#include <optional>
1213

1314
namespace sw
1415
{
1516

16-
struct SW_BUILDER_API Program : File, Executable
17+
struct SW_BUILDER_API Program : File, detail::Executable
1718
{
1819
virtual ~Program() = default;
1920

src/driver/cpp/solution.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,12 +1317,12 @@ path Build::build_configs(const std::unordered_set<ExtendedPackageData> &pkgs)
13171317
// generate main source file
13181318
if (many_files)
13191319
{
1320-
Context ctx;
1320+
CppContext ctx;
13211321

1322-
Context build;
1322+
CppContext build;
13231323
build.beginFunction("void build(Solution &s)");
13241324

1325-
Context check;
1325+
CppContext check;
13261326
check.beginFunction("void check(Checker &c)");
13271327

13281328
for (auto &r : pkgs)

src/driver/cpp/target.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ struct Directory;
136136
using TargetBaseType = Target;
137137
using TargetBaseTypePtr = std::shared_ptr<TargetBaseType>;
138138

139-
struct SW_DRIVER_CPP_API TargetBase : virtual Node, LanguageStorage, ProjectDirectories
139+
struct SW_DRIVER_CPP_API TargetBase : Node, LanguageStorage, ProjectDirectories
140140
{
141141
using TargetMap = std::unordered_map<PackageId, TargetBaseTypePtr>;
142142

@@ -751,6 +751,8 @@ struct SW_DRIVER_CPP_API LibraryTarget : NativeExecutedTarget
751751
bool prepare() override;
752752
};
753753

754+
using Library = LibraryTarget;
755+
754756
/**
755757
* \brief Executable target.
756758
*/
@@ -771,6 +773,8 @@ struct SW_DRIVER_CPP_API ExecutableTarget : NativeExecutedTarget//, Program
771773
path getOutputDir() const override;
772774
};
773775

776+
using Executable = ExecutableTarget;
777+
774778
struct SW_DRIVER_CPP_API LibraryTargetBase : NativeExecutedTarget
775779
{
776780
using NativeExecutedTarget::NativeExecutedTarget;
@@ -798,6 +802,8 @@ struct SW_DRIVER_CPP_API StaticLibraryTarget : LibraryTargetBase
798802
}
799803
};
800804

805+
using StaticLibrary = StaticLibraryTarget;
806+
801807
/**
802808
* \brief Shared only target.
803809
*/
@@ -820,6 +826,8 @@ struct SW_DRIVER_CPP_API SharedLibraryTarget : LibraryTargetBase
820826
}
821827
};
822828

829+
using SharedLibrary = SharedLibraryTarget;
830+
823831
/**
824832
* \brief Module only target.
825833
*/

src/tools/self_builder.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ int main(int argc, char **argv)
223223

224224
};
225225

226-
Context ctx_packages;
226+
CppContext ctx_packages;
227227
ctx_packages.beginBlock("static UnresolvedPackages required_packages");
228228

229229
UnresolvedPackages deps;
@@ -240,16 +240,16 @@ int main(int argc, char **argv)
240240

241241
auto m = resolve_dependencies(deps);
242242

243-
Context ctx;
243+
CppContext ctx;
244244
ctx.addLine("#define SW_PRAGMA_HEADER 1");
245245
ctx.addLine();
246246

247-
Context build;
247+
CppContext build;
248248
build.beginFunction("void build_self_generated(Solution &s)");
249249
build.addLine("auto sdir_old = s.SourceDir;");
250250
build.addLine();
251251

252-
Context check;
252+
CppContext check;
253253
check.beginFunction("void check_self_generated(Checker &c)");
254254

255255
std::set<PackageVersionGroupNumber> used_gns;

0 commit comments

Comments
 (0)