-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Gradle repository in third_party/android_deps.
- Loading branch information
Showing
19 changed files
with
582 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.gradle/ | ||
.settings/ | ||
buildSrc/.gradle/ | ||
buildSrc/build/ | ||
artifacts/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Copyright (c) 2021 Project CHIP Authors | ||
# | ||
# Licensed 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. | ||
|
||
# === This BUILD file is auto-generated, modify the GnBuildGenerator task instead of editing this file manually. === | ||
|
||
import("//build_overrides/chip.gni") | ||
import("${chip_root}/build/chip/java/rules.gni") | ||
|
||
java_prebuilt("annotation") { | ||
jar_path = "artifacts/annotation-1.1.0.jar" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Third party Android dependencies | ||
|
||
This directory contains files relevant to specifying Android dependencies, | ||
downloading them, and generating GN build targets from them. | ||
|
||
To add a new Android dependency, add a Gradle dependency to the `chipDeps` | ||
configuration in `android_deps.gradle`. Then, run | ||
|
||
```shell | ||
./set_up_android_deps.py | ||
``` | ||
|
||
to download dependencies to `artifacts/`, and generate GN build targets in | ||
`BUILD.gn`. | ||
|
||
The application code can then depend on | ||
`${chip_root}/third_party/android_deps:my_dep`. The target name `my_dep` will be | ||
generated based on the Gradle dependency name. For example, | ||
"androidx.annotation:annotation:1.1.0" in `build.gradle` becomes the target name | ||
"annotation" in `BUILD.gn`. | ||
|
||
Changes to `BUILD.gn` should be committed to the repository, so developers can | ||
track where dependencies lead. `artifacts/` should not, as it contains binaries. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// This file is kept separate from build.gradle, so that the chipDeps configuration it defines can be shared. | ||
|
||
apply plugin: 'base' | ||
|
||
repositories { | ||
google() | ||
mavenCentral() | ||
} | ||
|
||
configurations { | ||
chipDeps | ||
} | ||
|
||
dependencies { | ||
chipDeps "androidx.annotation:annotation:1.1.0" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
apply plugin: 'base' | ||
apply from: 'android_deps.gradle' | ||
|
||
task setUpAndroidDeps(type: GnBuildGenerator) {} | ||
|
||
task copyArtifacts(type: Copy) { | ||
// Defined in android_deps.gradle | ||
from configurations.chipDeps | ||
into 'artifacts' | ||
} | ||
|
||
clean { | ||
delete 'artifacts' | ||
} | ||
|
||
setUpAndroidDeps.dependsOn copyArtifacts |
71 changes: 71 additions & 0 deletions
71
third_party/android_deps/buildSrc/src/main/groovy/GnBuildGenerator.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import java.util.regex.Pattern | ||
import org.gradle.api.DefaultTask | ||
import org.gradle.api.tasks.TaskAction | ||
import org.gradle.api.artifacts.ResolvedDependency | ||
|
||
/** Task that generates a BUILD.gn file based on dependencies in the chipDeps configuration. */ | ||
class GnBuildGenerator extends DefaultTask { | ||
private static final GENERATED_WARNING = | ||
"# === This BUILD file is auto-generated, modify the GnBuildGenerator task instead of editing this file manually. ===" | ||
private static final COPIED_ARTIFACTS_DIR = "artifacts" | ||
private static final ANDROID_DEPS_DIR = "/third_party/android_deps" | ||
|
||
@TaskAction | ||
void main() { | ||
def chipDepsConfiguration = project.configurations.chipDeps | ||
def chipRoot = System.getenv("PW_PROJECT_ROOT"); | ||
def absoluteAndroidDepsDir = "$chipRoot/$ANDROID_DEPS_DIR"; | ||
|
||
def buildFile = new File("$absoluteAndroidDepsDir/BUILD.gn"); | ||
if (!buildFile.exists()) { | ||
buildFile.createNewFile() | ||
} | ||
|
||
def stringBuilder = new StringBuilder() | ||
def copyrightHeader = new File("$absoluteAndroidDepsDir/copyright_header.txt") | ||
stringBuilder.append(copyrightHeader.text + "\n\n") | ||
|
||
stringBuilder.append(GENERATED_WARNING + "\n\n") | ||
|
||
stringBuilder.append("""\ | ||
import("//build_overrides/chip.gni") | ||
import("\${chip_root}/build/chip/java/rules.gni") | ||
""".stripIndent()) | ||
|
||
def allDeps = new HashSet<ResolvedDependency>() | ||
chipDepsConfiguration.resolvedConfiguration.firstLevelModuleDependencies.each { | ||
allDeps += it | ||
it.children.each { | ||
allDeps += it | ||
} | ||
} | ||
|
||
allDeps.each { | ||
def artifact = it.moduleArtifacts[0] | ||
if (it.moduleArtifacts.size() > 1 || artifact.extension != "jar") { | ||
throw new IllegalStateException( | ||
"Multiple top-level module artifacts or unsupported" | ||
+ " artifact extension (artifact count = $it.moduleArtifacts.size(), extension" | ||
+ " = $artifact.extension).") | ||
} | ||
|
||
def deps = [] | ||
it.children.each { | ||
deps += "\":$it.module.id.name\"" | ||
} | ||
|
||
stringBuilder.append("\n") | ||
stringBuilder.append("""\ | ||
java_prebuilt("$it.module.id.name") { | ||
jar_path = "$COPIED_ARTIFACTS_DIR/${artifact.file.name}" | ||
""".stripIndent()) | ||
|
||
if (!deps.isEmpty()) { | ||
stringBuilder.append(" deps = $deps\n") | ||
} | ||
stringBuilder.append("}\n") | ||
} | ||
|
||
buildFile.write(stringBuilder.toString()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Copyright (c) 2021 Project CHIP Authors | ||
# | ||
# Licensed 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. |
Binary file not shown.
5 changes: 5 additions & 0 deletions
5
third_party/android_deps/gradle/wrapper/gradle-wrapper.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
Oops, something went wrong.