Skip to content

Commit

Permalink
Reorganize the directory structure to better support proposals.
Browse files Browse the repository at this point in the history
Following the organization sketched out here:

WebAssembly#360

This PR adds several new directories and starts a work-in-progress
make-snapshot.sh script for creating snapshots.

The `phases` directory is not yet removed; that can happen once
we've transitioned everything to the new organization.
  • Loading branch information
sunfishcode committed Jan 13, 2021
1 parent 8deb71d commit a333ebe
Show file tree
Hide file tree
Showing 6 changed files with 195 additions and 0 deletions.
4 changes: 4 additions & 0 deletions proposal-template/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Proposal template

This directory will hold a template for creating new proposals, to help people
get started.
8 changes: 8 additions & 0 deletions proposals/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Proposals

This directory contains overviews for proposals that are included in this
repository.

This is analogous to [the correpsonding directory in the spec repository].

[the correpsonding directory in the spec repository]: https://github.com/WebAssembly/spec/tree/master/proposals
7 changes: 7 additions & 0 deletions repos/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
The spec and proposal repositories will be cloned in this directory by the
make-testsuite.sh script. Don't apply local changes to these repositories, as
the script may destroy them.

This is analogous to [the coresponding wasm testsuite directory].

[the coresponding wasm testsuite directory]: https://github.com/WebAssembly/testsuite/tree/master/repos
5 changes: 5 additions & 0 deletions snapshots/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# WASI Snapshots

To balance between the needs of development and stability, snapshots
represent the state of all active proposals at a moment in time. Individual
Snapshots are stable, but WASI as a whole is evolving.
159 changes: 159 additions & 0 deletions snapshots/make-snapshot.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
#!/bin/bash
# Creates a snapshot based on upstream proposal repositories.
# Derived from update-testsuite.sh in https://github.com/WebAssembly/testsuite
set -e
set -u
set -o pipefail

ignore_dirs=''

# TODO: Add the rest.
repos='
WASI
wasi-filesystem
wasi-clocks
wasi-random
'

log_and_run() {
echo ">>" $*
if ! $*; then
echo "sub-command failed: $*"
exit
fi
}

try_log_and_run() {
echo ">>" $*
$*
}

pushdir() {
pushd $1 >/dev/null || exit
}

popdir() {
popd >/dev/null || exit
}

update_repo() {
local repo=$1
pushdir repos
if [ -d ${repo} ]; then
log_and_run git -C ${repo} fetch origin
log_and_run git -C ${repo} reset origin/master --hard
else
log_and_run git clone https://github.com/WebAssembly/${repo}
fi

# Add upstream WASI as "WASI" remote.
if [ "${repo}" != "WASI" ]; then
pushdir ${repo}
if ! git remote | grep WASI >/dev/null; then
log_and_run git remote add WASI https://github.com/WebAssembly/WASI
fi

log_and_run git fetch WASI
popdir
fi
popdir
}

merge_with_WASI() {
local repo=$1

[ "${repo}" == "WASI" ] && return

pushdir repos/${repo}
# Create and checkout "try-merge" branch.
if ! git branch | grep try-merge >/dev/null; then
log_and_run git branch try-merge origin/master
fi
log_and_run git checkout try-merge

# Attempt to merge with WASI/master.
log_and_run git reset origin/master --hard
try_log_and_run git merge -q WASI/master -m "merged"
if [ $? -ne 0 ]; then
# Ignore merge conflicts in non-test directories.
# We don't care about those changes.
try_log_and_run git checkout --ours ${ignore_dirs}
try_log_and_run git add ${ignore_dirs}
try_log_and_run git -c core.editor=true merge --continue
if [ $? -ne 0 ]; then
git merge --abort
popdir
return 1
fi
fi
popdir
return 0
}

snapshot_name=$(date --iso-8601)
snapshot_dir=snapshots/$snapshot_name
mkdir -p $snapshot_dir

commit_message_file=$PWD/commit_message
echo -e "Update repos\n" > $commit_message_file

failed_repos=

for repo in ${repos}; do
echo "++ updating ${repo}"
update_repo ${repo}

if ! merge_with_WASI ${repo}; then
echo -e "!! error merging ${repo}, skipping\n"
failed_repos="${failed_repos} ${repo}"
continue
fi

if [ "${repo}" = "WASI" ]; then
dest_dir=$snapshot_dir
log_and_run cp -r repos/${repo}/standard ${dest_dir}
else
dest_dir=$snapshot_dir/proposals/${repo}
mkdir -p ${dest_dir}

# Don't add tests from proposal that are the same as WASI.
pushdir repos/${repo}
for new in $(find standard -type f); do
old=../../repos/WASI/${new}
if [[ ! -f ${old} ]] || ! diff ${old} ${new} >/dev/null; then
log_and_run cp ${new} ../../${dest_dir}
fi
done
popdir
fi

# Check whether any files were removed.
for old in $(find ${dest_dir} -type f); do
new=$(find repos/${repo}/standard -name ${old##*/})
if [[ ! -f ${new} ]]; then
log_and_run git rm ${old}
fi
done

# Check whether any files were updated.
if [ $(git status -s ${dest_dir} | wc -l) -ne 0 ]; then
log_and_run git add ${dest_dir}/*

repo_sha=$(git -C repos/${repo} log --max-count=1 --oneline origin/master| sed -e 's/ .*//')
echo " ${repo}:" >> $commit_message_file
echo " https://github.com/WebAssembly/${repo}/commit/${repo_sha}" >> $commit_message_file
fi

echo -e "-- ${repo}\n"
done

echo "" >> $commit_message_file
echo "This change was automatically generated by \`make-snapshot.sh\`" >> $commit_message_file
git commit -a -F $commit_message_file
# git push

echo "done"

if [ -n "${failed_repos}" ]; then
echo "!! failed to update repos: ${failed_repos}"
fi
12 changes: 12 additions & 0 deletions standard/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# WASI Standard

In the [main WASI repository], this directory holds proposals which have
[completed the standardization process].

In a proposal repository, which is a fork of the main WASI repository,
this directory holds the current proposal, including witx specifications,
tests, and documentation. When the proposal is standardized, the fork is
merged into the main repository.

[main WASI repository]: https://github.com/WebAssembly/WASI/issues/360
[completed the standardization process]: https://github.com/WebAssembly/meetings/blob/master/process/phases.md#5-the-feature-is-standardized-working-group

0 comments on commit a333ebe

Please sign in to comment.