xref: /aosp_15_r20/build/soong/android/defs.go (revision 333d2b3687b3a337dbcca9d65000bca186795e39)
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
15package android
16
17import (
18	"github.com/google/blueprint"
19)
20
21var (
22	pctx = NewPackageContext("android/soong/android")
23
24	cpPreserveSymlinks = pctx.VariableConfigMethod("cpPreserveSymlinks",
25		Config.CpPreserveSymlinksFlags)
26
27	// A phony rule that is not the built-in Ninja phony rule.  The built-in
28	// phony rule has special behavior that is sometimes not desired.  See the
29	// Ninja docs for more details.
30	Phony = pctx.AndroidStaticRule("Phony",
31		blueprint.RuleParams{
32			Command:     "# phony $out",
33			Description: "phony $out",
34		})
35
36	// GeneratedFile is a rule for indicating that a given file was generated
37	// while running soong.  This allows the file to be cleaned up if it ever
38	// stops being generated by soong.
39	GeneratedFile = pctx.AndroidStaticRule("GeneratedFile",
40		blueprint.RuleParams{
41			Command:     "# generated $out",
42			Description: "generated $out",
43			Generator:   true,
44		})
45
46	// A copy rule.
47	Cp = pctx.AndroidStaticRule("Cp",
48		blueprint.RuleParams{
49			Command:     "rm -f $out && cp $cpPreserveSymlinks $cpFlags $in $out$extraCmds",
50			Description: "cp $out",
51		},
52		"cpFlags", "extraCmds")
53
54	// A copy rule that doesn't preserve symlinks.
55	CpNoPreserveSymlink = pctx.AndroidStaticRule("CpNoPreserveSymlink",
56		blueprint.RuleParams{
57			Command:     "rm -f $out && cp $cpFlags $in $out$extraCmds",
58			Description: "cp $out",
59		},
60		"cpFlags", "extraCmds")
61
62	// A copy rule that only updates the output if it changed.
63	CpIfChanged = pctx.AndroidStaticRule("CpIfChanged",
64		blueprint.RuleParams{
65			Command:     "if ! cmp -s $in $out; then cp $in $out; fi",
66			Description: "cp if changed $out",
67			Restat:      true,
68		})
69
70	CpExecutable = pctx.AndroidStaticRule("CpExecutable",
71		blueprint.RuleParams{
72			Command:     "rm -f $out && cp $cpFlags $in $out && chmod +x $out$extraCmds",
73			Description: "cp $out",
74		},
75		"cpFlags", "extraCmds")
76
77	// A timestamp touch rule.
78	Touch = pctx.AndroidStaticRule("Touch",
79		blueprint.RuleParams{
80			Command:     "touch $out",
81			Description: "touch $out",
82		})
83
84	// A symlink rule.
85	Symlink = pctx.AndroidStaticRule("Symlink",
86		blueprint.RuleParams{
87			Command:     "rm -f $out && ln -f -s $fromPath $out",
88			Description: "symlink $out",
89		},
90		"fromPath")
91
92	ErrorRule = pctx.AndroidStaticRule("Error",
93		blueprint.RuleParams{
94			Command:     `echo "$error" && false`,
95			Description: "error building $out",
96		},
97		"error")
98
99	Cat = pctx.AndroidStaticRule("Cat",
100		blueprint.RuleParams{
101			Command:     "rm -f $out && cat $in > $out",
102			Description: "concatenate files to $out",
103		})
104
105	// Used only when USE_GOMA=true is set, to restrict non-goma jobs to the local parallelism value
106	localPool = blueprint.NewBuiltinPool("local_pool")
107
108	// Used only by RuleBuilder to identify remoteable rules. Does not actually get created in ninja.
109	remotePool = blueprint.NewBuiltinPool("remote_pool")
110
111	// Used for processes that need significant RAM to ensure there are not too many running in parallel.
112	highmemPool = blueprint.NewBuiltinPool("highmem_pool")
113)
114
115func init() {
116	pctx.Import("github.com/google/blueprint/bootstrap")
117
118	pctx.VariableFunc("RBEWrapper", func(ctx PackageVarContext) string {
119		return ctx.Config().RBEWrapper()
120	})
121}
122