Skip to content

Commit d774069

Browse files
pstephensswannodette
authored andcommitted
CLJS-1403: Added & updated Windows shell scripts.
1 parent e5491d5 commit d774069

File tree

4 files changed

+182
-5
lines changed

4 files changed

+182
-5
lines changed

bin/cljsc.bat

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
21
@echo off
32
setLocal EnableDelayedExpansion
43

54
if "%CLOJURESCRIPT_HOME%" == "" set CLOJURESCRIPT_HOME=%~dp0..\
65

7-
set CLASSPATH=%CLOJURESCRIPT_HOME%src\clj;%CLOJURESCRIPT_HOME%src\cljs"
8-
for /R "%CLOJURESCRIPT_HOME%\lib" %%a in (*.jar) do (
6+
set CLASSPATH=%CLOJURESCRIPT_HOME%src\main\clojure;%CLOJURESCRIPT_HOME%src\main\cljs;%CLOJURESCRIPT_HOME%src\test\cljs
7+
for /R "%CLOJURESCRIPT_HOME%lib" %%a in (*.jar) do (
98
set CLASSPATH=!CLASSPATH!;%%a
109
)
11-
set CLASSPATH=!CLASSPATH!"
10+
set CLASSPATH=!CLASSPATH!
1211

1312
if (%1) == () (
1413
echo Usage: "cljsc <file-or-dir> > out.js"

bin/cljsc.clj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
opts-string (apply str (interpose " " (rest args)))
1515
options (when (> (count opts-string) 1)
1616
(try (read-string opts-string)
17-
(catch Exception e (println e))))]
17+
(catch Exception e
18+
(binding [*out* *err*]
19+
(println "Failed to parse command line args:" e)))))]
1820
{:source source :options (merge {:output-to :print} options)}))
1921

2022
(let [args (transform-cl-args *command-line-args*)]

script/bootstrap.ps1

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
$ErrorActionPreference = "Stop"
2+
$root = Resolve-Path "$PSScriptRoot\.."
3+
$shell = New-Object -com shell.application
4+
5+
# Read white listed dependency version info from the /bin/sh script and store in variables
6+
Get-Content $root\script\bootstrap |
7+
Where-Object { $_ -match '^\s*(\w+)\s*=\s*\"([^\"]*)\"\s*$' } |
8+
Where-Object { $matches[1] -in "CLOJURE_RELEASE", "CLOSURE_RELEASE",
9+
"DJSON_RELEASE", "GCLOSURE_LIB_RELEASE", "RHINO_RELEASE", "TREADER_RELEASE" } |
10+
Foreach-Object { New-Variable $matches[1] $matches[2] -Scope private }
11+
12+
function Get-WebResource($url, $dstPath) {
13+
Write-Verbose "Downloading '$url' -> '$dstPath'"
14+
Invoke-RestMethod $url -OutFile $dstPath
15+
}
16+
17+
function Expand-ZipFile($srcPath, $dstDir, $items) {
18+
Write-Verbose "Unzipping '$srcPath'"
19+
20+
function Get-ShellFolder($dir) {
21+
$folder = $shell.NameSpace($dir)
22+
if($folder -eq $null) {
23+
throw "Failed to bind to folder '$dir'"
24+
}
25+
$folder
26+
}
27+
28+
function Copy-ShellItem([Parameter(ValueFromPipeline=$true)] $src) {
29+
process {
30+
Write-Verbose "Expanding '$($src.Path)' -> '$dstDir'"
31+
$dstFolder.CopyHere($src, 4 + 16 + 1024)
32+
}
33+
}
34+
35+
function Parse-ShellItem([Parameter(ValueFromPipeline=$true)] $name) {
36+
process {
37+
$x = $srcFolder.ParseName($name)
38+
if($x -eq $null) {
39+
throw "Failed fo find item '$name' in zip file '$srcPath'"
40+
}
41+
$x
42+
}
43+
}
44+
45+
$srcFolder = Get-ShellFolder($srcPath)
46+
$dstFolder = Get-ShellFolder($dstDir)
47+
48+
if($items -ne $null) {
49+
$items | Parse-ShellItem | Copy-ShellItem
50+
}
51+
else {
52+
$srcFolder.Items() | Copy-ShellItem
53+
}
54+
}
55+
56+
function Move-File($srcPath, $dstPath) {
57+
Delete-File $dstPath
58+
Write-Verbose "Moving '$srcPath' -> '$dstPath'"
59+
Move-Item $srcPath $dstPath
60+
}
61+
62+
function Copy-File($srcPath, $dstPath) {
63+
Delete-File $dstPath
64+
Write-Verbose "Copying '$srcPath' -> '$dstPath'"
65+
Copy-Item $srcPath $dstPath
66+
}
67+
68+
function Delete-File([Parameter(ValueFromPipeline=$true)] $path)
69+
{
70+
process {
71+
if(Test-Path $path) {
72+
Write-Verbose "Deleting '$path'"
73+
Remove-Item $path -Recurse
74+
}
75+
}
76+
}
77+
78+
function Make-Dir($dir) {
79+
if(!(Test-Path $dir -Type Container)) {
80+
Write-Verbose "Making directory '$dir'"
81+
New-Item $dir -ItemType Directory | Out-Null
82+
}
83+
}
84+
85+
Make-Dir $root\lib
86+
Make-Dir $root\closure\library
87+
Make-Dir $root\closure\compiler
88+
89+
Write-Host "Fetching Clojure..."
90+
Get-WebResource `
91+
https://repo1.maven.org/maven2/org/clojure/clojure/$CLOJURE_RELEASE/clojure-$CLOJURE_RELEASE.zip `
92+
$root\clojure-$CLOJURE_RELEASE.zip
93+
Delete-File $root\lib\clojure-$CLOJURE_RELEASE.jar
94+
Expand-ZipFile $root\clojure-$CLOJURE_RELEASE.zip $root\lib clojure-$CLOJURE_RELEASE\clojure-$CLOJURE_RELEASE.jar
95+
Move-File $root\lib\clojure-$CLOJURE_RELEASE.jar $root\lib\clojure.jar
96+
Delete-File $root\clojure-$CLOJURE_RELEASE.zip
97+
98+
Write-Host "Fetching data.json..."
99+
Get-WebResource `
100+
https://repo1.maven.org/maven2/org/clojure/data.json/$DJSON_RELEASE/data.json-$DJSON_RELEASE.jar `
101+
$root\lib\data.json-$DJSON_RELEASE.jar
102+
103+
# TODO: Implement Closure SVN support
104+
Write-Host "Fetching Google Closure library..."
105+
Get-WebResource `
106+
https://repo1.maven.org/maven2/org/clojure/google-closure-library/$GCLOSURE_LIB_RELEASE/google-closure-library-$GCLOSURE_LIB_RELEASE.jar `
107+
$root\lib\google-closure-library-$GCLOSURE_LIB_RELEASE.jar
108+
Get-WebResource `
109+
https://repo1.maven.org/maven2/org/clojure/google-closure-library-third-party/$GCLOSURE_LIB_RELEASE/google-closure-library-third-party-$GCLOSURE_LIB_RELEASE.jar `
110+
$root\lib\google-closure-library-third-party-$GCLOSURE_LIB_RELEASE.jar
111+
112+
Write-Host "Fetching Google Closure compiler..."
113+
Get-WebResource `
114+
https://dl.google.com/closure-compiler/compiler-$CLOSURE_RELEASE.zip `
115+
$root\compiler-$CLOSURE_RELEASE.zip
116+
Get-ChildItem $root\closure\compiler\* | Delete-File
117+
Expand-ZipFile $root\compiler-$CLOSURE_RELEASE.zip $root\closure\compiler
118+
Copy-File $root\closure\compiler\compiler.jar $root\lib\compiler.jar
119+
Delete-File $root\compiler-$CLOSURE_RELEASE.zip
120+
121+
Write-Host "Fetching Rhino..."
122+
Get-WebResource `
123+
https://github.com/mozilla/rhino/releases/download/Rhino${RHINO_RELEASE}_RELEASE/rhino$RHINO_RELEASE.zip `
124+
$root\rhino$RHINO_RELEASE.zip
125+
Delete-File $root\lib\js.jar
126+
Expand-ZipFile $root\rhino$RHINO_RELEASE.zip $root\lib rhino$RHINO_RELEASE\js.jar
127+
Delete-File $root\rhino$RHINO_RELEASE.zip
128+
129+
Write-Host "Fetching tools.reader $TREADER_RELEASE ..."
130+
Get-WebResource `
131+
https://repo1.maven.org/maven2/org/clojure/tools.reader/$TREADER_RELEASE/tools.reader-$TREADER_RELEASE.jar `
132+
$root\lib\tools.reader-$TREADER_RELEASE.jar
133+
134+
Write-Host "[Bootstrap Completed]"

script/test.ps1

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
$ErrorActionPreference = "Stop"
2+
$root = Resolve-Path $PSScriptRoot\..
3+
4+
$testjs = "builds/out-adv/core-advanced-test.js"
5+
6+
$targets =
7+
@{ env="V8_HOME"; name="V8"; cmd={ & "$env:V8_HOME\d8" $testjs } },
8+
@{ env="SPIDERMONKEY_HOME"; name="SpiderMonkey"; cmd={ & "$env:SPIDERMONKEY_HOME\js" -f $testjs } },
9+
@{ env="JSC_HOME"; name="JavaScriptCore"; cmd={ & "$env:JSC_HOME\jsc" -f $testjs } },
10+
@{ env="NASHORN_HOME"; name="Nashorn"; cmd={ & "$env:NASHORN_HOME\jjs" $testjs } }
11+
$ran = 0
12+
13+
$opts = '{:optimizations :advanced :output-wrapper true :verbose true :compiler-stats true :output-dir \"builds\\out-adv\"}'
14+
15+
function Test-It($env, $name, [scriptblock] $cmd) {
16+
$env_val = if(Test-Path env:$env) { (Get-Item env:$env).Value } else { "" }
17+
if("$env_val" -eq "") {
18+
Write-Host "$env not set, skipping $name tests"
19+
} else {
20+
Write-Host "Testing with $name"
21+
& $cmd
22+
$ran++
23+
}
24+
}
25+
26+
Push-Location $root
27+
try {
28+
"builds\out-adv", "out", "target" |
29+
Where-Object { Test-Path $_ -Type leaf } |
30+
Foreach-Object { Remove-Item $_ -recurse -force }
31+
32+
New-Item builds\out-adv -ItemType Directory -Force | Out-Null
33+
34+
bin\cljsc src\test/cljs $opts | Set-Content $testjs
35+
36+
$targets | Foreach-Object { Test-It @_ }
37+
}
38+
finally {
39+
Pop-Location
40+
41+
Write-Host "Tested with $ran out of $($targets.Length) possible js targets"
42+
}

0 commit comments

Comments
 (0)