Skip to content
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

Fix issue #2190 - windows: dub won't run if TEMP is unset or empty #2719

Merged
merged 1 commit into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions source/dub/commandline.d
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,8 @@ unittest {
*/
int runDubCommandLine(string[] args)
{
import std.file : tempDir;

static string[] toSinglePackageArgs (string args0, string file, string[] trailing)
{
return [args0, "run", "-q", "--temp-build", "--single", file, "--"] ~ trailing;
Expand All @@ -382,11 +384,24 @@ int runDubCommandLine(string[] args)

logDiagnostic("DUB version %s", getDUBVersion());

version(Windows){
// rdmd uses $TEMP to compute a temporary path. since cygwin substitutes backslashes
// with slashes, this causes OPTLINK to fail (it thinks path segments are options)
// we substitute the other way around here to fix this.
environment["TEMP"] = environment["TEMP"].replace("/", "\\");
{
version(Windows) {
// Guarantee that this environment variable is set
// this is specifically needed because of the Windows fix that follows this statement.
// While it probably isn't needed for all targets, it does simplify things a bit.
// Question is can it be more generic? Probably not due to $TMP
if ("TEMP" !in environment)
environment["TEMP"] = tempDir();

// rdmd uses $TEMP to compute a temporary path. since cygwin substitutes backslashes
// with slashes, this causes OPTLINK to fail (it thinks path segments are options)
// we substitute the other way around here to fix this.

// In case the environment variable TEMP is empty (it should never be), we'll swap out
// opIndex in favor of get with the fallback.

environment["TEMP"] = environment.get("TEMP", null).replace("/", "\\");
}
}

auto handler = CommandLineHandler(getCommands());
Expand Down
51 changes: 51 additions & 0 deletions test/issue2190-unset-TEMP.script.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/+ dub.json: {
"name": "issue2190_unset_TEMP"
} +/

module issue2190_unset_TEMP.script;

int main()
{
import std.stdio;
import std.algorithm;
import std.path;
import std.process;

const dir = __FILE_FULL_PATH__.dirName();

// doesn't matter, just pick something
const file = buildPath(dir, "single-file-sdl-default-name.d");

const dub = environment.get("DUB", buildPath(dirName(dir), "bin", "dub.exe"));

int exitCode;

void runTest(scope const string[] cmd)
{
const result = execute(cmd);

if (result.status || result.output.canFind("Failed"))
{
writefln("\n> %-(%s %)", cmd);
writeln("===========================================================");
writeln(result.output);
writeln("===========================================================");
writeln("Last command failed with exit code ", result.status, '\n');
exitCode = 1;
}
}

environment.remove("TEMP");

// only guaranteed to be there on Windows
// See: runDubCommandLine in commandline
version(Windows)
{
runTest([
dub, "build",
"--single", file,
]);
}

return exitCode;
}
Loading