Diff

Differences From Artifact [f3437e4a72]:

To Artifact [ff68791fbb]:


     1      1   <?
     2      2   	package require sha1
     3      3   
     4      4   	load_response args
            5  +
            6  +	proc normalize_platform {platform platform_names} {
            7  +		set platform [string tolower $platform]
            8  +		if {$platform in $platform_names} {
            9  +			return $platform
           10  +		}
           11  +
           12  +		set platform [regsub {[-]x86_64$} $platform {-amd64}]
           13  +		set platform [regsub {[-]sun4[muv]$} $platform {-sparc}]
           14  +		if {$platform in $platform_names} {
           15  +			return $platform
           16  +		}
           17  +	}
     5     18   
     6     19   	proc versionEncoded {versionString} {
     7     20   		set output 0
     8     21   
     9     22   		if {$versionString eq "trunk"} {
    10     23   			return [versionEncoded "255.255.255"]
    11     24   		}
................................................................................
    21     34   		return $output
    22     35   	}
    23     36   
    24     37   	set sourcedir "/web/rkeene/devel/kitcreator/all"
    25     38   	set queue "/home/rkeene/devel/kitcreator/build/web/queue"
    26     39   	set secretfile "/home/rkeene/etc/kitcreator-web-secret"
    27     40   
           41  +	# KitCreator Versions
    28     42   	foreach file [glob -tails -nocomplain -directory $sourcedir "kitcreator-*.tar.gz"] {
    29     43   		regexp {^kitcreator-(.*).tar.gz$} $file -> vers
    30     44   		set kitcreator_versions($vers) $vers
    31     45   	}
    32     46   	set kitcreator_version_selected [lindex [lsort -dictionary [array names kitcreator_versions]] end]
    33     47   
    34     48   	set kitcreator_versions(trunk) "Fossil Trunk Tip"
    35     49   
           50  +	# Tcl Versions
    36     51   	set tcl_versions(8.5.15) 8.5.15
    37     52   	set tcl_versions(8.5.16) 8.5.16
    38     53   	set tcl_versions(8.5.17) 8.5.17
    39     54   	set tcl_versions(8.5.18) 8.5.18
    40     55   	set tcl_versions(8.5.19) 8.5.19
    41     56   	set tcl_versions(8.6.1) 8.6.1
    42     57   	set tcl_versions(8.6.2) 8.6.2
................................................................................
    45     60   	set tcl_versions(8.6.5) 8.6.5
    46     61   	set tcl_versions(8.6.6) 8.6.6
    47     62   	set tcl_versions(8.6.7) 8.6.7
    48     63   	set tcl_versions(8.6.8) 8.6.8
    49     64   	set tcl_versions(8.6.9) 8.6.9
    50     65   	set tcl_versions(fossil_trunk) "Fossil Trunk Tip"
    51     66   
           67  +	set tcl_version_list [lsort -dictionary [array names tcl_versions]]
           68  +	set tcl_version_selected [lindex $tcl_version_list end-1]
           69  +
           70  +	# Platforms
    52     71   	set platforms(android-arm) "Android/ARM"
    53     72   	set platforms(freebsd-amd64) "FreeBSD/amd64"
    54     73   	set platforms(hpux-hppa64) "HP-UX/PA-RISC 2.0"
    55     74   	set platforms(aix-ppc) "AIX/POWER"
    56     75   	set platforms(linux-amd64) "Linux/amd64"
    57     76   	set platforms(linux-amd64-static) "Linux/amd64 (static)"
    58     77   	set platforms(linux-arm) "Linux/ARM"
................................................................................
    86    105   	set packages(nsf) "Next Scripting Framework"
    87    106   	set packages(tdom) "tDOM"
    88    107   	set packages(tuapi) "Tcl UNIX API"
    89    108   	set packages(lmdb) "LMDB"
    90    109   	set packages(tclcurl) "cURL"
    91    110   	set packages(duktape) "Duktape"
    92    111   
          112  +	set options_info(threaded) "Kit: Threaded"
          113  +	set options_info(kitdll) "Kit: Build Library (KitDLL)"
          114  +	set options_info(debug) "Kit: Debugging Build"
          115  +	set options_info(dynamictk) "Kit: Always link Tk dynamically (if Tk is built)"
          116  +	set options_info(minbuild) "Kit: \"Minimal\" build (remove extra packages shipped as part of Tcl and reduce encodings)"
          117  +	set options_info(staticlibssl) "TLS: Statically link to LibSSL"
          118  +	set options_info(buildlibssl) "TLS: Build LibreSSL for this platform"
          119  +	set options_info(staticpkgs) "Kit: Statically link packages in pkgs directory"
          120  +	set options_info(tclutfmax6) "Kit: TCL_UTF_MAX=6 (incompatibility with standard Tcl)"
          121  +
    93    122   	set disable {
    94    123   		platform linux-mipsel {package_tk package_tcc4tcl package_tclx kitdll}
    95    124   		platform android-arm {package_tk package_tclx}
    96    125   		platform freebsd-amd64 {package_tuapi}
    97    126   		platform hpux-hppa64 {package_tuapi}
    98    127   		platform aix-ppc {package_tuapi kitdll}
    99    128   		platform netbsd-amd64 {package_tk package_tcc4tcl package_tclx package_tuapi}
................................................................................
   122    151   
   123    152   	set specific {
   124    153   		platform win32 file icon {Kit Icon}
   125    154   		platform win32 text description {Description}
   126    155   		platform win64 file icon {Kit Icon}
   127    156   		platform win64 text description {Description}
   128    157   	}
          158  +
          159  +	if {[info exists args(dict)] || [info exists args(json)]} {
          160  +		package require json
          161  +		package require json::write
          162  +	}
          163  +
          164  +	if {[info exists args(json)]} {
          165  +		set args(dict) [::json::json2dict $args(json)]
          166  +		unset args(json)
          167  +		set apiReturnFormat json
          168  +	}
          169  +
          170  +	set resultIsAPI false
          171  +	if {[info exists args(dict)]} {
          172  +		headers set "Access-Control-Allow-Origin" "*"
          173  +		if {![info exists apiReturnFormat]} {
          174  +			set apiReturnFormat dict
          175  +		}
          176  +
          177  +		set apiMethod build
          178  +		catch {
          179  +			set apiMethod [dict get $args(dict) action]
          180  +		}
          181  +
          182  +		switch -exact -- $apiMethod {
          183  +			build {
          184  +				# Do nothing, handled below
          185  +			}
          186  +			platforms {
          187  +				set apiResultDict [array get platforms]
          188  +			}
          189  +			tcl_versions {
          190  +				set apiResultDict [array get tcl_versions]
          191  +				dict set apiResultDict default $tcl_version_selected
          192  +			}
          193  +			kitcreator_versions {
          194  +				set apiResultDict [array get kitcreator_versions]
          195  +				dict set apiResultDict default $kitcreator_version_selected
          196  +			}
          197  +			options {
          198  +				set apiResultDict [array get options_info]
          199  +			}
          200  +			packages {
          201  +				set apiResultDict [array get packages]
          202  +			}
          203  +			help {
          204  +				set apiResultDict {
          205  +					build {Build a TclKit.  Accepts arguments: platform [mandatory, string], tcl_version [string], kitcreator_version [string], storage [string, one of mk4, cvfs, zip], options [array], packages [array]}
          206  +					platforms {Get a list of platforms to use as the "platform" argument to build}
          207  +					tcl_versions {Get a list of Tcl versions and their descriptions to use as the "tcl_version" argument to build}
          208  +					kitcreator_versions {Get a list of KitCreator versions and their descriptions to use as the "kitcreator_version" argument to build}
          209  +					options {Get a list of options and their descriptions}
          210  +					packages {Get a list of packages and their descriptions}
          211  +					examples {A few examples}
          212  +					help {This help}
          213  +				}
          214  +			}
          215  +			examples {
          216  +				set apiResultDict {
          217  +					simple {curl -d 'json={"action": "build", "platform": "linux-amd64"}' http://kitcreator.rkeene.org/kitcreator}
          218  +				}
          219  +			}
          220  +			default {
          221  +				set apiResultDict [dict create error "Invalid action \"$apiMethod\""]
          222  +			}
          223  +		}
          224  +
          225  +		if {$apiMethod eq "build" && ![dict exists $args(dict) platform]} {
          226  +			set apiMethod error
          227  +			set apiResultDict [dict create error "The argument \"platform\" must be supplied when building"]
          228  +		}
          229  +
          230  +		if {$apiMethod ne "build"} {
          231  +			if {[dict exists $apiResultDict error]} {
          232  +				headers numeric 500
          233  +			}
          234  +
          235  +			switch -exact -- $apiReturnFormat {
          236  +				"json" {
          237  +					headers type application/json
          238  +
          239  +					set apiResultDictEncoded [list]
          240  +					foreach {key value} $apiResultDict {
          241  +						lappend apiResultDictEncoded $key [json::write string $value]
          242  +					}
          243  +					set apiResultJSON [json::write object {*}$apiResultDictEncoded]
          244  +					puts $apiResultJSON
          245  +				}
          246  +				"dict" {
          247  +					headers type text/plain
          248  +					
          249  +					puts [dict create {*}$apiResultDict]
          250  +				}
          251  +			}
          252  +
          253  +			rivet_flush
          254  +			abort_page
          255  +		}
          256  +
          257  +		set resultIsAPI true
          258  +		set args(platform) [dict get $args(dict) platform]
          259  +		set args(tcl_version) $tcl_version_selected
          260  +		set args(kitcreator_version) $kitcreator_version_selected
          261  +
          262  +		foreach arg {tcl_version kitcreator_version option_storage} {
          263  +			set dictArg $arg
          264  +			switch -exact -- $arg {
          265  +				option_storage {
          266  +					set dictArg "storage"
          267  +				}
          268  +			}
          269  +
          270  +			catch {
          271  +				set args($arg) [dict get $args(dict) $dictArg]
          272  +			}
          273  +		}
          274  +
          275  +		set selectedPackages [list]
          276  +		catch {
          277  +			set selectedPackages [dict get $args(dict) packages]
          278  +		}
          279  +		foreach arg $selectedPackages {
          280  +			set args(option_package_$arg) true
          281  +		}
          282  +
          283  +		set selectedOptions [list]
          284  +		catch {
          285  +			set selectedOptions [dict get $args(dict) options]
          286  +		}
          287  +		foreach arg $selectedOptions {
          288  +			switch -glob -- $arg {
          289  +				"package_*" {
          290  +					continue
          291  +				}
          292  +			}
          293  +
          294  +			set args(option_$arg) true
          295  +		}
          296  +	}
   129    297   
   130    298   	if {[info exists args(platform)] && [info exists args(tcl_version)] && [info exist args(kitcreator_version)]} {
   131    299   		# Read in arguments
   132    300   		## Mandatory arguments
   133         -		set build_platform $args(platform)
          301  +		set build_platform [normalize_platform $args(platform) [array names platforms]]
   134    302   		set build_tcl_version $args(tcl_version)
   135    303   		set build_kitcreator_version $args(kitcreator_version)
          304  +
          305  +		if {$build_tcl_version eq "default"} {
          306  +			set build_tcl_version $tcl_version_selected
          307  +		}
          308  +
          309  +		if {$build_kitcreator_version eq "default"} {
          310  +			set build_kitcreator_version $kitcreator_version_selected
          311  +		}
   136    312   
   137    313   		## Optional Arguments
   138    314   		set build_packages [list]
   139    315   		set build_options(threaded) 0
   140    316   		set build_options(kitdll) 0
   141    317   		set build_options(debug) 0
   142    318   		set build_options(dynamictk) 0
................................................................................
   270    446   
   271    447   		# Queue build up and wait for it to complete
   272    448   		set fd [open $queue a+]
   273    449   		puts $fd [list filename $filename key $key platform $build_platform tcl_version $build_tcl_version kitcreator_version $build_kitcreator_version packages $build_packages options [array get build_options]]
   274    450   		close $fd
   275    451   
   276    452   		set url "http://kitcreator.rkeene.org/kits/building/$key/"
          453  +		set kiturl "http://kitcreator.rkeene.org/kits/$key/$filename"
   277    454   
   278         -		headers redirect $url
          455  +		if {!$resultIsAPI} {
          456  +			headers redirect $url
   279    457   ?><html>
   280    458   	<head>
   281    459   		<title>KitCreator, Web Interface</title>
   282    460   	</head>
   283    461   	<body>
   284    462   		<h1>KitCreator Web Interface</h1>
   285    463   		<p>Build in progress, see <a href="<? puts -nonewline $url ?>"><? puts -nonewline $url ?></a> for build information</p>
   286    464   	</body>
   287    465   </html>
   288    466   <?
          467  +		} else {
          468  +			switch -exact -- $apiReturnFormat {
          469  +				"json" {
          470  +					puts "{\"kit_url\": \"${kiturl}\"}"
          471  +				}
          472  +				"dict" {
          473  +					puts [dict create kit_url $kiturl]
          474  +				}
          475  +			}
          476  +		}
   289    477   	} else {
   290    478   ?><html>
   291    479     <head>
   292    480       <title>KitCreator, Web Interface</title>
   293    481       <script>
   294    482   <!--
   295    483   	function enableOption(option) {
................................................................................
   423    611             </td>
   424    612           </tr>
   425    613           <tr>
   426    614             <td>Tcl Version:</td>
   427    615             <td>
   428    616               <select name="tcl_version" onChange="verifyOptions();">
   429    617   <?
   430         -	set tcl_version_list [lsort -dictionary [array names tcl_versions]]
   431         -	set tcl_version_selected [lindex $tcl_version_list end-1]
   432    618   	foreach tcl_version $tcl_version_list {
   433    619   		set tcl_version_name $tcl_versions($tcl_version)
   434    620   
   435    621   		if {$tcl_version == $tcl_version_selected} {
   436    622   			set selected " selected"
   437    623   		} else {
   438    624   			set selected ""