mirror of https://github.com/apache/lucene.git
85 lines
2.8 KiB
Groovy
85 lines
2.8 KiB
Groovy
/*
|
|
* 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.
|
|
*/
|
|
|
|
import org.apache.tools.ant.taskdefs.condition.Os
|
|
|
|
// This is the master switch to disable all tasks that compile
|
|
// native (cpp) code.
|
|
rootProject.ext {
|
|
buildNative = propertyOrDefault("build.native", false).toBoolean()
|
|
}
|
|
|
|
// Explicitly list all projects that should be configured for native extensions.
|
|
// We could scan for projects with a the cpp-library plugin but this is faster.
|
|
def nativeProjects = allprojects.findAll {it.path in [
|
|
":lucene:misc:native"
|
|
]}
|
|
|
|
def javaProjectsWithNativeDeps = allprojects.findAll {it.path in [
|
|
":lucene:misc"
|
|
]}
|
|
|
|
// Set up defaults for projects with native dependencies.
|
|
configure(javaProjectsWithNativeDeps, {
|
|
configurations {
|
|
nativeDeps {
|
|
attributes {
|
|
attributes.attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage.class, Usage.NATIVE_RUNTIME))
|
|
attributes.attribute(CppBinary.OPTIMIZED_ATTRIBUTE, false)
|
|
}
|
|
}
|
|
}
|
|
|
|
plugins.withType(JavaPlugin) {
|
|
ext {
|
|
testOptions += [
|
|
[propName: 'tests.native', value: buildNative, description: "Enable tests that require native extensions."]
|
|
]
|
|
|
|
nativeDepsDir = file("${buildDir}/nativeDeps")
|
|
}
|
|
|
|
// Only copy and attach native deps if native build is enabled.
|
|
if (buildNative && Os.isFamily(Os.FAMILY_WINDOWS)) {
|
|
task copyNativeDeps(type: Sync) {
|
|
from configurations.nativeDeps
|
|
into nativeDepsDir
|
|
}
|
|
|
|
tasks.withType(Test) {
|
|
dependsOn copyNativeDeps
|
|
systemProperty "java.library.path", nativeDepsDir
|
|
}
|
|
}
|
|
}
|
|
})
|
|
|
|
// If native build is disabled we just disable all tasks in the active task set that
|
|
// originate from "native" projects.
|
|
//
|
|
// Perhaps there is a cleaner way to do it but removing their references from
|
|
// settings.gradle would remove them from IDE detection, dependency resolution, etc.
|
|
// This way seems better.
|
|
if (!buildNative) {
|
|
gradle.taskGraph.whenReady { taskGraph ->
|
|
def tasks = taskGraph.getAllTasks()
|
|
tasks.findAll { task -> task.project in nativeProjects }.each { task ->
|
|
task.enabled = false
|
|
}
|
|
}
|
|
}
|