1#!/usr/bin/env bash
2# Copyright (c) Meta Platforms, Inc. and affiliates.
3#
4# This source code is licensed under the MIT license found in the
5# LICENSE file in the root directory of this source tree.
6
7
8function usage {
9  echo "usage: sync-css-layout.sh <pathToGithubRepo> <pathToFbSourceRepo>";
10}
11
12function patchfile {
13  # Add React Native copyright
14  printf "/**\n"  > /tmp/yogasync.tmp
15  printf " * Copyright (c) 2014-present, Facebook, Inc.\n"  >> /tmp/yogasync.tmp
16  printf " *\n" >> /tmp/yogasync.tmp
17  printf " * This source code is licensed under the MIT license found in the\n"  >> /tmp/yogasync.tmp
18  printf " * LICENSE file in the root directory of this source tree.\n"  >> /tmp/yogasync.tmp
19  printf " */\n\n"  >> /tmp/yogasync.tmp
20  printf "// NOTE: this file is auto-copied from https://github.com/facebook/css-layout\n" >> /tmp/yogasync.tmp
21  # The following is split over four lines so Phabricator doesn't think this file is generated
22  printf "// @g" >> /tmp/yogasync.tmp
23  printf "enerated <<S" >> /tmp/yogasync.tmp
24  printf "ignedSource::*O*zOeWoEQle#+L" >> /tmp/yogasync.tmp
25  printf "!plEphiEmie@IsG>>\n\n" >> /tmp/yogasync.tmp
26  tail -n +9 $1 >> /tmp/yogasync.tmp
27  mv /tmp/yogasync.tmp $1
28  "$ROOT"/tools/signedsource.py sign "$1"
29}
30
31if [ -z $1 ]; then
32  usage
33  exit 1
34fi
35
36if [ -z $2 ]; then
37  usage
38  exit 1
39fi
40
41GITHUB=$1
42ROOT=$2
43
44set -e # exit if any command fails
45
46echo "Making github project..."
47pushd $GITHUB
48COMMIT_ID=$(git rev-parse HEAD)
49popd
50
51C_SRC=$GITHUB/src/
52JAVA_SRC=$GITHUB/src/java/src/com/facebook/yoga
53TESTS=$GITHUB/src/java/tests/com/facebook/yoga
54FBA_SRC=$ROOT/xplat/js/react-native-github/ReactAndroid/src/main/java/com/facebook/yoga/
55FBA_TESTS=$ROOT/fbandroid/javatests/com/facebook/yoga/
56FBO_SRC=$ROOT/xplat/js/react-native-github/React/Layout/
57
58echo "Copying fbandroid src files over..."
59cp $JAVA_SRC/*.java $FBA_SRC
60echo "Copying fbandroid test files over..."
61cp $TESTS/*.java $FBA_TESTS
62echo "Copying fbobjc src files over..."
63cp $C_SRC/Layout.{c,h} $FBO_SRC
64
65echo "Patching files..."
66for sourcefile in $FBA_SRC/*.java; do
67  patchfile $sourcefile
68done
69for testfile in $FBA_TESTS/*.java; do
70  patchfile $testfile
71done
72for sourcefile in $FBO_SRC/Layout.{c,h}; do
73  patchfile $sourcefile
74done
75
76echo "Writing README"
77
78echo "The source of truth for css-layout is: https://github.com/facebook/css-layout
79
80The code here should be kept in sync with GitHub.
81HEAD at the time this code was synced: https://github.com/facebook/css-layout/commit/$COMMIT_ID
82
83There is generated code in:
84 - README (this file)
85 - fbandroid/java/com/facebook/yoga
86 - fbandroid/javatests/com/facebook/yoga
87 - xplat/js/react-native-github/React/Layout
88
89The code was generated by running 'make' in the css-layout folder and running:
90
91  scripts/sync-css-layout.sh <pathToGithubRepo> <pathToFbSourceRepo>
92" > /tmp/yogasync.tmp
93
94cp /tmp/yogasync.tmp "$FBA_SRC/README"
95cp /tmp/yogasync.tmp "$FBO_SRC/README"
96