-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 74f4c2a
Showing
26 changed files
with
1,047 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* text=auto eol=LF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/cache | ||
/build | ||
lint_report.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
version: 2 | ||
|
||
before: | ||
hooks: | ||
- go mod tidy | ||
- go mod download | ||
|
||
upx: | ||
- enabled: true | ||
compress: best | ||
lzma: true | ||
# TODO: delete this string when upx fix segfault | ||
# https://github.com/upx/upx/issues/612 | ||
goos: [linux, windows] | ||
|
||
builds: | ||
- id: "agb" | ||
main: ./cmd/agb | ||
binary: agb | ||
env: | ||
- CGO_ENABLED=0 | ||
goos: | ||
- linux | ||
- darwin | ||
- windows | ||
goarch: | ||
- amd64 | ||
- arm64 | ||
|
||
archives: | ||
- id: "agb" | ||
format: zip | ||
builds: | ||
- "agb" | ||
name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}" | ||
wrap_in_directory: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}" | ||
files: | ||
- docs/ | ||
- scripts/ | ||
- Dockerfile | ||
- LICENSE.md | ||
- README.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# build base image | ||
FROM golang:1.23-alpine3.19 as base | ||
ENV CGO_ENABLED=0 | ||
WORKDIR /build | ||
COPY ./agb/* . | ||
RUN go mod download && go generate ./... | ||
|
||
# launch the linter | ||
FROM golangci/golangci-lint:v1.60-alpine as lint | ||
ENV CGO_ENABLED=0 | ||
WORKDIR /src | ||
COPY --from=base /build . | ||
COPY ./agb/.golangci.yaml . | ||
RUN go mod download && golangci-lint run --timeout 5m | ||
|
||
# build the binary | ||
FROM base as build | ||
WORKDIR /build | ||
COPY --from=lint /src/lint_report.json . | ||
RUN go test ./agb/... && go build -o /build/agb ./cmd/agb | ||
|
||
# build final image | ||
FROM alpine:3.19 | ||
WORKDIR /app | ||
COPY --from=build /build/agb ./agb | ||
ADD https://storage.googleapis.com/git-repo-downloads/repo /usr/local/bin/ | ||
RUN chmod -R 755 /usr/local/bin/repo | ||
|
||
CMD [ "/bin/sh" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# AGB - Android GKI Builder | ||
|
||
> [!IMPORTANT] | ||
> | ||
> This tool is currently under heavy development. Please use with caution. | ||
Android GKI builds made easy. | ||
|
||
## Description | ||
|
||
AGB does not add any extra functionality into the kernel. | ||
|
||
It only acts as a comprehensive build wrapper managing all of the aspects of kernel building process, including source collection, environment preparation, resource management etc. Kernel source modification is up to the user. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
run: | ||
tests: false | ||
output: | ||
formats: | ||
- format: colored-line-number | ||
- format: checkstyle | ||
path: lint_report.json | ||
linters: | ||
enable: | ||
- errcheck | ||
- gosimple | ||
- govet | ||
- ineffassign | ||
- typecheck | ||
- unused | ||
- cyclop | ||
- gofmt | ||
- lll |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"agb/command" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// newBuildCmd registers the "build" command. | ||
func newBuildCmd() *cobra.Command { | ||
var ( | ||
linuxKernelVersion float64 | ||
androidVersion int | ||
patchVersion string | ||
defconfigPath string | ||
modulesPath string | ||
clangUrl string | ||
sourceLocation string | ||
kernelSu bool | ||
) | ||
|
||
command := &cobra.Command{ | ||
Use: "build", | ||
Short: "Build the Android kernel.", | ||
ValidArgs: []string{ | ||
"linux-kernel-version", | ||
"android-version", | ||
"patch-version", | ||
"defconfig-path", | ||
"modules-path", | ||
"clang-url", | ||
"source-location", | ||
"kernelsu", | ||
}, | ||
Args: cobra.MatchAll(cobra.OnlyValidArgs), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
command_obj := command.NewBuildCommand( | ||
linuxKernelVersion, | ||
androidVersion, | ||
patchVersion, | ||
defconfigPath, | ||
clangUrl, | ||
sourceLocation, | ||
modulesPath, | ||
kernelSu, | ||
) | ||
|
||
res := command_obj.Execute() | ||
return res | ||
}, | ||
} | ||
|
||
flags := command.Flags() | ||
flags.Float64VarP( | ||
&linuxKernelVersion, | ||
"linux-kernel-version", | ||
"l", | ||
0, | ||
"Linux kernel version number (required)", | ||
) | ||
flags.IntVarP( | ||
&androidVersion, | ||
"android-version", | ||
"a", | ||
0, | ||
"Android version number (required)", | ||
) | ||
flags.StringVarP( | ||
&patchVersion, | ||
"patch-version", | ||
"p", | ||
"", | ||
"patch version number", | ||
) | ||
flags.StringVarP( | ||
&defconfigPath, | ||
"defconfig-path", | ||
"d", | ||
"", | ||
"custom path to defconfig", | ||
) | ||
flags.StringVarP( | ||
&modulesPath, | ||
"modules-path", | ||
"m", | ||
"", | ||
"custom path to kernel modules", | ||
) | ||
flags.StringVarP( | ||
&clangUrl, | ||
"clang-url", | ||
"c", | ||
"https://android.googlesource.com/platform/prebuilts/clang/host/linux-x86/+archive/eed2fff8b93ce059eea7ccd8fc5eee37f8adb432/clang-r458507.tar.gz", | ||
"path to a Clang pre-build zip", | ||
) | ||
flags.StringVarP( | ||
&sourceLocation, | ||
"source-location", | ||
"s", | ||
"", | ||
"custom location to GKI kernel sources (local path or URL to git repo)", | ||
) | ||
flags.BoolVarP( | ||
&kernelSu, | ||
"kernelsu", | ||
"k", | ||
false, | ||
"optional KernelSU support (for GKI mode)", | ||
) | ||
|
||
command.MarkFlagRequired("linux-kernel-version") | ||
command.MarkFlagRequired("android-version") | ||
|
||
return command | ||
} | ||
|
||
// newCleanCmd registers the "clean" command. | ||
func newCleanCmd() *cobra.Command { | ||
return &cobra.Command{ | ||
Use: "clean", | ||
Short: "Clean the build environment.", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
// check if anything at all was provided for the query | ||
if len(args) < 1 { | ||
fmt.Println("WIP") | ||
} | ||
|
||
fmted_args := strings.Join(args[:], " ") | ||
fmt.Println(fmted_args) | ||
}, | ||
} | ||
} | ||
|
||
func main() { | ||
rootCmd := &cobra.Command{ | ||
Use: "agb", | ||
Short: "Android GKI Builder.", | ||
} | ||
|
||
rootCmd.AddCommand(newBuildCmd()) | ||
rootCmd.AddCommand(newCleanCmd()) | ||
|
||
rootCmd.Execute() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package command | ||
|
||
import ( | ||
"agb/core" | ||
"agb/manager" | ||
) | ||
|
||
// BuildCommand is a representation of "build" command. | ||
type BuildCommand struct { | ||
LinuxKernelVersion float64 | ||
AndroidVersion int | ||
PatchVersion string | ||
DefconfigPath string | ||
ClangUrl string | ||
SourceLocation string | ||
ModulesUrl string | ||
KernelSu bool | ||
} | ||
|
||
// Create new instance of BuildCommand. | ||
func NewBuildCommand( | ||
lkv float64, | ||
av int, | ||
pv string, | ||
dp string, | ||
cu string, | ||
sloc string, | ||
murl string, | ||
ksu bool, | ||
) *BuildCommand { | ||
return &BuildCommand{ | ||
LinuxKernelVersion: lkv, | ||
AndroidVersion: av, | ||
PatchVersion: pv, | ||
DefconfigPath: dp, | ||
ClangUrl: cu, | ||
SourceLocation: sloc, | ||
ModulesUrl: murl, | ||
KernelSu: ksu, | ||
} | ||
} | ||
|
||
// Execute runs "build" command's logic. | ||
func (bc *BuildCommand) Execute() error { | ||
resource_manager := manager.NewResourceManager( | ||
bc.ClangUrl, | ||
bc.SourceLocation, | ||
) | ||
|
||
kernel_builder := core.NewGkiBuilder( | ||
bc.LinuxKernelVersion, | ||
bc.AndroidVersion, | ||
bc.PatchVersion, | ||
bc.DefconfigPath, | ||
bc.SourceLocation, | ||
bc.ModulesUrl, | ||
bc.KernelSu, | ||
resource_manager, | ||
) | ||
|
||
if err := kernel_builder.Prepare(); err != nil { | ||
return err | ||
} | ||
|
||
//if err := kernel_builder.Build(); err != nil { | ||
// return err | ||
//} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package command | ||
|
||
type CleanCommand struct{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package config | ||
|
||
import ( | ||
"github.com/spf13/viper" | ||
) | ||
|
||
type Config struct { | ||
Directory struct { | ||
Root string | ||
Kernelsource string | ||
Kernelbuild string | ||
Clang string | ||
} | ||
Url struct { | ||
Source string | ||
Toolchain string | ||
Anykernel3 string | ||
} | ||
Buildenv string | ||
} | ||
|
||
// Read reads the config file. | ||
func (c Config) Read() error { | ||
cfgFile := "config.yaml" | ||
viper.SetConfigFile(cfgFile) | ||
return nil | ||
} | ||
|
||
// Validate checks that read config is valid. | ||
func (c Config) Validate() bool { | ||
return true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package config | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
// DirectoryConfig represents a config containing internal paths to multiple resources. | ||
type DirectoryConfig struct { | ||
RootPath string | ||
KernelSourcePath string | ||
KernelBuildPath string | ||
ClangPath string | ||
Anykernel3Path string | ||
} | ||
|
||
// NewDirectoryConfig returns new instance of DirectoryConfig | ||
func NewDirectoryConfig() *DirectoryConfig { | ||
// get the root path and use it as a base for everything | ||
root, _ := filepath.Abs(filepath.Dir(os.Args[0])) | ||
|
||
return &DirectoryConfig{ | ||
RootPath: root, | ||
KernelSourcePath: filepath.Join(root, "kernel_source"), | ||
KernelBuildPath: filepath.Join(root, "kernel_build"), | ||
ClangPath: filepath.Join(root, "clang"), | ||
Anykernel3Path: filepath.Join(root, "anykernel3"), | ||
} | ||
} |
Oops, something went wrong.