feat: add build dart script for windows

This commit is contained in:
Kingkor Roy Tirtho 2024-05-06 19:20:59 +06:00
parent 4ca893950b
commit 38dc934f40
15 changed files with 227 additions and 24 deletions

View File

@ -55,7 +55,6 @@ jobs:
- name: Replace version in files
run: |
choco install sed make -y
sed -i "s/%{{SPOTUBE_VERSION}}%/${{ env.BUILD_VERSION }}/" windows/runner/Runner.rc
sed -i "s/%{{SPOTUBE_VERSION}}%/${{ env.BUILD_VERSION }}/" choco-struct/tools/VERIFICATION.txt
sed -i "s/%{{SPOTUBE_VERSION}}%/${{ env.BUILD_VERSION }}/" choco-struct/spotube.nuspec

View File

@ -1,11 +1,11 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled.
# This file should be version controlled and should not be manually edited.
version:
revision: eb6d86ee27deecba4a83536aa20f366a6044895c
channel: stable
revision: "300451adae589accbece3490f4396f10bdf15e6e"
channel: "stable"
project_type: app
@ -13,11 +13,11 @@ project_type: app
migration:
platforms:
- platform: root
create_revision: eb6d86ee27deecba4a83536aa20f366a6044895c
base_revision: eb6d86ee27deecba4a83536aa20f366a6044895c
- platform: macos
create_revision: eb6d86ee27deecba4a83536aa20f366a6044895c
base_revision: eb6d86ee27deecba4a83536aa20f366a6044895c
create_revision: 300451adae589accbece3490f4396f10bdf15e6e
base_revision: 300451adae589accbece3490f4396f10bdf15e6e
- platform: windows
create_revision: 300451adae589accbece3490f4396f10bdf15e6e
base_revision: 300451adae589accbece3490f4396f10bdf15e6e
# User provided section

4
cli/README.md Normal file
View File

@ -0,0 +1,4 @@
## Spotube Configuration CLI
This is used for building the project for multiple platforms and having utilities specific for the project.
Written in Dart

10
cli/cli.dart Normal file
View File

@ -0,0 +1,10 @@
import 'package:args/command_runner.dart';
void main(List<String> args) {
final commandRunner = CommandRunner(
"cli",
"Configuration CLI for Spotube",
);
commandRunner.run(args);
}

View File

View File

@ -0,0 +1,41 @@
import 'dart:io';
import 'package:args/command_runner.dart';
import 'package:path/path.dart';
import 'package:process_run/shell_run.dart';
import 'package:pubspec_parse/pubspec_parse.dart';
mixin BuildCommandCommonSteps on Command {
final shell = Shell();
Directory get cwd => Directory.current;
Pubspec? _pubspec;
Pubspec get pubspec {
if (_pubspec != null) {
return _pubspec!;
}
final pubspecFile = File(join(cwd.path, "pubspec.yaml"));
_pubspec = Pubspec.parse(pubspecFile.readAsStringSync());
return _pubspec!;
}
String get versionWithoutBuildNumber {
return "${pubspec.version!.major}.${pubspec.version!.minor}.${pubspec.version!.patch}";
}
RegExp get versionVarRegExp =>
RegExp(r"\%\{\{SPOTUBE_VERSION\}\}\%", multiLine: true);
Future<void> bootstrap() async {
await shell.run(
"""
flutter pub get
dart run build_runner build --delete-conflicting-outputs
dart pub global activate flutter_distributor
""",
);
}
}

View File

View File

View File

View File

@ -0,0 +1,105 @@
import 'dart:io';
import 'package:args/command_runner.dart';
import 'package:path/path.dart';
import 'package:crypto/crypto.dart';
import 'common.dart';
class WindowsBuildCommand extends Command with BuildCommandCommonSteps {
@override
String get description => "Build Windows exe";
@override
String get name => "windows";
Future<void> innoInstall() async {
final innoInstallerPath = join(cwd.path, "build", "installer.exe");
const innoVersion = "6.2.0";
final innoDependencyPath = join(cwd.path, "build", "inno-depend");
await shell.run(
"""
curl -o $innoInstallerPath http://files.jrsoftware.org/is/6/innosetup-$innoVersion.exe
git clone https://github.com/DomGries/InnoDependencyInstaller.git $innoDependencyPath
$innoInstallerPath /verysilent /allusers /dir=build\\iscc
""",
);
}
@override
void run() async {
stdout.writeln("Replace versions");
final chocoFiles = [
join(cwd.path, "choco-struct", "tools", "VERIFICATION.txt"),
join(cwd.path, "choco-struct", "spotube.nuspec"),
];
for (final filePath in chocoFiles) {
final file = File(filePath);
final content = file.readAsStringSync();
final newContent =
content.replaceAll(versionVarRegExp, versionWithoutBuildNumber);
file.writeAsStringSync(newContent);
}
await bootstrap();
await innoInstall();
await shell.run(
"flutter_distributor package --platform=windows --targets=exe --skip-clean",
);
final ogExe = File(
join(
cwd.path,
"dist",
pubspec.version.toString(),
"spotube-${pubspec.version}-windows-setup.exe",
),
);
final exePath = join(cwd.path, "dist", "Spotube-windows-x86_64-setup.exe");
await ogExe.copy(exePath);
await ogExe.delete();
stdout.writeln("✅ Windows exe built at $exePath");
final exeFile = File(exePath);
final hash = sha256.convert(exeFile.readAsBytesSync()).toString();
final chocoVerificationFile = File(chocoFiles.first);
chocoVerificationFile.writeAsStringSync(
chocoVerificationFile.readAsStringSync().replaceAll(
RegExp(r"\%\{\{WIN_SHA256\}\}\%"),
hash,
),
);
final chocoToolsPath = join(cwd.path, "choco-struct", "tools");
exeFile.copySync(chocoToolsPath);
await shell.run(
"choco pack ${chocoFiles[1]} --outputdirectory ${join(cwd.path, "dist")}",
);
final chocoNupkg = File(
join(cwd.path, "dist", "spotube.$versionWithoutBuildNumber.nupkg"),
);
final distNupkgPath = join(
cwd.path,
"dist",
"Spotube-windows-x86_64.nupkg",
);
await chocoNupkg.copy(distNupkgPath);
await chocoNupkg.delete();
stdout.writeln("✅ Windows nupkg built at $distNupkgPath");
}
}

22
cli/core/env.dart Normal file
View File

@ -0,0 +1,22 @@
import 'dart:io';
enum BuildChannel {
stable,
nightly;
factory BuildChannel.fromEnvironment(String name) {
final channel = Platform.environment[name]!;
if (channel == "stable") {
return BuildChannel.stable;
} else if (channel == "nightly") {
return BuildChannel.nightly;
} else {
throw Exception("Invalid channel: $channel");
}
}
}
class CliEnv {
static final channel = BuildChannel.fromEnvironment("CHANNEL");
static final dotenv = Platform.environment["DOTENV"]!;
}

View File

@ -1734,6 +1734,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "5.0.2"
process_run:
dependency: "direct dev"
description:
name: process_run
sha256: "8d9c6198b98fbbfb511edd42e7364e24d85c163e47398919871b952dc86a423e"
url: "https://pub.dev"
source: hosted
version: "0.14.2"
provider:
dependency: transitive
description:

View File

@ -144,6 +144,7 @@ dev_dependencies:
freezed: ^2.5.2
custom_lint: ^0.6.4
riverpod_lint: ^2.3.10
process_run: ^0.14.2
dependency_overrides:
uuid: ^4.4.0

View File

@ -1,13 +1,16 @@
# Project-level configuration.
cmake_minimum_required(VERSION 3.14)
project(spotube LANGUAGES CXX)
# The name of the executable created for the application. Change this to change
# the on-disk name of your application.
set(BINARY_NAME "spotube")
cmake_policy(SET CMP0063 NEW)
# Explicitly opt in to modern CMake behaviors to avoid warnings with recent
# versions of CMake.
cmake_policy(VERSION 3.14...3.25)
set(CMAKE_INSTALL_RPATH "$ORIGIN/lib")
# Configure build options.
# Define build configuration option.
get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(IS_MULTICONFIG)
set(CMAKE_CONFIGURATION_TYPES "Debug;Profile;Release"
@ -20,7 +23,7 @@ else()
"Debug" "Profile" "Release")
endif()
endif()
# Define settings for the Profile build mode.
set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}")
set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}")
set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE}")
@ -30,6 +33,10 @@ set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE}")
add_definitions(-DUNICODE -D_UNICODE)
# Compilation settings that should be applied to most targets.
#
# Be cautious about adding new options here, as plugins use this function by
# default. In most cases, you should add new options to specific targets instead
# of modifying this function.
function(APPLY_STANDARD_SETTINGS TARGET)
target_compile_features(${TARGET} PUBLIC cxx_std_17)
target_compile_options(${TARGET} PRIVATE /W4 /WX /wd"4100")
@ -38,14 +45,14 @@ function(APPLY_STANDARD_SETTINGS TARGET)
target_compile_definitions(${TARGET} PRIVATE "$<$<CONFIG:Debug>:_DEBUG>")
endfunction()
set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter")
# Flutter library and tool build rules.
set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter")
add_subdirectory(${FLUTTER_MANAGED_DIR})
# Application build
# Application build; see runner/CMakeLists.txt.
add_subdirectory("runner")
# Generated plugin build rules, which manage building the plugins and adding
# them to the application.
include(flutter/generated_plugins.cmake)
@ -80,6 +87,12 @@ if(PLUGIN_BUNDLED_LIBRARIES)
COMPONENT Runtime)
endif()
# Copy the native assets provided by the build.dart from all packages.
set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/windows/")
install(DIRECTORY "${NATIVE_ASSETS_DIR}"
DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
COMPONENT Runtime)
# Fully re-copy the assets directory on each build to avoid having stale files
# from a previous install.
set(FLUTTER_ASSET_DIR_NAME "flutter_assets")

View File

@ -60,16 +60,16 @@ IDI_APP_ICON ICON "resources\\app_icon.ico"
// Version
//
#ifdef FLUTTER_BUILD_NUMBER
#define VERSION_AS_NUMBER FLUTTER_BUILD_NUMBER
#if defined(FLUTTER_VERSION_MAJOR) && defined(FLUTTER_VERSION_MINOR) && defined(FLUTTER_VERSION_PATCH) && defined(FLUTTER_VERSION_BUILD)
#define VERSION_AS_NUMBER FLUTTER_VERSION_MAJOR,FLUTTER_VERSION_MINOR,FLUTTER_VERSION_PATCH,FLUTTER_VERSION_BUILD
#else
#define VERSION_AS_NUMBER 1,0,0
#define VERSION_AS_NUMBER 1,0,0,0
#endif
#ifdef FLUTTER_BUILD_NAME
#define VERSION_AS_STRING #FLUTTER_BUILD_NAME
#if defined(FLUTTER_VERSION)
#define VERSION_AS_STRING FLUTTER_VERSION
#else
#define VERSION_AS_STRING "%{{SPOTUBE_VERSION}}%"
#define VERSION_AS_STRING "3.6.0"
#endif
VS_VERSION_INFO VERSIONINFO
@ -93,7 +93,7 @@ BEGIN
VALUE "FileDescription", "Spotube" "\0"
VALUE "FileVersion", VERSION_AS_STRING "\0"
VALUE "InternalName", "spotube" "\0"
VALUE "LegalCopyright", "Copyright (C) 2022 oss.krtirtho. All rights reserved." "\0"
VALUE "LegalCopyright", "Copyright (C) 2024 oss.krtirtho. All rights reserved." "\0"
VALUE "OriginalFilename", "spotube.exe" "\0"
VALUE "ProductName", "spotube" "\0"
VALUE "ProductVersion", VERSION_AS_STRING "\0"