Skip to content

Commit 30df8ec

Browse files
committed
Merge pull request graalvm#2 in G/simpletool from initial-pr to master
* commit 'ec221ee2c20882652c89fe0e7268d70afca29d6e': Initial ci config. Shellcheck. Added simpletools script updated the example. Copy from graal srcipt, similart to SL. Print entire file on output. Sync on the map. Merge the CLI class into the instrument. Make options stable. Better comment for disabling class path isolation. Simplify pom file. Refactor: rename. Refactor and document the coverage node and factory. Typo. Use correct jar in runJsWithCoverage. Removed unused field. Refactor: rename. Clean up and comment the test file. Cleanup and documentation. Initial commit.
2 parents cada82f + ec221ee commit 30df8ec

File tree

11 files changed

+785
-0
lines changed

11 files changed

+785
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/target/

.travis.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
os:
2+
- linux
3+
- osx
4+
5+
language: java
6+
7+
env:
8+
- GRAALVM_VERSION="19.0.2"
9+
- GRAALVM_VERSION="NONE" SL_BUILD_NATIVE="false"
10+
11+
install:
12+
- |
13+
cd .. && mv simpletool "simple tool" && cd "simple tool"
14+
if [[ "$GRAALVM_VERSION" != "NONE" ]]; then
15+
if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then DOWNLOAD_OS_NAME="darwin"; fi
16+
if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then DOWNLOAD_OS_NAME="linux"; fi
17+
curl -LJ "https://github.com/oracle/graal/releases/download/vm-$GRAALVM_VERSION/graalvm-ce-$DOWNLOAD_OS_NAME-amd64-$GRAALVM_VERSION.tar.gz" --output graalvm.tar.gz
18+
tar -xzf graalvm.tar.gz
19+
export JAVA_HOME="$(pwd)/graalvm-ce-$GRAALVM_VERSION"
20+
if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then export JAVA_HOME="$JAVA_HOME/Contents/Home"; fi
21+
"$JAVA_HOME/bin/gu" install native-image
22+
else
23+
if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then export JAVA_HOME=$(/usr/libexec/java_home); fi
24+
fi
25+
26+
script:
27+
- mvn package
28+
- ./simpletool js example.js

ci.jsonnet

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
local basicBuild = {
3+
targets: ['gate'],
4+
timelimit: '00:59:59',
5+
run: [
6+
['mvn', 'clean'],
7+
['mvn', 'package'],
8+
['./simpletool', 'js', 'example.js'],
9+
],
10+
},
11+
12+
local graalvm = {
13+
downloads+: {
14+
JAVA_HOME: { name: 'graalvm', version: '19.0.2', platformspecific: true },
15+
},
16+
},
17+
18+
local linux = {
19+
capabilities+: ['linux', 'amd64'],
20+
packages+: {
21+
maven: '==3.3.9',
22+
},
23+
},
24+
25+
local darwin = {
26+
capabilities+: ['darwin_sierra', 'amd64'],
27+
environment+: {
28+
MACOSX_DEPLOYMENT_TARGET: '10.11',
29+
},
30+
},
31+
32+
builds: [
33+
basicBuild + linux + graalvm + { name: 'linux' },
34+
35+
basicBuild + darwin + graalvm + { name: 'darwin' },
36+
],
37+
}

copy_from_graal.py

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
# Since Simple Tool is not developed on this repository, we need to periodically sync this repository with the developement one.
5+
# This scipt automates cloning the source repository and copying the ST code from there to here.
6+
# Requires git to be installed.
7+
8+
import os
9+
import sys
10+
from subprocess import call
11+
12+
GRAAL_REPO = "https://github.com/oracle/graal"
13+
GRAAL_DIR = "../" + GRAAL_REPO.split('/')[-1]
14+
15+
def fail(message):
16+
""" Print message to stderr and exit script
17+
18+
"""
19+
print >> sys.stderr, message
20+
sys.exit(1)
21+
22+
def clone(repo, path = ""):
23+
""" Clones the given repo url using git
24+
25+
:repo: String containing the url
26+
27+
"""
28+
if call(["git", "clone", repo, path]) != 0:
29+
fail("Could not clone " + repo)
30+
pass
31+
32+
def checkout(path, commit, create = False):
33+
""" Checks out a new branch in SL
34+
35+
:cwd: path to the git repo
36+
:commit: String, name for the new branch
37+
:create: create new or expect it to exist
38+
39+
"""
40+
command = ["git", "checkout"]
41+
if create:
42+
command.append("-b")
43+
command.append(commit)
44+
if call(command, cwd=path) != 0:
45+
fail("Could not checkout " + commit + " from " + path)
46+
47+
def replace(source, dest):
48+
""" Replace contents of dest dir with contents of source dir
49+
50+
:source: String path to source
51+
:dest: String path do destination
52+
53+
"""
54+
call(["rm", "-rf", dest])
55+
call(["mkdir", "-p", dest])
56+
call(["cp", "-RTf", source, dest])
57+
58+
def copy_st():
59+
""" Copies ST from graal to simpletool
60+
61+
"""
62+
replace(GRAAL_DIR + "/truffle/src/com.oracle.truffle.st/src/com" , "src/main/java/com")
63+
replace(GRAAL_DIR + "/truffle/src/com.oracle.truffle.st.test/src/com" , "src/test/java/com")
64+
65+
def update_st(revision):
66+
""" Updates the SL repo from the graal repo given a revision
67+
68+
:revision: the hash of the commit in the graal repo to be used
69+
70+
"""
71+
checkout(".", "st_update_"+revision, True)
72+
if os.path.isdir(GRAAL_DIR):
73+
call(['git', 'fetch'], cwd=GRAAL_DIR)
74+
else:
75+
clone(GRAAL_REPO, GRAAL_DIR)
76+
checkout(GRAAL_DIR, revision)
77+
copy_st()
78+
print ""
79+
print "NOTE: Update the version in st, README.md and all pom.xml files!"
80+
print "NOTE: Follow the instructions in README.md and make sure mvn package executes correctly!"
81+
print "NOTE: Make sure project open correctly on the supported IDEs!"
82+
print ""
83+
84+
if __name__ == "__main__":
85+
if (len(sys.argv) != 2):
86+
fail("usage: " + sys.argv[0] + " idOfGraalCommitToUseAsBase")
87+
update_st(sys.argv[1])

example.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
var N = 2000;
2+
var EXPECTED = 17393;
3+
4+
function Natural() {
5+
x = 2;
6+
return {
7+
'next' : function() { return x++; }
8+
};
9+
}
10+
11+
function Filter(number, filter) {
12+
var self = this;
13+
this.number = number;
14+
this.filter = filter;
15+
this.accept = function(n) {
16+
var filter = self;
17+
for (;;) {
18+
if (n % filter.number === 0) {
19+
return false;
20+
}
21+
filter = filter.filter;
22+
if (filter === null) {
23+
break;
24+
}
25+
}
26+
return true;
27+
};
28+
return this;
29+
}
30+
31+
function Primes(natural) {
32+
var self = this;
33+
this.natural = natural;
34+
this.filter = null;
35+
this.next = function() {
36+
for (;;) {
37+
var n = self.natural.next();
38+
if (self.filter === null || self.filter.accept(n)) {
39+
self.filter = new Filter(n, self.filter);
40+
return n;
41+
}
42+
}
43+
};
44+
}
45+
46+
var holdsAFunctionThatIsNeverCalled = function(natural) {
47+
var self = this;
48+
this.natural = natural;
49+
this.filter = null;
50+
this.next = function() {
51+
for (;;) {
52+
var n = self.natural.next();
53+
if (self.filter === null || self.filter.accept(n)) {
54+
self.filter = new Filter(n, self.filter);
55+
return n;
56+
}
57+
}
58+
};
59+
}
60+
61+
var holdsAFunctionThatIsNeverCalledOneLine = function() {return null;}
62+
63+
function primesMain() {
64+
var primes = new Primes(Natural());
65+
var primArray = [];
66+
for (var i=0;i<=N;i++) { primArray.push(primes.next()); }
67+
if (primArray[N] != EXPECTED) { throw new Error('wrong prime found: ' + primArray[N]); }
68+
}
69+
primesMain();

pom.xml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<groupId>com.oracle</groupId>
6+
<artifactId>simpletool</artifactId>
7+
<version>19.0.2-SNAPSHOT</version>
8+
9+
<name>simpletool</name>
10+
11+
<properties>
12+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
13+
<maven.compiler.source>1.8</maven.compiler.source>
14+
<maven.compiler.target>1.8</maven.compiler.target>
15+
<graalvm.version>19.0.2</graalvm.version>
16+
</properties>
17+
18+
<dependencies>
19+
<dependency>
20+
<groupId>junit</groupId>
21+
<artifactId>junit</artifactId>
22+
<version>4.11</version>
23+
<scope>test</scope>
24+
</dependency>
25+
<dependency>
26+
<groupId>org.graalvm.truffle</groupId>
27+
<artifactId>truffle-api</artifactId>
28+
<version>${graalvm.version}</version>
29+
</dependency>
30+
<dependency>
31+
<groupId>org.graalvm.truffle</groupId>
32+
<artifactId>truffle-dsl-processor</artifactId>
33+
<version>${graalvm.version}</version>
34+
</dependency>
35+
</dependencies>
36+
37+
<build>
38+
<pluginManagement>
39+
<plugins>
40+
<plugin>
41+
<artifactId>maven-compiler-plugin</artifactId>
42+
<version>3.8.0</version>
43+
</plugin>
44+
<plugin>
45+
<groupId>org.apache.maven.plugins</groupId>
46+
<artifactId>maven-surefire-plugin</artifactId>
47+
<version>2.9</version>
48+
<configuration>
49+
<!--Disables classpath issolation making testing simpler, not for use in production scenarios -->
50+
<argLine>-XX:-UseJVMCIClassLoader</argLine>
51+
</configuration>
52+
</plugin>
53+
</plugins>
54+
</pluginManagement>
55+
</build>
56+
</project>

runJsWithCoverage.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
./simpletool js example.js

simpletool

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
3+
function printUsage() {
4+
echo "Usage:"
5+
echo "$0 <GraalVM launcher> <launcher args>"
6+
echo "Example:"
7+
echo "$0 js example.js"
8+
exit 0
9+
}
10+
11+
[ -z "$1" ] || [ "$1" == "--help" ] || [ "$1" == "-help" ] && printUsage
12+
13+
LAUNCHER=$1
14+
shift
15+
16+
"$JAVA_HOME/bin/$LAUNCHER" \
17+
--jvm \
18+
--vm.Dtruffle.class.path.append=target/simpletool-19.0.2-SNAPSHOT.jar \
19+
--simple-code-coverage \
20+
"$@"

0 commit comments

Comments
 (0)