Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/tools/ProjectCreator/FileTreeCreatorVC10.java
32285 views
/*1* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324import static java.nio.file.FileVisitResult.CONTINUE;2526import java.io.IOException;27import java.nio.file.FileSystems;28import java.nio.file.FileVisitResult;29import java.nio.file.Files;30import java.nio.file.Path;31import java.nio.file.attribute.BasicFileAttributes;32import java.util.Stack;33import java.util.Vector;3435public class FileTreeCreatorVC10 extends FileTreeCreator {3637public FileTreeCreatorVC10(Path startDir, Vector<BuildConfig> allConfigs, WinGammaPlatformVC10 wg) {38super(startDir, allConfigs, wg);39}4041@Override42public FileVisitResult visitFile(Path file, BasicFileAttributes attr) {43DirAttributes currentFileAttr = attributes.peek().clone();44boolean usePch = false;45boolean disablePch = false;46boolean useIgnore = false;47boolean isAltSrc = false; // only needed as a debugging crumb48boolean isReplacedByAltSrc = false;49String fileName = file.getFileName().toString();5051// TODO hideFile5253// usePch applies to all configs for a file.54if (fileName.equals(BuildConfig.getFieldString(null, "UseToGeneratePch"))) {55usePch = true;56}5758String fileLoc = vcProjLocation.relativize(file).toString();5960// isAltSrc and isReplacedByAltSrc applies to all configs for a file61if (BuildConfig.matchesRelativeAltSrcInclude(62file.toAbsolutePath().toString())) {63// current file is an alternate source file so track it64isAltSrc = true;65BuildConfig.trackRelativeAltSrcFile(66file.toAbsolutePath().toString());67} else if (BuildConfig.matchesRelativeAltSrcFile(68file.toAbsolutePath().toString())) {69// current file is a regular file that matches an alternate70// source file so yack about replacing the regular file71isReplacedByAltSrc = true;72System.out.println("INFO: alternate source file '" +73BuildConfig.getMatchingRelativeAltSrcFile(74file.toAbsolutePath().toString()) +75"' replaces '" + fileLoc + "'");76}7778for (BuildConfig cfg : allConfigs) {79if (cfg.lookupHashFieldInContext("IgnoreFile", fileName) != null) {80useIgnore = true;81currentFileAttr.setIgnore(cfg);82} else if (cfg.matchesIgnoredPath(file.toAbsolutePath().toString())) {83useIgnore = true;84currentFileAttr.setIgnore(cfg);85}8687if (cfg.lookupHashFieldInContext("DisablePch", fileName) != null) {88disablePch = true;89currentFileAttr.setDisablePch(cfg);90}9192Vector<String> rv = new Vector<String>();93cfg.collectRelevantVectors(rv, "AdditionalFile");94for(String addFile : rv) {95if (addFile.equals(fileName)) {96// supress any ignore97// TODO - may need some adjustments98if (file.toAbsolutePath().toString().contains(cfg.get("Flavour"))) {99currentFileAttr.removeFromIgnored(cfg);100}101}102}103}104105String tagName = wg10.getFileTagFromSuffix(fileName);106107if (!useIgnore && !disablePch && !usePch && !isReplacedByAltSrc) {108wg.tag(tagName, new String[] { "Include", fileLoc});109} else {110wg.startTag(111tagName,112new String[] { "Include", fileLoc});113114for (BuildConfig cfg : allConfigs) {115boolean ignore = currentFileAttr.hasIgnore(cfg);116if (ignore) {117wg.tagData("ExcludedFromBuild", "true", "Condition", "'$(Configuration)|$(Platform)'=='" + cfg.get("Name") + "'");118}119if (usePch) {120wg.tagData("PrecompiledHeader", "Create", "Condition", "'$(Configuration)|$(Platform)'=='" + cfg.get("Name") + "'");121}122if (disablePch) {123wg.tag("PrecompiledHeader", "Condition", "'$(Configuration)|$(Platform)'=='" + cfg.get("Name") + "'");124}125if (isReplacedByAltSrc) {126wg.tagData("ExcludedFromBuild", "true", "Condition",127"'$(Configuration)|$(Platform)'=='" +128cfg.get("Name") + "'");129}130}131wg.endTag();132}133134String filter = startDir.relativize(file.getParent().toAbsolutePath()).toString();135wg10.addFilterDependency(fileLoc, filter);136137return CONTINUE;138}139140@Override141public FileVisitResult preVisitDirectory(Path path, BasicFileAttributes attrs)142throws IOException {143Boolean hide = false;144// TODO remove attrs, if path is matched in this dir, then it is too in every subdir.145// And we will check anyway146DirAttributes newAttr = attributes.peek().clone();147148// check per config ignorePaths!149for (BuildConfig cfg : allConfigs) {150if (cfg.matchesIgnoredPath(path.toAbsolutePath().toString())) {151newAttr.setIgnore(cfg);152}153154// Hide is always on all configs. And additional files are never hiddden155if (cfg.matchesHidePath(path.toAbsolutePath().toString())) {156hide = true;157break;158}159}160161if (!hide) {162String name = startDir.relativize(path.toAbsolutePath()).toString();163if (!"".equals(name)) {164wg10.addFilter(name);165}166167attributes.push(newAttr);168return super.preVisitDirectory(path, attrs);169} else {170return FileVisitResult.SKIP_SUBTREE;171}172}173174@Override175public FileVisitResult postVisitDirectory(Path dir, IOException exc) {176//end matching attributes set by ignorepath177attributes.pop();178return CONTINUE;179}180181@Override182public FileVisitResult visitFileFailed(Path file, IOException exc) {183return CONTINUE;184}185186public void writeFileTree() throws IOException {187Files.walkFileTree(this.startDir, this);188}189}190191192