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
The following commit(s) were added to refs/heads/scons-build by this push: new 08e2346 Redo the Install target to output files per directory. 08e2346 is described below commit 08e2346aa6bd735495b133ef95378274fb7f8082 Author: Damjan Jovanovic <dam...@apache.org> AuthorDate: Tue Feb 11 08:03:35 2020 +0200 Redo the Install target to output files per directory. Patch by: me --- .../openoffice/gotoSCons/SConsConverter.java | 82 +++++++++++++++++----- 1 file changed, 66 insertions(+), 16 deletions(-) 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 c1c8c29..99f5a7e 100644 --- a/gotoSCons/src/main/java/org/apache/openoffice/gotoSCons/SConsConverter.java +++ b/gotoSCons/src/main/java/org/apache/openoffice/gotoSCons/SConsConverter.java @@ -24,6 +24,8 @@ package org.apache.openoffice.gotoSCons; import java.io.File; import java.io.PrintStream; import java.util.Map; +import java.util.TreeMap; +import java.util.TreeSet; import org.apache.opeonoffice.gotoSCons.targets.BaseBinary; import org.apache.opeonoffice.gotoSCons.targets.Executable; import org.apache.opeonoffice.gotoSCons.targets.Library; @@ -55,22 +57,7 @@ public class SConsConverter { } for (Pkg pkg : module.getPackages().values()) { - for (Map.Entry<String, String> entry : pkg.getFilesToFrom().entrySet()) { - String toPath = entry.getKey(); - String fromPath = pkg.getBaseDir() + '/' + entry.getValue(); - - File moduleDir = module.getFilename().getParentFile().getCanonicalFile(); - String expandedFromPath = fromPath.replace("$(SRCDIR)", moduleDir.getParentFile().getCanonicalPath()); - String moduleRelativeFromPath; - if (expandedFromPath.startsWith(moduleDir.getCanonicalPath())) { - moduleRelativeFromPath = expandedFromPath.substring(moduleDir.getCanonicalPath().length() + 1); - } else { - throw new Exception("Cannot find module relative path to " + fromPath); - } - - out.println(String.format("Install('${OUTDIR}/%s', '%s')", toPath, moduleRelativeFromPath)); - } - out.println(); + convertPackage(module, pkg); } } @@ -279,4 +266,67 @@ public class SConsConverter { return objectsVariable; } + + private void convertPackage(Module module, Pkg pkg) throws Exception { + Map<String, TreeSet<String>> filesByInstallDir = new TreeMap<>(); + + for (Map.Entry<String, String> entry : pkg.getFilesToFrom().entrySet()) { + String toPath = entry.getKey(); + String fromPath = pkg.getBaseDir() + '/' + entry.getValue(); + + if (!filenameFromPath(toPath).equals(filenameFromPath(fromPath))) { + throw new Exception("Src/dst file changes name: " + toPath + " vs " + fromPath); + } + + File moduleDir = module.getFilename().getParentFile().getCanonicalFile(); + String expandedFromPath = fromPath.replace("$(SRCDIR)", moduleDir.getParentFile().getCanonicalPath()); + String moduleRelativeFromPath; + if (expandedFromPath.startsWith(moduleDir.getCanonicalPath())) { + moduleRelativeFromPath = expandedFromPath.substring(moduleDir.getCanonicalPath().length() + 1); + } else { + throw new Exception("Cannot find module relative path to " + fromPath); + } + + String installDir = parentDir(toPath); + TreeSet<String> installFiles = filesByInstallDir.get(installDir); + if (installFiles == null) { + installFiles = new TreeSet<>(); + filesByInstallDir.put(installDir, installFiles); + } + installFiles.add(moduleRelativeFromPath); + } + + for (Map.Entry<String,TreeSet<String>> entry : filesByInstallDir.entrySet()) { + out.println(String.format("Install('${OUTDIR}/%s', [", entry.getKey())); + boolean first = true; + for (String fromPath : entry.getValue()) { + if (!first) { + out.println(","); + } + out.print(" '" + fromPath + "'"); + first = false; + } + out.println(); + out.println("])"); + } + out.println(); + } + + private static String parentDir(String path) throws Exception { + int lastSlash = path.lastIndexOf('/'); + if (lastSlash >= 0) { + return path.substring(0, lastSlash); + } else { + throw new Exception("Doesn't contain directory path: " + path); + } + } + + private static String filenameFromPath(String path) { + int lastSlash = path.lastIndexOf('/'); + if (lastSlash >= 0) { + return path.substring(lastSlash + 1); + } else { + return path; + } + } }