Search in sources :

Example 1 with Include

use of org.gradle.language.nativeplatform.internal.Include in project gradle by gradle.

the class RegexBackedCSourceParser method parseFile.

private List<Include> parseFile(File file) {
    List<Include> includes = Lists.newArrayList();
    try {
        BufferedReader bf = new BufferedReader(new PreprocessingReader(new BufferedReader(new FileReader(file))));
        try {
            String line;
            while ((line = bf.readLine()) != null) {
                Matcher m = includePattern.matcher(line.trim());
                if (m.matches()) {
                    boolean isImport = "import".equals(m.group(1));
                    String value = m.group(2);
                    includes.add(DefaultInclude.parse(value, isImport));
                }
            }
        } finally {
            IOUtils.closeQuietly(bf);
        }
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
    return includes;
}
Also used : Matcher(java.util.regex.Matcher) BufferedReader(java.io.BufferedReader) Include(org.gradle.language.nativeplatform.internal.Include) FileReader(java.io.FileReader) UncheckedIOException(org.gradle.api.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(org.gradle.api.UncheckedIOException)

Example 2 with Include

use of org.gradle.language.nativeplatform.internal.Include in project gradle by gradle.

the class RegexBackedCSourceParser method parseSource.

protected IncludeDirectives parseSource(Reader sourceReader) throws IOException {
    Set<Include> includes = Sets.newLinkedHashSet();
    List<Macro> macros = Lists.newArrayList();
    List<MacroFunction> macroFunctions = Lists.newArrayList();
    BufferedReader reader = new BufferedReader(sourceReader);
    PreprocessingReader lineReader = new PreprocessingReader(reader);
    Buffer buffer = new Buffer();
    while (true) {
        buffer.reset();
        if (!lineReader.readNextLine(buffer.value)) {
            break;
        }
        buffer.consumeWhitespace();
        if (!buffer.consume('#')) {
            continue;
        }
        buffer.consumeWhitespace();
        if (buffer.consume("define")) {
            parseDefineDirectiveBody(buffer, macros, macroFunctions);
        } else if (buffer.consume("include")) {
            parseIncludeOrImportDirectiveBody(buffer, false, includes);
        } else if (buffer.consume("import")) {
            parseIncludeOrImportDirectiveBody(buffer, true, includes);
        }
    }
    return new DefaultIncludeDirectives(ImmutableList.copyOf(includes), ImmutableList.copyOf(macros), ImmutableList.copyOf(macroFunctions));
}
Also used : MacroFunction(org.gradle.language.nativeplatform.internal.MacroFunction) Macro(org.gradle.language.nativeplatform.internal.Macro) BufferedReader(java.io.BufferedReader) Include(org.gradle.language.nativeplatform.internal.Include)

Example 3 with Include

use of org.gradle.language.nativeplatform.internal.Include in project gradle by gradle.

the class NativeCompiler method maybeGetPCHArgs.

protected List<String> maybeGetPCHArgs(final T spec, File sourceFile) {
    if (spec.getPreCompiledHeader() == null) {
        return Lists.newArrayList();
    }
    final IncludeDirectives includes = spec.getSourceFileIncludeDirectives().get(sourceFile);
    final String header = spec.getPreCompiledHeader();
    List<Include> headers = includes.getAll();
    boolean usePCH = !headers.isEmpty() && header.equals(headers.get(0).getValue());
    if (usePCH) {
        return getPCHArgs(spec);
    } else {
        boolean containsHeader = CollectionUtils.any(headers, new Spec<Include>() {

            @Override
            public boolean isSatisfiedBy(Include include) {
                return include.getValue().equals(header);
            }
        });
        if (containsHeader) {
            logger.log(LogLevel.WARN, getCantUsePCHMessage(spec.getPreCompiledHeader(), sourceFile));
        }
        return Lists.newArrayList();
    }
}
Also used : IncludeDirectives(org.gradle.language.nativeplatform.internal.IncludeDirectives) Include(org.gradle.language.nativeplatform.internal.Include)

Aggregations

Include (org.gradle.language.nativeplatform.internal.Include)3 BufferedReader (java.io.BufferedReader)2 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 Matcher (java.util.regex.Matcher)1 UncheckedIOException (org.gradle.api.UncheckedIOException)1 IncludeDirectives (org.gradle.language.nativeplatform.internal.IncludeDirectives)1 Macro (org.gradle.language.nativeplatform.internal.Macro)1 MacroFunction (org.gradle.language.nativeplatform.internal.MacroFunction)1