Skip to content

Commit

Permalink
roadmap download github dependencies (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
kreempuff authored Sep 22, 2024
2 parents 1dace1f + 966059d commit 407617a
Show file tree
Hide file tree
Showing 8 changed files with 171 additions and 112 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ jobs:
- uses: actions/cache@v4
with:
path: ~/.cache/bazel
key: ${{ runner.os }}-bazel-${{ hashFiles('./WORKSPACE', '**/BUILD', '**/BUILD.bzl', '**/*.bzl', '.bazelrc') }}
key: ${{ runner.os }}-bazel-${{ hashFiles('./MODULE.bazel', './MODULE.bazel.lock', '**/BUILD', '**/BUILD.bzl', '**/*.bzl', '.bazelrc') }}
restore-keys: |
${{ runner.os }}-bazel-
- run: bazel test --config ci //:unreal_target_test
- run: bazel build --config ci //:rules-unreal-engine

28 changes: 0 additions & 28 deletions BUILD
Original file line number Diff line number Diff line change
@@ -1,33 +1,5 @@
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
load("@bazel_gazelle//:def.bzl", "gazelle")
load(":rules_test.bzl", "unreal_target_test_suite")

# gazelle:prefix kreempuff.dev/rules-unreal-engine
gazelle(name = "gazelle")

gazelle(
name = "gazelle-update-repos",
args = [
"-from_file=go.mod",
"-to_macro=deps.bzl%go_dependencies",
"-prune",
],
command = "update-repos",
)

go_library(
name = "rules-unreal-engine_lib",
srcs = ["main.go"],
importpath = "kreempuff.dev/rules-unreal-engine",
visibility = ["//visibility:private"],
deps = ["//cmd"],
)

go_binary(
name = "rules-unreal-engine",
embed = [":rules-unreal-engine_lib"],
visibility = ["//visibility:public"],
)

unreal_target_test_suite(
name = "unreal_target_test",
Expand Down
13 changes: 12 additions & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
module(
name = "rules_unreal_engine",
version = "0.0.1",
)
)

bazel_dep(name = "bazel_skylib", version = "1.7.1")

unreal_engine = use_repo_rule("//internal/repo:rule.bzl", "unreal_engine")

unreal_engine(
name = "unreal_engine",
commit = "kreempuff-release",
# git_repository = "https://github.com/kreempuff/UnrealEngine.git",
git_repository = "file:///Users/kareemmarch/Projects/UnrealEngine",
)
111 changes: 111 additions & 0 deletions MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

76 changes: 0 additions & 76 deletions WORKSPACE

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# 2. Use deno/typscript for all scripting and bazel adjacent work

Date: 2024-05-24

## Status

Accepted

## Context

While Bazel is the main tool being used to build the project, there are many tasks that are not well suited to Bazel. These include:

- Preprocessing files
- Generating code
- Doing one-off tasks to get things ready for Bazel

I started by using Golang as a way to not need to have external dependencies, but it's not a great language for scripting. I started using deno since it supports TypeScript and has a mechanism for importing modules from the web without needing to set up a package manager.

## Decision

For everything that can't be done with Bazel, use deno/TypeScript.

## Consequences

- Deno would need to be installed at some point during the build process
- This will cause a split in where to put certain logic but I'm hoping defaulting to Bazel will be enough to make it clear where to put things
7 changes: 4 additions & 3 deletions internal/repo/rule.bzl
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
def _unreal_engine_impl(repo_ctx):
repo_ctx.file("WORKSPACE", "")
repo_ctx.file("BUILD", """""")

exec_result = repo_ctx.execute(["git", "clone", repo_ctx.attr.git_repository, "--depth", "1", "--branch", repo_ctx.attr.commit, "UnrealEngine"], quiet = False)
if exec_result.return_code != 0:
fail("Failed to clone Unreal Engine")
repo_ctx.file("UnrealEngine/BUILD", """exports_files(["Setup.sh"])""")
fail("Failed to clone Unreal Engine: " + exec_result.stdout + exec_result.stderr)

version = "v1.30.1"
arch = ""
Expand All @@ -29,7 +29,8 @@ def _unreal_engine_impl(repo_ctx):
repo_ctx.execute(["chmod", "+x", "tools/deno/deno"])
repo_ctx.execute(["tools/deno/deno", "run", "--allow-read", "--allow-write", repo_ctx.path(repo_ctx.attr._parse_xml_script), "UnrealEngine/Engine/Build/Commit.gitdeps.xml", "Commit.gitdeps.json"])

# repo_ctx.execute(["tools/deno/deno", "run", "--allow-read", "--allow-write", "--allow-run", repo_ctx.attr._parse_xml_script.path, "UnrealEngine/Engine/Build/Commit.gitdeps.xml", "Commit.gitdeps.json"])
# Create build file
repo_ctx.file("UnrealEngine/BUILD", """exports_files(["Setup.sh"])""")

unreal_engine = repository_rule(
implementation = _unreal_engine_impl,
Expand Down
18 changes: 17 additions & 1 deletion parse-xml-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,30 @@ import {parseString} from "npm:xml2js";
const decoder = new TextDecoder("utf-8");
const data = decoder.decode(await Deno.readFile(Deno.args[0]));

/**
* {
* "downloadUrl": "",
* "id": "",
* }
*/
parseString(data, (err, result) => {
if (err) {
console.error(err);
return;
}
const baseUrl = result["DependencyManifest"]["$"]["BaseUrl"];

const packs = result["DependencyManifest"]["Packs"][0]["Pack"].reduce((shaMap, pack) => {
shaMap[pack["$"]["Hash"]] = {
downloadUrl: `${baseUrl}/${pack["$"]["RemotePath"]}/${pack["$"]["Hash"]}`,
id: pack["$"]["Hash"]
};
return shaMap;
}, {})

try {
Deno.writeTextFileSync(Deno.args[1], JSON.stringify(result, null, 4));
// Deno.writeTextFileSync(Deno.args[1], JSON.stringify(result, null, 4));
Deno.writeTextFileSync(Deno.args[1], JSON.stringify(packs, null));
} catch (writeErr) {
console.error(writeErr);
}
Expand Down

0 comments on commit 407617a

Please sign in to comment.