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 268d3522466e6d95d3051212b6d14f30a3929138 Author: Damjan Jovanovic <dam...@apache.org> AuthorDate: Sun Jul 5 04:41:22 2020 +0200 Implement the Zip target and conversion to it. Patch by: me --- .../openoffice/gotoSCons/SConsConverter.java | 24 ++++++ .../openoffice/gotoSCons/targets/Module.java | 10 +++ .../openoffice/gotoSCons/targets/ZipTarget.java | 97 ++++++++++++++++++++++ main/site_scons/Zip.py | 42 ++++++++++ main/site_scons/site_init.py | 1 + 5 files changed, 174 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 b3f17a9..5683526 100644 --- a/gotoSCons/src/main/java/org/apache/openoffice/gotoSCons/SConsConverter.java +++ b/gotoSCons/src/main/java/org/apache/openoffice/gotoSCons/SConsConverter.java @@ -39,6 +39,7 @@ import org.apache.openoffice.gotoSCons.targets.Pkg; import org.apache.openoffice.gotoSCons.targets.Repository; import org.apache.openoffice.gotoSCons.targets.SrsTarget; import org.apache.openoffice.gotoSCons.targets.StaticLibrary; +import org.apache.openoffice.gotoSCons.targets.ZipTarget; public class SConsConverter { private Repository repo; @@ -70,6 +71,10 @@ public class SConsConverter { convertAllLangResTarget(allLangResTarget); } + for (ZipTarget zipTarget : module.getZipTargets().values()) { + convertZipTarget(zipTarget); + } + for (Pkg pkg : module.getPackages().values()) { convertPackage(module, pkg); } @@ -192,6 +197,25 @@ public class SConsConverter { } out.println(); } + + private void convertZipTarget(ZipTarget zipTarget) throws Exception { + String zipVariableName = zipTarget.getName() + "Zip"; + out.println(String.format("%s = AOOZip('%s', '%s')", + zipVariableName, zipTarget.getName(), zipTarget.getBaseDirectory())); + out.println(String.format("%s.AddSourceFiles([", zipVariableName)); + boolean first = true; + for (String sourceFile : zipTarget.getSourceFiles()) { + if (!first) { + out.println(","); + } + out.print(" '" + sourceFile + "'"); + first = false; + } + out.println(); + out.println("])"); + + out.println(); + } private void convertGoogleTest(GoogleTest gtest) throws Exception { String objectsVariable = convertObjects(gtest); 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 47a0f31..05f13a0 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 @@ -43,6 +43,7 @@ public class Module extends BaseTarget { private Map<String, Executable> executables = new TreeMap<>(); private Map<String, StaticLibrary> staticLibraries = new TreeMap<>(); private Map<String, AntTarget> antTargets = new TreeMap<>(); + private Map<String, ZipTarget> zipTargets = new TreeMap<>(); private TreeSet<String> targets = new TreeSet<>(); private Map<String, Pkg> packages = new TreeMap<>(); private Map<String, JunitTest> junitTests = new TreeMap<>(); @@ -128,6 +129,11 @@ public class Module extends BaseTarget { if (antTargets.put(arg, antTarget) != null) { throw new Exception("Duplicate add of target " + arg); } + } else if (arg.startsWith("Zip_")) { + ZipTarget zipTarget = new ZipTarget(makefile); + if (zipTargets.put(arg, zipTarget) != 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) { @@ -217,6 +223,10 @@ public class Module extends BaseTarget { return packages; } + public Map<String, ZipTarget> getZipTargets() { + return zipTargets; + } + public Map<String, JunitTest> getJunitTests() { return junitTests; } diff --git a/gotoSCons/src/main/java/org/apache/openoffice/gotoSCons/targets/ZipTarget.java b/gotoSCons/src/main/java/org/apache/openoffice/gotoSCons/targets/ZipTarget.java new file mode 100644 index 0000000..68835de --- /dev/null +++ b/gotoSCons/src/main/java/org/apache/openoffice/gotoSCons/targets/ZipTarget.java @@ -0,0 +1,97 @@ +/* + * 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 java.util.Set; +import java.util.TreeSet; +import org.apache.openoffice.gotoSCons.GBuildParser; +import org.apache.openoffice.gotoSCons.Utils; +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 ZipTarget extends BaseTarget { + private File filename; + private String name; + private String baseDirectory; + private Set<String> sourceFiles = new TreeSet<>(); + + public ZipTarget(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_Zip_Zip")) { + parseZipZip(args); + } else if (function.equals("gb_Zip_add_files")) { + parseZipAddFiles(args); + } else { + throw new Exception("UNHANDLED FUNCTION " + function); + } + } else { + throw new Exception("Call args not a value"); + } + } + + private void parseZipZip(String[] args) throws Exception { + if (args.length != 2) { + throw new Exception("Expected 2 args, got " + Arrays.toString(args)); + } + this.name = args[0]; + this.baseDirectory = args[1]; + } + + private void parseZipAddFiles(String[] args) throws Exception { + if (args.length != 2) { + throw new Exception("Expected 2 args, got " + Arrays.toString(args)); + } + if (!args[0].equals(name)) { + throw new Exception("Target name isn't " + name); + } + + for (String arg : Utils.spaceSeparatedTokens(args[1])) { + if (!sourceFiles.add(arg)) { + throw new Exception("Duplicate source file " + arg); + } + } + } + + public String getName() { + return name; + } + + public String getBaseDirectory() { + return baseDirectory; + } + + public Set<String> getSourceFiles() { + return sourceFiles; + } +} diff --git a/main/site_scons/Zip.py b/main/site_scons/Zip.py new file mode 100644 index 0000000..3c85088 --- /dev/null +++ b/main/site_scons/Zip.py @@ -0,0 +1,42 @@ +#************************************************************** +# +# 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 * + +class AOOZip: + def __init__(self, name, baseDirectory): + self.env = DefaultEnvironment().Clone() + + + self.baseDirectory = self.env.Dir(baseDirectory) + self.target = File('Zip/' + name + '.zip') + self.outdirTarget = self.env.Dir('${OUTDIR}/pck') + + def AddSourceFiles(self, sourceFiles): + inputFiles = [] + for sourceFile in sourceFiles: + inputFiles.append(File(sourceFile, self.baseDirectory)) + + self.env.Zip(self.target, inputFiles) + Install(self.outdirTarget, self.target) + diff --git a/main/site_scons/site_init.py b/main/site_scons/site_init.py index e238aca..5c1e6ae 100644 --- a/main/site_scons/site_init.py +++ b/main/site_scons/site_init.py @@ -67,6 +67,7 @@ from Ant import * from AllLangRes import * from JunitTest import * from GoogleTest import * +from Zip import * def CreateSharedLibraryEnvironment(name, group): env = Environment()