-
Notifications
You must be signed in to change notification settings - Fork 296
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[vcpkg-artifacts] Find git using vcpkg fetch git
.
#569
Changes from 7 commits
f64cb53
077526e
82822a8
9585410
95f1414
2e544c9
42c711c
969ae18
7eaeadf
6e3eead
e380d40
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { spawn } from "child_process"; | ||
import { Session } from "./session"; | ||
|
||
/** @internal */ | ||
export class Vcpkg { | ||
constructor(private readonly session: Session) {} | ||
|
||
fetch(fetchKey: string): Promise<string | undefined> { | ||
return this.runVcpkg(['fetch', fetchKey, '--x-stderr-status']).then((results) => { | ||
if (results === undefined) { | ||
if (fetchKey === 'git') { | ||
this.session.channels.warning('failed to fetch git, falling back to attempting to use git from the PATH'); | ||
return 'git'; | ||
} | ||
|
||
return results; | ||
} | ||
|
||
return results.trimEnd(); | ||
}); | ||
} | ||
|
||
private runVcpkg(args: string[]): Promise<string | undefined> { | ||
return new Promise((accept, reject) => { | ||
if (!this.session.vcpkgCommand) { | ||
accept(undefined); | ||
return; | ||
} | ||
|
||
const subproc = spawn(this.session.vcpkgCommand, args, {stdio: ['ignore', 'pipe', 'pipe']}); | ||
let result = ''; | ||
subproc.stdout.on('data', (chunk) => { result += chunk; }); | ||
subproc.stderr.pipe(process.stdout); | ||
subproc.on('error', (err) => { reject(err); }); | ||
subproc.on('close', (code, signal) => { | ||
if (code === 0) { accept(result); } | ||
accept(undefined); | ||
}); | ||
}); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -205,23 +205,23 @@ namespace vcpkg::msg | |||||
} | ||||||
|
||||||
template<class Message, class... Ts> | ||||||
void print(Message m, Ts... args) | ||||||
typename Message::is_message_type print(Message m, Ts... args) | ||||||
{ | ||||||
print(format(m, args...)); | ||||||
} | ||||||
template<class Message, class... Ts> | ||||||
void println(Message m, Ts... args) | ||||||
typename Message::is_message_type println(Message m, Ts... args) | ||||||
{ | ||||||
print(format(m, args...).append_raw('\n')); | ||||||
} | ||||||
|
||||||
template<class Message, class... Ts> | ||||||
void print(Color c, Message m, Ts... args) | ||||||
typename Message::is_message_type print(Color c, Message m, Ts... args) | ||||||
{ | ||||||
print(c, format(m, args...)); | ||||||
} | ||||||
template<class Message, class... Ts> | ||||||
void println(Color c, Message m, Ts... args) | ||||||
typename Message::is_message_type println(Color c, Message m, Ts... args) | ||||||
{ | ||||||
print(c, format(m, args...).append_raw('\n')); | ||||||
} | ||||||
|
@@ -340,4 +340,60 @@ namespace vcpkg::msg | |||||
{ | ||||||
return format(msgErrorMessage).append(m, args...); | ||||||
} | ||||||
|
||||||
} | ||||||
|
||||||
namespace vcpkg | ||||||
{ | ||||||
struct MessageSink | ||||||
{ | ||||||
virtual void print(Color c, StringView sv) = 0; | ||||||
|
||||||
void println() { this->print(Color::none, "\n"); } | ||||||
void print(const LocalizedString& s) { this->print(Color::none, s); } | ||||||
void println(Color c, const LocalizedString& s) | ||||||
{ | ||||||
this->print(c, s); | ||||||
this->print(Color::none, "\n"); | ||||||
} | ||||||
inline void println(const LocalizedString& s) | ||||||
{ | ||||||
this->print(Color::none, s); | ||||||
this->print(Color::none, "\n"); | ||||||
} | ||||||
|
||||||
template<class Message, class... Ts> | ||||||
typename Message::is_message_type print(Message m, Ts... args) | ||||||
{ | ||||||
this->print(Color::none, msg::format(m, args...)); | ||||||
} | ||||||
|
||||||
template<class Message, class... Ts> | ||||||
typename Message::is_message_type println(Message m, Ts... args) | ||||||
{ | ||||||
this->print(Color::none, msg::format(m, args...).append_raw('\n')); | ||||||
} | ||||||
|
||||||
template<class Message, class... Ts> | ||||||
typename Message::is_message_type print(Color c, Message m, Ts... args) | ||||||
{ | ||||||
this->print(c, msg::format(m, args...)); | ||||||
} | ||||||
|
||||||
template<class Message, class... Ts> | ||||||
typename Message::is_message_type println(Color c, Message m, Ts... args) | ||||||
{ | ||||||
this->print(c, msg::format(m, args...).append_raw('\n')); | ||||||
} | ||||||
|
||||||
MessageSink(const MessageSink&) = delete; | ||||||
MessageSink& operator=(const MessageSink&) = delete; | ||||||
|
||||||
protected: | ||||||
MessageSink() = default; | ||||||
~MessageSink() = default; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Agreed nobody should ever be deleting it through the interface, but it seems good practice anyway. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Being |
||||||
}; | ||||||
|
||||||
extern MessageSink& stdout_sink; | ||||||
extern MessageSink& stderr_sink; | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be
or just
reject(result)
?