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
|
|
|
}
|
|
|
|
|
2017-09-28 02:41:35 +02:00
|
|
|
func ResourceDirsToJarArgs(ctx android.ModuleContext,
|
2018-09-13 20:26:19 +02:00
|
|
|
resourceDirs, excludeResourceDirs, excludeResourceFiles []string) (args []string, deps android.Paths) {
|
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 {
|
|
|
|
dirs := ctx.Glob(android.PathForModuleSrc(ctx).Join(ctx, exclude).String(), nil)
|
|
|
|
for _, dir := range dirs {
|
|
|
|
excludeDirs = append(excludeDirs, dir.String())
|
|
|
|
excludeFiles = append(excludeFiles, dir.(android.ModuleSrcPath).Join(ctx, "**/*").String())
|
|
|
|
}
|
2015-04-25 00:16:39 +02:00
|
|
|
}
|
|
|
|
|
2018-09-13 20:26:19 +02:00
|
|
|
excludeFiles = append(excludeFiles, ctx.ExpandSources(excludeResourceFiles, nil).Strings()...)
|
|
|
|
|
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
|
|
|
|
dirs := ctx.Glob(android.PathForModuleSrc(ctx).Join(ctx, resourceDir).String(), excludeDirs)
|
|
|
|
for _, dir := range dirs {
|
|
|
|
files := ctx.GlobFiles(filepath.Join(dir.String(), "**/*"), excludeFiles)
|
2017-10-03 23:50:08 +02:00
|
|
|
|
2018-04-10 22:07:42 +02:00
|
|
|
deps = append(deps, files...)
|
2017-10-03 23:50:08 +02:00
|
|
|
|
2018-04-10 22:07:42 +02:00
|
|
|
if len(files) > 0 {
|
|
|
|
args = append(args, "-C", dir.String())
|
2017-10-03 23:50:08 +02:00
|
|
|
|
2018-04-10 22:07:42 +02:00
|
|
|
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))
|
|
|
|
}
|
2018-09-19 02:05:15 +02:00
|
|
|
args = append(args, "-f", pathtools.MatchEscape(path))
|
2017-10-03 23:50:08 +02:00
|
|
|
}
|
|
|
|
}
|
2015-04-25 00:16:39 +02: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)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Convert java_resources properties to arguments to soong_zip -jar, keeping files that should
|
|
|
|
// normally not used as resources like *.java
|
|
|
|
func SourceFilesToJarArgs(ctx android.ModuleContext,
|
|
|
|
res, exclude []string) (args []string, deps android.Paths) {
|
|
|
|
|
|
|
|
return resourceFilesToJarArgs(ctx, res, exclude)
|
|
|
|
}
|
|
|
|
|
|
|
|
func resourceFilesToJarArgs(ctx android.ModuleContext,
|
|
|
|
res, exclude []string) (args []string, deps android.Paths) {
|
|
|
|
|
2017-09-28 02:42:05 +02:00
|
|
|
files := ctx.ExpandSources(res, exclude)
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
return args, files
|
|
|
|
}
|