Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 7e602b9b9353
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 1aba62533d78
Choose a head ref
  • 3 commits
  • 2 files changed
  • 1 contributor

Commits on Jul 27, 2016

  1. [Truffle] Mx: Implement mx ruby.

    * Add JRuby+Truffle Ruby core files to the jar.
    * Extract RUBY-ZIP in mxbuild.
    eregon committed Jul 27, 2016
    Copy the full SHA
    ad233f3 View commit details
  2. Copy the full SHA
    66acf18 View commit details
  3. [Truffle] Mx: no need to install truffle in the local Maven repo.

    * Since it's built directly with mx.
    eregon committed Jul 27, 2016
    Copy the full SHA
    1aba625 View commit details
Showing with 107 additions and 28 deletions.
  1. +97 −28 mx.jruby/mx_jruby.py
  2. +10 −0 mx.jruby/suite.py
125 changes: 97 additions & 28 deletions mx.jruby/mx_jruby.py
Original file line number Diff line number Diff line change
@@ -13,6 +13,8 @@
import shutil
import json
import time
import tarfile
import zipfile
from threading import Thread
from os.path import join, exists

@@ -25,28 +27,56 @@

# Project and BuildTask classes

class ArchiveProject(mx.Project):
class ArchiveBaseProject(mx.Project):
def __init__(self, suite, name, deps, workingSets, theLicense, **args):
mx.Project.__init__(self, suite, name, "", [], deps, workingSets, _suite.dir, theLicense)
assert 'prefix' in args
assert 'outputDir' in args

def getBuildTask(self, args):
return ArchiveBuildTask(self, args)

def getResults(self):
results = []
outputDir = join(_suite.dir, self.outputDir)
for root, _, files in os.walk(outputDir):
for name in files:
path = join(root, name)
results.append(path)
return results

class JavaArchiveProject(ArchiveBaseProject):
def __init__(self, suite, name, deps, workingSets, theLicense, **args):
ArchiveBaseProject.__init__(self, suite, name, deps, workingSets, theLicense, **args)
self.javaCompliance = "1.8"

def isJavaProject(self):
return True

def archive_prefix(self):
return self.prefix

def output_dir(self, relative=False):
return join(_suite.dir, self.outputDir)

def source_gen_dir(self, relative=False):
return None

def source_dirs(self):
return []

def annotation_processors(self):
return []

class ArchiveProject(ArchiveBaseProject):
def isNativeProject(self):
return True # for archiving purposes

def getOutput(self):
return '.'

def getResults(self):
result = []
output_dir = join(_suite.dir, self.prefix)
for root, _, files in os.walk(output_dir):
for name in files:
path = join(root, name)
result.append(path)
return result
# Paths in the tarball will be relative to output,
# so we need prefix to be the same as outputDir.
assert self.prefix == self.outputDir
return _suite.dir

class ArchiveBuildTask(mx.BuildTask):
def __init__(self, project, args):
@@ -158,27 +188,28 @@ def needsBuild(self, newestInput):
return (True, jni_libs)

for watched in self.subject.watch:
watched = join(_suite.dir, watched)
if not exists(watched):
return (True, watched)
return (True, watched + ' does not exist')
elif os.path.isfile(watched) and TimeStampFile(watched).isNewerThan(jar):
return (True, watched)
return (True, watched + ' is newer than the jar')
else:
for root, _, files in os.walk(watched):
for name in files:
source = join(root, name)
if TimeStampFile(source).isNewerThan(jar):
return (True, source)
return (True, source + ' is newer than the jar')

return (False, 'all files are up to date')

def newestOutput(self):
return TimeStampFile(self.subject.jar)
return TimeStampFile(join(_suite.dir, self.subject.jar))

def build(self):
mx.log('...perform build of {}'.format(self.subject))

cwd = _suite.dir
mavenDir = join(cwd, 'mxbuild', 'mvn')
maven_repo_arg = '-Dmaven.repo.local=' + mavenDir

# HACK: since the maven executable plugin does not configure the
# java executable that is used we unfortunately need to append it to the PATH
@@ -189,23 +220,12 @@ def build(self):

mx.run(['java', '-version'])

# Truffle version
truffle = mx.suite('truffle')
truffle_commit = truffle.vc.parent(truffle.dir)
maven_version_arg = '-Dtruffle.version=' + truffle_commit
maven_repo_arg = '-Dmaven.repo.local=' + mavenDir

for name in ['truffle-api', 'truffle-debug', 'truffle-dsl-processor', 'truffle-tck']:
jar_path = join(mavenDir, 'com', 'oracle', 'truffle', name, truffle_commit, "%s-%s.jar" % (name, truffle_commit))
if not exists(jar_path):
mx.run_mx(['maven-install', '--repo', mavenDir, '--only', 'TRUFFLE_API,TRUFFLE_DEBUG,TRUFFLE_DSL_PROCESSOR,TRUFFLE_TCK'], suite=truffle)

# Build jruby-truffle
env = os.environ.copy()
env['JRUBY_BUILD_MORE_QUIET'] = 'true'

mx.log("Building jruby-core with Maven")
mx.run_maven(['-q', '-DskipTests', maven_version_arg, maven_repo_arg, '-pl', 'core'], cwd=cwd, env=env)
mx.run_maven(['-q', '-DskipTests', maven_repo_arg, '-pl', 'core'], cwd=cwd, env=env)

# mx.run(['bin/jruby', 'bin/gem', 'install', 'bundler', '-v', '1.10.6'], cwd=cwd)

@@ -219,6 +239,55 @@ def clean(self, forBuild=False):
if jar.exists():
os.remove(jar.path)

# Commands

def extractArguments(args):
vmArgs = []
rubyArgs = []
for i in range(len(args)):
arg = args[i]
if arg.startswith('-J-'):
vmArgs.append(arg[2:])
elif arg.startswith('-X'):
vmArgs.append('-Djruby.' + arg[2:])
else:
rubyArgs.append(arg)
return vmArgs, rubyArgs

def extractTarball(file, target_dir):
if file.endswith('tar'):
with tarfile.open(file, 'r:') as tf:
tf.extractall(target_dir)
elif file.endswith('jar') or file.endswith('zip'):
with zipfile.ZipFile(file, "r") as zf:
zf.extractall(target_dir)
else:
mx.abort('Unsupported compressed file ' + file)

def setup_jruby_home():
rubyZip = mx.distribution('RUBY-ZIP').path
assert exists(rubyZip)
extractPath = join(_suite.dir, 'mxbuild', 'ruby-zip-extracted')
if TimeStampFile(extractPath).isOlderThan(rubyZip):
if exists(extractPath):
shutil.rmtree(extractPath)
extractTarball(rubyZip, extractPath)
env = os.environ.copy()
env['JRUBY_HOME'] = extractPath
return env

def ruby_command(args):
"""runs Ruby"""
vmArgs, rubyArgs = extractArguments(args)
vmArgs += ['-cp', mx.classpath(['TRUFFLE_API', 'RUBY'])]
vmArgs += ['org.jruby.Main', '-X+T']
env = setup_jruby_home()
mx.run_java(vmArgs + rubyArgs, env=env)

mx.update_commands(_suite, {
'ruby' : [ruby_command, '[ruby args|@VM options]'],
})

# Utilities

def jt(args, suite=None, nonZeroIsFatal=True, out=None, err=None, timeout=None, env=None, cwd=None):
10 changes: 10 additions & 0 deletions mx.jruby/suite.py
Original file line number Diff line number Diff line change
@@ -101,20 +101,29 @@ def mavenLib(mavenDep, sha1):
"workingSets": "JRubyTruffle",
},

"jruby-truffle-ruby": {
"class": "JavaArchiveProject",
"outputDir": "truffle/src/main/ruby",
"prefix": "jruby-truffle",
},

# Depends on jruby-maven extracting jni libs in lib/jni
"jruby-lib-jni": {
"class": "ArchiveProject",
"outputDir": "lib/jni",
"prefix": "lib/jni",
"dependencies": [ "jruby-core" ],
},

"jruby-lib-ruby": {
"class": "ArchiveProject",
"outputDir": "lib/ruby",
"prefix": "lib/ruby",
},

"jruby-licences": {
"class": "LicensesProject",
"outputDir": ".",
"prefix": ".",
},
},
@@ -128,6 +137,7 @@ def mavenLib(mavenDep, sha1):
"dependencies": [
"jruby-core",
"jruby-truffle",
"jruby-truffle-ruby",
],
"exclude": [
"truffle:JLINE",