Skip to content

Commit

Permalink
Compiles on Windows, "install dvm" and http fetching now work.
Browse files Browse the repository at this point in the history
  • Loading branch information
Abscissa committed May 23, 2011
1 parent b76c380 commit 229d215
Show file tree
Hide file tree
Showing 11 changed files with 118 additions and 30 deletions.
31 changes: 19 additions & 12 deletions dvm/commands/DvmInstall.d
Expand Up @@ -22,8 +22,8 @@ class DvmInstall : Command
{
private
{
const postInstallInstrcutions = import("post_install_instructions.txt");
const failedInstallInstrcutions = import("failed_install_instructions.txt");
const postInstallInstructions = import("post_install_instructions.txt");
const failedInstallInstructions = import("failed_install_instructions.txt");

version (Posix)
const dvmScript = import("dvm.sh");
Expand All @@ -49,7 +49,7 @@ private:
copyExecutable;
writeScript;
setPermissions;
installBashInclude(createBashInclude);
version (Posix) installBashInclude(createBashInclude);
}

void update ()
Expand Down Expand Up @@ -87,11 +87,15 @@ private:

void setPermissions ()
{
verbose("Setting permissions:");
permission(options.path.dvmScript, "+x");
permission(options.path.dvmExecutable, "+x");
version (Posix)
{
verbose("Setting permissions:");
permission(options.path.dvmScript, "+x");
permission(options.path.dvmExecutable, "+x");
}
}

version (Posix)
void installBashInclude (ShellScript sh)
{
auto home = homeFolder;
Expand All @@ -107,12 +111,12 @@ private:

else
throw new DvmException(format(`Cannot find "{}" or "{}". Please perform the post installation manually by following the instructions below:{}{}`,
bashrc, bash_profile, "\n\n", failedInstallInstrcutions), __FILE__, __LINE__);
bashrc, bash_profile, "\n\n", failedInstallInstructions), __FILE__, __LINE__);

verbose("Installing dvm in the shell loading file: ", shPath);
File.append(shPath, sh.content);

println(postInstallInstrcutions);
println(postInstallInstructions);
}

void createPath (string path)
Expand All @@ -123,10 +127,13 @@ private:

void permission (string path, string mode)
{
verbose(options.indentation, "mode: " ~ mode);
verbose(options.indentation, "file: " ~ path, '\n');

Path.permission(path, mode);
version (Posix)
{
verbose(options.indentation, "mode: " ~ mode);
verbose(options.indentation, "file: " ~ path, '\n');

Path.permission(path, mode);
}
}

void copy (string source, string destination)
Expand Down
20 changes: 17 additions & 3 deletions dvm/commands/Fetch.d
Expand Up @@ -78,9 +78,22 @@ protected:
const int width = 40;
int num = width;

const clearLine = "\033[1K"; // clear backwards
const saveCursor = "\0337";
const restoreCursor = "\0338";
version (Posix)
{
const clearLine = "\033[1K"; // clear backwards
const saveCursor = "\0337";
const restoreCursor = "\0338";
}

else
{
const clearLine = "\r";

// Leaving these empty string causes a linker error:
// http://d.puremagic.com/issues/show_bug.cgi?id=4324
const saveCursor = "\0";
const restoreCursor = "\0";
}

print(saveCursor);

Expand Down Expand Up @@ -119,6 +132,7 @@ protected:
void writeFile (void[] data, string filename)
{
auto file = new File(filename, File.WriteCreate);
scope(exit) file.close();
file.write(data);
}

Expand Down
11 changes: 7 additions & 4 deletions dvm/commands/Install.d
Expand Up @@ -311,10 +311,13 @@ private:

void permission (string path, string mode)
{
verbose(options.indentation, "mode: " ~ mode);
verbose(options.indentation, "file: " ~ path, '\n');

Path.permission(path, mode);
version (Posix)
{
verbose(options.indentation, "mode: " ~ mode);
verbose(options.indentation, "file: " ~ path, '\n');

Path.permission(path, mode);
}
}

string getLibSource (string platformRoot)
Expand Down
9 changes: 6 additions & 3 deletions dvm/commands/Use.d
Expand Up @@ -86,10 +86,13 @@ private:

void setPermission (string path, string mode)
{
verbose(options.indentation, "mode: ", mode);
verbose(options.indentation, "file: ", path);
version (Posix)
{
verbose(options.indentation, "mode: ", mode);
verbose(options.indentation, "file: ", path);

permission(path, mode);
permission(path, mode);
}
}

ShellScript createShellScript ()
Expand Down
2 changes: 2 additions & 0 deletions dvm/dvm/Application.d
Expand Up @@ -19,6 +19,8 @@ import dvm.util._;
import dvm.commands._;
import dvm.commands.Install;

version (Windows) pragma(lib, "zlib.lib");

class Application
{
private static Application instance_;
Expand Down
7 changes: 6 additions & 1 deletion dvm/dvm/Options.d
Expand Up @@ -7,6 +7,7 @@
module dvm.dvm.Options;

import tango.io.Path;
import tango.sys.Environment;
import tango.sys.HomeFolder;

import dvm.core.string;
Expand Down Expand Up @@ -107,8 +108,12 @@ private struct Path
{
if (home_.length > 0)
return home_;

version (Posix)
return home_ = homeFolder;

return home_ = homeFolder;
version (Windows)
return home_ = standard(Environment.get("APPDATA"));
}

string dvm ()
Expand Down
26 changes: 21 additions & 5 deletions dvm/dvm/ShellScript.d
Expand Up @@ -57,12 +57,20 @@ class ShellScript
return this;
}

version (Posix)
ShellScript exec (string name, string args = "", string a = "")
{
append(Sh.exec(name, args, a));
return this;
}

version (Windows)
ShellScript exec (string name, string args = "")
{
append(Sh.exec(name, args));
return this;
}

ShellScript export_ (string name, string content, bool quote = true)
{
append(Sh.export_(name, content, quote));
Expand Down Expand Up @@ -256,7 +264,7 @@ struct Sh
return "%*";
}

string command (string c)
string comment (string c)
{
return "rem " ~ c;
}
Expand All @@ -266,7 +274,7 @@ struct Sh
return format("set {}={}", name, value);
}

void export_ (string name, string content, bool quote = true)
string export_ (string name, string content, bool quote = true)
{
return format("set {}={}", name, content);
}
Expand All @@ -276,14 +284,22 @@ struct Sh
return format("call {}", path);
}

string exec (string command)
string exec (string name, string args = ""/+, string a = ""+/)
{
return source(command);
/+a = a == "" ? "" : format("-a {} ", a);
args = args == "" ? "" : ' ' ~ args;+/

return format("call {}{}", name, args);
}

string ifFileIsNotEmpty (string path, string delegate () block)
{
return format("if exist {} {}", path, block());
return format("if exist {} ( {} )", path, block());
}

string variable (string name, bool quote = true)
{
return quote ? format(`"%{}%"`, name) : '%' ~ name ~ '%';
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion dvm/dvm/Wrapper.d
Expand Up @@ -44,7 +44,8 @@ struct Wrapper
sh.nl;

sh.ifFileIsNotEmpty(dmdPath, {
sh.exec(dmdPath, Sh.allArgs, dmdPath);
version (Posix) sh.exec(dmdPath, Sh.allArgs, dmdPath);
version (Windows) sh.exec(dmdPath, Sh.allArgs);
}, {
sh.printError(format(`Missing target: "{}"`, target), true);
});
Expand Down
9 changes: 8 additions & 1 deletion dvm/io/Path.d
Expand Up @@ -8,7 +8,7 @@ module dvm.io.Path;

import tango.core.Exception;
public import tango.io.Path;
import tango.stdc.posix.sys.stat;
version (Posix) import tango.stdc.posix.sys.stat;
import tango.sys.Common;

import dvm.core._;
Expand Down Expand Up @@ -56,6 +56,7 @@ int remove (string path, bool recursive = false)
return removePath(path) ? result + 1 : result;
}

version (Posix)
enum Owner
{
Read = S_IRUSR,
Expand All @@ -64,6 +65,7 @@ enum Owner
All = S_IRWXU
}

version (Posix)
enum Group
{
Read = S_IRGRP,
Expand All @@ -72,6 +74,7 @@ enum Group
All = S_IRWXG
}

version (Posix)
enum Others
{
Read = S_IROTH,
Expand All @@ -80,12 +83,14 @@ enum Others
All = S_IRWXO
}

version (Posix)
void permission (string path, ushort mode)
{
if (chmod((path ~ '\0').ptr, mode) == -1)
throw new IOException(path ~ ": " ~ SysError.lastMsg);
}

version (Posix)
private template permissions (alias reference)
{
const permissions = "if (add)
Expand Down Expand Up @@ -118,6 +123,7 @@ void validatePath (string path)
throw new IOException("File not found \"" ~ path ~ "\"");
}

version (Posix)
void permission (string path, string mode)
{
ushort m = permission(path);
Expand Down Expand Up @@ -182,6 +188,7 @@ void permission (string path, string mode)
permission(path, m);
}

version (Posix)
private ushort permission (string path)
{
int status;
Expand Down
30 changes: 30 additions & 0 deletions resources/dvm.bat
@@ -0,0 +1,30 @@
@echo off

set dvm_prefix=%APPDATA%\
set dvm_path=%dvm_prefix%dvm

set dvm_tmp_path=%dvm_path%/tmp
set dvm_result_path=%dvm_tmp_path%/result.bat
set dvm_bin_path=%dvm_path%/bin
set dvm_exe_path=%dvm_bin_path%/dvm.exe
set dvm_default_env_path=%dvm_path%/env/default
set dvm_default_bin_path=%dvm_bin_path%/dvm-default-dc
set dvm_current_path=%dvm_bin_path%/dvm-current-dc

set PATH=%dvm_bin_path%;%PATH%

if exist "%dvm_exe_path%" (
call "%dvm_default_env_path%"
)

copy /Y "%dvm_default_bin_path%" "%dvm_current_path%" > NUL

if exist "%dvm_exe_path%" (
"%dvm_exe_path%" %*
)

if exist "%dvm_result_path%" (
call "%dvm_result_path%"
)

del /Q /F /S "%dvm_tmp_path%" > NUL
Binary file added zlib.lib
Binary file not shown.

0 comments on commit 229d215

Please sign in to comment.