You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openoffice.apache.org by da...@apache.org on 2020/07/04 18:44:13 UTC
[openoffice] 10/11: Add initial half-working SCons conversion for
Ant targets.
This is an automated email from the ASF dual-hosted git repository.
damjan pushed a commit to branch scons-build
in repository https://gitbox.apache.org/repos/asf/openoffice.git
commit 2fff3eb090a1ba53200bce9af32cd04f61bb8702
Author: Damjan Jovanovic <da...@apache.org>
AuthorDate: Sat Jul 4 11:04:57 2020 +0200
Add initial half-working SCons conversion for Ant targets.
Patch by: me
---
.../openoffice/gotoSCons/SConsConverter.java | 9 ++
.../openoffice/gotoSCons/targets/AntTarget.java | 95 ++++++++++++++++++++++
.../openoffice/gotoSCons/targets/Module.java | 10 +++
main/site_scons/Ant.py | 79 ++++++++++++++++++
main/site_scons/site_init.py | 1 +
5 files changed, 194 insertions(+)
diff --git a/gotoSCons/src/main/java/org/apache/openoffice/gotoSCons/SConsConverter.java b/gotoSCons/src/main/java/org/apache/openoffice/gotoSCons/SConsConverter.java
index e181fd7..ddc0e3a 100644
--- a/gotoSCons/src/main/java/org/apache/openoffice/gotoSCons/SConsConverter.java
+++ b/gotoSCons/src/main/java/org/apache/openoffice/gotoSCons/SConsConverter.java
@@ -28,6 +28,7 @@ import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
import org.apache.openoffice.gotoSCons.targets.AllLangResTarget;
+import org.apache.openoffice.gotoSCons.targets.AntTarget;
import org.apache.openoffice.gotoSCons.targets.BaseBinary;
import org.apache.openoffice.gotoSCons.targets.Executable;
import org.apache.openoffice.gotoSCons.targets.GoogleTest;
@@ -61,6 +62,10 @@ public class SConsConverter {
convertExecutable(exe);
}
+ for (AntTarget antTarget : module.getAntTargets().values()) {
+ convertAntTarget(antTarget);
+ }
+
for (AllLangResTarget allLangResTarget : module.getAllLangResTargets().values()) {
convertAllLangResTarget(allLangResTarget);
}
@@ -177,6 +182,10 @@ public class SConsConverter {
out.println();
}
+ private void convertAntTarget(AntTarget antTarget) throws Exception {
+
+ }
+
private void convertGoogleTest(GoogleTest gtest) throws Exception {
String objectsVariable = convertObjects(gtest);
diff --git a/gotoSCons/src/main/java/org/apache/openoffice/gotoSCons/targets/AntTarget.java b/gotoSCons/src/main/java/org/apache/openoffice/gotoSCons/targets/AntTarget.java
new file mode 100644
index 0000000..29d0e44
--- /dev/null
+++ b/gotoSCons/src/main/java/org/apache/openoffice/gotoSCons/targets/AntTarget.java
@@ -0,0 +1,95 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package org.apache.openoffice.gotoSCons.targets;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStreamReader;
+import java.util.Arrays;
+import org.apache.openoffice.gotoSCons.GBuildParser;
+import org.apache.openoffice.gotoSCons.raw.ListNode;
+import org.apache.openoffice.gotoSCons.raw.Node;
+import org.apache.openoffice.gotoSCons.raw.ValueNode;
+
+/**
+ *
+ * @author dj
+ */
+public class AntTarget extends BaseTarget {
+ private File filename;
+ private String name;
+ private String pathToBuildXml;
+ private String componentPath;
+ private String layer;
+
+ public AntTarget(File filename) throws Exception {
+ this.filename = filename;
+ try (
+ BufferedReader reader = new BufferedReader(new InputStreamReader(
+ new FileInputStream(filename)))
+ ) {
+ ListNode rootNode = new GBuildParser().parse(reader);
+ parse(rootNode);
+ }
+ }
+
+ @Override
+ protected void parseCall(Node argsNode) throws Exception {
+ if (argsNode instanceof ValueNode) {
+ String value = ((ValueNode)argsNode).value;
+ String[] tokens = value.split(",");
+
+ String function = tokens[0].trim();
+ String[] args = Arrays.copyOfRange(tokens, 1, tokens.length);
+
+ if (function.equals("gb_Ant_Ant")) {
+ parseAntAnt(args);
+ } else if (function.equals("gb_Ant_set_componentfile")) {
+ parseAntSetComponentfile(args);
+ } else {
+ throw new Exception("UNHANDLED FUNCTION " + function);
+ }
+ } else {
+ throw new Exception("Call args not a value");
+ }
+ }
+
+ private void parseAntAnt(String[] args) throws Exception {
+ if (args.length != 2) {
+ throw new Exception("Expected 2 args, got " + Arrays.toString(args));
+ }
+ this.name = args[0];
+ this.pathToBuildXml = args[1];
+ }
+
+ private void parseAntSetComponentfile(String[] args) throws Exception {
+ if (args.length != 3) {
+ throw new Exception("Expected 3 args, got " + Arrays.toString(args));
+ }
+ if (!args[0].equals(name)) {
+ throw new Exception("Target name isn't " + name);
+ }
+ this.componentPath = args[1];
+ this.layer = args[2];
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getPathToBuildXml() {
+ return pathToBuildXml;
+ }
+
+ public String getComponentPath() {
+ return componentPath;
+ }
+
+ public String getLayer() {
+ return layer;
+ }
+}
diff --git a/gotoSCons/src/main/java/org/apache/openoffice/gotoSCons/targets/Module.java b/gotoSCons/src/main/java/org/apache/openoffice/gotoSCons/targets/Module.java
index 85ed77f..47a0f31 100644
--- a/gotoSCons/src/main/java/org/apache/openoffice/gotoSCons/targets/Module.java
+++ b/gotoSCons/src/main/java/org/apache/openoffice/gotoSCons/targets/Module.java
@@ -42,6 +42,7 @@ public class Module extends BaseTarget {
private Map<String, Library> libraries = new TreeMap<>();
private Map<String, Executable> executables = new TreeMap<>();
private Map<String, StaticLibrary> staticLibraries = new TreeMap<>();
+ private Map<String, AntTarget> antTargets = new TreeMap<>();
private TreeSet<String> targets = new TreeSet<>();
private Map<String, Pkg> packages = new TreeMap<>();
private Map<String, JunitTest> junitTests = new TreeMap<>();
@@ -122,6 +123,11 @@ public class Module extends BaseTarget {
if (staticLibraries.put(arg, staticLibrary) != null) {
throw new Exception("Duplicate add of target " + arg);
}
+ } else if (arg.startsWith("Ant_")) {
+ AntTarget antTarget = new AntTarget(makefile);
+ if (antTargets.put(arg, antTarget) != null) {
+ throw new Exception("Duplicate add of target " + arg);
+ }
} else if (arg.startsWith("Package_")) {
Pkg pkg = new Pkg(makefile);
if (packages.put(arg, pkg) != null) {
@@ -202,6 +208,10 @@ public class Module extends BaseTarget {
public Map<String, Executable> getExecutables() {
return executables;
}
+
+ public Map<String, AntTarget> getAntTargets() {
+ return antTargets;
+ }
public Map<String, Pkg> getPackages() {
return packages;
diff --git a/main/site_scons/Ant.py b/main/site_scons/Ant.py
new file mode 100644
index 0000000..5c2234c
--- /dev/null
+++ b/main/site_scons/Ant.py
@@ -0,0 +1,79 @@
+#**************************************************************
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#**************************************************************
+
+from SCons.Script import *
+from config import soenv
+from globals import *
+import os
+import subprocess
+
+class AOOAnt:
+ def __init__(self, name, pathToBuildXml):
+ self.env = DefaultEnvironment().Clone()
+ self.env.Append(ENV=os.environ)
+ self.env['AOO_ANT'] = soenv['ANT']
+
+ self.buildXml = File(pathToBuildXml)
+
+ outputDir = Dir('Ant/' + name)
+ depFile = File('deps', outputDir)
+ targetName = Dir(name + '.jar', outputDir)
+
+ if self.env.GetOption('clean'):
+ # We cannot register a custom clean target with scons,
+ # so do Ant's cleaning in the preparation phase of the build.
+ cleanProcess = subprocess.run(
+ args = ' '.join([
+ soenv['ANT'],
+ '-f',
+ self.buildXml.srcnode().abspath,
+ 'clean']),
+ shell = True,
+ env = self.env['ENV']
+ )
+ if cleanProcess.returncode != 0:
+ raise Exception('ant clean failed with exit code ' + cleanProcess.returncode)
+ else:
+ # Ant might require dependencies from other modules,
+ # which we need to know to establish build order.
+ depsProcess = subprocess.run(
+ args = ' '.join([
+ soenv['ANT'],
+ '-Ddependencies.outfile=' + depFile.abspath,
+ '-f',
+ self.buildXml.srcnode().abspath,
+ 'dependencies'
+ ]),
+ shell = True,
+ env = self.env['ENV']
+ )
+ if depsProcess.returncode == 0:
+ with open(depFile.abspath, 'rt') as f:
+ for dep in f.readline().split():
+ Depends(targetName, depFile)
+ else:
+ raise Exception('ant failed with exit code ' + depsProcess.returncode)
+
+ self.target = self.env.Command(targetName, self.buildXml.srcnode(),
+ '${AOO_ANT} -f ${SOURCE}')
+ # Ant will depend on its internally known .java etc.
+ # so we must always run it
+ AlwaysBuild(self.target)
diff --git a/main/site_scons/site_init.py b/main/site_scons/site_init.py
index b9bfd73..e238aca 100644
--- a/main/site_scons/site_init.py
+++ b/main/site_scons/site_init.py
@@ -63,6 +63,7 @@ else:
from sharedLibrary import AOOSharedLibrary
from sharedObjects import AOOSharedObjects
+from Ant import *
from AllLangRes import *
from JunitTest import *
from GoogleTest import *