Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 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 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 15 | package android |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 16 | |
| 17 | import ( |
Colin Cross | 70b4059 | 2015-03-23 12:57:34 -0700 | [diff] [blame] | 18 | "github.com/google/blueprint" |
Dan Willemsen | 24f2f8d | 2015-07-15 14:34:02 -0700 | [diff] [blame] | 19 | _ "github.com/google/blueprint/bootstrap" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 20 | ) |
| 21 | |
| 22 | var ( |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 23 | pctx = NewPackageContext("android/soong/common") |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 24 | |
| 25 | cpPreserveSymlinks = pctx.VariableConfigMethod("cpPreserveSymlinks", |
| 26 | Config.CpPreserveSymlinksFlags) |
| 27 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 28 | // A phony rule that is not the built-in Ninja phony rule. The built-in |
| 29 | // phony rule has special behavior that is sometimes not desired. See the |
| 30 | // Ninja docs for more details. |
Colin Cross | 9d45bb7 | 2016-08-29 16:14:13 -0700 | [diff] [blame] | 31 | Phony = pctx.AndroidStaticRule("Phony", |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 32 | blueprint.RuleParams{ |
| 33 | Command: "# phony $out", |
| 34 | Description: "phony $out", |
| 35 | }) |
| 36 | |
| 37 | // GeneratedFile is a rule for indicating that a given file was generated |
| 38 | // while running soong. This allows the file to be cleaned up if it ever |
| 39 | // stops being generated by soong. |
Colin Cross | 9d45bb7 | 2016-08-29 16:14:13 -0700 | [diff] [blame] | 40 | GeneratedFile = pctx.AndroidStaticRule("GeneratedFile", |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 41 | blueprint.RuleParams{ |
| 42 | Command: "# generated $out", |
| 43 | Description: "generated $out", |
| 44 | Generator: true, |
| 45 | }) |
| 46 | |
| 47 | // A copy rule. |
Colin Cross | 9d45bb7 | 2016-08-29 16:14:13 -0700 | [diff] [blame] | 48 | Cp = pctx.AndroidStaticRule("Cp", |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 49 | blueprint.RuleParams{ |
Josh Gao | ae15271 | 2017-07-26 14:09:50 -0700 | [diff] [blame] | 50 | Command: "rm -f $out && cp $cpPreserveSymlinks $cpFlags $in $out", |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 51 | Description: "cp $out", |
| 52 | }, |
| 53 | "cpFlags") |
| 54 | |
Colin Cross | 5c51792 | 2017-08-31 12:29:17 -0700 | [diff] [blame] | 55 | CpExecutable = pctx.AndroidStaticRule("CpExecutable", |
| 56 | blueprint.RuleParams{ |
| 57 | Command: "rm -f $out && cp $cpPreserveSymlinks $cpFlags $in $out && chmod +x $out", |
| 58 | Description: "cp $out", |
| 59 | }, |
| 60 | "cpFlags") |
| 61 | |
Dan Albert | 5d723ab | 2016-07-18 22:29:52 -0700 | [diff] [blame] | 62 | // A timestamp touch rule. |
Colin Cross | 9d45bb7 | 2016-08-29 16:14:13 -0700 | [diff] [blame] | 63 | Touch = pctx.AndroidStaticRule("Touch", |
Dan Albert | 5d723ab | 2016-07-18 22:29:52 -0700 | [diff] [blame] | 64 | blueprint.RuleParams{ |
| 65 | Command: "touch $out", |
| 66 | Description: "touch $out", |
| 67 | }) |
| 68 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 69 | // A symlink rule. |
Colin Cross | 9d45bb7 | 2016-08-29 16:14:13 -0700 | [diff] [blame] | 70 | Symlink = pctx.AndroidStaticRule("Symlink", |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 71 | blueprint.RuleParams{ |
| 72 | Command: "ln -f -s $fromPath $out", |
| 73 | Description: "symlink $out", |
| 74 | }, |
| 75 | "fromPath") |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 76 | |
Colin Cross | 9d45bb7 | 2016-08-29 16:14:13 -0700 | [diff] [blame] | 77 | ErrorRule = pctx.AndroidStaticRule("Error", |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 78 | blueprint.RuleParams{ |
| 79 | Command: `echo "$error" && false`, |
| 80 | Description: "error building $out", |
| 81 | }, |
| 82 | "error") |
Colin Cross | 9d45bb7 | 2016-08-29 16:14:13 -0700 | [diff] [blame] | 83 | |
Dan Albert | c6345fb | 2016-10-20 01:36:11 -0700 | [diff] [blame] | 84 | Cat = pctx.AndroidStaticRule("Cat", |
| 85 | blueprint.RuleParams{ |
| 86 | Command: "cat $in > $out", |
| 87 | Description: "concatenate licenses $out", |
| 88 | }) |
| 89 | |
Nan Zhang | 2700511 | 2017-05-12 14:02:13 -0700 | [diff] [blame] | 90 | // ubuntu 14.04 offcially use dash for /bin/sh, and its builtin echo command |
| 91 | // doesn't support -e option. Therefore we force to use /bin/bash when writing out |
| 92 | // content to file. |
Dan Albert | 30c9d6e | 2017-03-28 14:54:55 -0700 | [diff] [blame] | 93 | WriteFile = pctx.AndroidStaticRule("WriteFile", |
| 94 | blueprint.RuleParams{ |
Nan Zhang | 2700511 | 2017-05-12 14:02:13 -0700 | [diff] [blame] | 95 | Command: "/bin/bash -c 'echo -e $$0 > $out' '$content'", |
Dan Albert | 30c9d6e | 2017-03-28 14:54:55 -0700 | [diff] [blame] | 96 | Description: "writing file $out", |
| 97 | }, |
| 98 | "content") |
| 99 | |
Colin Cross | 9d45bb7 | 2016-08-29 16:14:13 -0700 | [diff] [blame] | 100 | // Used only when USE_GOMA=true is set, to restrict non-goma jobs to the local parallelism value |
| 101 | localPool = blueprint.NewBuiltinPool("local_pool") |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 102 | ) |
Dan Willemsen | 24f2f8d | 2015-07-15 14:34:02 -0700 | [diff] [blame] | 103 | |
| 104 | func init() { |
| 105 | pctx.Import("github.com/google/blueprint/bootstrap") |
| 106 | } |