Code to automatically find a physical drive for running a build, triggered as necessary.
authorSimon Howkins <simonh@symbian.org>
Tue, 26 Jan 2010 12:13:01 +0000
changeset 858 f9fc2a3f8f70
parent 857 c72c6eafadc6
child 859 206902c43bdb
Code to automatically find a physical drive for running a build, triggered as necessary.
common/build.xml
common/common_props.ant.xml
common/tools/findPhysicalDrive.pl
--- a/common/build.xml	Wed Jan 20 12:34:36 2010 +0000
+++ b/common/build.xml	Tue Jan 26 12:13:01 2010 +0000
@@ -18,8 +18,20 @@
         </then>
     </if>
     
+    <!-- If we've not has a physical drive specified, then we'd better be able to work one out... -->
+    <if>
+        <not><isset property="sf.spec.job.root.drive"/></not>
+        <then>
+            <exec executable="perl" outputproperty="sf.spec.job.root.drive" logerror="true" failonerror="true">
+                <arg value="${sf.common.config.dir}/tools/findPhysicalDrive.pl"/>
+            </exec>
+        </then>
+    </if>
+    
     <!-- Import common properties -->
     <import file="${sf.common.config.dir}/common_props.ant.xml" />
+
+    <property name="sf.spec.job.rootdir" value="${sf.spec.job.root.drive}/${sf.spec.job.root.path}"/>
     
     <!-- setup Helium internal properties from their equivalent in the project spec -->
     <property name="build.name" value="${sf.spec.job.name}"/>
--- a/common/common_props.ant.xml	Wed Jan 20 12:34:36 2010 +0000
+++ b/common/common_props.ant.xml	Tue Jan 26 12:13:01 2010 +0000
@@ -7,7 +7,8 @@
     <property name="sf.spec.job.name" value="myproduct"/>
     <property name="sf.spec.job.codeline" value="MCL"/>
     <property name="sf.spec.job.number" value="001"/> <!-- this is always overriden from the commandline -->
-    <property name="sf.spec.job.rootdir" value="D:\fbf_job"/>
+    <!-- <property name="sf.spec.job.root.drive" value="D:"/> Set this to force the physical drive for the build storage. Leave unset to allow any non-system physical drive to be found-->
+    <property name="sf.spec.job.root.path" value="fbf_job"/>
     <property name="sf.spec.job.drive" value="M:"/>
     <property name="sf.spec.job.freespace" value="10"/>
     <property name="sf.spec.email.from" value="fbf@symbian.org"/> <!-- needs to be defined for S60 platform builds -->
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/common/tools/findPhysicalDrive.pl	Tue Jan 26 12:13:01 2010 +0000
@@ -0,0 +1,51 @@
+#!perl -w
+#
+# Copyright (c) 2010 Symbian Foundation Ltd
+# This component and the accompanying materials are made available
+# under the terms of the License "Eclipse Public License v1.0"
+# which accompanies this distribution, and is available
+# at the URL "http://www.eclipse.org/legal/epl-v10.html".
+#
+# Initial Contributors:
+# Symbian Foundation Ltd - initial contribution.
+# 
+# Contributors:
+#
+# Description:
+# Find and output the drive letter mapped to the physical volume with the
+# largest amount of free space
+# 
+
+use strict;
+
+# Use Windows command to list physical volumes on the machine
+# (No substed drives, or mapped network drives)
+my @drives = map {chomp;$_} `echo list volume | diskpart`;
+
+my %drives;
+for my $driveLine (@drives)
+{
+	# If this line of output is actually about a healthy HD volume...
+	if ($driveLine =~ m{^\s+Volume \d+\s+([A-Z]).*?(Partition|RAID-5)\s+\d+ [A-Z]+\s+Healthy} )
+	{
+		my $letter = $1;
+		# Ignore the system drive
+		next if ($driveLine =~ m{System\s*$});
+
+		# Use dir to get the freespace (bytes)
+		my @bytesFree = grep { s{^.*?(\d+) bytes free\s*$}{$1} } map {chomp;$_} `cmd /c dir /-C $letter:\\`;
+		# Take the value from the bottom of the report
+		my $bytesFree = $bytesFree[-1];
+
+		# Record info for this volume
+		$drives{$letter} = $bytesFree;
+	}
+}
+
+die "Unable to find any suitable drives at all\n" unless %drives;
+
+# Switch keys and values
+%drives = reverse %drives;
+# Sort by space to find the volume with the largest amount of space and print out the corresponding letter
+print "$drives{(reverse sort keys %drives)[0]}:\n";
+