| // Versions that we are building. |
| Properties properties = new Properties() |
| File versionRootDir = rootDir |
| String relativeVersionPath = "base/common/release_version.bzl" |
| File versionProperties = new File(versionRootDir, relativeVersionPath) |
| |
| project.ext['versionProperties'] = versionProperties |
| |
| while (!versionProperties.exists() && versionRootDir.parentFile != null && |
| versionRootDir.parentFile.exists()) { |
| versionRootDir = versionRootDir.parentFile |
| versionProperties = new File(versionRootDir, relativeVersionPath) |
| } |
| |
| versionProperties.withReader { properties.load(it) } |
| |
| String releaseProperty = project.providers.gradleProperty("release").getOrElse("false") |
| boolean release = releaseProperty.equalsIgnoreCase("true") |
| if (!release && !releaseProperty.equalsIgnoreCase("false")) throw new IllegalStateException("Expected release property to be true or false, but was '$releaseProperty'") |
| |
| String nextMajorProperty = project.providers.gradleProperty("nextMajor").getOrElse("false") |
| boolean nextMajor = nextMajorProperty.equalsIgnoreCase("true") |
| if (!nextMajor && !nextMajorProperty.equalsIgnoreCase("false")) throw new IllegalStateException("Expected release property to be true or false, but was '$nextMajorProperty'") |
| |
| String releaseBaseVersion = properties.getProperty('BASE_VERSION') - '"' - '"' |
| String releaseBuildVersion = properties.getProperty('BUILD_VERSION') - '"' - '"' |
| |
| String dev(String release) { |
| release.split('-')[0] + '-dev' |
| } |
| |
| String bazelBaseVersion = release ? releaseBaseVersion : dev(releaseBaseVersion) |
| project.ext['baseVersion'] = bazelBaseVersion |
| |
| String bazelBuildVersion = release ? releaseBuildVersion : dev(releaseBuildVersion) |
| |
| String baseMajorVersionString = bazelBaseVersion.split('\\.')[0] |
| int currentMajor = baseMajorVersionString.toInteger() |
| |
| int nextMajorIncrementedValue = currentMajor + 1 |
| |
| project.ext['buildVersion'] = nextMajor ? "${nextMajorIncrementedValue}.0.0-dev" : (bazelBuildVersion) |
| |
| project.ext['releaseBuildVersion'] = releaseBuildVersion |
| // This will be replaced with a dependency catalog soon. |
| |
| // Deep copy the dependency map to give more helpful error messages, |
| private Map<String, ?> dependencyMapOf(Map<String, ?> sourceMap, prefix) { |
| Map<String, ?> dependencyMap = [:].withDefault { |
| key -> throw new IllegalArgumentException('"' + prefix + key + '" is not a valid dependency.\nDependencies ' + libs.keySet()) |
| } |
| sourceMap.each { |
| if (it.value instanceof Map) { |
| dependencyMap[it.key] = dependencyMapOf(it.value, it.key + ".") |
| } else if (it.value instanceof String || it.value instanceof Provider || it.value instanceof FileCollection) { |
| dependencyMap[it.key] = it.value |
| } else { |
| throw new IllegalArgumentException('"' + prefix + it.key + '" is not a valid dependency type.') |
| } |
| } |
| return Collections.unmodifiableMap(dependencyMap) |
| } |
| |
| // Add ext.libs for library versions |
| Properties dependencies = new Properties() |
| File dependenciesProperties = new File(versionRootDir, "buildSrc/base/dependencies.properties") |
| dependenciesProperties.withReader { dependencies.load(it) } |
| Map<String, ?> libs = [:] |
| |
| // TODO(b/143864616): These will be replaced by a version catalog |
| libs['versions'] = [ |
| 'base': provider { project.ext['baseVersion'] }, |
| 'build': provider { bazelBuildVersion } |
| ] |
| for (name in dependencies.stringPropertyNames()) { |
| // Use . separated names in preparation for migration to a version catalog |
| Iterator<String> paths = Arrays.asList(name.split('_')).iterator() |
| Map<String, ?> sub = libs |
| while (paths.hasNext()) { |
| String path = paths.next() |
| if (!paths.hasNext()) { |
| // TODO(b/143864616): switch to version catalog |
| sub[path] = dependencies.getProperty(name).replace(':buildVersion', ':' + libs.versions.build.get()).replace(':baseVersion', ':' + libs.versions.base.get()) |
| continue |
| } |
| if (sub[path] == null) sub[path] = [:] |
| if (!(sub[path] instanceof Map)) { |
| break |
| } // Ignore clashing foo_sub if there's a dependency foo |
| sub = sub[path] |
| } |
| // The old way |
| if (name.contains('_')) { |
| libs[name] = dependencies.getProperty(name) |
| } |
| } |
| rootProject.ext['libs'] = dependencyMapOf(libs, "") |
| |
| |
| Map<String, FileCollection> externalTestFixtures = [:] |
| |
| externalTestFixtures['common'] = files("$rootDir/../bazel-bin/tools/base/common/libtools.fixtures.jar") |
| externalTestFixtures['repository'] = files("$rootDir/../bazel-bin/tools/base/repository/libtools.testlib.jar") |
| externalTestFixtures['apkanalyzer'] = files("$rootDir/../bazel-bin/tools/base/apkparser/cli/libtools.analyzer-cli.jar") |
| |
| ext['externalTestFixtures'] = dependencyMapOf(externalTestFixtures, "") |