specs/stx-jv.rbspec
changeset 11 f7dc950d8df8
parent 10 cb3e0e3ca28f
child 13 ba905210e6bb
--- a/specs/stx-jv.rbspec	Wed May 25 13:50:49 2016 +0100
+++ b/specs/stx-jv.rbspec	Wed May 25 17:19:27 2016 +0100
@@ -1,5 +1,43 @@
 load "jv-branch.deps.rake"
 
+
+# A helper function to download and unpack pre-built stc and librun
+# for those who are not lucky enough to have an access to sources
+def download_blob_matching(pattern, directory)
+  plat = nil
+  blob = nil
+  sha256 = nil
+  if win32? then        
+      plat = 'Windows'
+  elsif linux?        
+    plat = 'Linux'
+  else        
+    error_unsupported_platform()
+  end
+  build = Jenkins::Build.new(%Q{https://swing.fit.cvut.cz/jenkins/job/stx_jv_new/ARCH=#{ARCH},PLATFORM=#{plat}N/lastSuccessfulBuild})
+  build.artifacts.each do | artifact |
+    if pattern =~ artifact.name then
+      if artifact.name.end_with? '.sha256' then
+        sha256 = artifact
+      else
+        blob = artifact
+      end
+    end
+  end
+  if not blob then
+    error "No artifact matching given pattern found"
+  end
+  puts "Downloading binary component #{blob.name}"
+  blob.download_to(directory)
+  if sha256 then
+    sha256.download_to(directory)
+  end
+  unzip directory / blob.name, remove: true
+  rm_f directory / sha256.name
+end
+
+
+
 project :'stx:jv-branch-core' do
   # Core Smalltalk/X - does contain only standard libraries,
   # and development tools. Does not contain any other 'features'
@@ -51,30 +89,18 @@
     end
 
     redefine BUILD_DIR / 'stx' / 'stc' => BUILD_DIR do
-      if core_developer_machine? then
+      if core_developer? or jenkins? then
         checkout :'swing:private:hg', 'stx/stc', :branch => 'jv'
       else
-        lastSicessfulBuild = Jenkins::Build.new(%q{https://swing.fit.cvut.cz/jenkins/job/stx_jv_new/ARCH=i386,PLATFORM=LinuxN/lastSuccessfulBuild})
-        lastSicessfulBuild.artifacs(/prebuilt\-stc/).each do | each |
-          if not each.name.end_with? '.sha256' then
-            each.download_to(BUILD_DIR / 'stx')
-            unzip BUILD_DIR / 'stx' / each.name
-          end
-        end
+        download_blob_matching(/prebuilt-stc/, BUILD_DIR / 'stx')
       end
     end
 
     redefine BUILD_DIR / 'stx' / 'librun' => BUILD_DIR do      
-      if core_developer_machine? then
+      if core_developer? or jenkins? then
         checkout :'swing:private:hg', 'stx/librun', :branch => 'jv'
       else        
-        lastSicessfulBuild = Jenkins::Build.new(%q{https://swing.fit.cvut.cz/jenkins/job/stx_jv_new/ARCH=i386,PLATFORM=LinuxN/lastSuccessfulBuild})
-        lastSicessfulBuild.artifacs(/prebuilt\-librun/).each do | each |
-          if not each.name.end_with? '.sha256' then
-            each.download_to(BUILD_DIR / 'stx')
-            unzip BUILD_DIR / 'stx' / each.name
-          end
-        end
+        download_blob_matching(/prebuilt-librun/, BUILD_DIR / 'stx')
       end
     end
 
@@ -374,14 +400,14 @@
       # Just to be sure, refuse to create stc and librun archives
       # if the directory contain sources. This is to prevent accidental
       # leak of non-disclosed sources. Better safe than sorry!
-      if core_developer_machine? || (File.exist? BUILD_DIR / 'stx' / 'stc' / '.hg') || (File.exist? BUILD_DIR / 'stx' / 'stc' / 'CVS') then
+      if core_developer? || (File.exist? BUILD_DIR / 'stx' / 'stc' / '.hg') || (File.exist? BUILD_DIR / 'stx' / 'stc' / 'CVS') then
         puts "WARNING: NOT CREATING stc archive since directory contains sources!!!"
       else
         # Be paranoid, do cleanup here. Should have been done, but who knows...
         cleanup_stc() 
     	  zip BUILD_DIR / 'stx' / 'stc' , archive: ARTIFACTS_DIR / "#{project.app_name}-#{project.app_version}_#{ARCH}-#{win32? ? 'win32' : RbConfig::CONFIG['host_os']}_prebuilt-stc"
       end
-      if core_developer_machine? || (File.exist? BUILD_DIR / 'stx' / 'librun' / '.hg') || (File.exist? BUILD_DIR / 'stx' / 'librun' / 'CVS') then
+      if core_developer? || (File.exist? BUILD_DIR / 'stx' / 'librun' / '.hg') || (File.exist? BUILD_DIR / 'stx' / 'librun' / 'CVS') then
         puts  "WARNING: NOT CREATING librun archive since directory contains sources!!!"
       else
         # Be paranoid, do cleanup here. Should have been done, but who knows...