build codesign cipd pkg (#1901)

diff --git a/codesign/LICENSE b/codesign/LICENSE
new file mode 100644
index 0000000..5f65eeb
--- /dev/null
+++ b/codesign/LICENSE
@@ -0,0 +1,25 @@
+Copyright 2019 The Flutter Authors. All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+    * Redistributions of source code must retain the above copyright
+      notice, this list of conditions and the following disclaimer.
+    * Redistributions in binary form must reproduce the above
+      copyright notice, this list of conditions and the following
+      disclaimer in the documentation and/or other materials provided
+      with the distribution.
+    * Neither the name of Google Inc. nor the names of its
+      contributors may be used to endorse or promote products derived
+      from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\ No newline at end of file
diff --git a/codesign/README.md b/codesign/README.md
index 64a9995..ddf6353 100644
--- a/codesign/README.md
+++ b/codesign/README.md
@@ -1 +1,53 @@
-A standalone tool to codesign Mac engine binaries.
\ No newline at end of file
+# codesign
+
+A standalone tool to codesign Mac engine binaries.
+
+## Building
+
+This tool is meant to be published as an
+[AOT compiled binary](https://chrome-infra-packages.appspot.com/p/flutter/codesign)
+distributed via CIPD.
+
+Build the tool for different host platforms on corresponding machines. It will
+automatically download a suitable version of Dart to build the binary.
+
+To create the CIPD package, make sure that the `build/` folder does not exist.
+
+### Auto build
+
+Every new commit will trigger pre-submit builders to auto build a new version
+for different platforms without any tag/ref.
+
+When a new commit is submitted, post-submit builders will trigger a new version
+with a tag of `commit_sha`, and a ref of `staging`.
+
+### Manual build
+
+Running `tool/build.sh` will build an executable binary in
+the `build` folder. Then push to cipd by running
+
+```bash
+cipd create -in build                   \
+  -name flutter/device_doctor/<os>-amd64 \
+  -ref <ref>                     \
+  -tag sha_timestamp:<revision>_<timestamp>
+```
+
+* os: `linux`, `mac`, or `windows`.
+* ref: `release` or `staging`
+
+## How to use
+
+`codesign` is the executable binary, and can be called
+
+```bash
+/path/to/codesign --commit <commit_sha> (--production)
+--filepath <darwin-x64/FlutterMacOS.framework.zip>
+--filepath <ios/artifacts.zip>
+--filepath <more_file_path>
+```
+
+Use `/path/to/codesign --help` to learn more.
+
+**Note**: Do not add the --production flag unless the binaries are
+intended to be uploaded back to Google Cloud Storage.
\ No newline at end of file
diff --git a/codesign/pubspec.lock b/codesign/pubspec.lock
index 5476789..1d265fe 100644
--- a/codesign/pubspec.lock
+++ b/codesign/pubspec.lock
@@ -324,4 +324,4 @@
     source: hosted
     version: "3.1.1"
 sdks:
-  dart: ">=2.18.0-170.0.dev <3.0.0"
+  dart: ">=2.17.0-266.1.beta <3.0.0"
diff --git a/codesign/pubspec.yaml b/codesign/pubspec.yaml
index d34a1bd..4f3240d 100644
--- a/codesign/pubspec.yaml
+++ b/codesign/pubspec.yaml
@@ -4,7 +4,7 @@
 homepage: https://github.com/flutter/cocoon
 
 environment:
-  sdk: '>=2.18.0-170.0.dev <3.0.0'
+  sdk: '>=2.17.0-266.1.beta <3.0.0'
 
 dev_dependencies:
   lints: ^2.0.0
diff --git a/codesign/tool/build.sh b/codesign/tool/build.sh
new file mode 100644
index 0000000..e95784b
--- /dev/null
+++ b/codesign/tool/build.sh
@@ -0,0 +1,36 @@
+#!/bin/bash
+# Copyright 2019 The Flutter Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+# Fetches corresponding dart sdk from CIPD for different platforms, builds
+# an executable binary of codesign to `build` folder.
+#
+# This build script will be triggered on Mac code signing machines. 
+
+set -e
+
+command -v cipd > /dev/null || {
+  echo "Please install CIPD (available from depot_tools) and add to path first.";
+  exit -1;
+}
+
+DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd)"
+OS="`uname`"
+
+cipd ensure -ensure-file $DIR/ensure_file -root $DIR
+
+pushd $DIR/..
+
+if [[ -d "build" ]]; then
+  echo "Please remove the build directory before proceeding"
+  exit -1
+fi
+
+mkdir -p build
+tool/dart-sdk/bin/dart pub get
+tool/dart-sdk/bin/dart compile exe bin/codesign.dart -o build/codesign
+
+cp -f LICENSE build/
+
+popd
diff --git a/codesign/tool/ensure_file b/codesign/tool/ensure_file
new file mode 100644
index 0000000..a6985f8
--- /dev/null
+++ b/codesign/tool/ensure_file
@@ -0,0 +1,3 @@
+$ServiceURL https://chrome-infra-packages.appspot.com/
+
+dart/dart-sdk/${os}-${arch} beta