github.com/westcoastroms/westcoastroms-build@v0.0.0-20190928114312-2350e5a73030/build/soong/java/gen.go (about)

     1  // Copyright 2015 Google Inc. All rights reserved.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package java
    16  
    17  // This file generates the final rules for compiling all C/C++.  All properties related to
    18  // compiling should have been translated into builderFlags or another argument to the Transform*
    19  // functions.
    20  
    21  import (
    22  	"github.com/google/blueprint"
    23  
    24  	"android/soong/android"
    25  )
    26  
    27  func init() {
    28  	pctx.HostBinToolVariable("aidlCmd", "aidl")
    29  	pctx.SourcePathVariable("logtagsCmd", "build/tools/java-event-log-tags.py")
    30  	pctx.SourcePathVariable("mergeLogtagsCmd", "build/tools/merge-event-log-tags.py")
    31  }
    32  
    33  var (
    34  	aidl = pctx.AndroidStaticRule("aidl",
    35  		blueprint.RuleParams{
    36  			Command:     "$aidlCmd -d$depFile $aidlFlags $in $out",
    37  			CommandDeps: []string{"$aidlCmd"},
    38  		},
    39  		"depFile", "aidlFlags")
    40  
    41  	logtags = pctx.AndroidStaticRule("logtags",
    42  		blueprint.RuleParams{
    43  			Command:     "$logtagsCmd -o $out $in",
    44  			CommandDeps: []string{"$logtagsCmd"},
    45  		})
    46  
    47  	mergeLogtags = pctx.AndroidStaticRule("mergeLogtags",
    48  		blueprint.RuleParams{
    49  			Command:     "$mergeLogtagsCmd -o $out $in",
    50  			CommandDeps: []string{"$mergeLogtagsCmd"},
    51  		})
    52  )
    53  
    54  func genAidl(ctx android.ModuleContext, aidlFile android.Path, aidlFlags string) android.Path {
    55  	javaFile := android.GenPathWithExt(ctx, "aidl", aidlFile, "java")
    56  	depFile := javaFile.String() + ".d"
    57  
    58  	ctx.Build(pctx, android.BuildParams{
    59  		Rule:        aidl,
    60  		Description: "aidl " + aidlFile.Rel(),
    61  		Output:      javaFile,
    62  		Input:       aidlFile,
    63  		Args: map[string]string{
    64  			"depFile":   depFile,
    65  			"aidlFlags": aidlFlags,
    66  		},
    67  	})
    68  
    69  	return javaFile
    70  }
    71  
    72  func genLogtags(ctx android.ModuleContext, logtagsFile android.Path) android.Path {
    73  	javaFile := android.GenPathWithExt(ctx, "logtags", logtagsFile, "java")
    74  
    75  	ctx.Build(pctx, android.BuildParams{
    76  		Rule:        logtags,
    77  		Description: "logtags " + logtagsFile.Rel(),
    78  		Output:      javaFile,
    79  		Input:       logtagsFile,
    80  	})
    81  
    82  	return javaFile
    83  }
    84  
    85  func (j *Module) genSources(ctx android.ModuleContext, srcFiles android.Paths,
    86  	flags javaBuilderFlags) android.Paths {
    87  
    88  	outSrcFiles := make(android.Paths, 0, len(srcFiles))
    89  
    90  	for _, srcFile := range srcFiles {
    91  		switch srcFile.Ext() {
    92  		case ".aidl":
    93  			javaFile := genAidl(ctx, srcFile, flags.aidlFlags)
    94  			outSrcFiles = append(outSrcFiles, javaFile)
    95  		case ".logtags":
    96  			j.logtagsSrcs = append(j.logtagsSrcs, srcFile)
    97  			javaFile := genLogtags(ctx, srcFile)
    98  			outSrcFiles = append(outSrcFiles, javaFile)
    99  		case ".proto":
   100  			srcJarFile := genProto(ctx, srcFile, flags)
   101  			outSrcFiles = append(outSrcFiles, srcJarFile)
   102  		default:
   103  			outSrcFiles = append(outSrcFiles, srcFile)
   104  		}
   105  	}
   106  
   107  	return outSrcFiles
   108  }
   109  
   110  func LogtagsSingleton() android.Singleton {
   111  	return &logtagsSingleton{}
   112  }
   113  
   114  type logtagsProducer interface {
   115  	logtags() android.Paths
   116  }
   117  
   118  type logtagsSingleton struct{}
   119  
   120  func (l *logtagsSingleton) GenerateBuildActions(ctx android.SingletonContext) {
   121  	var allLogtags android.Paths
   122  	ctx.VisitAllModules(func(module android.Module) {
   123  		if logtags, ok := module.(logtagsProducer); ok {
   124  			allLogtags = append(allLogtags, logtags.logtags()...)
   125  		}
   126  	})
   127  
   128  	ctx.Build(pctx, android.BuildParams{
   129  		Rule:        mergeLogtags,
   130  		Description: "merge logtags",
   131  		Output:      android.PathForIntermediates(ctx, "all-event-log-tags.txt"),
   132  		Inputs:      allLogtags,
   133  	})
   134  }