1 # Copyright 2020 The Pigweed Authors
3 # Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 # use this file except in compliance with the License. You may obtain a copy of
7 # https://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 # License for the specific language governing permissions and limitations under
14 """Installs rust tools using cargo."""
22 def install(install_dir, package_files, env):
23 """Installs rust tools using cargo."""
24 # Adding to PATH at the beginning to suppress a warning about this not
26 env.prepend('PATH', os.path.join(install_dir, 'bin'))
28 if 'CARGO_TARGET_DIR' not in os.environ:
29 env.set('CARGO_TARGET_DIR', os.path.expanduser('~/.cargo-cache'))
32 for package_file in package_files:
33 with open(package_file, 'r') as ins:
36 if not line or line.startswith('#'):
39 package, version = line.split()
43 # If downgrading (which could happen when switching
44 # branches) '--force' is required.
46 '--root', install_dir,
51 # TODO(pwbug/135) Use function from common utility module.
52 with tempfile.TemporaryFile(mode='w+') as temp:
54 subprocess.check_call(cmd,
56 stderr=subprocess.STDOUT)
57 except subprocess.CalledProcessError:
59 sys.stderr.write(temp.read())