diff --git a/bin/dpm b/bin/dpm deleted file mode 100644 index eaa43ca..0000000 --- a/bin/dpm +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/sh -set -e - -# delete old vpm.d if another run left it in /tmp -rm -f /tmp/vpm.d - -# find the executable location (note: must stay mac compatible here) -VIBEBINARY=$(readlink "$0" || true) -if [ ! -n "$VIBEBINARY" ]; then VIBEBINARY="$0"; fi -VIBEPATH=$(dirname "$VIBEBINARY") - -# use pkg-config if possible or fallback to default flags -LIBS=$(pkg-config --libs libevent libevent_pthreads libssl 2>/dev/null || echo "-levent_pthreads -levent -lssl -lcrypto") -LIBS=$(echo "$LIBS" | sed 's/^-L/-L-L/; s/ -L/ -L-L/g; s/^-l/-L-l/; s/ -l/ -L-l/g') -export LIBS - -# generate a file name for the temporary compile/run script -START_SCRIPT=`mktemp -t vpm.start.XXXXXXXX` - -# copy vpm.d to /tmp and make it deletable by anyone -cp -p "$VIBEPATH"/vpm.d /tmp/vpm.d -chmod 666 /tmp/vpm.d - -# run VPM and delete the vpm.d file again, VPM will output the compile/run script -rdmd -g -w -property -I"$VIBEPATH"/../source $LIBS -Jviews -Isource /tmp/vpm.d "$VIBEPATH" "$START_SCRIPT" $1 $2 $3 $4 $5 $6 $7 $8 $9 -rm /tmp/vpm.d - -# compile/run the application -chmod +x "$START_SCRIPT" -"$START_SCRIPT" -rm "$START_SCRIPT" diff --git a/bin/dpm.cmd b/bin/dpm.cmd deleted file mode 100644 index 3e7809d..0000000 --- a/bin/dpm.cmd +++ /dev/null @@ -1,20 +0,0 @@ -@echo off -set VIBE_BIN=%~dps0 -set LIBDIR=%VIBE_BIN%..\lib\win-i386 -set BINDIR=%VIBE_BIN%..\lib\bin -set LIBS="%LIBDIR%\event2.lib" "%LIBDIR%\eay.lib" "%LIBDIR%\ssl.lib" ws2_32.lib -set EXEDIR=%TEMP%\.rdmd\source -set START_SCRIPT=%EXEDIR%\vibe.cmd - -if NOT EXIST %EXEDIR% ( - mkdir %EXEDIR% -) -copy "%VIBE_BIN%*.dll" %EXEDIR% > nul 2>&1 -if "%1" == "build" copy "%VIBE_BIN%*.dll" . > nul 2>&1 -copy "%VIBE_BIN%vpm.d" %EXEDIR% > nul 2>&1 - -rem Run, execute, do everything.. but when you do it, do it with the vibe! -rdmd -debug -g -w -property -of%EXEDIR%\vpm.exe -I%VIBE_BIN%..\source %LIBS% %EXEDIR%\vpm.d %VIBE_BIN% %START_SCRIPT% %* - -rem Finally, start the app, if vpm succeded. -if ERRORLEVEL 0 %START_SCRIPT% diff --git a/bin/dub b/bin/dub new file mode 100644 index 0000000..79daca0 --- /dev/null +++ b/bin/dub @@ -0,0 +1,31 @@ +#!/bin/sh +set -e + +# delete old dub.d if another run left it in /tmp +rm -f /tmp/dub.d + +# find the executable location (note: must stay mac compatible here) +VIBEBINARY=$(readlink "$0" || true) +if [ ! -n "$VIBEBINARY" ]; then VIBEBINARY="$0"; fi +VIBEPATH=$(dirname "$VIBEBINARY") + +# use pkg-config if possible or fallback to default flags +LIBS=$(pkg-config --libs libevent libevent_pthreads libssl 2>/dev/null || echo "-levent_pthreads -levent -lssl -lcrypto") +LIBS=$(echo "$LIBS" | sed 's/^-L/-L-L/; s/ -L/ -L-L/g; s/^-l/-L-l/; s/ -l/ -L-l/g') +export LIBS + +# generate a file name for the temporary compile/run script +START_SCRIPT=`mktemp -t dub.start.XXXXXXXX` + +# copy dub.d to /tmp and make it deletable by anyone +cp -p "$VIBEPATH"/dub.d /tmp/dub.d +chmod 666 /tmp/dub.d + +# run VPM and delete the dub.d file again, VPM will output the compile/run script +rdmd -g -w -property -I"$VIBEPATH"/../source $LIBS -Jviews -Isource /tmp/dub.d "$VIBEPATH" "$START_SCRIPT" $1 $2 $3 $4 $5 $6 $7 $8 $9 +rm /tmp/dub.d + +# compile/run the application +chmod +x "$START_SCRIPT" +"$START_SCRIPT" +rm "$START_SCRIPT" diff --git a/bin/dub.cmd b/bin/dub.cmd new file mode 100644 index 0000000..70e432a --- /dev/null +++ b/bin/dub.cmd @@ -0,0 +1,20 @@ +@echo off +set VIBE_BIN=%~dps0 +set LIBDIR=%VIBE_BIN%..\lib\win-i386 +set BINDIR=%VIBE_BIN%..\lib\bin +set LIBS="%LIBDIR%\event2.lib" "%LIBDIR%\eay.lib" "%LIBDIR%\ssl.lib" ws2_32.lib +set EXEDIR=%TEMP%\.rdmd\source +set START_SCRIPT=%EXEDIR%\vibe.cmd + +if NOT EXIST %EXEDIR% ( + mkdir %EXEDIR% +) +copy "%VIBE_BIN%*.dll" %EXEDIR% > nul 2>&1 +if "%1" == "build" copy "%VIBE_BIN%*.dll" . > nul 2>&1 +copy "%VIBE_BIN%dub.d" %EXEDIR% > nul 2>&1 + +rem Run, execute, do everything.. but when you do it, do it with the vibe! +rdmd -debug -g -w -property -of%EXEDIR%\dub.exe -I%VIBE_BIN%..\source %LIBS% %EXEDIR%\dub.d %VIBE_BIN% %START_SCRIPT% %* + +rem Finally, start the app, if dub succeded. +if ERRORLEVEL 0 %START_SCRIPT% diff --git a/bin/dub.d b/bin/dub.d new file mode 100644 index 0000000..6e092a6 --- /dev/null +++ b/bin/dub.d @@ -0,0 +1,298 @@ +/** + The entry point to vibe.d + + Copyright: © 2012 Matthias Dondorff + License: Subject to the terms of the MIT license, as written in the included LICENSE.txt file. + Authors: Matthias Dondorff +*/ +module dub; + +import vibe.core.file; +import vibe.core.log; +import vibe.inet.url; +import vibe.dub.dub; +import vibe.dub.registry; +import vibe.utils.string; + +import std.algorithm; +import std.array; +import std.conv; +import std.exception; +import std.file; +import std.getopt; +import std.process; + + +int main(string[] args) +{ + string cmd; + + try { + if( args.length < 3 ){ + logError("Usage: %s <vibe-binary-path> <start-script-output-file> [<command>] [args...] [-- [applicatio args]]\n", args[0]); + // vibe-binary-path: the installation folder of the vibe installation + // start-script-output-file: destination of the script, which can be used to run the app + return 1; + } + + // parse general options + bool verbose, vverbose, quiet, vquiet; + bool help, nodeps, annotate; + LogLevel loglevel = LogLevel.Info; + getopt(args, + "v|verbose", &verbose, + "vverbose", &vverbose, + "q|quiet", &quiet, + "vquiet", &vquiet, + "h|help", &help, + "nodeps", &nodeps, + "annotate", &annotate + ); + + if( vverbose ) loglevel = LogLevel.Trace; + else if( verbose ) loglevel = LogLevel.Debug; + else if( vquiet ) loglevel = LogLevel.None; + else if( quiet ) loglevel = LogLevel.Warn; + setLogLevel(loglevel); + if( loglevel >= LogLevel.Info ) setPlainLogging(true); + + + // extract the destination paths + enforce(isDir(args[1]), "Specified binary path is not a directory."); + Path vibedDir = Path(args[1]); + Path dstScript = Path(args[2]); + + // extract the command + if( args.length > 3 && !args[3].startsWith("-") ){ + cmd = args[3]; + args = args[0] ~ args[4 .. $]; + } else { + cmd = "run"; + args = args[0] ~ args[3 .. $]; + } + + // contrary to the documentation, getopt does not remove -- + if( args.length >= 2 && args[1] == "--" ) args = args[0] ~ args[2 .. $]; + + // display help if requested + if( help ){ + showHelp(cmd); + return 0; + } + + auto appPath = getcwd(); + string appStartScript; + Url registryUrl = Url.parse("http://registry.vibed.org/"); + logDebug("Using dub registry url '%s'", registryUrl); + + // handle the command + switch( cmd ){ + default: + enforce(false, "Command is unknown."); + assert(false); + case "init": + string dir = "."; + if( args.length >= 2 ) dir = args[1]; + initDirectory(dir); + break; + case "run": + case "build": + Vpm dub = new Vpm(Path(appPath), new RegistryPS(registryUrl)); + if( !nodeps ){ + logInfo("Checking dependencies in '%s'", appPath); + logDebug("dub initialized"); + dub.update(annotate ? UpdateOptions.JustAnnotate : UpdateOptions.None); + } + + //Added check for existance of [AppNameInPackagejson].d + //If exists, use that as the starting file. + string binName = getBinName(dub); + version(Windows) { string appName = binName[0..$-4]; } + version(Posix) { string appName = binName; } + + logDebug("Application Name is '%s'", binName); + + // Create start script, which will be used by the calling bash/cmd script. + // build "rdmd --force %DFLAGS% -I%~dp0..\source -Jviews -Isource @deps.txt %LIBS% source\app.d" ~ application arguments + // or with "/" instead of "\" + string[] flags = ["--force"]; + if( cmd == "build" ){ + flags ~= "--build-only"; + flags ~= "-of"~binName; + } + flags ~= "-g"; + flags ~= "-I" ~ (vibedDir ~ ".." ~ "source").toNativeString(); + flags ~= "-Isource"; + flags ~= "-Jviews"; + flags ~= dub.dflags; + flags ~= getLibs(vibedDir); + flags ~= getPackagesAsVersion(dub); + flags ~= (Path("source") ~ appName).toNativeString(); + flags ~= args[1 .. $]; + + appStartScript = "rdmd " ~ getDflags() ~ " " ~ join(flags, " "); + break; + case "upgrade": + logInfo("Upgrading application in '%s'", appPath); + Vpm dub = new Vpm(Path(appPath), new RegistryPS(registryUrl)); + logDebug("dub initialized"); + dub.update(UpdateOptions.Reinstall | (annotate ? UpdateOptions.JustAnnotate : UpdateOptions.None)); + break; + } + + auto script = openFile(to!string(dstScript), FileMode.CreateTrunc); + scope(exit) script.close(); + script.write(appStartScript); + + return 0; + } + catch(Throwable e) + { + logError("Error executing command '%s': %s\n", cmd, e.msg); + logDebug("Full exception: %s", sanitizeUTF8(cast(ubyte[])e.toString())); + showHelp(cmd); + return -1; + } +} + + +private void showHelp(string command) +{ + // This help is actually a mixup of help for this application and the + // supporting dub script / .cmd file. + logInfo( +"Usage: dub [<command>] [<vibe options...>] [-- <application options...>] + +Manages the vibe.d application in the current directory. A single -- can be used +to separate vibe options from options passed to the application. + +Possible commands: + init [<directory>] Initializes an empy project in the specified directory + run Compiles and runs the application + build Just compiles the application in the project directory + upgrade Forces an upgrade of all dependencies + +Options: + -v --verbose Also output debug messages + --vverbose Also output trace messages (produces a lot of output) + -q --quiet Only output warnings and errors + --vquiet No output + -h --help Print this help screen + --nodeps Do not check dependencies for 'run' or 'build' + --annotate Do not execute dependency installations, just print +"); +} + + +private string getDflags() +{ + auto globVibedDflags = environment.get("DFLAGS"); + if(globVibedDflags == null) + globVibedDflags = "-debug -g -w -property"; + return globVibedDflags; +} + +private string[] getLibs(Path vibedDir) +{ + version(Windows) + { + auto libDir = vibedDir ~ "..\\lib\\win-i386"; + return ["ws2_32.lib", + (libDir ~ "event2.lib").toNativeString(), + (libDir ~ "eay.lib").toNativeString(), + (libDir ~ "ssl.lib").toNativeString()]; + } + version(Posix) + { + return split(environment.get("LIBS", "-L-levent_openssl -L-levent")); + } +} + +private string stripDlangSpecialChars(string s) +{ + char[] ret = s.dup; + for(int i=0; i<ret.length; ++i) + if(!isAlpha(ret[i])) + ret[i] = '_'; + return to!string(ret); +} + +private string[] getPackagesAsVersion(const Vpm dub) +{ + string[] ret; + string[string] pkgs = dub.installedPackages(); + foreach(id, vers; pkgs) + ret ~= "-version=VPM_package_" ~ stripDlangSpecialChars(id); + return ret; +} + +private string getBinName(const Vpm dub) +{ + string ret; + if(existsFile(Path("source") ~ (dub.packageName() ~ ".d"))) + ret = dub.packageName(); + //Otherwise fallback to source/app.d + else + ret = (Path(".") ~ "app").toNativeString(); + version(Windows) { ret ~= ".exe"; } + + return ret; +} + +private void initDirectory(string fName) +{ + Path cwd; + //Check to see if a target directory is specified. + if(fName != ".") { + if(!existsFile(fName)) + createDirectory(fName); + cwd = Path(fName); + } + //Otherwise use the current directory. + else + cwd = Path("."); + + //raw strings must be unindented. + immutable packageJson = +`{ + "name": "`~(fName == "." ? "my-project" : fName)~`", + "version": "0.0.1", + "description": "An example project skeleton", + "homepage": "http://example.org", + "copyright": "Copyright © 2000, Edit Me", + "authors": [ + "Your Name" + ], + "dependencies": { + } +} +`; + immutable appFile = +`import vibe.d; + +static this() +{ + logInfo("Edit source/app.d to start your project."); +} +`; + //Make sure we do not overwrite anything accidentally + if( (existsFile(cwd ~ "package.json")) || + (existsFile(cwd ~ "source" )) || + (existsFile(cwd ~ "views" )) || + (existsFile(cwd ~ "public" ))) + { + logInfo("The current directory is not empty.\n" + "vibe init aborted."); + //Exit Immediately. + return; + } + //Create the common directories. + createDirectory(cwd ~ "source"); + createDirectory(cwd ~ "views" ); + createDirectory(cwd ~ "public"); + //Create the common files. + openFile(cwd ~ "package.json", FileMode.Append).write(packageJson); + openFile(cwd ~ "source/app.d", FileMode.Append).write(appFile); + //Act smug to the user. + logInfo("Successfully created empty project."); +} diff --git a/bin/vpm.d b/bin/vpm.d deleted file mode 100644 index 7bf45c6..0000000 --- a/bin/vpm.d +++ /dev/null @@ -1,298 +0,0 @@ -/** - The entry point to vibe.d - - Copyright: © 2012 Matthias Dondorff - License: Subject to the terms of the MIT license, as written in the included LICENSE.txt file. - Authors: Matthias Dondorff -*/ -module vpm; - -import vibe.core.file; -import vibe.core.log; -import vibe.inet.url; -import vibe.vpm.vpm; -import vibe.vpm.registry; -import vibe.utils.string; - -import std.algorithm; -import std.array; -import std.conv; -import std.exception; -import std.file; -import std.getopt; -import std.process; - - -int main(string[] args) -{ - string cmd; - - try { - if( args.length < 3 ){ - logError("Usage: %s <vibe-binary-path> <start-script-output-file> [<command>] [args...] [-- [applicatio args]]\n", args[0]); - // vibe-binary-path: the installation folder of the vibe installation - // start-script-output-file: destination of the script, which can be used to run the app - return 1; - } - - // parse general options - bool verbose, vverbose, quiet, vquiet; - bool help, nodeps, annotate; - LogLevel loglevel = LogLevel.Info; - getopt(args, - "v|verbose", &verbose, - "vverbose", &vverbose, - "q|quiet", &quiet, - "vquiet", &vquiet, - "h|help", &help, - "nodeps", &nodeps, - "annotate", &annotate - ); - - if( vverbose ) loglevel = LogLevel.Trace; - else if( verbose ) loglevel = LogLevel.Debug; - else if( vquiet ) loglevel = LogLevel.None; - else if( quiet ) loglevel = LogLevel.Warn; - setLogLevel(loglevel); - if( loglevel >= LogLevel.Info ) setPlainLogging(true); - - - // extract the destination paths - enforce(isDir(args[1]), "Specified binary path is not a directory."); - Path vibedDir = Path(args[1]); - Path dstScript = Path(args[2]); - - // extract the command - if( args.length > 3 && !args[3].startsWith("-") ){ - cmd = args[3]; - args = args[0] ~ args[4 .. $]; - } else { - cmd = "run"; - args = args[0] ~ args[3 .. $]; - } - - // contrary to the documentation, getopt does not remove -- - if( args.length >= 2 && args[1] == "--" ) args = args[0] ~ args[2 .. $]; - - // display help if requested - if( help ){ - showHelp(cmd); - return 0; - } - - auto appPath = getcwd(); - string appStartScript; - Url registryUrl = Url.parse("http://registry.vibed.org/"); - logDebug("Using vpm registry url '%s'", registryUrl); - - // handle the command - switch( cmd ){ - default: - enforce(false, "Command is unknown."); - assert(false); - case "init": - string dir = "."; - if( args.length >= 2 ) dir = args[1]; - initDirectory(dir); - break; - case "run": - case "build": - Vpm vpm = new Vpm(Path(appPath), new RegistryPS(registryUrl)); - if( !nodeps ){ - logInfo("Checking dependencies in '%s'", appPath); - logDebug("vpm initialized"); - vpm.update(annotate ? UpdateOptions.JustAnnotate : UpdateOptions.None); - } - - //Added check for existance of [AppNameInPackagejson].d - //If exists, use that as the starting file. - string binName = getBinName(vpm); - version(Windows) { string appName = binName[0..$-4]; } - version(Posix) { string appName = binName; } - - logDebug("Application Name is '%s'", binName); - - // Create start script, which will be used by the calling bash/cmd script. - // build "rdmd --force %DFLAGS% -I%~dp0..\source -Jviews -Isource @deps.txt %LIBS% source\app.d" ~ application arguments - // or with "/" instead of "\" - string[] flags = ["--force"]; - if( cmd == "build" ){ - flags ~= "--build-only"; - flags ~= "-of"~binName; - } - flags ~= "-g"; - flags ~= "-I" ~ (vibedDir ~ ".." ~ "source").toNativeString(); - flags ~= "-Isource"; - flags ~= "-Jviews"; - flags ~= vpm.dflags; - flags ~= getLibs(vibedDir); - flags ~= getPackagesAsVersion(vpm); - flags ~= (Path("source") ~ appName).toNativeString(); - flags ~= args[1 .. $]; - - appStartScript = "rdmd " ~ getDflags() ~ " " ~ join(flags, " "); - break; - case "upgrade": - logInfo("Upgrading application in '%s'", appPath); - Vpm vpm = new Vpm(Path(appPath), new RegistryPS(registryUrl)); - logDebug("vpm initialized"); - vpm.update(UpdateOptions.Reinstall | (annotate ? UpdateOptions.JustAnnotate : UpdateOptions.None)); - break; - } - - auto script = openFile(to!string(dstScript), FileMode.CreateTrunc); - scope(exit) script.close(); - script.write(appStartScript); - - return 0; - } - catch(Throwable e) - { - logError("Error executing command '%s': %s\n", cmd, e.msg); - logDebug("Full exception: %s", sanitizeUTF8(cast(ubyte[])e.toString())); - showHelp(cmd); - return -1; - } -} - - -private void showHelp(string command) -{ - // This help is actually a mixup of help for this application and the - // supporting vibe script / .cmd file. - logInfo( -"Usage: vibe [<command>] [<vibe options...>] [-- <application options...>] - -Manages the vibe.d application in the current directory. A single -- can be used -to separate vibe options from options passed to the application. - -Possible commands: - init [<directory>] Initializes an empy project in the specified directory - run Compiles and runs the application - build Just compiles the application in the project directory - upgrade Forces an upgrade of all dependencies - -Options: - -v --verbose Also output debug messages - --vverbose Also output trace messages (produces a lot of output) - -q --quiet Only output warnings and errors - --vquiet No output - -h --help Print this help screen - --nodeps Do not check dependencies for 'run' or 'build' - --annotate Do not execute dependency installations, just print -"); -} - - -private string getDflags() -{ - auto globVibedDflags = environment.get("DFLAGS"); - if(globVibedDflags == null) - globVibedDflags = "-debug -g -w -property"; - return globVibedDflags; -} - -private string[] getLibs(Path vibedDir) -{ - version(Windows) - { - auto libDir = vibedDir ~ "..\\lib\\win-i386"; - return ["ws2_32.lib", - (libDir ~ "event2.lib").toNativeString(), - (libDir ~ "eay.lib").toNativeString(), - (libDir ~ "ssl.lib").toNativeString()]; - } - version(Posix) - { - return split(environment.get("LIBS", "-L-levent_openssl -L-levent")); - } -} - -private string stripDlangSpecialChars(string s) -{ - char[] ret = s.dup; - for(int i=0; i<ret.length; ++i) - if(!isAlpha(ret[i])) - ret[i] = '_'; - return to!string(ret); -} - -private string[] getPackagesAsVersion(const Vpm vpm) -{ - string[] ret; - string[string] pkgs = vpm.installedPackages(); - foreach(id, vers; pkgs) - ret ~= "-version=VPM_package_" ~ stripDlangSpecialChars(id); - return ret; -} - -private string getBinName(const Vpm vpm) -{ - string ret; - if(existsFile(Path("source") ~ (vpm.packageName() ~ ".d"))) - ret = vpm.packageName(); - //Otherwise fallback to source/app.d - else - ret = (Path(".") ~ "app").toNativeString(); - version(Windows) { ret ~= ".exe"; } - - return ret; -} - -private void initDirectory(string fName) -{ - Path cwd; - //Check to see if a target directory is specified. - if(fName != ".") { - if(!existsFile(fName)) - createDirectory(fName); - cwd = Path(fName); - } - //Otherwise use the current directory. - else - cwd = Path("."); - - //raw strings must be unindented. - immutable packageJson = -`{ - "name": "`~(fName == "." ? "my-project" : fName)~`", - "version": "0.0.1", - "description": "An example project skeleton", - "homepage": "http://example.org", - "copyright": "Copyright © 2000, Edit Me", - "authors": [ - "Your Name" - ], - "dependencies": { - } -} -`; - immutable appFile = -`import vibe.d; - -static this() -{ - logInfo("Edit source/app.d to start your project."); -} -`; - //Make sure we do not overwrite anything accidentally - if( (existsFile(cwd ~ "package.json")) || - (existsFile(cwd ~ "source" )) || - (existsFile(cwd ~ "views" )) || - (existsFile(cwd ~ "public" ))) - { - logInfo("The current directory is not empty.\n" - "vibe init aborted."); - //Exit Immediately. - return; - } - //Create the common directories. - createDirectory(cwd ~ "source"); - createDirectory(cwd ~ "views" ); - createDirectory(cwd ~ "public"); - //Create the common files. - openFile(cwd ~ "package.json", FileMode.Append).write(packageJson); - openFile(cwd ~ "source/app.d", FileMode.Append).write(appFile); - //Act smug to the user. - logInfo("Successfully created empty project."); -}