Skip to content

Commit 2a8998c

Browse files
committed
Build separate files. Add install command. Some cleanups.
1 parent 7131af4 commit 2a8998c

16 files changed

Lines changed: 175 additions & 303 deletions

File tree

cppan.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ projects:
147147
- src/driver/cpp/.*
148148
exclude_from_build:
149149
- src/driver/cpp/misc/.*
150+
- src/driver/cpp/inserts/cppan.cpp
150151

151152
include_directories:
152153
- include

include/sw/driver/cpp/sw.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
#include <resolver.h>
1717

1818
// support stuff
19-
#include <primitives/hash.h>
20-
#include <primitives/http.h>
19+
//#include <primitives/hash.h>
20+
//#include <primitives/http.h>
2121
#include <boost/algorithm/string.hpp>
2222

2323
//namespace sw {}
@@ -33,6 +33,6 @@ using namespace sw::driver::cpp;
3333
#pragma warning(disable : 4068)
3434
#endif
3535

36-
#ifdef _WIN32
36+
#ifdef _MSC_VER
3737
#include "sw1.h"
3838
#endif

src/client/client.cpp

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,12 @@ int setup_main(const Strings &args)
102102
// some initial stuff
103103

104104
if (!working_directory.empty())
105-
fs::current_path(working_directory);
105+
{
106+
if (fs::is_regular_file(working_directory))
107+
fs::current_path(working_directory.parent_path());
108+
else
109+
fs::current_path(working_directory);
110+
}
106111

107112
if (jobs > 0)
108113
getExecutor(jobs);
@@ -229,6 +234,8 @@ static cl::opt<String> build_arg_generate(cl::Positional, cl::desc("File or dire
229234
static cl::opt<String> build_arg_update(cl::Positional, cl::desc("File or directory to use to generate projects"), cl::init("."), cl::sub(subcommand_update));
230235
static cl::opt<String> build_arg_test(cl::Positional, cl::desc("File or directory to use to generate projects"), cl::init("."), cl::sub(subcommand_test));
231236
static cl::opt<String> list_arg(cl::Positional, cl::desc("Package regex to list"), cl::init("."), cl::sub(subcommand_list));
237+
static cl::opt<String> install_arg(cl::Positional, cl::desc("Packages to add"), cl::sub(subcommand_install));
238+
static cl::list<String> install_args(cl::ConsumeAfter, cl::desc("Packages to add"), cl::sub(subcommand_install));
232239

233240
// ide commands
234241
static cl::opt<String> target_build("target", cl::desc("Target to build")/*, cl::sub(subcommand_ide)*/);
@@ -463,7 +470,7 @@ SUBCOMMAND_DECL(ide)
463470
{
464471
try_single_process_job(fs::current_path() / ".sw" / "ide", []()
465472
{
466-
auto s = sw::load("sw.cpp");
473+
auto s = sw::load(working_directory);
467474
auto &b = *((sw::Build*)s.get());
468475
b.ide = true;
469476
auto pkg = sw::extractFromStringPackageId(target_build);
@@ -475,7 +482,7 @@ SUBCOMMAND_DECL(ide)
475482
{
476483
single_process_job(fs::current_path() / ".sw" / "ide", []()
477484
{
478-
auto s = sw::load("sw.cpp");
485+
auto s = sw::load(working_directory);
479486
auto &b = *((sw::Build*)s.get());
480487
b.ide = true;
481488
s->execute();
@@ -545,7 +552,7 @@ SUBCOMMAND_DECL(list)
545552

546553
SUBCOMMAND_DECL(pack)
547554
{
548-
555+
// http://www.king-foo.com/2011/11/creating-debianubuntu-deb-packages/
549556
}
550557

551558
extern bool gWithTesting;
@@ -557,6 +564,21 @@ SUBCOMMAND_DECL(test)
557564
cli_build();
558565
}
559566

567+
SUBCOMMAND_DECL(install)
568+
{
569+
sw::UnresolvedPackages pkgs;
570+
install_args.push_back(install_arg);
571+
for (auto &p : install_args)
572+
pkgs.insert(extractFromString(p));
573+
resolveAllDependencies(pkgs);
574+
for (auto &[p1, d] : getPackageStore().resolved_packages)
575+
{
576+
for (auto &p2 : install_args)
577+
if (p1 == p2)
578+
d.installed = true;
579+
}
580+
}
581+
560582
extern ::cl::opt<bool> dry_run;
561583
SUBCOMMAND_DECL(update)
562584
{

src/client/commands.inl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ SUBCOMMAND(build, "Build files, dirs or packages") COMMA
2323
SUBCOMMAND(generate, "Generate IDE projects") COMMA
2424
SUBCOMMAND(ide, "Used to invoke sw application to do IDE tasks: generate project files, clean, rebuild etc.") COMMA
2525
SUBCOMMAND(init, "Used to do some system setup which may require administrator access.") COMMA
26+
SUBCOMMAND(install, "Add package to lock.") COMMA
2627
SUBCOMMAND(list, "List packages in database.") COMMA
2728
SUBCOMMAND(pack, "Used to prepare distribution packages.") COMMA
2829
SUBCOMMAND(test, "Run tests.") COMMA

src/driver/cpp/compiler.cpp

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -739,13 +739,6 @@ void VisualStudioASMCompiler::setOutputFile(const path &output_file)
739739
ObjectFile = output_file;
740740
}
741741

742-
/*Files VisualStudioASMCompiler::getGeneratedDirs() const
743-
{
744-
Files f;
745-
f.insert(ObjectFile().parent_path());
746-
return f;
747-
}*/
748-
749742
void VisualStudioASMCompiler::setSourceFile(const path &input_file, path &output_file)
750743
{
751744
InputFile = input_file.u8string();
@@ -803,13 +796,6 @@ void VisualStudioCompiler::setOutputFile(const path &output_file)
803796
ObjectFile = output_file;
804797
}
805798

806-
/*Files VisualStudioCompiler::getGeneratedDirs() const
807-
{
808-
Files f;
809-
f.insert(ObjectFile().parent_path());
810-
return f;
811-
}*/
812-
813799
std::shared_ptr<Program> VisualStudioCompiler::clone() const
814800
{
815801
return std::make_shared<VisualStudioCompiler>(*this);
@@ -875,13 +861,6 @@ void ClangCompiler::setOutputFile(const path &output_file)
875861
OutputFile = output_file;
876862
}
877863

878-
/*Files ClangCompiler::getGeneratedDirs() const
879-
{
880-
Files f;
881-
f.insert(OutputFile().parent_path());
882-
return f;
883-
}*/
884-
885864
std::shared_ptr<Program> ClangCompiler::clone() const
886865
{
887866
return std::make_shared<ClangCompiler>(*this);
@@ -940,13 +919,6 @@ void ClangClCompiler::setOutputFile(const path &output_file)
940919
ObjectFile = output_file;
941920
}
942921

943-
/*Files ClangClCompiler::getGeneratedDirs() const
944-
{
945-
Files f;
946-
f.insert(ObjectFile().parent_path());
947-
return f;
948-
}*/
949-
950922
std::shared_ptr<Program> ClangClCompiler::clone() const
951923
{
952924
return std::make_shared<ClangClCompiler>(*this);
@@ -1014,13 +986,6 @@ void GNUASMCompiler::setOutputFile(const path &output_file)
1014986
OutputFile = output_file;
1015987
}
1016988

1017-
/*Files GNUASMCompiler::getGeneratedDirs() const
1018-
{
1019-
Files f;
1020-
f.insert(OutputFile().parent_path());
1021-
return f;
1022-
}*/
1023-
1024989
void GNUASMCompiler::setSourceFile(const path &input_file, path &output_file)
1025990
{
1026991
InputFile = input_file.u8string();
@@ -1069,13 +1034,6 @@ void GNUCompiler::setOutputFile(const path &output_file)
10691034
OutputFile = output_file;
10701035
}
10711036

1072-
/*Files GNUCompiler::getGeneratedDirs() const
1073-
{
1074-
Files f;
1075-
f.insert(OutputFile().parent_path());
1076-
return f;
1077-
}*/
1078-
10791037
std::shared_ptr<Program> GNUCompiler::clone() const
10801038
{
10811039
return std::make_shared<GNUCompiler>(*this);

src/driver/cpp/compiler.h

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,12 @@ struct SW_DRIVER_CPP_API ToolBase
5757
mutable std::shared_ptr<driver::cpp::Command> cmd;
5858
};
5959

60+
// compilers
61+
6062
struct SW_DRIVER_CPP_API CompilerToolBase : ToolBase
6163
{
6264
virtual ~CompilerToolBase() = default;
6365

64-
// consider as static
65-
//virtual bool findToolchain(struct Solution &s) const = 0;
66-
6766
protected:
6867
virtual Version gatherVersion(const path &program) const = 0;
6968
};
@@ -84,7 +83,6 @@ struct SW_DRIVER_CPP_API NativeCompiler : Compiler,
8483

8584
virtual void setSourceFile(const path &input_file, path &output_file) = 0;
8685
virtual String getObjectExtension() const { return ".o"; }
87-
//virtual Files getGeneratedDirs() const = 0;
8886

8987
protected:
9088
mutable Files dependencies;
@@ -113,7 +111,6 @@ struct SW_DRIVER_CPP_API VisualStudioCompiler : VisualStudio,
113111
std::shared_ptr<builder::Command> getCommand() const override;
114112
void setOutputFile(const path &output_file);
115113
String getObjectExtension() const override { return ".obj"; }
116-
//Files getGeneratedDirs() const override;
117114
void setSourceFile(const path &input_file, path &output_file) override;
118115

119116
protected:
@@ -132,16 +129,13 @@ struct SW_DRIVER_CPP_API VisualStudioASMCompiler : VisualStudio, NativeCompiler,
132129
void setSourceFile(const path &input_file, path &output_file) override;
133130
void setOutputFile(const path &output_file);
134131
String getObjectExtension() const override { return ".obj"; }
135-
//Files getGeneratedDirs() const override;
136132

137133
protected:
138134
Version gatherVersion() const override { return VisualStudio::gatherVersion(file); }
139135
};
140136

141137
struct SW_DRIVER_CPP_API Clang : CompilerToolBase
142138
{
143-
//bool findToolchain(struct Solution &s) const override;
144-
145139
protected:
146140
Version gatherVersion(const path &program) const override;
147141
};
@@ -155,7 +149,6 @@ struct SW_DRIVER_CPP_API ClangCompiler : Clang, NativeCompiler,
155149
std::shared_ptr<builder::Command> getCommand() const override;
156150
void setOutputFile(const path &output_file);
157151
String getObjectExtension() const override { return ".obj"; }
158-
//Files getGeneratedDirs() const override;
159152
void setSourceFile(const path &input_file, path &output_file) override;
160153

161154
protected:
@@ -177,7 +170,6 @@ struct SW_DRIVER_CPP_API ClangClCompiler : ClangCl,
177170
std::shared_ptr<builder::Command> getCommand() const override;
178171
void setOutputFile(const path &output_file);
179172
String getObjectExtension() const override { return ".obj"; }
180-
//Files getGeneratedDirs() const override;
181173
void setSourceFile(const path &input_file, path &output_file) override;
182174

183175
protected:
@@ -202,7 +194,6 @@ struct SW_DRIVER_CPP_API GNUASMCompiler : GNU, NativeCompiler,
202194
void setSourceFile(const path &input_file, path &output_file) override;
203195
void setOutputFile(const path &output_file);
204196
String getObjectExtension() const override { return ".o"; }
205-
//Files getGeneratedDirs() const override;
206197

207198
protected:
208199
Version gatherVersion() const override { return GNU::gatherVersion(file); }
@@ -222,13 +213,14 @@ struct SW_DRIVER_CPP_API GNUCompiler : GNU, NativeCompiler,
222213
std::shared_ptr<builder::Command> getCommand() const override;
223214
void setOutputFile(const path &output_file);
224215
String getObjectExtension() const override { return ".o"; }
225-
//Files getGeneratedDirs() const override;
226216
void setSourceFile(const path &input_file, path &output_file) override;
227217

228218
protected:
229219
Version gatherVersion() const override { return GNU::gatherVersion(file); }
230220
};
231221

222+
// linkers
223+
232224
struct SW_DRIVER_CPP_API Linker : Program
233225
{
234226
virtual ~Linker() = default;

src/driver/cpp/driver.cpp

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ optional<path> CppDriver::resolveConfig(const path &file_or_dir) const
3939

4040
PackageScriptPtr CppDriver::build(const path &file_or_dir) const
4141
{
42+
throw std::runtime_error("function disabled");
43+
4244
auto f = resolveConfig(file_or_dir);
4345
if (!f)
4446
return {};
@@ -54,8 +56,20 @@ PackageScriptPtr CppDriver::build(const path &file_or_dir) const
5456
PackageScriptPtr CppDriver::load(const path &file_or_dir) const
5557
{
5658
auto f = resolveConfig(file_or_dir);
57-
if (!f)
58-
return {};
59+
if (!f || f.value().filename() != getConfigFilename())
60+
{
61+
path p = file_or_dir;
62+
if (fs::is_directory(p))
63+
current_thread_path(p);
64+
else
65+
current_thread_path(p = p.parent_path());
66+
67+
auto b = std::make_unique<Build>();
68+
b->Local = true;
69+
b->configure = true;
70+
b->load_configless(file_or_dir);
71+
return b;
72+
}
5973
current_thread_path(f.value().parent_path());
6074

6175
auto b = std::make_unique<Build>();
@@ -81,12 +95,7 @@ PackageScriptPtr CppDriver::load(const path &file_or_dir) const
8195

8296
bool CppDriver::execute(const path &file_or_dir) const
8397
{
84-
auto f = resolveConfig(file_or_dir);
85-
if (!f)
86-
return {};
87-
current_thread_path(f.value().parent_path());
88-
89-
if (auto s = load(f.value()); s)
98+
if (auto s = load(file_or_dir); s)
9099
return s->execute();
91100
return false;
92101
}

src/driver/cpp/generator/generator.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,7 @@ void VSGenerator::generate(const Build &b)
844844
ctx.endGlobal();
845845

846846
const auto compiler_name = boost::to_lower_copy(toString(b.Settings.Native.CompilerType));
847-
String fn = "sw_";
847+
String fn = b.ide_solution_name + "_";
848848
fn += compiler_name + "_" + toPathString(type);
849849
fn += ".sln";
850850
write_file(dir / fn, ctx.getText());
@@ -902,9 +902,9 @@ void VSGeneratorNMake::generate(const Build &b)
902902
else if (b.Settings.Native.CompilerType == CompilerType::MSVC)
903903
compiler = "--compiler msvc";
904904

905-
pctx.addBlock("NMakeBuildCommandLine", "sw -d " + cwd + " " + cfg + " " + compiler + " --do-not-rebuild-config ide");
906-
pctx.addBlock("NMakeCleanCommandLine", "sw -d " + cwd + " " + cfg + " ide --clean");
907-
pctx.addBlock("NMakeReBuildCommandLine", "sw -d " + cwd + " " + cfg + " " + compiler + " ide --rebuild");
905+
pctx.addBlock("NMakeBuildCommandLine", "sw -d " + normalize_path(b.config_file_or_dir) + " " + cfg + " " + compiler + " --do-not-rebuild-config ide");
906+
pctx.addBlock("NMakeCleanCommandLine", "sw -d " + normalize_path(b.config_file_or_dir) + " " + cfg + " ide --clean");
907+
pctx.addBlock("NMakeReBuildCommandLine", "sw -d " + normalize_path(b.config_file_or_dir) + " " + cfg + " " + compiler + " ide --rebuild");
908908

909909
pctx.endBlock();
910910
});
@@ -1016,10 +1016,10 @@ void VSGeneratorNMake::generate(const Build &b)
10161016
auto o = nt->makeOutputFile();
10171017
o = o.parent_path().parent_path() / s.getConfig(t.get()) / o.filename();
10181018
o += nt->getOutputFile().extension();
1019-
pctx.addBlock("NMakeBuildCommandLine", "sw -d " + cwd + " " + cfg + " " + compiler + " --do-not-rebuild-config --target " + p.target_name + " ide");
1019+
pctx.addBlock("NMakeBuildCommandLine", "sw -d " + normalize_path(b.config_file_or_dir) + " " + cfg + " " + compiler + " --do-not-rebuild-config --target " + p.target_name + " ide");
10201020
pctx.addBlock("NMakeOutput", o.u8string());
1021-
pctx.addBlock("NMakeCleanCommandLine", "sw -d " + cwd + " " + cfg + " ide --clean");
1022-
pctx.addBlock("NMakeReBuildCommandLine", "sw -d " + cwd + " " + cfg + " " + compiler + " ide --rebuild");
1021+
pctx.addBlock("NMakeCleanCommandLine", "sw -d " + normalize_path(b.config_file_or_dir) + " " + cfg + " ide --clean");
1022+
pctx.addBlock("NMakeReBuildCommandLine", "sw -d " + normalize_path(b.config_file_or_dir) + " " + cfg + " " + compiler + " ide --rebuild");
10231023
String defs;
10241024
for (auto &[k, v] : nt->Definitions)
10251025
{
@@ -1127,7 +1127,7 @@ void VSGeneratorNMake::generate(const Build &b)
11271127
ctx.endGlobal();
11281128

11291129
const auto compiler_name = boost::to_lower_copy(toString(b.Settings.Native.CompilerType));
1130-
String fn = "sw_";
1130+
String fn = b.ide_solution_name + "_";
11311131
fn += compiler_name + "_" + toPathString(type);
11321132
fn += ".sln";
11331133
write_file(dir / fn, ctx.getText());

0 commit comments

Comments
 (0)