1 /*
  2  * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  */
 23 package jdk.internal.jextract.impl;
 24 
 25 import java.util.ArrayList;
 26 import java.util.Collections;
 27 import java.util.List;
 28 
 29 public final class Options {
 30 
 31     // The args for parsing C
 32     public final List<String> clangArgs;
 33     // The list of library names
 34     public final List<String> libraryNames;
 35     public final List<String> filters;
 36     // target package
 37     public final String targetPackage;
 38     // output directory
 39     public final String outputDir;
 40     public final boolean source;
 41     public final IncludeHelper includeHelper;
 42 
 43     private Options(List<String> clangArgs, List<String> libraryNames,
 44             List<String> filters, String targetPackage,
 45             String outputDir, boolean source, IncludeHelper includeHelper) {
 46         this.clangArgs = clangArgs;
 47         this.libraryNames = libraryNames;
 48         this.filters = filters;
 49         this.targetPackage = targetPackage;
 50         this.outputDir = outputDir;
 51         this.source = source;
 52         this.includeHelper = includeHelper;
 53     }
 54 
 55     public static Builder builder() {
 56         return new Builder();
 57     }
 58 
 59     public static Options createDefault() {
 60         return builder().build();
 61     }
 62 
 63     public static class Builder {
 64         private final List<String> clangArgs;
 65         private final List<String> libraryNames;
 66         private final List<String> filters;
 67         private String targetPackage;
 68         private String outputDir;
 69         private boolean source;
 70         private IncludeHelper includeHelper = new IncludeHelper();
 71 
 72         public Builder() {
 73             this.clangArgs = new ArrayList<>();
 74             this.libraryNames = new ArrayList<>();
 75             this.filters = new ArrayList<>();
 76             this.targetPackage = "";
 77             this.outputDir = ".";
 78             this.source = false;
 79         }
 80 
 81         public Options build() {
 82             return new Options(
 83                     Collections.unmodifiableList(clangArgs),
 84                     Collections.unmodifiableList(libraryNames),
 85                     Collections.unmodifiableList(filters),
 86                     targetPackage, outputDir, source, includeHelper
 87             );
 88         }
 89 
 90         public void addClangArg(String arg) {
 91             clangArgs.add(arg);
 92         }
 93 
 94         public void addLibraryName(String name) {
 95             libraryNames.add(name);
 96         }
 97 
 98         public void setOutputDir(String outputDir) {
 99             this.outputDir = outputDir;
100         }
101 
102         public void setTargetPackage(String pkg) {
103             this.targetPackage = pkg;
104         }
105 
106         public void addFilter(String filter) {
107             filters.add(filter);
108         }
109 
110         public void setGenerateSource() {
111             source = true;
112         }
113 
114         public void setDumpIncludeFile(String dumpIncludesFile) {
115             includeHelper.dumpIncludesFile = dumpIncludesFile;
116         }
117 
118         public void addIncludeSymbol(IncludeHelper.IncludeKind kind, String symbolName) {
119             includeHelper.addSymbol(kind, symbolName);
120         }
121     }
122 }