2015-03-31 02:20:39 +02:00
|
|
|
// Copyright 2015 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
package java
|
|
|
|
|
|
|
|
import (
|
2017-09-28 02:42:05 +02:00
|
|
|
"fmt"
|
2015-03-31 02:20:39 +02:00
|
|
|
"path/filepath"
|
2017-09-28 02:42:05 +02:00
|
|
|
"strings"
|
2015-03-31 02:20:39 +02:00
|
|
|
|
2018-09-19 02:05:15 +02:00
|
|
|
"github.com/google/blueprint/pathtools"
|
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
"android/soong/android"
|
2015-03-31 02:20:39 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
var resourceExcludes = []string{
|
2015-04-25 00:16:39 +02:00
|
|
|
"**/*.java",
|
|
|
|
"**/package.html",
|
|
|
|
"**/overview.html",
|
|
|
|
"**/.*.swp",
|
|
|
|
"**/.DS_Store",
|
|
|
|
"**/*~",
|
2015-03-31 02:20:39 +02:00
|
|
|
}
|
|
|
|
|
2022-03-23 21:20:42 +01:00
|
|
|
type resourceDeps struct {
|
|
|
|
dir android.Path
|
|
|
|
files android.Paths
|
|
|
|
}
|
|
|
|
|
|
|
|
func ResourceDirsToFiles(ctx android.BaseModuleContext,
|
|
|
|
resourceDirs, excludeResourceDirs, excludeResourceFiles []string) (deps []resourceDeps) {
|
2018-04-10 22:07:42 +02:00
|
|
|
var excludeDirs []string
|
|
|
|
var excludeFiles []string
|
2015-03-31 02:20:39 +02:00
|
|
|
|
2018-04-10 22:07:42 +02:00
|
|
|
for _, exclude := range excludeResourceDirs {
|
2019-03-05 21:46:40 +01:00
|
|
|
dirs := ctx.Glob(android.PathForSource(ctx, ctx.ModuleDir()).Join(ctx, exclude).String(), nil)
|
2018-04-10 22:07:42 +02:00
|
|
|
for _, dir := range dirs {
|
|
|
|
excludeDirs = append(excludeDirs, dir.String())
|
2019-03-05 21:46:40 +01:00
|
|
|
excludeFiles = append(excludeFiles, dir.(android.SourcePath).Join(ctx, "**/*").String())
|
2018-04-10 22:07:42 +02:00
|
|
|
}
|
2015-04-25 00:16:39 +02:00
|
|
|
}
|
|
|
|
|
2019-03-06 07:25:09 +01:00
|
|
|
excludeFiles = append(excludeFiles, android.PathsForModuleSrc(ctx, excludeResourceFiles).Strings()...)
|
2018-09-13 20:26:19 +02:00
|
|
|
|
2018-04-10 22:07:42 +02:00
|
|
|
excludeFiles = append(excludeFiles, resourceExcludes...)
|
2015-04-25 00:16:39 +02:00
|
|
|
|
2018-04-10 22:07:42 +02:00
|
|
|
for _, resourceDir := range resourceDirs {
|
|
|
|
// resourceDir may be a glob, resolve it first
|
2019-03-05 21:46:40 +01:00
|
|
|
dirs := ctx.Glob(android.PathForSource(ctx, ctx.ModuleDir()).Join(ctx, resourceDir).String(), excludeDirs)
|
2018-04-10 22:07:42 +02:00
|
|
|
for _, dir := range dirs {
|
|
|
|
files := ctx.GlobFiles(filepath.Join(dir.String(), "**/*"), excludeFiles)
|
2022-03-23 21:20:42 +01:00
|
|
|
deps = append(deps, resourceDeps{
|
|
|
|
dir: dir,
|
|
|
|
files: files,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2017-10-03 23:50:08 +02:00
|
|
|
|
2022-03-23 21:20:42 +01:00
|
|
|
return deps
|
|
|
|
}
|
|
|
|
|
|
|
|
func ResourceDirsToJarArgs(ctx android.ModuleContext,
|
|
|
|
resourceDirs, excludeResourceDirs, excludeResourceFiles []string) (args []string, deps android.Paths) {
|
|
|
|
resDeps := ResourceDirsToFiles(ctx, resourceDirs, excludeResourceDirs, excludeResourceFiles)
|
2017-10-03 23:50:08 +02:00
|
|
|
|
2022-03-23 21:20:42 +01:00
|
|
|
for _, resDep := range resDeps {
|
|
|
|
dir, files := resDep.dir, resDep.files
|
2017-10-03 23:50:08 +02:00
|
|
|
|
2022-03-23 21:20:42 +01:00
|
|
|
if len(files) > 0 {
|
|
|
|
args = append(args, "-C", dir.String())
|
|
|
|
deps = append(deps, files...)
|
|
|
|
|
|
|
|
for _, f := range files {
|
|
|
|
path := f.String()
|
|
|
|
if !strings.HasPrefix(path, dir.String()) {
|
|
|
|
panic(fmt.Errorf("path %q does not start with %q", path, dir))
|
2017-10-03 23:50:08 +02:00
|
|
|
}
|
2022-03-23 21:20:42 +01:00
|
|
|
args = append(args, "-f", pathtools.MatchEscape(path))
|
2017-10-03 23:50:08 +02:00
|
|
|
}
|
2015-04-25 00:16:39 +02:00
|
|
|
}
|
2022-03-23 21:20:42 +01:00
|
|
|
|
2015-03-31 02:20:39 +02:00
|
|
|
}
|
|
|
|
|
2017-09-28 02:41:35 +02:00
|
|
|
return args, deps
|
2015-03-31 02:20:39 +02:00
|
|
|
}
|
2017-09-28 02:42:05 +02:00
|
|
|
|
2017-10-03 22:14:07 +02:00
|
|
|
// Convert java_resources properties to arguments to soong_zip -jar, ignoring common patterns
|
|
|
|
// that should not be treated as resources (including *.java).
|
2017-09-28 02:42:05 +02:00
|
|
|
func ResourceFilesToJarArgs(ctx android.ModuleContext,
|
|
|
|
res, exclude []string) (args []string, deps android.Paths) {
|
2017-10-03 22:14:07 +02:00
|
|
|
|
|
|
|
exclude = append([]string(nil), exclude...)
|
|
|
|
exclude = append(exclude, resourceExcludes...)
|
|
|
|
return resourceFilesToJarArgs(ctx, res, exclude)
|
|
|
|
}
|
|
|
|
|
|
|
|
func resourceFilesToJarArgs(ctx android.ModuleContext,
|
|
|
|
res, exclude []string) (args []string, deps android.Paths) {
|
|
|
|
|
2019-03-06 07:25:09 +01:00
|
|
|
files := android.PathsForModuleSrcExcludes(ctx, res, exclude)
|
2017-09-28 02:42:05 +02:00
|
|
|
|
2019-05-06 23:04:11 +02:00
|
|
|
args = resourcePathsToJarArgs(files)
|
|
|
|
|
|
|
|
return args, files
|
|
|
|
}
|
|
|
|
|
|
|
|
func resourcePathsToJarArgs(files android.Paths) []string {
|
|
|
|
var args []string
|
|
|
|
|
2017-10-03 23:50:08 +02:00
|
|
|
lastDir := ""
|
|
|
|
for i, f := range files {
|
2017-09-28 02:42:05 +02:00
|
|
|
rel := f.Rel()
|
|
|
|
path := f.String()
|
|
|
|
if !strings.HasSuffix(path, rel) {
|
|
|
|
panic(fmt.Errorf("path %q does not end with %q", path, rel))
|
|
|
|
}
|
2017-10-03 23:50:08 +02:00
|
|
|
dir := filepath.Clean(strings.TrimSuffix(path, rel))
|
|
|
|
if i == 0 || dir != lastDir {
|
|
|
|
args = append(args, "-C", dir)
|
|
|
|
}
|
2018-09-19 02:05:15 +02:00
|
|
|
args = append(args, "-f", pathtools.MatchEscape(path))
|
2017-10-03 23:50:08 +02:00
|
|
|
lastDir = dir
|
2017-09-28 02:42:05 +02:00
|
|
|
}
|
|
|
|
|
2019-05-06 23:04:11 +02:00
|
|
|
return args
|
2017-09-28 02:42:05 +02:00
|
|
|
}
|