Files
react-native/packages/react-native-codegen/scripts/oss/build.sh
T
Igor Klemenski 5dc15222b2 Fix building RN Android from source on Windows. (#30535)
Summary:
Running `.\gradlew installArchives` is currently broken on Windows. This is because .sh scripts were added in the codegen module, which cannot be run by the Command Prompt on Windows. It can be worked around by installing eg. Git Bash., which can be then leveraged using the code modifications in this PR, which include sanitizing mixed Linux-Windows relative paths, and other minor Windows-specific adjustments.

It's required that the user adds a Windows Environment variable storing the path to their bash binary named `REACT_WINDOWS_BASH`.

Pair-programmed with davinci26
## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://github.com/facebook/react-native/wiki/Changelog
-->

[Android] [Fix] - Fix building React Android on Windows.

Fixes https://github.com/facebook/react-native/issues/30271

Pull Request resolved: https://github.com/facebook/react-native/pull/30535

Reviewed By: ShikaSD

Differential Revision: D25909760

Pulled By: appden

fbshipit-source-id: ea0e6e7c161a5e4a937d46e8e6972ce142fead4e
2021-01-28 11:53:56 -08:00

62 lines
1.9 KiB
Bash
Executable File

#!/bin/bash
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
# This script assumes yarn is already installed.
THIS_DIR=$(cd -P "$(dirname "$(readlink "${BASH_SOURCE[0]}" || echo "${BASH_SOURCE[0]}")")" && pwd)
set -e
set -u
CODEGEN_DIR="$THIS_DIR/../.."
rm -rf "${CODEGEN_DIR:?}/lib" "${CODEGEN_DIR:?}/node_modules"
# Fallback to npm if yarn is not available
if [ -x "$(command -v yarn)" ]; then
YARN_OR_NPM=$(command -v yarn)
else
YARN_OR_NPM=$(command -v npm)
fi
YARN_BINARY="${YARN_BINARY:-$YARN_OR_NPM}"
if [[ ${FBSOURCE_ENV:-0} -eq 1 ]]; then
# Custom FB-specific setup
pushd "$CODEGEN_DIR" >/dev/null
"$YARN_BINARY" install 2> >(grep -v '^warning' 1>&2)
# Note: Within FBSOURCE_ENV, this has to explicitly run build.
"$YARN_BINARY" run build
popd >/dev/null
else
# Run yarn install in a separate tmp dir to avoid conflict with the rest of the repo.
# Note: OSS-only.
TMP_DIR=$(mktemp -d)
# On Windows this script gets run by a seprate Git Bash instance, which cannot perform the copy
# due to file locks created by the host process. Need to exclude .lock files while copying.
# Using in-memory tar operation because piping `find` and `grep` doesn't preserve folder structure
# during recursive copying, and `rsync` is not installed by default in Git Bash.
# As an added benefit, blob copy is faster.
if [ "$OSTYPE" = "msys" ] || [ "$OSTYPE" = "cygwin" ]; then
tar cf - --exclude='*.lock' "$CODEGEN_DIR" | (cd "$TMP_DIR" && tar xvf - );
else
cp -R "$CODEGEN_DIR/." "$TMP_DIR";
fi
pushd "$TMP_DIR" >/dev/null
# Note: this automatically runs build as well.
"$YARN_BINARY" install 2> >(grep -v '^warning' 1>&2)
popd >/dev/null
mv "$TMP_DIR/lib" "$TMP_DIR/node_modules" "$CODEGEN_DIR"
rm -rf "$TMP_DIR"
fi