Bug 386740 - Windows file versions are incorrect, r=luser
authorbenjamin@smedbergs.us
Mon, 14 Jan 2008 07:24:19 -0800
changeset 10257 2630a67dc51be324ca2efb83198f4ce85caa208a
parent 10256 c7e0729465f69538d21bdea30b7fc179b91cb85c
child 10258 f3f1a898aeb235ee8a332e1bcfc4da667aa356e3
push id1
push userbsmedberg@mozilla.com
push dateThu, 20 Mar 2008 16:49:24 +0000
treeherdermozilla-central@61007906a1f8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersluser
bugs386740
milestone1.9b3pre
Bug 386740 - Windows file versions are incorrect, r=luser
config/Makefile.in
config/version.mk
config/version_win.pl
toolkit/xre/Makefile.in
toolkit/xre/make-platformini.py
--- a/config/Makefile.in
+++ b/config/Makefile.in
@@ -100,16 +100,25 @@ HEADERS = \
 export:: $(TARGETS) $(HEADERS)
 	$(INSTALL) $(IFLAGS1) $(HEADERS) $(DIST)/include
 	-rm -f $(FINAL_LINK_COMPS) $(FINAL_LINK_LIBS) $(FINAL_LINK_COMP_NAMES)
 	-rm -f $(DIST)/bin/chrome/chromelist.txt
 ifdef HOST_PROGRAM
 	$(INSTALL) $(HOST_PROGRAM) $(DIST)/bin
 endif
 
+# Generate a new buildid every time we "export" in config... that's only
+# supposed to be once per-build!
+export::
+ifdef MOZ_BUILD_DATE
+	printf "%s" $(MOZ_BUILD_DATE) > buildid
+else
+	$(PYTHON) $(topsrcdir)/toolkit/xre/make-platformini.py --print-buildid > buildid
+endif
+
 ifdef WRAP_SYSTEM_INCLUDES
 export::
 	if test ! -d system_wrappers; then mkdir system_wrappers; fi
 	$(PERL) $(topsrcdir)/config/preprocessor.pl $(DEFINES) $(ACDEFINES) \
 		-DBUILD_STATIC_LIBS=$(BUILD_STATIC_LIBS) \
 		-DMOZ_TREE_CAIRO=$(MOZ_TREE_CAIRO) \
 		-DMOZ_ENABLE_LIBXUL=$(MOZ_ENABLE_LIBXUL) \
 		-DMOZ_NATIVE_ZLIB=$(MOZ_NATIVE_ZLIB) \
--- a/config/version.mk
+++ b/config/version.mk
@@ -31,18 +31,16 @@
 # the provisions above, a recipient may use your version of this file under
 # the terms of any one of the MPL, the GPL or the LGPL.
 #
 # ***** END LICENSE BLOCK *****
 
 ifndef INCLUDED_VERSION_MK
 INCLUDED_VERSION_MK=1
 
-
-
 # Windows gmake build:
 # Build default .rc file if $(RESFILE) isn't defined.
 # TODO:
 # PBI      : Private build info.  Not used currently.
 #            Guessing the best way would be to set an env var.
 # BINARY   : Binary name.  Not used currently.
 ifeq ($(MOZ_WIDGET_TOOLKIT),windows)
 ifndef RESFILE
@@ -73,23 +71,15 @@ ifdef RCINCLUDE
 _RC_STRING += -RCINCLUDE $(srcdir)/$(RCINCLUDE)
 endif
 
 GARBAGE += $(RESFILE) $(RCFILE)
 
 #dummy target so $(RCFILE) doesn't become the default =P
 all::
 
-$(RCFILE): $(RCINCLUDE)
+$(RCFILE): $(RCINCLUDE) $(topsrcdir)/config/version_win.pl
 	$(PERL) $(topsrcdir)/config/version_win.pl $(_RC_STRING)
 
 endif  # RESFILE
 endif  # Windows
 
-
-ifdef VERSION_TMPL
-GARBAGE += $(VERSION_TMPL)
-
-export::
-	$(PERL) $(topsrcdir)/config/milestone.pl --topsrcdir $(topsrcdir) --objdir . --srcdir $(srcdir) --template $(VERSION_TMPL)
 endif
-
-endif
--- a/config/version_win.pl
+++ b/config/version_win.pl
@@ -38,24 +38,37 @@
 #use diagnostics;
 require strict;
 my $dir = $0;
 $dir =~ s/[^\/]*$//;
 push(@INC, "$dir");
 require "Moz/Milestone.pm";
 use Getopt::Long;
 use Getopt::Std;
+use POSIX;
+
+# Calculate the number of days since Jan. 1, 2000 from a buildid string
+sub daysFromBuildID
+{
+    my ($buildid,) = @_;
+
+    my ($y, $m, $d, $h) = ($buildid =~ /^(\d{4})(\d{2})(\d{2})(\d{2})$/);
+    $d || die("Unrecognized buildid string.");
+
+    my $secondstodays = 60 * 60 * 24;
+    return (POSIX::mktime(00, 00, 00, $d, $m, $y - 1900) -
+            POSIX::mktime(00, 00, 00, 01, 01, 100)) / $secondstodays;
+}
 
 #Creates version resource file
 
 #Paramaters are passed on the command line:
 
-#Example: -PBI=blah -DEBUG=1
+#Example: -MODNAME nsToolkitCompsModule -DEBUG=1
 
-# PBI - your private build information (if not a milestone or nightly)
 # DEBUG - Mozilla's global debug variable - tells if its debug version
 # OFFICIAL - tells Mozilla is building a milestone or nightly
 # MSTONE - tells which milestone is being built;
 # OBJDIR - Holds the object directory;
 # MODNAME - tells what the name of the module is like nsBMPModule
 # DEPTH - Holds the path to the root obj dir
 # TOPSRCDIR - Holds the path to the root mozilla dir
 # SRCDIR - Holds module.ver and source
@@ -85,64 +98,61 @@ sub getNextEntry
 				$value =~ s/^\s*(.*?)\s*$/$1/;
 				return ($entry,$value);
 			}
 		}
 	}
 	return undef;
 }
 
-my ($quiet,$privateinfo,$objdir,$debug,$official,$milestone,$module,$binary,$depth,$rcinclude,$bits,$srcdir);
+my ($quiet,$objdir,$debug,$official,$milestone,$buildid,$module,$binary,$depth,$rcinclude,$bits,$srcdir,$fileversion,$productversion);
 
 GetOptions( "QUIET" => \$quiet,
-		"PBI=s" => \$privateinfo,
 		"DEBUG=s" => \$debug,
 		"OFFICIAL=s" => \$official,
 		"MSTONE=s" => \$milestone,
 		"MODNAME=s" => \$module,
 		"BINARY=s" => \$binary,
 		"DISPNAME=s" => \$displayname,
 		"SRCDIR=s" => \$srcdir,
 		"TOPSRCDIR=s" => \$topsrcdir,
 		"DEPTH=s" => \$depth,
 		"RCINCLUDE=s" => \$rcinclude,
 		"OBJDIR=s" => \$objdir,
 		"BITS=s" => \$bits);
-if (!defined($privateinfo)) {$privateinfo="";}
 if (!defined($debug)) {$debug="";}
 if (!defined($official)) {$official="";}
 if (!defined($milestone)) {$milestone="";}
 if (!defined($module)) {$module="";}
 if (!defined($binary)) {$binary="";}
 if (!defined($displayname)) {$displayname="Mozilla";}
 if (!defined($depth)) {$depth=".";}
 if (!defined($rcinclude)) {$rcinclude="";}
 if (!defined($objdir)) {$objdir=".";}
 if (!defined($srcdir)) {$srcdir=".";}
 if (!defined($topsrcdir)) {$topsrcdir=".";}
 if (!defined($bits)) {$bits="";}
 my $mfversion = "Personal";
 my $mpversion = "Personal";
-my $fileflags = "VS_FF_PRIVATEBUILD";
+my @fileflags = ("0");
 my $comment="";
 my $description="";
 if (!defined($module))
 {
 	$module = $binary;
 	($module) = split(/\./,$module);
 }
 
-my $productversion = "0,0,0,0";
-my $fileversion = $productversion;
 my $fileos = "VOS__WINDOWS32";
 if ($bits eq "16") { $fileos="VOS__WINDOWS16"; }
 
 my $bufferstr="    ";
 
 my $MILESTONE_FILE = "$topsrcdir/config/milestone.txt";
+my $BUILDID_FILE = "$depth/config/buildid";
 
 #Read module.ver file
 #Version file overrides for WIN32:
 #WIN32_MODULE_COMMENT
 #WIN32_MODULE_DESCRIPTION
 #WIN32_MODULE_FILEVERSION
 #WIN32_MODULE_COMPANYNAME
 #WIN32_MODULE_FILEVERSION_STRING
@@ -196,73 +206,70 @@ else
 #Get rid of trailing and leading whitespace
 $debug =~ s/^\s*(.*)\s*$/$1/;
 $comment =~ s/^\s*(.*)\s*$/$1/;
 $official =~ s/^\s*(.*)\s*$/$1/;
 $milestone =~ s/^\s*(.*)\s*$/$1/;
 $description =~ s/^\s*(.*)\s*$/$1/;
 $module =~ s/^\s*(.*)\s*$/$1/;
 $depth =~ s/^\s*(.*)\s*$/$1/;
-$privateinfo =~ s/^\s*(.*)\s*$/$1/;
 $binary =~ s/^\s*(.*)\s*$/$1/;
 $displayname =~ s/^\s*(.*)\s*$/$1/;
 
+open(BUILDID, "<", $BUILDID_FILE) || die("Couldn't open buildid file: $BUILDID_FILE");
+$buildid = <BUILDID>;
+$buildid =~ s/\s*$//;
+close BUILDID;
+
+my $daycount = daysFromBuildID($buildid);
+
+if ($milestone eq "") {
+    $milestone = Moz::Milestone::getOfficialMilestone($MILESTONE_FILE);
+}
+
+$mfversion = $mpversion = $milestone;
+
 if ($debug eq "1")
 {
-	$fileflags .= " | VS_FF_DEBUG";
+	push @fileflags, "VS_FF_DEBUG";
 	$mpversion .= " Debug";
 	$mfversion .= " Debug";
 }
 
-if ($official eq "1") {
-	#its an official build
-	$privateinfo = "";
-	$fileflags = "VS_FF_PRERELEASE";
-	if ($debug eq "1") {
-		$fileflags = "VS_FF_PRERELEASE | VS_FF_DEBUG";
-	}
+if ($official ne "1") {
+    push @fileflags, "VS_FF_PRIVATEBUILD";
+}
+
+if ($milestone =~ /[a-z]/) {
+    push @fileflags, "VS_FF_PRERELEASE";
+}
 
-        # Try to grab milestone.
-        # I'd love to put this in the makefiles rather than here,
-        # since I could run it once per build rather than once per
-        # dll/program, but I can't seem to get backticks working
-        # properly in the makefiles =P
-        if ($milestone eq "") {
-            $milestone = Moz::Milestone::getOfficialMilestone($MILESTONE_FILE);
-        }
-
-	if ($milestone ne "" && $milestone !~ /\+$/) {
-		#its a milestone build
-
-		$mpversion = $milestone;
-
-		$fileflags = "0";
-	      
-		my @mstone = split(/\./,$milestone);
-		$mstone[1] =~s/\D*$//g;
-		$productversion="$mstone[0],$mstone[1],0,0";
-
-	}
-
-	$mfversion = $mpversion = "$milestone";
+my @mstone = split(/\./,$milestone);
+$mstone[1] =~s/\D.*$//;
+if (!$mstone[2]) {
+    $mstone[2] = "0";
 }
+else {
+    $mstone[2] =~s/\D.*$//;
+}
+$fileversion = $productversion="$mstone[0],$mstone[1],$mstone[2],$daycount";
 
 my $copyright = "License: MPL 1.1/GPL 2.0/LGPL 2.1";
 my $company = "Mozilla Foundation";
 my $trademarks = "Mozilla";
 my $productname = $displayname;
 
 
 if (defined($override_comment)){$override_comment =~ s/\@MOZ_APP_DISPLAYNAME\@/$displayname/g; $comment=$override_comment;}
 if (defined($override_description)){$override_description =~ s/\@MOZ_APP_DISPLAYNAME\@/$displayname/g; $description=$override_description;}
 if (defined($override_fileversion)){$fileversion=$override_fileversion;}
 if (defined($override_mfversion)){$mfversion=$override_mfversion;}
 if (defined($override_company)){$company=$override_company;}
 if (defined($override_module)){$override_module =~ s/\@MOZ_APP_DISPLAYNAME\@/$displayname/g; $module=$override_module;}
-if (defined($override_copyright)){$override_copyright =~ s/\@MOZ_APP_DISPLAYNAME\@/$displayname/g; $copyright=$override_company;}
+if (defined($override_copyright)){$override_copyright =~ s/\@MOZ_APP_DISPLAYNAME\@/$displayname/g; $copyright=$override_copyright;}
 if (defined($override_trademarks)){$override_trademarks =~ s/\@MOZ_APP_DISPLAYNAME\@/$displayname/g; $trademarks=$override_trademarks;}
 if (defined($override_filename)){$binary=$override_filename;}
 if (defined($override_productname)){$override_productname =~ s/\@MOZ_APP_DISPLAYNAME\@/$displayname/g; $productname=$override_productname;}
 if (defined($override_productversion)){$productversion=$override_productversion;}
 if (defined($override_mpversion)){$mpversion=$override_mpversion;}
 
 
 #Override section
@@ -365,25 +372,28 @@ if (open(RCINCLUDE, "<$rcinclude"))
 #					print RCFILE "$nocomment\n";	
 #				}
 #			}
 #		}
 #	}
 	
 }
 
+my $fileflags = join(' | ', @fileflags);
+
 print RCFILE qq{
 
 
 /////////////////////////////////////////////////////////////////////////////
 //
 // Version
 //
 
 1 VERSIONINFO
+ FILEVERSION    $fileversion
  PRODUCTVERSION $productversion
  FILEFLAGSMASK 0x3fL
  FILEFLAGS $fileflags
  FILEOS $fileos
  FILETYPE VFT_DLL
  FILESUBTYPE 0x0L
 BEGIN
     BLOCK "StringFileInfo"
@@ -394,24 +404,18 @@ BEGIN
             VALUE "LegalCopyright", "$copyright"
             VALUE "CompanyName", "$company"
             VALUE "FileDescription", "$description"
             VALUE "FileVersion", "$mfversion"
             VALUE "ProductVersion", "$mpversion"
             VALUE "InternalName", "$module"
             VALUE "LegalTrademarks", "$trademarks"
             VALUE "OriginalFilename", "$binary"
-};
-if ($official ne "1") {
-print RCFILE qq{
-            VALUE "PrivateBuild", "$privateinfo"
-};
-}
-print RCFILE qq{
             VALUE "ProductName", "$productname"
+            VALUE "BuildID", "$buildid"
         END
     END
     BLOCK "VarFileInfo"
     BEGIN
         VALUE "Translation", 0x0, 1200
     END
 END
 
--- a/toolkit/xre/Makefile.in
+++ b/toolkit/xre/Makefile.in
@@ -240,15 +240,15 @@ DEFINES += -DTOOLKIT_EM_VERSION=\"$(shel
 ifdef WRAP_SYSTEM_INCLUDES
 DEFINES		+= -DWRAP_SYSTEM_INCLUDES
 endif
 
 export:: $(addprefix $(topsrcdir)/xpfe/bootstrap/, $(SHAREDCPPSRCS))
 	$(INSTALL) $^ .
 
 platform.ini: FORCE
-	$(PYTHON) $(srcdir)/make-platformini.py $(topsrcdir)/config/milestone.txt > $@
+	$(PYTHON) $(srcdir)/make-platformini.py --buildid=$(shell cat $(DEPTH)/config/buildid) $(topsrcdir)/config/milestone.txt > $@
 
 libs:: platform.ini
 	$(INSTALL) $^ $(DIST)/bin
 
 install::
 	$(INSTALL) $(IFLAGS1) $^ $(DESTDIR)$(mozappdir)
--- a/toolkit/xre/make-platformini.py
+++ b/toolkit/xre/make-platformini.py
@@ -1,31 +1,35 @@
 #!/usr/bin/python
 
 from optparse import OptionParser
 from datetime import datetime
 import sys
 import os
 
 o = OptionParser()
+o.add_option("--buildid", dest="buildid")
 o.add_option("--print-buildid", action="store_true", dest="print_buildid")
 
 (options, args) = o.parse_args()
-buildid = os.environ.get('MOZ_BUILD_DATE', datetime.now().strftime('%Y%m%d%H'))
 
 if options.print_buildid:
-    print buildid
+    print datetime.now().strftime('%Y%m%d%H')
     sys.exit(0)
 
+if not options.buildid:
+    print >>sys.stderr, "--buildid is required"
+    sys.exit(1)
+
 (milestoneFile,) = args
 for line in open(milestoneFile, 'r'):
     if line[0] == '#':
         continue
 
     line = line.strip()
     if line == '':
         continue
 
     milestone = line
 
 print """[Build]
 BuildID=%s
-Milestone=%s""" % (buildid, milestone)
+Milestone=%s""" % (options.buildid, milestone)