Commit 86be3f17 authored by František Haas's avatar František Haas

added disl.py to run the example

added ant target to make source distribution package - dist-tar, dist-zip
added script that tries to guess java_home directory
parent 597657be
......@@ -15,6 +15,7 @@ bin=bin
build=build
build.thread=build-thread
build.afterbootstrap=build-abs
dist=dist
extendedthread.path=${build}/extendedthread.jar
......
......@@ -48,6 +48,7 @@
</target>
<target name="compile-agent-c">
<exec executable="make" dir="${src.agent.c}/javahome" />
<exec executable="make" dir="${src.agent.c}" />
</target>
......@@ -64,6 +65,7 @@
</target>
<target name="compile-reagent">
<exec executable="make" dir="${src.reagent}/javahome" />
<exec executable="make" dir="${src.reagent}" />
</target>
......@@ -166,9 +168,16 @@
<delete dir="${build}" />
<delete dir="${build.thread}" />
<delete dir="${build.afterbootstrap}" />
<delete dir="${dist}" />
<exec executable="make" dir="${src.agent.c}/javahome">
<arg value="clean" />
</exec>
<exec executable="make" dir="${src.agent.c}">
<arg value="clean" />
</exec>
<exec executable="make" dir="${src.reagent}/javahome">
<arg value="clean" />
</exec>
<exec executable="make" dir="${src.reagent}">
<arg value="clean" />
</exec>
......@@ -179,7 +188,32 @@
<target name="javadoc" depends="package,eclipse">
<javadoc access="public" author="true" overview="doc/overview.html" classpath="build/eclipse-dynamicbypass.jar:${asm.path}" destdir="doc" nodeprecated="false" nodeprecatedlist="false" noindex="false" nonavbar="false" notree="false" packagenames="ch.usi.dag.disl.guardcontext,ch.usi.dag.disl.staticcontext,ch.usi.dag.disl.dynamiccontext,ch.usi.dag.disl.classcontext,ch.usi.dag.disl.marker,ch.usi.dag.disl.transformer,ch.usi.dag.disl.processorcontext,ch.usi.dag.disl.annotation" source="1.7" sourcefiles="src/ch/usi/dag/disl/scope/Scope.java,src/ch/usi/dag/disl/scope/ScopeImpl.java,src/ch/usi/dag/disl/DiSL.java,src/ch/usi/dag/disl/snippet/Shadow.java" sourcepath="src-test:src-agent-java:src" splitindex="true" use="true" version="true"/>
</target>
<property name="dist.excludes" value="
.classpath,
.project,
${dist}/**,
bin/**,
build/**,
src-test/**,
run**" />
<target name="dist-tar">
<mkdir dir="${dist}" />
<tar
destfile="${dist}/disl-src-${disl.version}.tar"
basedir="."
excludes="${dist.excludes}" />
</target>
<target name="dist-zip">
<mkdir dir="${dist}" />
<zip
destfile="${dist}/disl-src-${disl.version}.zip"
basedir="."
excludes="${dist.excludes}" />
</target>
<!-- *** test instrumentaion package *** -->
<target name="check-test-property">
......
#!/usr/bin/env python
import argparse
import itertools
import os
import platform
import time
from subprocess import *
######################################################################
# CONSTANTS
######################################################################
# defualt disl_home value, relative to the script
default_disl_home = "../"
# string to be substituted by the actual value of DISL_HOME in paths
variable_disl_home = "${DISL_HOME}"
######################################################################
# DISL_HOME
#
# @return
# DISL_HOME to be used in paths. Either default or from env.
######################################################################
def disl_home():
if os.getenv("DISL_HOME") is None:
return default_disl_home
else:
return os.getenv("DISL_HOME")
######################################################################
# GENERAL_PARSER
######################################################################
def general_parser(parser):
group = parser.add_argument_group("GENERAL")
# positional variant of i for simplicity
# both cannot be set at once
group.add_argument("instr",
default=None,
nargs="?",
help="path to jar containing disl instrumentation code, same as '-i'")
group.add_argument("-i",
dest="instrumentation",
default=None,
metavar="PATH",
help="path to jar containing disl instrumentation code, same as 'instr'")
return
######################################################################
# CLIENT_PARSER
######################################################################
def client_parser(parser):
parser.add_argument("-c",
action="store_true",
default=False,
dest="client",
help="set to start the server")
group = parser.add_argument_group("CLIENT")
# positional variant of c_app for simplicity
# both cannot be set at once
group.add_argument("app",
default=None,
nargs="*",
help="client jar or class and its arguments, same as '-c_app'")
group.add_argument("-c_opts",
action="append",
default=[],
metavar="A",
nargs="+",
help="java options of the client application")
group.add_argument("-c_app",
action="append",
default=None,
metavar="A",
nargs="+",
help="client jar or class and its arguments, same as 'app'")
if platform.system() == "Darwin":
group.add_argument("-c_cagent",
default=variable_disl_home+"/build/libdislagent.jnilib",
metavar="PATH",
help="path to c-agent library")
else:
group.add_argument("-c_cagent",
default=variable_disl_home+"/build/libdislagent.so",
metavar="PATH",
help="path to c-agent library")
group.add_argument("-c_jagent",
default=variable_disl_home+"/build/disl-agent.jar",
metavar="PATH",
help="path to java-agent library")
group.add_argument("-c_noexcepthandler",
action="store_true",
default=False,
help="")
group.add_argument("-c_exclusionlist",
default=None,
metavar="PATH",
help="")
return
######################################################################
# SERVER_PARSER
######################################################################
def server_parser(parser):
parser.add_argument("-s",
action="store_true",
default=False,
dest="server",
help="set to start the to be instrumented client application")
group = parser.add_argument_group("SERVER")
group.add_argument("-s_opts",
action="append",
default=[],
metavar="A",
nargs="+",
help="java options of the server")
group.add_argument('-s_jar',
default=variable_disl_home+"/build/disl-server.jar",
metavar="PATH",
help="path to disl server jar")
group.add_argument("-s_args",
action="append",
default=[],
metavar="A",
nargs="+",
help="arguments to the server application")
group.add_argument("-s_instrumented",
default=None,
metavar="PATH",
help="")
group.add_argument("-s_uninstrumented",
default=None,
metavar="PATH",
help="")
return
######################################################################
# EVALUATION_PARSER
######################################################################
def evaluation_parser(parser):
parser.add_argument("-e",
action="store_true",
default=False,
dest="evaluation",
help="set to start the remote instrumentation evaluation server")
group = parser.add_argument_group("EVALUATION")
group.add_argument("-e_opts",
action="append",
default=[],
nargs="+",
metavar="A",
help="java options of the evaluation server")
group.add_argument("-e_args",
action="append",
default=[],
nargs="+",
metavar="A",
help="arguments to the evaluation server application")
return
######################################################################
# DOCUMENTATION_PARSER
######################################################################
def documentation_parser(parser):
parser.formatter_class=argparse.RawTextHelpFormatter
parser.description = """
This script is a DiSL client application, server and evaluation server starter.
By default a client application that will be instrumented and the server that
will instrument the application will be started. To specify what should be
started switch '-c', -'s and '-e' options. If any of these is switched then
default values are ignored and only specified module is started.
To pass option like arguments (starting with dash) one must either use equal
sign or positional variant of the argument if it's present. For example
'-c_app="-jar"' instead of '-c_app "-jar"'. The positional version must be
preceded with '--' as in the example.
The '-d' option specifies where the DiSL framework is installed. In some cases
it might work thanks to default relative path. In other cases one must either
specify the correct location at the command line or set 'DISL_HOME' system
variable.
"""
parser.epilog = """
EXAMPLES:
To execute the example application run following:
./disl.py -s -c -i=instr/build/disl-instr.jar -c_app=-jar c_app=app/build/example-app.jar
or
./disl.py -- instr/build/disl-instr.jar -jar app/build/example-app.jar
"""
######################################################################
# MAKE_PARSER
######################################################################
def make_parser():
parser = argparse.ArgumentParser()
parser.add_argument("-p",
action="store_true",
default=False,
dest="print_namespace",
help="show all set options and default values")
parser.add_argument("-d",
default=disl_home(),
dest="disl_home",
help="disl home directory")
general_parser(parser)
client_parser(parser)
server_parser(parser)
evaluation_parser(parser)
documentation_parser(parser)
return parser
######################################################################
# FLATTEN_ALL
# Makes a list from nested lists or even a single non list
# argument. Does not slice strings.
######################################################################
def flatten_all(object):
if object is None:
return None
if isinstance(object, basestring):
return [object]
result = []
for x in object:
if hasattr(x, "__iter__") and not isinstance(x, basestring):
result.extend(flatten_all(x))
else:
result.append(x)
return result
#return list(itertools.chain.from_iterable(object))
######################################################################
# PARSE_ARGUMENTS
######################################################################
def parse_arguments(parser):
args = parser.parse_args()
# substite ${DISL_HOME}
if args.c_cagent.startswith(variable_disl_home):
args.c_cagent = args.c_cagent.replace(variable_disl_home, args.disl_home)
if args.c_jagent.startswith(variable_disl_home):
args.c_jagent = args.c_jagent.replace(variable_disl_home, args.disl_home)
if args.s_jar.startswith(variable_disl_home):
args.s_jar = args.s_jar.replace(variable_disl_home, args.disl_home)
args.c_opts = flatten_all(args.c_opts)
args.c_app = flatten_all(args.c_app)
args.app = flatten_all(args.app)
if args.c_noexcepthandler is True:
args.c_opts+= ["-Ddisl.noexcepthandler"]
if args.c_exclusionlist is not None:
args.c_opts+= ["-Ddisl.exclusionList="+args.c_exclusionlist]
args.s_opts = flatten_all(args.s_opts)
args.s_args = flatten_all(args.s_args)
if args.s_instrumented is not None:
args.c_opts+= ["-Ddislserver.instrumented="+args.s_instrumented]
if args.s_uninstrumented is not None:
args.c_opts+= ["-Ddislserver.uninstrumented="+args.s_uninstrumented]
args.e_opts = flatten_all(args.e_opts)
args.e_args = flatten_all(args.e_args)
# supply instrumentation from positional instr if set
if args.instrumentation is not None and args.instr is not None:
parser.error("-i and instr set both")
if args.instr is not None:
args.instrumentation = args.instr
# supply c_app from positional app if set
if args.c_app is not None and args.app is not None:
parser.error("-c_app and app set both")
if args.app is not None:
args.c_app = args.app
# by default run client and server
if args.client is False and args.server is False and args.evaluation is False:
args.client = True
args.server = True
if args.print_namespace:
for key in args.__dict__:
value = args.__dict__[key]
print key + "=" + str(value)
return args
######################################################################
# RUN_SERVER
######################################################################
def run_server(args, parser):
if args.instrumentation is None:
parser.error("argument instr (-i) is required to run the client")
try:
with open(".server.pid", "r") as pid_file:
pid = pid_file.readline()
kill = Popen(["kill", pid], stdout=PIPE, shell=False)
except IOError:
pass
s_class = "ch.usi.dag.dislserver.DiSLServer"
s_cmd = ["java"]
s_cmd+= args.s_opts
s_cmd+= ["-cp", args.instrumentation + ":" + args.s_jar]
s_cmd+= [s_class]
s_cmd+= args.s_args
#print s_cmd
server = Popen(s_cmd, shell=False)
with open(".server.pid", "w") as pid_file:
pid_file.write(str(server.pid))
time.sleep(3)
return
######################################################################
# RUN_CLIENT
######################################################################
def run_client(args, parser):
if args.c_app is None:
parser.error("argument app (-c_app) is required to run the client")
if args.instrumentation is None:
parser.error("argument instr (-i) is required to run the client")
c_cmd = ["java"]
c_cmd+= args.c_opts
c_cmd+= ["-agentpath:"+args.c_cagent]
c_cmd+= ["-javaagent:"+args.c_jagent]
c_cmd+= ["-Xbootclasspath/a:"+args.c_jagent+":"+args.instrumentation]
c_cmd+= args.c_app
#print c_cmd
client = Popen(c_cmd, shell=False)
client.wait()
return
######################################################################
# MAIN
######################################################################
def main():
parser = make_parser()
args = parse_arguments(parser)
if args.server == True:
run_server(args, parser)
if args.client == True:
run_client(args, parser)
return
######################################################################
# ENTRY_POINT
######################################################################
if __name__ == "__main__":
main()
# if there is Makefile.local file then include it
ifneq (, $(wildcard Makefile.local))
include Makefile.local
# if there is JAVA_HOME var file then include it
ifneq (, $(wildcard javahome/var))
include javahome/var
endif
BUILDDIR=../build
......
ifeq ($(OS),Windows_NT)
UNAME := Windows
ifneq (,$(findstring /cygdrive/,$(PATH)))
UNAME := Cygwin
endif
else
UNAME := $(shell uname -s)
endif
.PHONY: all, clean
all: $(UNAME)
Linux:
@./find.sh
Darwin:
@./find.sh
Windows:
@echo Windows not yet supported.
Cygwin:
@echo "Cygwin not yet supported."
clean:
@rm -f var
The Java finder works in the following order.
1. If there is a file "var.local" then it is used. It's supposed there is
JAVA_HOME specified as in the "var.local.tmpl".
2. If there is no such file then the script checks the environment for the
JAVA_HOME variable.
3. If the envorinment variable is not found the script tries to guess based on
currently prefered java compiler and derives the destination of JAVA_HOME.
#!/bin/bash
# use variable specified by the user
if [ -f "var.local" ]; then
cp -f "var.local" "var"
exit 0
fi
# use environment variable
if [ ! -z "$JAVA_HOME" ]; then
echo "JAVA_HOME="$JAVA_HOME > "var"
exit 0
fi
# guess
JAVAC=`which javac 2>/dev/null`
JH=`readlink -f ${JAVAC}`
JH=`echo ${JH%/*}`
JH=`echo ${JH%/*}`
echo "JAVA_HOME="${JH} > "var"
JAVA_HOME=/path/to/java/directory
# if there is Makefile.local file then include it
ifneq (, $(wildcard Makefile.local))
include Makefile.local
# if there is JAVA_HOME var file then include it
ifneq (, $(wildcard javahome/var))
include javahome/var
endif
BUILDDIR=../build
......@@ -59,4 +59,4 @@ debug:
debugfull:
$(MAKE) DEBUGFULL=TRUE
all: build
\ No newline at end of file
all: build
ifeq ($(OS),Windows_NT)
UNAME := Windows
ifneq (,$(findstring /cygdrive/,$(PATH)))
UNAME := Cygwin
endif
else
UNAME := $(shell uname -s)
endif
.PHONY: all, clean
all: $(UNAME)
Linux:
@./find.sh
Darwin:
@echo "Darwin is supported"
Windows:
@echo Windows not yet supported.
Cygwin:
@echo "Cygwin not yet supported."
clean:
@rm -f var
The Java finder works in the following order.
1. If there is a file "var.local" then it is used. It's supposed there is
JAVA_HOME specified as in the "var.local.tmpl".
2. If there is no such file then the script checks the environment for the
JAVA_HOME variable.
3. If the envorinment variable is not found the script tries to guess based on
currently prefered java compiler and derives the destination of JAVA_HOME.