Showing posts with label development. Show all posts
Showing posts with label development. Show all posts

Wednesday, February 27, 2013

Windows Dev and Dashboard Prompt

First set up a cmd file (a batch file with a *.cmd extension) whose sole purpose is to set environment variables.

Mine, called DashboardEnv.cmd, looks like this on one of the machines where I have Visual Studio 2010 Express Edition installed:

    @call "%VS100COMNTOOLS%\vsvars32.bat"
    @set PATH=C:\Program Files\Git\bin;%PATH%
    @set PATH=%USERPROFILE%\DevBox\cmake-2.8.10.2\bin;%PATH%
    @set PATH=C:\Python27;%PATH%
    @set PATH=C:\Qt\4.8.4-vs10\bin;%PATH%
    @set PATH=C:\dev\tools\bin;%PATH%


As you can see by inspecting that file, it sets up the environment just like a Visual Studio command prompt, and then adds a bunch of useful stuff to the PATH environment variable: git, cmake, python, qmake, ninja and jom, to name a few. I have ninja and jom in the C:\dev\tools\bin directory -- they could be anywhere, you just have to add the right directory to the PATH here in this script.

Next, set up a cmd file in the same directory as the environment batch file to display a "developer cmd prompt."

Mine, called DashboardPrompt.cmd, looks like this:

    @call "%~dp0DashboardEnv.cmd"

    @title Dashboard Prompt

    @echo.
    @echo Environment set by "%~f0"
    @echo.

    @call "%COMSPEC%"


If you prefer the "git bash" prompt to the raw Windows cmd prompt, you can change the call COMSPEC line to:

    @call "C:\Program Files\Git\bin\sh.exe" --login -i
After you have both of those setup, double click the prompt cmd file to test it out. Then you can create a shortcut to the prompt cmd file, put it on your desktop, or whereever you like, and then just double-click the shortcut to get a new instance of your customized developer prompt.

Some things I do to make the command prompt itself slightly less intolerable:
  • edit the command prompt window properties: with the window open, click on the icon in the top left corner, and choose "Properties" from the menu
  • modify the properties of the window to allow "select-and-Enter-key to copy, right-click to paste" behavior by choosing the "QuickEdit Mode" checkbox
  • set the screen buffer height (number of scroll back lines) to 9999, the max allowed
  • set the window size to something larger so you can see more text at once (120 by 40-50 is nice depending on your usual screen)
  • set the font to Lucida Console, and choose a font size large enough to read
  • if prompted, check "modify the shortcut that started this prompt" on the way out
Now that you're all set up for an interactive prompt with the right environment... here's the reason why separating it into two scripts is good for you. You can easily run any other script with the very same environment by adding one line at the top of it:

    @call "%~dp0DashboardEnv.cmd"

The %~dp0 there means "drive letter (d) and full path of containing directory (p) without any double quotes (~) of this script file (arg 0) including the trailing '\' character (implicit in p)" -- so if you write a script that references another script in the same directory, using %~dp0 is a reliable way to reference it, regardless of how the batch file was invoked. See the output of "help for" in a Windows command prompt for all the gory details about possible letter codes you can use in such constructs.

So: to run dashboards or other automated builds with the same environment that you use for interactive development, you can write a script that uses your Env.cmd file.

Mine, called RunDashboards.cmd, looks like this:

    @call "%~dp0DashboardEnv.cmd"

    @title Run Dashboards

    @echo.
    @echo Running script "%~f0"
    @echo.  started on %DATE% at %TIME%
    @echo.

    @echo.
    @echo Updating VTKLargeData...
    @cd "C:\dev\My Tests\VTKLargeData"
    @git pull

    @echo.
    @echo Updating VTKData...
    @cd "C:\dev\My Tests\VTKData"
    @git pull

    @echo.
    @echo Running VTK Release dashboard...
    @cd "C:\dev\My Tests\VTK"
    @ctest -S C:\dev\EasyDashboardScripts\EasyDashboard.cmake,ninja-Nightly-Release

    @echo.
    @echo Running VTK Debug dashboard...
    @cd "C:\dev\My Tests\VTK"
    @ctest -S C:\dev\EasyDashboardScripts\EasyDashboard.cmake,ninja-Nightly-Debug


One nice thing about guaranteeing the right environment is set for running a script like this is being able to just use "git" and "ctest" in the script itself.

Obviously, you'll need to adjust path values according to tool installations on different machines.

For more details on setting up to run dashboards on Windows, see this page over on the CMake blog. (Also published on the Kitware blog.)

Good luck -- tweet me @DLRdave or ping me on G+ if you use this technique.

Wednesday, May 04, 2011

Sgt Fitness: now available in the App Store

Help me give $1,000,000 to charity!

My latest creation for the iPhone, Sgt Fitness, the workout coach for the Twitter generation, is now available in the App Store.

It's an exercise reminder app that drills you daily with short workout sessions that you can do anywhere, anytime. Each one only takes a minute or two, but over the course of the day, these drills add up to way more activity than you normally get just sitting in front of your computer.

If you've been making excuses like "I don't have time for a workout" or "I can't afford a gym membership" or "there's no shower at work" or ... then Sgt Fitness is for you. Everybody's got time for a minute or two here and there, the app costs way less than a gym membership, and working out in micro-bursts of activity won't get you too sweaty for your officemates.

Sgt Fitness converts your iPhone into a pocket-sized dose of self-discipline to help you get and stay fit.

Watch out, though. Sgt Fitness has a voice! If the sound is on, sarge'll let you know it's time for a drill with a verbal "Drop and give me 20!" Or, if you're like me, and you hate it when your phone makes sounds in the middle of a conversation with somebody, you'll get the old "vvvmmmppp" vibration alert. Either way, it's time for some activity, private.

Got ADD? No worries: the sergeant tells you exactly what to do and when to do it. You don't even have to think about it. And by the time you get distracted while doing the drill, it's over anyway. On to the next shiny thing, and before you know it, another couple of hours and a few hundred web pages have gone by, and it's time for the next drill.

"David, this is fantastic!" you say. "I've been thinking I should get more fit, and Sgt Fitness will help me there. I get it. But how will this help you give a million dollars to charity?"

I'm glad you asked. But I'm not going to answer that question until the next blog post. For now, suffice it to say that I am seeking the first 4,000 users of Sgt Fitness, and that I hope to recruit them within a month. Friends and family, I implore you: help me sell Sgt Fitness to the whole wide world -- blog, tweet, linked-in and facebook it up for me.

Sgt Fitness is available exclusively for iPhone, iPad and iPod Touch devices. Buy a copy today, and then let all your friends know there's a new workout in town. No gym membership required.

Stay fit!

Follow @SgtFitnessApp on Twitter for news and updates about the app... And check out the Sgt Fitness web page.

Thursday, April 28, 2011

Building an iPhone Web Page

Excellent article on building a web page for display on an iPhone or iPod Touch: http://www.engageinteractive.co.uk/blog/2008/06/19/tutorial-building-a-website-for-the-iphone/

Thanks, man. That was helpful.

(Hard to believe that page is almost 3 years old now...)

Wednesday, March 31, 2010

"Fun" With Batch Files

Here's how to compute the root Program Files directory of the Visual Studio 2008 installation from the VS90COMNTOOLS environment variable... (for example...) Obviously: same technique may apply to other env vars and other programs.

The Line of Code
In a batch file:
for /f "usebackq delims=" %%d in (`echo "%VS90COMNTOOLS%\..\.."`) do set VS_ROOT_DIR=%%~fd

Directly in a command prompt:
for /f "usebackq delims=" %d in (`echo "%VS90COMNTOOLS%\..\.."`) do set VS_ROOT_DIR=%~fd

The only difference between the two is the doubling up of the "%%d" percents when referencing for loop variables. Don't ask why, just learn: that's the way it is. Actually, if you want to ask why and then go figure out the answer... that would be a good blog post for you to write.

The Dissection
On my machine, the command...
echo "%VS90COMNTOOLS%\..\.."

...produces:
"C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\Tools\\..\.."

Nice. Accurate and all, but look at all the ugliness we've produced. Doubled up backslashes, enclosing double quotes, ..s, not to mention the length.

So. That fancy "for /f" line. Let's clean up that output to remove the ugliness.

Using "for /f" with the "usebackq" option allows you to put a command inside backticks, as in `echo something`, and capture the output of that command in the for loop variable. In this dead simple example, the for loop would iterate exactly once, and the value "something" would be in the loop variable.

Using the "delims=" option allows you to split the output by delimiter characters. When you say "delims=" with the equal sign right up against the closing double quote, that means: no delimiter characters, give me the full output all at once. Much different result than "delims= " with a space in between... that one loops over the output separating by space characters, giving multiple for loop iterations based on how many spaces are in the output. You could also say "delims=\" to split at the path separator character, or "delims= \/:" to split at common date time separators.

Now that usebackq and delims are well understood, or at least explained, how does that help us get rid of the ugliness? Well... it's mostly the magical "%~fd" at the very end of our friendly line of code that makes the universe beautiful again. The usebackq/delims pain we went through was really just a way to get the string we want into a for loop variable so we can take advantage of for loop variable expansion modifiers.

for /f "usebackq delims=" %d in (`echo "%VS90COMNTOOLS%\..\.."`) do set VS_ROOT_DIR=%~fd

The "%~fd" says this: give me the value of the loop variable %d, and while you're at it, remove any enclosing double quotes (~), and resolve it to a full path, assuming the variable represents a file or directory name (f).

The net effect of all this is that our line of code...
for /f "usebackq delims=" %d in (`echo "%VS90COMNTOOLS%\..\.."`) do set VS_ROOT_DIR=%~fd

Finally, in the end, simply evaluates to the line of code we wanted to write in the first place, but without hard coding a machine specific path name in a batch file:
set VS_ROOT_DIR=C:\Program Files (x86)\Microsoft Visual Studio 9.0

Type "help for" in a Windows command prompt for more of the gory, sickening details regarding loop variable expansion.

And help keep the universe beautiful. Even if you still have to write batch files once in a while.

Saturday, October 03, 2009

xampp on Vista: Problem Solved

So xampp is cool. When it works. It's everything you need all rolled into an easy-to-install package to turn your computer into a web server. (This is crucial if you are a web developer and are trying to build/debug a web site. You must have one of the computers that is in the same room with you acting as a web server...)

But here's the problem: there's so much junk installed on computers these days that it is quite common to get "port conflicts" with some other piece of installed software. When you try to enable the Apache web server or the MySQL database server that are installed with xampp, sometimes they just won't start up. They seem like they're trying to, but then... nothing.

I googled it. Turn off skype, they say. I don't have Skype, can't be that.

Google again. Turn off the anti-virus. Nope. Not that.

Google again. Turn off World Wide Web Publishing Service. Nope. Not there. Not even listed as a service on my Vista laptop.

For the life of me, I could not see what was opening port 80. I use Process Explorer all the time on Windows. But there are so many things running on my Vista laptop, it would have taken me forever to find port 80 looking through things one at a time. I finally traced it down to a process called "System:4" (process ID 4, that is) by using a tool called Tcpview, from the same very cool cat that keeps Process Explorer in tip top shape. Thanks, Mark.

Finally... google led me to this post saying that I should also turn off "SQL Server Reporting Services (MSSQLServer)". Additionally, I turned off everything else SQL Server related in the services control panel. I really probably don't need them for anything that I actually use. They were "accidentally" installed/activated as a side effect of installing some Visual Studio or SDK, I'm sure...

Whew. Hopefully this helps somebody out. Maybe save you the handful of hours I just donated to the bit bucket.

One more comment: I really do not understand why Skype, WWW Publishing, SQL Reporting, or any of these other things should be grabbing onto port 80. What the heck? Port 80's for a web server. Go away unless you're a web server! Leave me alone so when I want to run a web server, it just works like it's supposed to. Or at least show me something when I go to http://localhost in my browser.

But hey, I'm done ranting. Apache and MySQL are running now. I can run CDash on my Vista laptop again and....


Life is Good (really, it is.... :-)
Dave