From 801fd954a2b3ad4daa47893b5596f30b79d0ca7c Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Mon, 13 Nov 2023 09:40:39 -0800 Subject: [PATCH] Automatically export support and tools to its own repository. --- .github/filter-support/LICENSE-filtered | 21 +++ .github/filter-support/Makefile-filtered | 186 ++++++++++++++++++++++ .github/filter-support/README-filtered.md | 12 ++ .github/filter-support/close.yml | 13 ++ .github/filter-support/filter.sh | 34 ++++ .github/workflows/chores.yml | 159 ++++++++++-------- 6 files changed, 356 insertions(+), 69 deletions(-) create mode 100644 .github/filter-support/LICENSE-filtered create mode 100644 .github/filter-support/Makefile-filtered create mode 100644 .github/filter-support/README-filtered.md create mode 100644 .github/filter-support/close.yml create mode 100755 .github/filter-support/filter.sh diff --git a/.github/filter-support/LICENSE-filtered b/.github/filter-support/LICENSE-filtered new file mode 100644 index 000000000..490e7cb3e --- /dev/null +++ b/.github/filter-support/LICENSE-filtered @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 PCSX-Redux authors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/.github/filter-support/Makefile-filtered b/.github/filter-support/Makefile-filtered new file mode 100644 index 000000000..d5961061e --- /dev/null +++ b/.github/filter-support/Makefile-filtered @@ -0,0 +1,186 @@ +BUILD ?= Release +DESTDIR ?= /usr/local +CROSS ?= none + +UNAME_S := $(shell uname -s) +UNAME_M := $(shell uname -m) +rwildcard=$(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2)) +CC_IS_CLANG := $(shell $(CC) --version | grep -q clang && echo true || echo false) + +PACKAGES := zlib + +ifeq ($(wildcard third_party/ELFIO/elfio/elfio.hpp),) +HAS_SUBMODULES = false +else +HAS_SUBMODULES = true +endif + +CXXFLAGS += -std=c++2b +CPPFLAGS += `pkg-config --cflags $(PACKAGES)` +CPPFLAGS += -I. +CPPFLAGS += -Isrc +CPPFLAGS += -Ithird_party +CPPFLAGS += -Ithird_party/ELFIO +CPPFLAGS += -Ithird_party/fmt/include/ +CPPFLAGS += -Ithird_party/googletest/googletest/include +CPPFLAGS += -Ithird_party/ucl -Ithird_party/ucl/include +CPPFLAGS += -g + +CPPFLAGS_Release += -O3 +CPPFLAGS_Debug += -O0 +CPPFLAGS_Coverage += -O0 +ifeq ($(CC_IS_CLANG),true) + CPPFLAGS_Coverage += -fprofile-instr-generate -fcoverage-mapping +else + CPPFLAGS_Coverage += -fprofile-arcs -ftest-coverage +endif +CPPFLAGS_asan += -O1 -fsanitize=address -fno-omit-frame-pointer +CPPFLAGS_ubsan += -O1 -fsanitize=undefined -fno-omit-frame-pointer +CPPFLAGS_lto += -O3 -flto=auto -fno-fat-lto-objects -flto-partition=one + +ifeq ($(CC_IS_CLANG),true) + CXXFLAGS += -fcoroutines-ts +else + CXXFLAGS += -fcoroutines +endif + +ifeq ($(UNAME_S),Darwin) + CPPFLAGS += -mmacosx-version-min=10.15 + CPPFLAGS += -stdlib=libc++ +endif + +LDFLAGS += `pkg-config --libs $(PACKAGES)` + +ifeq ($(UNAME_S),Darwin) + LDFLAGS += -lc++ + LDFLAGS += -mmacosx-version-min=10.15 +else + LDFLAGS += -lstdc++fs +endif + +LDFLAGS += -ldl +LDFLAGS += -g + +ifeq ($(CC_IS_CLANG),true) + LDFLAGS_Coverage += -fprofile-instr-generate -fcoverage-mapping +else + LDFLAGS_Coverage += -fprofile-arcs -ftest-coverage +endif +LDFLAGS_asan += -fsanitize=address +LDFLAGS_ubsan += -fsanitize=undefined +LDFLAGS_lto += -O3 -flto=auto -flto-partition=one + +CPPFLAGS += $(CPPFLAGS_$(BUILD)) -pthread +LDFLAGS += $(LDFLAGS_$(BUILD)) -pthread + +ifeq ($(CROSS),arm64) + CPPFLAGS += -fPIC -Wl,-rpath-link,/opt/cross/sysroot/usr/lib/aarch64-linux-gnu -L/opt/cross/sysroot/usr/lib/aarch64-linux-gnu + LDFLAGS += -fPIC -Wl,-rpath-link,/opt/cross/sysroot/usr/lib/aarch64-linux-gnu -L/opt/cross/sysroot/usr/lib/aarch64-linux-gnu +endif + +LD := $(CXX) + +SRCS := $(call rwildcard,src/,*.cc) +SRCS += third_party/fmt/src/os.cc third_party/fmt/src/format.cc +SRCS += $(wildcard third_party/cueparser/*.c) +SRCS += $(wildcard third_party/iec-60908b/*.c) +SRCS += third_party/ucl/src/n2e_99.c third_party/ucl/src/alloc.c + +TOOLS = exe2elf exe2iso ps1-packer psyq-obj-parser + +############################################################################## + +OBJECTS += $(patsubst %.c,%.o,$(filter %.c,$(SRCS))) +OBJECTS += $(patsubst %.cc,%.o,$(filter %.cc,$(SRCS))) +OBJECTS += $(patsubst %.cpp,%.o,$(filter %.cpp,$(SRCS))) +OBJECTS += $(patsubst %.mm,%.o,$(filter %.mm,$(SRCS))) + +TESTS_SRC := $(call rwildcard,tests/,*.cc) +TESTS := $(patsubst %.cc,%,$(TESTS_SRC)) + +CP ?= cp +MKDIRP ?= mkdir -p + +all: check_submodules dep tools + +ifeq ($(HAS_SUBMODULES),true) +check_submodules: + +else +check_submodules: + @echo "You need to clone this repository recursively, in order to get its submodules." + @false +endif + +strip: all + strip $(TOOLS) + +install: all strip + $(MKDIRP) $(DESTDIR)/bin + $(CP) $(TOOLS) $(DESTDIR)/bin + +%.o: %.c + $(CC) -c -o $@ $< $(CPPFLAGS) $(EXTRA_CPPFLAGS) $(CFLAGS) + +%.o: %.cc + $(CXX) -c -o $@ $< $(CPPFLAGS) $(EXTRA_CPPFLAGS) $(CXXFLAGS) + +%.o: %.cpp + $(CXX) -c -o $@ $< $(CPPFLAGS) $(EXTRA_CPPFLAGS) $(CXXFLAGS) + +%.o: %.mm + $(CC) -c -o $@ $< $(CPPFLAGS) $(EXTRA_CPPFLAGS) $(CFLAGS) + +%.dep: %.c + $(CC) $(CPPFLAGS) $(EXTRA_CPPFLAGS) $(CFLAGS) -M -MT $(addsuffix .o, $(basename $@)) -MF $@ $< + +%.dep: %.cc + $(CXX) $(CPPFLAGS) $(EXTRA_CPPFLAGS) $(CXXFLAGS) -M -MT $(addsuffix .o, $(basename $@)) -MF $@ $< + +%.dep: %.cpp + $(CXX) $(CPPFLAGS) $(EXTRA_CPPFLAGS) $(CXXFLAGS) -M -MT $(addsuffix .o, $(basename $@)) -MF $@ $< + +clean: + rm -f $(OBJECTS) $(TARGET) $(DEPS) gtest-all.o gtest_main.o + +gtest-all.o: $(wildcard third_party/googletest/googletest/src/*.cc) + $(CXX) -O3 -g $(CXXFLAGS) -Ithird_party/googletest/googletest -Ithird_party/googletest/googletest/include -c third_party/googletest/googletest/src/gtest-all.cc + +gtest_main.o: third_party/googletest/googletest/src/gtest_main.cc + $(CXX) -O3 -g $(CXXFLAGS) -Ithird_party/googletest/googletest -Ithird_party/googletest/googletest/include -c third_party/googletest/googletest/src/gtest_main.cc + +gitclean: + git clean -f -d -x + git submodule foreach --recursive git clean -f -d -x + +tests: $(foreach t,$(TESTS),$(t).o) $(NONMAIN_OBJECTS) gtest-all.o gtest_main.o + $(LD) -o tests $(NONMAIN_OBJECTS) gtest-all.o gtest_main.o $(foreach t,$(TESTS),$(t).o) -Ithird_party/googletest/googletest/include $(LDFLAGS) + +runtests: tests + ./tests + +define TOOLDEF +$(1): $(OBJECTS) tools/$(1)/$(1).o + $(LD) -o $(1) $(CPPFLAGS) $(CXXFLAGS) $(OBJECTS) tools/$(1)/$(1).o -static $(LDFLAGS) + +endef + +$(foreach tool,$(TOOLS),$(eval $(call TOOLDEF,$(tool)))) + +tools: $(TOOLS) + +.PHONY: all dep clean gitclean runtests install strip tools + +DEPS += $(patsubst %.c,%.dep,$(filter %.c,$(SRCS))) +DEPS := $(patsubst %.cc,%.dep,$(filter %.cc,$(SRCS))) +DEPS += $(patsubst %.cpp,%.dep,$(filter %.cpp,$(SRCS))) + +dep: $(DEPS) + +ifneq ($(MAKECMDGOALS), clean) +ifneq ($(MAKECMDGOALS), gitclean) +ifeq ($(HAS_SUBMODULES), true) +-include $(DEPS) +endif +endif +endif diff --git a/.github/filter-support/README-filtered.md b/.github/filter-support/README-filtered.md new file mode 100644 index 000000000..dae0caca8 --- /dev/null +++ b/.github/filter-support/README-filtered.md @@ -0,0 +1,12 @@ +# PCSX-Redux's Support & Tools + +This repository is a read-only reduced mirror of +[the PCSX-Redux project](https://github.com/grumpycoders/pcsx-redux). It only contains the necessary parts to build the [tools](https://github.com/grumpycoders/pcsx-redux/tree/main/tools) only, as well as the [support libraries](https://github.com/grumpycoders/pcsx-redux/tree/main/support). +Its purpose is to be used as a submodule for projects that want to use the tools and libraries +contained herein without bringing the whole of PCSX-Redux's codebase. + +Please consult [the upstream repository](https://github.com/grumpycoders/pcsx-redux) and [its documentation](https://pcsx-redux.consoledev.net) for more information. There is also some documentation nested within the folders. + +This repository will be updated periodically to match the upstream repository, and its history will be rewritten to remove all commits that are not related to the tools. While care is taken to try and ensure some sort of consistency, a simple `git pull` may not work to update it. Resetting to the remote HEAD is recommended when updating. + +All of the code here is MIT-licensed. See the [LICENSE](LICENSE) file for more information. diff --git a/.github/filter-support/close.yml b/.github/filter-support/close.yml new file mode 100644 index 000000000..6e82c70a4 --- /dev/null +++ b/.github/filter-support/close.yml @@ -0,0 +1,13 @@ +name: Close Pull Request + +on: + pull_request_target: + types: [opened] + +jobs: + run: + runs-on: ubuntu-latest + steps: + - uses: superbrothers/close-pull-request@v3 + with: + comment: "Thank you for your pull request, but this repository is a read-only mirror of the [PCSX-Redux project](https://github.com/grumpycoders/pcsx-redux). Please open your pull request there instead." diff --git a/.github/filter-support/filter.sh b/.github/filter-support/filter.sh new file mode 100755 index 000000000..b04d81aa1 --- /dev/null +++ b/.github/filter-support/filter.sh @@ -0,0 +1,34 @@ +#!/bin/sh + +set -e + +ROOT=$(dirname $0) +CWD=$(pwd) +cd $ROOT +ROOT=$(pwd) +cd $CWD + +# Delete non-tools source code +git filter-branch -f --tree-filter '(mv src/mips . || true) && (mv src/support . || true) && (mv src/supportpsx . || true) && rm -rf src && mkdir -p src && (mv mips src || true) && (mv support src || true) && mv supportpsx src || true' --tag-name-filter cat --prune-empty +git filter-branch -f --tree-filter 'find src/mips -depth -type f -not -path src/mips/common/\* -delete || true' --tag-name-filter cat --prune-empty + +# Delete some root files. +git filter-branch -f --tree-filter 'rm -f *.yml LICENSE* mips.ps1 TODO.md' --tag-name-filter cat --prune-empty + +# Delete irrelevant folders +git filter-branch -f --tree-filter 'rm -rf .github hardware i18n resources .vscode vsprojects tests/pcsxrunner' --tag-name-filter cat --prune-empty + +# Need to delete submodules actively. +# Done in two passes for speed. +git filter-branch -f --tree-filter 'find third_party -maxdepth 1 -type d -and -not -name third_party -and -not -path third_party/cueparser* -and -not -path third_party/ELFIO\* -and -not -path third_party/expected\* -and -not -path third_party/fmt\* -and -not -path third_party/googletest\* -and -not -path third_party/iec-60908b\* -and -not -path third_party/magic_enum\* -and -not -path third_party/ucl\* -exec rm -rf {} \; || true' --tag-name-filter cat --prune-empty +git filter-branch -f --tree-filter 'find third_party -maxdepth 1 -type d -and -not -name third_party -and -not -path third_party/cueparser* -and -not -path third_party/ELFIO\* -and -not -path third_party/expected\* -and -not -path third_party/fmt\* -and -not -path third_party/googletest\* -and -not -path third_party/iec-60908b\* -and -not -path third_party/magic_enum\* -and -not -path third_party/ucl\* -exec git rm -f {} \; || true' --tag-name-filter cat --prune-empty + +# Delete ffmpeg, versionning, Lua, and libuv-related source code +git filter-branch -f --tree-filter 'find src -type f -name \*lua\* -delete || true' --tag-name-filter cat --prune-empty +git filter-branch -f --tree-filter 'find src -type f -name assembler.\* -delete || true' --tag-name-filter cat --prune-empty +git filter-branch -f --tree-filter 'find src -type f -name ffmpeg\* -delete || true' --tag-name-filter cat --prune-empty +git filter-branch -f --tree-filter 'find src -type f -name uv\* -delete || true' --tag-name-filter cat --prune-empty +git filter-branch -f --tree-filter 'find src -type f -name version\* -delete || true' --tag-name-filter cat --prune-empty + +# Inject our new root files. +git filter-branch -f --tree-filter "cp ${ROOT}/README-filtered.md README.md && cp ${ROOT}/LICENSE-filtered LICENSE && cp ${ROOT}/Makefile-filtered Makefile && mkdir -p .github/workflows && cp ${ROOT}/close.yml .github/workflows" --tag-name-filter cat diff --git a/.github/workflows/chores.yml b/.github/workflows/chores.yml index eea961158..d7248c916 100644 --- a/.github/workflows/chores.yml +++ b/.github/workflows/chores.yml @@ -7,86 +7,107 @@ on: jobs: regen-i18n: - runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - with: - submodules: recursive - set-safe-directory: true - - uses: n1hility/cancel-previous-runs@v2 - with: - token: ${{ secrets.GITHUB_TOKEN }} - - name: Install gettext - run: sudo apt-get install -y gettext - - name: Regenerate i18n files - run: make regen-i18n - - name: Cleanup - run: rm -f i18n/*~ - - name: Create Pull Request - id: cpr - uses: peter-evans/create-pull-request@v3 - with: - token: ${{ secrets.PAT }} - commit-message: '[Chores] Regen i18n' - committer: GitHub - author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com> - signoff: false - branch: chores-i18n - delete-branch: true - title: '[Chores] Regen i18n' - draft: false + - uses: actions/checkout@v3 + with: + submodules: recursive + set-safe-directory: true + - uses: n1hility/cancel-previous-runs@v2 + with: + token: ${{ secrets.GITHUB_TOKEN }} + - name: Install gettext + run: sudo apt-get install -y gettext + - name: Regenerate i18n files + run: make regen-i18n + - name: Cleanup + run: rm -f i18n/*~ + - name: Create Pull Request + id: cpr + uses: peter-evans/create-pull-request@v3 + with: + token: ${{ secrets.PAT }} + commit-message: "[Chores] Regen i18n" + committer: GitHub + author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com> + signoff: false + branch: chores-i18n + delete-branch: true + title: "[Chores] Regen i18n" + draft: false code-format: - runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - with: - submodules: recursive - set-safe-directory: true - - uses: n1hility/cancel-previous-runs@v2 - with: - token: ${{ secrets.GITHUB_TOKEN }} - - name: Format code - run: ./tools/code-format/format.sh - - name: Create Pull Request - id: cpr - uses: peter-evans/create-pull-request@v3 - with: - token: ${{ secrets.PAT }} - commit-message: '[Chores] Format code' - committer: GitHub - author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com> - signoff: false - branch: chores-code-format - delete-branch: true - title: '[Chores] Format code' - draft: false + - uses: actions/checkout@v3 + with: + submodules: recursive + set-safe-directory: true + - uses: n1hility/cancel-previous-runs@v2 + with: + token: ${{ secrets.GITHUB_TOKEN }} + - name: Format code + run: ./tools/code-format/format.sh + - name: Create Pull Request + id: cpr + uses: peter-evans/create-pull-request@v3 + with: + token: ${{ secrets.PAT }} + commit-message: "[Chores] Format code" + committer: GitHub + author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com> + signoff: false + branch: chores-code-format + delete-branch: true + title: "[Chores] Format code" + draft: false export-mips: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + - uses: n1hility/cancel-previous-runs@v2 + with: + token: ${{ secrets.GITHUB_TOKEN }} + - name: Filter repository + env: + FILTER_BRANCH_SQUELCH_WARNING: 1 + run: | + cp -rv .github/filter-mips /tmp + /tmp/filter-mips/filter.sh + - name: Pushing result + env: + PAT: ${{ secrets.PAT }} + run: | + git config -l | grep 'http\..*\.extraheader' | cut -d= -f1 | xargs -L1 git config --unset-all + git remote add nugget https://nicolasnoble:$PAT@github.com/pcsx-redux/nugget.git + git push --force https://nicolasnoble:$PAT@github.com/pcsx-redux/nugget.git main + export-support: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - with: - fetch-depth: 0 - - uses: n1hility/cancel-previous-runs@v2 - with: - token: ${{ secrets.GITHUB_TOKEN }} - - name: Filter repository - env: - FILTER_BRANCH_SQUELCH_WARNING: 1 - run: | - cp -rv .github/filter-mips /tmp - /tmp/filter-mips/filter.sh - - name: Pushing result - env: - PAT: ${{ secrets.PAT }} - run: | - git config -l | grep 'http\..*\.extraheader' | cut -d= -f1 | xargs -L1 git config --unset-all - git remote add nugget https://nicolasnoble:$PAT@github.com/pcsx-redux/nugget.git - git push --force https://nicolasnoble:$PAT@github.com/pcsx-redux/nugget.git main + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + - uses: n1hility/cancel-previous-runs@v2 + with: + token: ${{ secrets.GITHUB_TOKEN }} + - name: Filter repository + env: + FILTER_BRANCH_SQUELCH_WARNING: 1 + run: | + cp -rv .github/filter-support /tmp + /tmp/filter-support/filter.sh + - name: Pushing result + env: + PAT: ${{ secrets.PAT }} + run: | + git config -l | grep 'http\..*\.extraheader' | cut -d= -f1 | xargs -L1 git config --unset-all + git remote add support https://nicolasnoble:$PAT@github.com/pcsx-redux/support.git + git push --force https://nicolasnoble:$PAT@github.com/pcsx-redux/support.git main