2015-03-31 08:20:39 +08: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 08:42:05 +08:00
|
|
|
"fmt"
|
2015-03-31 08:20:39 +08:00
|
|
|
"path/filepath"
|
2017-09-28 08:42:05 +08:00
|
|
|
"strings"
|
2015-03-31 08:20:39 +08:00
|
|
|
|
2016-05-19 06:37:25 +08:00
|
|
|
"android/soong/android"
|
2015-03-31 08:20:39 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
var resourceExcludes = []string{
|
2015-04-25 06:16:39 +08:00
|
|
|
"**/*.java",
|
|
|
|
"**/package.html",
|
|
|
|
"**/overview.html",
|
|
|
|
"**/.*.swp",
|
|
|
|
"**/.DS_Store",
|
|
|
|
"**/*~",
|
2015-03-31 08:20:39 +08:00
|
|
|
}
|
|
|
|
|
2017-09-28 08:41:35 +08:00
|
|
|
func ResourceDirsToJarArgs(ctx android.ModuleContext,
|
|
|
|
resourceDirs, excludeDirs []string) (args []string, deps android.Paths) {
|
2015-04-25 06:16:39 +08:00
|
|
|
var excludes []string
|
2015-03-31 08:20:39 +08:00
|
|
|
|
2015-07-01 09:15:24 +08:00
|
|
|
for _, exclude := range excludeDirs {
|
2017-10-03 07:57:40 +08:00
|
|
|
excludes = append(excludes,
|
|
|
|
filepath.Join(android.PathForModuleSrc(ctx, exclude).String(), "**/*"))
|
2015-04-25 06:16:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
excludes = append(excludes, resourceExcludes...)
|
|
|
|
|
2017-10-04 05:50:08 +08:00
|
|
|
for _, dir := range resourceDirs {
|
|
|
|
dir := android.PathForModuleSrc(ctx, dir).String()
|
|
|
|
files := ctx.Glob(filepath.Join(dir, "**/*"), excludes)
|
|
|
|
|
|
|
|
deps = append(deps, files...)
|
|
|
|
|
|
|
|
if len(files) > 0 {
|
|
|
|
args = append(args, "-C", dir)
|
|
|
|
|
|
|
|
for _, f := range files {
|
|
|
|
path := f.String()
|
|
|
|
if !strings.HasPrefix(path, dir) {
|
|
|
|
panic(fmt.Errorf("path %q does not start with %q", path, dir))
|
|
|
|
}
|
|
|
|
args = append(args, "-f", path)
|
|
|
|
}
|
2015-04-25 06:16:39 +08:00
|
|
|
}
|
2015-03-31 08:20:39 +08:00
|
|
|
}
|
|
|
|
|
2017-09-28 08:41:35 +08:00
|
|
|
return args, deps
|
2015-03-31 08:20:39 +08:00
|
|
|
}
|
2017-09-28 08:42:05 +08:00
|
|
|
|
2017-10-04 04:14:07 +08: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 08:42:05 +08:00
|
|
|
func ResourceFilesToJarArgs(ctx android.ModuleContext,
|
|
|
|
res, exclude []string) (args []string, deps android.Paths) {
|
2017-10-04 04:14:07 +08: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 08:42:05 +08:00
|
|
|
files := ctx.ExpandSources(res, exclude)
|
|
|
|
|
2017-10-04 05:50:08 +08:00
|
|
|
lastDir := ""
|
|
|
|
for i, f := range files {
|
2017-09-28 08:42:05 +08: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-04 05:50:08 +08:00
|
|
|
dir := filepath.Clean(strings.TrimSuffix(path, rel))
|
|
|
|
if i == 0 || dir != lastDir {
|
|
|
|
args = append(args, "-C", dir)
|
|
|
|
}
|
|
|
|
args = append(args, "-f", path)
|
|
|
|
lastDir = dir
|
2017-09-28 08:42:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return args, files
|
|
|
|
}
|