Some fixups for scala compilation in MCP. Scala should now be compilable and reobfuscatable with srgnames in MCP.

This commit is contained in:
Christian committed 2013-04-23 07:40:49 -04:00
1 parent e97834b433
commit cee176eb96
4 files changed
+112 -16

No files matched your search

+109 -15
View File
@@ -18,7 +18,62 @@
class Commands(object):
"""Contains the commands and initialisation for a full mcp run"""
@@ -796,6 +800,8 @@
@@ -194,6 +198,7 @@
sys.exit(1)
self.checkjava()
+ self.checkscala()
self.readcommands(verify, no_patch=no_patch)
def checkcommand(self, name, command, java=False, single_line=False, check_return=True, error=True):
@@ -230,6 +235,8 @@
self.checkcommand('java', '%s -version' % self.cmdjava)
self.checkcommand('javac', '%s -version' % self.cmdjavac)
self.checkcommand('javac runtime', '%s -J-version' % self.cmdjavac)
+ if self.cmdscalac: self.checkcommand('scalac', '%s -version' % self.cmdscalac)
+ if self.cmdscalac: self.checkcommand('scalac runtime', '%s -J-version' % self.cmdscalac)
self.checkcommand('retroguard', '%s --version' % self.retroguard, java=True)
self.exceptor = os.path.normpath(self.config.get('COMMANDS', 'Exceptor'))
@@ -350,6 +357,8 @@
self.cmdfernflower = self.config.get('COMMANDS', 'CmdFernflower', raw=1) % (self.cmdjava, self.fernflower)
self.cmdexceptor = self.config.get('COMMANDS', 'CmdExceptor', raw=1) % (self.cmdjava, self.exceptor)
self.cmdrecomp = self.config.get('COMMANDS', 'CmdRecomp', raw=1) % self.cmdjavac
+ if self.cmdscalac: self.cmdrecompscalac = self.config.get('COMMANDS', 'CmdRecompScalac', raw=1) % self.cmdscalac
+ else: self.cmdrecompscalac = None
self.cmdstartsrv = self.config.get('COMMANDS', 'CmdStartSrv', raw=1) % self.cmdjava
self.cmdstartclt = self.config.get('COMMANDS', 'CmdStartClt', raw=1) % self.cmdjava
@@ -751,6 +760,28 @@
self.cmdjavac = '"%s"' % os.path.join(results[0], 'javac')
self.cmdjava = '"%s"' % os.path.join(results[0], 'java')
+ def checkscala(self):
+ results = []
+ if not results:
+ try:
+ # TODO: Verify at least version 2.10
+ self.runcmd('scalac -version', quiet=True)
+ results.append('')
+ except (CalledProcessError, OSError):
+ pass
+ if not results: # Stupid windows...
+ try:
+ # TODO: Verify at least version 2.10
+ self.runcmd('scalac.bat -version', quiet=True)
+ results.append('')
+ except (CalledProcessError, OSError):
+ pass
+ if not results:
+ self.logger.warning('"scalac"" is not found on the PATH. Scala files will not be recompiled')
+ self.cmdscalac = None
+ else:
+ self.cmdscalac = '"%s"' % os.path.join(results[0], 'scalac')
+
def checkjars(self, side):
jarlk = {CLIENT: self.jarclient, SERVER: self.jarserver}
md5jarlk = {CLIENT: self.md5jarclt, SERVER: self.md5jarsrv}
@@ -796,6 +827,8 @@
binlk = {CLIENT: self.binclient, SERVER: self.binserver}
testlk = {CLIENT: self.testclient, SERVER: self.testserver}
@@ -27,17 +82,56 @@
if not os.path.exists(os.path.join(binlk[side], os.path.normpath(testlk[side] + '.class'))):
return False
return True
@@ -1037,6 +1043,9 @@
@@ -1036,6 +1069,9 @@
pathbinlk = {CLIENT: self.binclient, SERVER: self.binserver}
pathsrclk = {CLIENT: self.srcclient, SERVER: self.srcserver}
pathlog = {CLIENT: self.clientrecomplog, SERVER: self.serverrecomplog}
+
+ if side == SERVER: #Warn about server because FML recombines it into client
+ self.logger.info('Server side recompiling might be skipped, this is normal, do not complain to FML/Forge team about server side.')
+
if not os.path.exists(pathbinlk[side]):
os.makedirs(pathbinlk[side])
@@ -1070,7 +1079,7 @@
@@ -1049,6 +1085,29 @@
all_files = True
append_pattern = False
pkglist = filterdirs(pathsrclk[side], '*.java', append_pattern=append_pattern, all_files=all_files)
+ if self.cmdrecompscalac: # Compile scala before java as scala scans java files, but not vice-versa
+ pkglistscala = pkglist[:]
+ pkglistscala.extend(filterdirs(pathsrclk[side], '*.scala', append_pattern=append_pattern, all_files=all_files))
+ dirs = ' '.join(pkglistscala)
+ classpath = os.pathsep.join(cplk[side])
+ forkcmd = self.cmdrecompscalac.format(classpath=classpath, sourcepath=pathsrclk[side], outpath=pathbinlk[side], pkgs=dirs)
+ try:
+ self.runcmd(forkcmd, log_file=pathlog[side])
+ except CalledProcessError as ex:
+ self.logger.error('')
+ self.logger.error('== ERRORS FOUND in SCALA CODE ==')
+ self.logger.error('')
+ for line in ex.output.splitlines():
+ if line.strip():
+ if line.find("jvm-1.6") != -1:
+ self.logger.error(' === Your scala version is out of date, update to at least 2.10.0 ===')
+ if line[0] != '[' and line[0:4] != 'Note':
+ self.logger.error(line)
+ if '^' in line:
+ self.logger.error('')
+ self.logger.error('================================')
+ self.logger.error('')
+ raise
dirs = ' '.join(pkglist)
classpath = os.pathsep.join(cplk[side])
forkcmd = self.cmdrecomp.format(classpath=classpath, sourcepath=pathsrclk[side], outpath=pathbinlk[side],
@@ -1057,7 +1116,7 @@
self.runcmd(forkcmd, log_file=pathlog[side])
except CalledProcessError as ex:
self.logger.error('')
- self.logger.error('== ERRORS FOUND ==')
+ self.logger.error('== ERRORS FOUND in JAVA CODE ==')
self.logger.error('')
for line in ex.output.splitlines():
if line.strip():
@@ -1070,7 +1129,7 @@
raise
def startserver(self):
@@ -46,7 +140,7 @@
classpath = [os.path.join('..', p) for p in classpath]
classpath = os.pathsep.join(classpath)
os.chdir(self.dirjars)
@@ -1078,7 +1087,7 @@
@@ -1078,7 +1137,7 @@
self.runmc(forkcmd)
def startclient(self):
@@ -55,7 +149,7 @@
classpath = [os.path.join('..', p) for p in classpath]
classpath = os.pathsep.join(classpath)
natives = os.path.join('..', self.dirnatives)
@@ -1205,20 +1214,20 @@
@@ -1205,20 +1264,20 @@
with open(self.csvmethods, 'rb') as fh:
methodsreader = csv.DictReader(fh)
for row in methodsreader:
@@ -79,7 +173,7 @@
names['params'][row['param']] = row['name']
regexps = {
@@ -1352,13 +1361,13 @@
@@ -1352,13 +1411,13 @@
methods = {}
for row in methodsreader:
#HINT: Only include methods that have a non-empty description
@@ -95,7 +189,7 @@
fields[row['searge']] = row['desc'].replace('*/', '* /')
regexps = {
@@ -1435,7 +1444,7 @@
@@ -1435,7 +1494,7 @@
self.runcmd(forkcmd)
return True
@@ -104,7 +198,7 @@
if not reobf:
md5lk = {CLIENT: self.md5client, SERVER: self.md5server}
else:
@@ -1450,6 +1459,9 @@
@@ -1450,6 +1509,9 @@
class_path = ''
else:
class_path += '/'
@@ -114,7 +208,7 @@
for class_file in fnmatch.filter(filelist, '*.class'):
class_name = class_path + os.path.splitext(class_file)[0]
bin_file = os.path.normpath(os.path.join(path, class_file))
@@ -1546,6 +1558,8 @@
@@ -1546,6 +1608,8 @@
if not os.path.exists(outpathlk[side]):
os.makedirs(outpathlk[side])
@@ -123,7 +217,7 @@
# HINT: We extract the modified class files
with closing(zipfile.ZipFile(jarlk[side])) as zipjar:
for in_class in trgclasses:
@@ -1559,6 +1573,23 @@
@@ -1559,6 +1623,23 @@
out_class = out_class.replace(self.nullpkg, '')
if out_class[0] == '/':
out_class = out_class[1:]
@@ -147,7 +241,7 @@
try:
zipjar.extract(out_class, outpathlk[side])
self.logger.info('> Outputted %s to %s as %s', in_class.ljust(35), outpathlk[side], out_class)
@@ -1605,6 +1636,9 @@
@@ -1605,6 +1686,9 @@
sys.exit(1)
for entry in newfiles:
@@ -157,7 +251,7 @@
if entry[3] == 'U':
self.logger.info('Retrieving file from server : %s', entry[0])
cur_file = os.path.normpath(entry[0])
@@ -1625,6 +1659,9 @@
@@ -1625,6 +1709,9 @@
md5reoblk = {CLIENT: self.md5reobfclient, SERVER: self.md5reobfserver}
outpathlk = {CLIENT: self.srcmodclient, SERVER: self.srcmodserver}
src = {CLIENT: self.srcclient, SERVER: self.srcserver}
+1
View File
@@ -153,5 +153,6 @@ CmdJadretro = %s -jar %s {targetdir}
CmdFernflower = %s -Xmx512M -jar %s -din=0 -rbr=0 -dgs=1 -asc=1 -log=WARN {indir} {outdir}
CmdExceptor = %s -jar %s {input} {output} {conf} {log}
CmdRecomp = %s -encoding UTF-8 -Xlint:-options -deprecation -g -source 1.6 -target 1.6 -classpath "{classpath}" -sourcepath {sourcepath} -d {outpath} {pkgs}
CmdRecompScalac = %s -encoding UTF-8 -deprecation -target:jvm-1.6 -classpath "{classpath}" -sourcepath {sourcepath} -d {outpath} {pkgs}
CmdStartSrv = %s -Xincgc -Xms1024M -Xmx1024M -cp "{classpath}" net.minecraft.server.MinecraftServer
CmdStartClt = %s -Xincgc -Xms1024M -Xmx1024M -cp "{classpath}" -Djava.library.path={natives} Start
+1
View File
@@ -22,5 +22,6 @@
<classpathentry kind="lib" path="lib/bcprov-debug-jdk15on-148.jar" sourcepath="lib/bcprov-jdk15on-148-src.zip"/>
<classpathentry kind="lib" path="lib/asm-debug-all-4.1.jar" sourcepath="lib/asm-4.1-bin.zip"/>
<classpathentry kind="lib" path="lib/guava-14.0-rc3.jar" sourcepath="lib/guava-14.0-rc3-sources.jar"/>
<classpathentry kind="lib" path="lib/scala-library.jar" sourcepath="lib/scala-library.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
+1 -1
View File
@@ -12,7 +12,7 @@ mcp_version = '7.42'
def download_deps(mcp_path):
ret = True
for lib in ['argo-3.2-src.jar','guava-14.0-rc3.jar','asm-4.1.tar.gz','asm-debug-all-4.1.jar','bcprov-debug-jdk15on-148.jar','bcprov-jdk15on-148-src.zip','guava-14.0-rc3-sources.jar']:
for lib in ['argo-3.2-src.jar','guava-14.0-rc3.jar','asm-4.1.tar.gz','asm-debug-all-4.1.jar','bcprov-debug-jdk15on-148.jar','bcprov-jdk15on-148-src.zip','guava-14.0-rc3-sources.jar', 'scala-library.jar']:
libF = os.path.join(mcp_path, 'lib')
if not os.path.isdir(libF):
os.makedirs(libF)