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{ |
| 50 | Command: "cp $cpPreserveSymlinks $cpFlags $in $out", |
| 51 | Description: "cp $out", |
| 52 | }, |
| 53 | "cpFlags") |
| 54 | |
Dan Albert | 5d723ab | 2016-07-18 22:29:52 -0700 | [diff] [blame] | 55 | // A timestamp touch rule. |
Colin Cross | 9d45bb7 | 2016-08-29 16:14:13 -0700 | [diff] [blame] | 56 | Touch = pctx.AndroidStaticRule("Touch", |
Dan Albert | 5d723ab | 2016-07-18 22:29:52 -0700 | [diff] [blame] | 57 | blueprint.RuleParams{ |
| 58 | Command: "touch $out", |
| 59 | Description: "touch $out", |
| 60 | }) |
| 61 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 62 | // A symlink rule. |
Colin Cross | 9d45bb7 | 2016-08-29 16:14:13 -0700 | [diff] [blame] | 63 | Symlink = pctx.AndroidStaticRule("Symlink", |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 64 | blueprint.RuleParams{ |
| 65 | Command: "ln -f -s $fromPath $out", |
| 66 | Description: "symlink $out", |
| 67 | }, |
| 68 | "fromPath") |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 69 | |
Colin Cross | 9d45bb7 | 2016-08-29 16:14:13 -0700 | [diff] [blame] | 70 | ErrorRule = pctx.AndroidStaticRule("Error", |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 71 | blueprint.RuleParams{ |
| 72 | Command: `echo "$error" && false`, |
| 73 | Description: "error building $out", |
| 74 | }, |
| 75 | "error") |
Colin Cross | 9d45bb7 | 2016-08-29 16:14:13 -0700 | [diff] [blame] | 76 | |
Dan Albert | c6345fb | 2016-10-20 01:36:11 -0700 | [diff] [blame^] | 77 | Cat = pctx.AndroidStaticRule("Cat", |
| 78 | blueprint.RuleParams{ |
| 79 | Command: "cat $in > $out", |
| 80 | Description: "concatenate licenses $out", |
| 81 | }) |
| 82 | |
Colin Cross | 9d45bb7 | 2016-08-29 16:14:13 -0700 | [diff] [blame] | 83 | // Used only when USE_GOMA=true is set, to restrict non-goma jobs to the local parallelism value |
| 84 | localPool = blueprint.NewBuiltinPool("local_pool") |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 85 | ) |
Dan Willemsen | 24f2f8d | 2015-07-15 14:34:02 -0700 | [diff] [blame] | 86 | |
| 87 | func init() { |
| 88 | pctx.Import("github.com/google/blueprint/bootstrap") |
| 89 | } |