Skip to content

Commit 7f7b8b2

Browse files
authored
embedded git on windows (#167)
1 parent ece8fbe commit 7f7b8b2

File tree

4 files changed

+33
-5
lines changed

4 files changed

+33
-5
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ To install or update LODA, please follow the [installation instructions](https:/
66

77
* Fix CPU hour reporting using `wget`
88

9+
### Features
10+
11+
* Embedded `git` for BOINC on Windows
12+
913
### Enhancements
1014

1115
* Increase max number of interpreter cycles to 10 million

src/boinc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ void Boinc::run() {
4545
// check environment
4646
Log::get().info("Checking environment");
4747
#ifdef _WIN64
48-
fixWindowsEnv();
48+
fixWindowsEnv(project_dir);
4949
ensureEnv("TMP", project_dir);
5050
ensureEnv("TEMP", project_dir);
5151
#else

src/file.cpp

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
#include <mach/mach.h>
3434
#endif
3535

36+
#include "web_client.hpp"
37+
3638
void replaceAll(std::string &str, const std::string &from,
3739
const std::string &to) {
3840
if (from.empty()) {
@@ -87,12 +89,12 @@ std::string getPath() {
8789
return "";
8890
}
8991

90-
void execCmd(const std::string &cmd) {
92+
void execCmd(const std::string &cmd, bool fail_on_error = true) {
9193
auto exit_code = system(cmd.c_str());
9294
if (exit_code != 0) {
9395
Log::get().error("Error executing command (exit code " +
9496
std::to_string(exit_code) + "): " + cmd,
95-
true);
97+
fail_on_error);
9698
}
9799
}
98100

@@ -117,7 +119,7 @@ void ensureEnv(const std::string &key, const std::string &value) {
117119
}
118120
}
119121

120-
void fixWindowsEnv() {
122+
void fixWindowsEnv(std::string project_dir) {
121123
const std::string sys32 = "C:\\WINDOWS\\system32";
122124
ensureEnv("COMSPEC", sys32 + FILE_SEP + "cmd.exe");
123125
ensureEnv("SYSTEMROOT", "C:\\WINDOWS");
@@ -131,22 +133,44 @@ void fixWindowsEnv() {
131133
program_files = std::string(p);
132134
}
133135
ensureTrailingFileSep(program_files);
136+
if (!project_dir.empty()) {
137+
ensureTrailingFileSep(project_dir);
138+
}
134139
bool update = false;
135140
if (path.find("Git\\cmd") == std::string::npos) {
136141
if (!path.empty()) {
137142
path += ";";
138143
}
139144
path += program_files + "Git\\cmd";
145+
if (!project_dir.empty()) {
146+
path += ";" + project_dir + "git\\cmd";
147+
}
140148
update = true;
141149
}
142150
if (path.find("Git\\usr\\bin") == std::string::npos) {
143151
if (!path.empty()) {
144152
path += ";";
145153
}
146154
path += program_files + "Git\\usr\\bin";
155+
if (!project_dir.empty()) {
156+
path += ";" + project_dir + "git\\usr\\bin";
157+
}
147158
update = true;
148159
}
149160
if (update) {
161+
const std::string mingit_dir = project_dir + "git";
162+
if (!project_dir.empty() && !isDir(mingit_dir)) {
163+
ensureDir(mingit_dir);
164+
const std::string mingit_url =
165+
"https://github.com/git-for-windows/git/releases/download/"
166+
"v2.37.1.windows.1/MinGit-2.37.1-64-bit.zip";
167+
const std::string mingit_zip = project_dir + "mingit.zip";
168+
if (WebClient::get(mingit_url, mingit_zip, false, false)) {
169+
execCmd("powershell -command \"Expand-Archive -Force '" + mingit_zip +
170+
"' '" + mingit_dir + "'\"");
171+
}
172+
std::remove(mingit_zip.c_str());
173+
}
150174
putEnv("PATH", path);
151175
}
152176
}

src/include/file.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ void moveFile(const std::string &from, const std::string &to);
2626
#ifdef _WIN64
2727
void ensureEnv(const std::string &key, const std::string &value);
2828

29-
void fixWindowsEnv();
29+
void fixWindowsEnv(std::string project_dir = "");
3030
#endif
3131

3232
void gunzip(const std::string &path);

0 commit comments

Comments
 (0)