Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
78ae72b0
Unverified
Commit
78ae72b0
authored
Apr 10, 2022
by
Janko Djuric
Committed by
GitHub
Apr 10, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[flutter_tools] Add --build-number and --build-name support to web and linux (#100377)
parent
391a39a6
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
103 additions
and
5 deletions
+103
-5
build_info.dart
packages/flutter_tools/lib/src/build_info.dart
+10
-0
linux.dart
...ges/flutter_tools/lib/src/build_system/targets/linux.dart
+19
-1
web.dart
packages/flutter_tools/lib/src/build_system/targets/web.dart
+20
-4
build_linux.dart
packages/flutter_tools/lib/src/commands/build_linux.dart
+2
-0
build_web.dart
packages/flutter_tools/lib/src/commands/build_web.dart
+2
-0
build_web_test.dart
...er_tools/test/commands.shard/hermetic/build_web_test.dart
+25
-0
build_info_test.dart
...ges/flutter_tools/test/general.shard/build_info_test.dart
+4
-0
linux_test.dart
...s/test/general.shard/build_system/targets/linux_test.dart
+5
-0
web_test.dart
...ols/test/general.shard/build_system/targets/web_test.dart
+16
-0
No files found.
packages/flutter_tools/lib/src/build_info.dart
View file @
78ae72b0
...
@@ -237,6 +237,10 @@ class BuildInfo {
...
@@ -237,6 +237,10 @@ class BuildInfo {
kFileSystemRoots:
fileSystemRoots
.
join
(
','
),
kFileSystemRoots:
fileSystemRoots
.
join
(
','
),
if
(
fileSystemScheme
!=
null
)
if
(
fileSystemScheme
!=
null
)
kFileSystemScheme:
fileSystemScheme
!,
kFileSystemScheme:
fileSystemScheme
!,
if
(
buildName
!=
null
)
kBuildName:
buildName
!,
if
(
buildNumber
!=
null
)
kBuildNumber:
buildNumber
!,
};
};
}
}
...
@@ -952,6 +956,12 @@ const String kIconTreeShakerFlag = 'TreeShakeIcons';
...
@@ -952,6 +956,12 @@ const String kIconTreeShakerFlag = 'TreeShakeIcons';
/// The input key for an SkSL bundle path.
/// The input key for an SkSL bundle path.
const
String
kBundleSkSLPath
=
'BundleSkSLPath'
;
const
String
kBundleSkSLPath
=
'BundleSkSLPath'
;
/// The define to pass build name
const
String
kBuildName
=
'BuildName'
;
/// The define to pass build number
const
String
kBuildNumber
=
'BuildNumber'
;
final
Converter
<
String
,
String
>
_defineEncoder
=
utf8
.
encoder
.
fuse
(
base64
.
encoder
);
final
Converter
<
String
,
String
>
_defineEncoder
=
utf8
.
encoder
.
fuse
(
base64
.
encoder
);
final
Converter
<
String
,
String
>
_defineDecoder
=
base64
.
decoder
.
fuse
(
utf8
.
decoder
);
final
Converter
<
String
,
String
>
_defineDecoder
=
base64
.
decoder
.
fuse
(
utf8
.
decoder
);
...
...
packages/flutter_tools/lib/src/build_system/targets/linux.dart
View file @
78ae72b0
...
@@ -5,6 +5,7 @@
...
@@ -5,6 +5,7 @@
import
'../../artifacts.dart'
;
import
'../../artifacts.dart'
;
import
'../../base/file_system.dart'
;
import
'../../base/file_system.dart'
;
import
'../../build_info.dart'
;
import
'../../build_info.dart'
;
import
'../../convert.dart'
;
import
'../../devfs.dart'
;
import
'../../devfs.dart'
;
import
'../../project.dart'
;
import
'../../project.dart'
;
import
'../build_system.dart'
;
import
'../build_system.dart'
;
...
@@ -135,7 +136,7 @@ abstract class BundleLinuxAssets extends Target {
...
@@ -135,7 +136,7 @@ abstract class BundleLinuxAssets extends Target {
environment
.
buildDir
.
childFile
(
'app.dill'
)
environment
.
buildDir
.
childFile
(
'app.dill'
)
.
copySync
(
outputDirectory
.
childFile
(
'kernel_blob.bin'
).
path
);
.
copySync
(
outputDirectory
.
childFile
(
'kernel_blob.bin'
).
path
);
}
}
final
String
versionInfo
=
FlutterProject
.
current
().
getVersionInfo
(
);
final
String
versionInfo
=
getVersionInfo
(
environment
.
defines
);
final
Depfile
depfile
=
await
copyAssets
(
final
Depfile
depfile
=
await
copyAssets
(
environment
,
environment
,
outputDirectory
,
outputDirectory
,
...
@@ -153,6 +154,23 @@ abstract class BundleLinuxAssets extends Target {
...
@@ -153,6 +154,23 @@ abstract class BundleLinuxAssets extends Target {
environment
.
buildDir
.
childFile
(
'flutter_assets.d'
),
environment
.
buildDir
.
childFile
(
'flutter_assets.d'
),
);
);
}
}
/// Return json encoded string that contains data about version for package_info
String
getVersionInfo
(
Map
<
String
,
String
>
defines
)
{
final
Map
<
String
,
dynamic
>
versionInfo
=
jsonDecode
(
FlutterProject
.
current
().
getVersionInfo
())
as
Map
<
String
,
dynamic
>;
if
(
defines
.
containsKey
(
kBuildNumber
))
{
versionInfo
[
'build_number'
]
=
defines
[
kBuildNumber
];
}
if
(
defines
.
containsKey
(
kBuildName
))
{
versionInfo
[
'version'
]
=
defines
[
kBuildName
];
}
return
jsonEncode
(
versionInfo
);
}
}
}
/// A wrapper for AOT compilation that copies app.so into the output directory.
/// A wrapper for AOT compilation that copies app.so into the output directory.
...
...
packages/flutter_tools/lib/src/build_system/targets/web.dart
View file @
78ae72b0
...
@@ -341,10 +341,7 @@ class WebReleaseBundle extends Target {
...
@@ -341,10 +341,7 @@ class WebReleaseBundle extends Target {
);
);
}
}
final
String
versionInfo
=
FlutterProject
.
current
().
getVersionInfo
();
createVersionFile
(
environment
,
environment
.
defines
);
environment
.
outputDir
.
childFile
(
'version.json'
)
.
writeAsStringSync
(
versionInfo
);
final
Directory
outputDirectory
=
environment
.
outputDir
.
childDirectory
(
'assets'
);
final
Directory
outputDirectory
=
environment
.
outputDir
.
childDirectory
(
'assets'
);
outputDirectory
.
createSync
(
recursive:
true
);
outputDirectory
.
createSync
(
recursive:
true
);
final
Depfile
depfile
=
await
copyAssets
(
final
Depfile
depfile
=
await
copyAssets
(
...
@@ -411,6 +408,25 @@ class WebReleaseBundle extends Target {
...
@@ -411,6 +408,25 @@ class WebReleaseBundle extends Target {
environment
.
buildDir
.
childFile
(
'web_resources.d'
),
environment
.
buildDir
.
childFile
(
'web_resources.d'
),
);
);
}
}
/// Create version.json file that contains data about version for package_info
void
createVersionFile
(
Environment
environment
,
Map
<
String
,
String
>
defines
)
{
final
Map
<
String
,
dynamic
>
versionInfo
=
jsonDecode
(
FlutterProject
.
current
().
getVersionInfo
())
as
Map
<
String
,
dynamic
>;
if
(
defines
.
containsKey
(
kBuildNumber
))
{
versionInfo
[
'build_number'
]
=
defines
[
kBuildNumber
];
}
if
(
defines
.
containsKey
(
kBuildName
))
{
versionInfo
[
'version'
]
=
defines
[
kBuildName
];
}
environment
.
outputDir
.
childFile
(
'version.json'
)
.
writeAsStringSync
(
jsonEncode
(
versionInfo
));
}
}
}
/// Static assets provided by the Flutter SDK that do not change, such as
/// Static assets provided by the Flutter SDK that do not change, such as
...
...
packages/flutter_tools/lib/src/commands/build_linux.dart
View file @
78ae72b0
...
@@ -22,6 +22,8 @@ class BuildLinuxCommand extends BuildSubCommand {
...
@@ -22,6 +22,8 @@ class BuildLinuxCommand extends BuildSubCommand {
})
:
_operatingSystemUtils
=
operatingSystemUtils
,
})
:
_operatingSystemUtils
=
operatingSystemUtils
,
super
(
verboseHelp:
verboseHelp
)
{
super
(
verboseHelp:
verboseHelp
)
{
addCommonDesktopBuildOptions
(
verboseHelp:
verboseHelp
);
addCommonDesktopBuildOptions
(
verboseHelp:
verboseHelp
);
usesBuildNumberOption
();
usesBuildNameOption
();
final
String
defaultTargetPlatform
=
final
String
defaultTargetPlatform
=
(
_operatingSystemUtils
.
hostPlatform
==
HostPlatform
.
linux_arm64
)
?
(
_operatingSystemUtils
.
hostPlatform
==
HostPlatform
.
linux_arm64
)
?
'linux-arm64'
:
'linux-x64'
;
'linux-arm64'
:
'linux-x64'
;
...
...
packages/flutter_tools/lib/src/commands/build_web.dart
View file @
78ae72b0
...
@@ -20,6 +20,8 @@ class BuildWebCommand extends BuildSubCommand {
...
@@ -20,6 +20,8 @@ class BuildWebCommand extends BuildSubCommand {
addTreeShakeIconsFlag
(
enabledByDefault:
false
);
addTreeShakeIconsFlag
(
enabledByDefault:
false
);
usesTargetOption
();
usesTargetOption
();
usesPubOption
();
usesPubOption
();
usesBuildNumberOption
();
usesBuildNameOption
();
addBuildModeFlags
(
verboseHelp:
verboseHelp
,
excludeDebug:
true
);
addBuildModeFlags
(
verboseHelp:
verboseHelp
,
excludeDebug:
true
);
usesDartDefineOption
();
usesDartDefineOption
();
usesWebRendererOption
();
usesWebRendererOption
();
...
...
packages/flutter_tools/test/commands.shard/hermetic/build_web_test.dart
View file @
78ae72b0
...
@@ -148,6 +148,31 @@ void main() {
...
@@ -148,6 +148,31 @@ void main() {
ProcessManager:
()
=>
FakeProcessManager
.
any
(),
ProcessManager:
()
=>
FakeProcessManager
.
any
(),
BuildSystem:
()
=>
TestBuildSystem
.
all
(
BuildResult
(
success:
true
)),
BuildSystem:
()
=>
TestBuildSystem
.
all
(
BuildResult
(
success:
true
)),
});
});
testUsingContext
(
'Web build supports build-name and build-number'
,
()
async
{
final
TestWebBuildCommand
buildCommand
=
TestWebBuildCommand
();
final
CommandRunner
<
void
>
runner
=
createTestCommandRunner
(
buildCommand
);
setupFileSystemForEndToEndTest
(
fileSystem
);
await
runner
.
run
(<
String
>[
'build'
,
'web'
,
'--no-pub'
,
'--build-name=1.2.3'
,
'--build-number=42'
,
]);
final
BuildInfo
buildInfo
=
await
buildCommand
.
webCommand
.
getBuildInfo
(
forcedBuildMode:
BuildMode
.
debug
);
expect
(
buildInfo
.
buildNumber
,
'42'
);
expect
(
buildInfo
.
buildName
,
'1.2.3'
);
},
overrides:
<
Type
,
Generator
>{
Platform:
()
=>
fakePlatform
,
FileSystem:
()
=>
fileSystem
,
FeatureFlags:
()
=>
TestFeatureFlags
(
isWebEnabled:
true
),
ProcessManager:
()
=>
FakeProcessManager
.
any
(),
BuildSystem:
()
=>
TestBuildSystem
.
all
(
BuildResult
(
success:
true
)),
});
}
}
void
setupFileSystemForEndToEndTest
(
FileSystem
fileSystem
)
{
void
setupFileSystemForEndToEndTest
(
FileSystem
fileSystem
)
{
...
...
packages/flutter_tools/test/general.shard/build_info_test.dart
View file @
78ae72b0
...
@@ -121,6 +121,8 @@ void main() {
...
@@ -121,6 +121,8 @@ void main() {
codeSizeDirectory:
'foo/code-size'
,
codeSizeDirectory:
'foo/code-size'
,
fileSystemRoots:
<
String
>[
'test5'
,
'test6'
],
fileSystemRoots:
<
String
>[
'test5'
,
'test6'
],
fileSystemScheme:
'scheme'
,
fileSystemScheme:
'scheme'
,
buildName:
'122'
,
buildNumber:
'22'
);
);
expect
(
buildInfo
.
toBuildSystemEnvironment
(),
<
String
,
String
>{
expect
(
buildInfo
.
toBuildSystemEnvironment
(),
<
String
,
String
>{
...
@@ -136,6 +138,8 @@ void main() {
...
@@ -136,6 +138,8 @@ void main() {
'CodeSizeDirectory'
:
'foo/code-size'
,
'CodeSizeDirectory'
:
'foo/code-size'
,
'FileSystemRoots'
:
'test5,test6'
,
'FileSystemRoots'
:
'test5,test6'
,
'FileSystemScheme'
:
'scheme'
,
'FileSystemScheme'
:
'scheme'
,
'BuildName'
:
'122'
,
'BuildNumber'
:
'22'
,
});
});
});
});
...
...
packages/flutter_tools/test/general.shard/build_system/targets/linux_test.dart
View file @
78ae72b0
...
@@ -100,6 +100,8 @@ void main() {
...
@@ -100,6 +100,8 @@ void main() {
fileSystem
.
currentDirectory
,
fileSystem
.
currentDirectory
,
defines:
<
String
,
String
>{
defines:
<
String
,
String
>{
kBuildMode:
'debug'
,
kBuildMode:
'debug'
,
kBuildName:
'2.0.0'
,
kBuildNumber:
'22'
,
},
},
inputs:
<
String
,
String
>{
inputs:
<
String
,
String
>{
kBundleSkSLPath:
'bundle.sksl'
,
kBundleSkSLPath:
'bundle.sksl'
,
...
@@ -133,6 +135,9 @@ void main() {
...
@@ -133,6 +135,9 @@ void main() {
expect
(
output
.
childFile
(
'kernel_blob.bin'
),
exists
);
expect
(
output
.
childFile
(
'kernel_blob.bin'
),
exists
);
expect
(
output
.
childFile
(
'AssetManifest.json'
),
exists
);
expect
(
output
.
childFile
(
'AssetManifest.json'
),
exists
);
expect
(
output
.
childFile
(
'version.json'
),
exists
);
expect
(
output
.
childFile
(
'version.json'
),
exists
);
final
String
versionFile
=
output
.
childFile
(
'version.json'
).
readAsStringSync
();
expect
(
versionFile
,
contains
(
'"version":"2.0.0"'
));
expect
(
versionFile
,
contains
(
'"build_number":"22"'
));
// SkSL
// SkSL
expect
(
output
.
childFile
(
'io.flutter.shaders.json'
),
exists
);
expect
(
output
.
childFile
(
'io.flutter.shaders.json'
),
exists
);
expect
(
output
.
childFile
(
'io.flutter.shaders.json'
).
readAsStringSync
(),
'{"data":{"A":"B"}}'
);
expect
(
output
.
childFile
(
'io.flutter.shaders.json'
).
readAsStringSync
(),
'{"data":{"A":"B"}}'
);
...
...
packages/flutter_tools/test/general.shard/build_system/targets/web_test.dart
View file @
78ae72b0
...
@@ -102,6 +102,22 @@ void main() {
...
@@ -102,6 +102,22 @@ void main() {
expect
(
environment
.
outputDir
.
childFile
(
'version.json'
),
exists
);
expect
(
environment
.
outputDir
.
childFile
(
'version.json'
),
exists
);
}));
}));
test
(
'override version values'
,
()
=>
testbed
.
run
(()
async
{
environment
.
defines
[
kBuildMode
]
=
'release'
;
environment
.
defines
[
kBuildName
]
=
'2.0.0'
;
environment
.
defines
[
kBuildNumber
]
=
'22'
;
final
Directory
webResources
=
environment
.
projectDir
.
childDirectory
(
'web'
);
webResources
.
childFile
(
'index.html'
).
createSync
(
recursive:
true
);
environment
.
buildDir
.
childFile
(
'main.dart.js'
).
createSync
();
await
const
WebReleaseBundle
().
build
(
environment
);
final
String
versionFile
=
environment
.
outputDir
.
childFile
(
'version.json'
)
.
readAsStringSync
();
expect
(
versionFile
,
contains
(
'"version":"2.0.0"'
));
expect
(
versionFile
,
contains
(
'"build_number":"22"'
));
}));
test
(
'Base href is created in index.html with given base-href after release build'
,
()
=>
testbed
.
run
(()
async
{
test
(
'Base href is created in index.html with given base-href after release build'
,
()
=>
testbed
.
run
(()
async
{
environment
.
defines
[
kBuildMode
]
=
'release'
;
environment
.
defines
[
kBuildMode
]
=
'release'
;
environment
.
defines
[
kBaseHref
]
=
'/basehreftest/'
;
environment
.
defines
[
kBaseHref
]
=
'/basehreftest/'
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment