Movatterモバイル変換


[0]ホーム

URL:


Google Git
Sign in
chromium /chromium /src /refs/heads/main /. /base /base_paths.cc
blob: 38241c6fbab6d466ac3fa0950b00c24eea6902bb [file] [log] [blame]
Avi Drissmane4622aa2022-09-08 20:36:06[diff] [blame]1// Copyright 2006-2008 The Chromium Authors
license.botbf09a502008-08-24 00:55:55[diff] [blame]2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commitd7cae122008-07-26 21:49:38[diff] [blame]4
5#include"base/base_paths.h"
6
Paul Semelf90c9dc52023-11-03 12:19:56[diff] [blame]7#include"base/environment.h"
brettw@chromium.org57999812013-02-24 05:40:52[diff] [blame]8#include"base/files/file_path.h"
brettw@chromium.orge3177dd52014-08-13 20:22:14[diff] [blame]9#include"base/files/file_util.h"
Paul Semelf90c9dc52023-11-03 12:19:56[diff] [blame]10#include"base/logging.h"
initial.commitd7cae122008-07-26 21:49:38[diff] [blame]11#include"base/path_service.h"
Paul Semelf90c9dc52023-11-03 12:19:56[diff] [blame]12#include"base/strings/utf_string_conversions.h"
Xiaohan Wang38e4ebb2022-01-19 06:57:43[diff] [blame]13#include"build/build_config.h"
initial.commitd7cae122008-07-26 21:49:38[diff] [blame]14
initial.commitd7cae122008-07-26 21:49:38[diff] [blame]15namespace base{
16
Paul Semelf90c9dc52023-11-03 12:19:56[diff] [blame]17// This provider aims at overriding the initial behaviour for all platforms. It
18// is meant to be run **before** the platform specific provider so that this one
19// prevails in case the overriding conditions are met. This provider is also
20// meant to fallback on the platform specific provider, which means it should
21// not handle the `BasePathKey` for which we do not have overriding behaviours.
22boolEnvOverridePathProvider(int key,FilePath* result){
23switch(key){
24case base::DIR_SRC_TEST_DATA_ROOT:{
25// Allow passing this in the environment, for more flexibility in build
26// tree configurations (sub-project builds, gyp --output_dir, etc.)
27 std::unique_ptr<Environment> env(Environment::Create());
Helmut Januschka726658b2025-03-21 22:44:57[diff] [blame]28 std::optional<std::string> cr_source_root= env->GetVar("CR_SOURCE_ROOT");
29if(cr_source_root.has_value()){
30FilePath path;
Paul Semelf90c9dc52023-11-03 12:19:56[diff] [blame]31#if BUILDFLAG(IS_WIN)
Helmut Januschka726658b2025-03-21 22:44:57[diff] [blame]32 path=FilePath(UTF8ToWide(cr_source_root.value()));
Paul Semelf90c9dc52023-11-03 12:19:56[diff] [blame]33#else
Helmut Januschka726658b2025-03-21 22:44:57[diff] [blame]34 path=FilePath(cr_source_root.value());
Paul Semelf90c9dc52023-11-03 12:19:56[diff] [blame]35#endif
36if(!path.IsAbsolute()){
37FilePath root;
38if(PathService::Get(DIR_EXE,&root)){
39 path= root.Append(path);
40}
41}
42if(DirectoryExists(path)){
43*result= path;
44returntrue;
45}
46 DLOG(WARNING)<<"CR_SOURCE_ROOT is set, but it appears to not "
47<<"point to a directory.";
48}
49returnfalse;
50}
51default:
52break;
53}
54returnfalse;
55}
56
evanm@google.com4792a262008-11-19 16:50:03[diff] [blame]57boolPathProvider(int key,FilePath* result){
gab@chromium.orgdea1d7d2012-09-20 16:24:52[diff] [blame]58// NOTE: DIR_CURRENT is a special case in PathService::Get
initial.commitd7cae122008-07-26 21:49:38[diff] [blame]59
initial.commitd7cae122008-07-26 21:49:38[diff] [blame]60switch(key){
tfarina@chromium.orgc4803e432013-03-28 00:40:04[diff] [blame]61case DIR_EXE:
Peter Kasting134ef9af2024-12-28 02:30:09[diff] [blame]62if(!PathService::Get(FILE_EXE, result)){
Sergey Ulanovd5ae68e2018-02-07 20:14:21[diff] [blame]63returnfalse;
Peter Kasting134ef9af2024-12-28 02:30:09[diff] [blame]64}
brettw@chromium.orgffaee18e2014-02-19 20:34:23[diff] [blame]65*result= result->DirName();
66returntrue;
Sylvain Defresnee7b66552023-06-20 08:23:30[diff] [blame]67#if !BUILDFLAG(IS_FUCHSIA) && !BUILDFLAG(IS_IOS)
tfarina@chromium.orgc4803e432013-03-28 00:40:04[diff] [blame]68case DIR_MODULE:
Peter Kasting134ef9af2024-12-28 02:30:09[diff] [blame]69if(!PathService::Get(FILE_MODULE, result)){
Sergey Ulanovd5ae68e2018-02-07 20:14:21[diff] [blame]70returnfalse;
Peter Kasting134ef9af2024-12-28 02:30:09[diff] [blame]71}
brettw@chromium.orgffaee18e2014-02-19 20:34:23[diff] [blame]72*result= result->DirName();
73returntrue;
Sergey Ulanovd5ae68e2018-02-07 20:14:21[diff] [blame]74case DIR_ASSETS:
75returnPathService::Get(DIR_MODULE, result);
Sylvain Defresnee7b66552023-06-20 08:23:30[diff] [blame]76#endif// !BUILDFLAG(IS_FUCHSIA) && !BUILDFLAG(IS_IOS)
tfarina@chromium.orgc4803e432013-03-28 00:40:04[diff] [blame]77case DIR_TEMP:
Sergey Ulanovd5ae68e2018-02-07 20:14:21[diff] [blame]78returnGetTempDir(result);
David Dorwinc694f722021-10-29 22:46:59[diff] [blame]79case DIR_HOME:
brettw@chromium.orgffaee18e2014-02-19 20:34:23[diff] [blame]80*result=GetHomeDir();
81returntrue;
Etienne Pierre-dorayf4dcbd6a2023-07-06 16:12:03[diff] [blame]82case base::DIR_SRC_TEST_DATA_ROOT:
83// This is only used by tests and overridden by each platform.
Peter Boströmde573332024-08-26 20:42:45[diff] [blame]84 NOTREACHED();
Etienne Pierre-dorayf4dcbd6a2023-07-06 16:12:03[diff] [blame]85#if !BUILDFLAG(IS_FUCHSIA) && !BUILDFLAG(IS_IOS)
86case DIR_OUT_TEST_DATA_ROOT:
87// On most platforms test binaries are run directly from the build-output
88// directory, so return the directory containing the executable.
89returnPathService::Get(DIR_MODULE, result);
90#endif// !BUILDFLAG(IS_FUCHSIA) && !BUILDFLAG(IS_IOS)
Etienne Pierre-doraybd109b42023-06-15 15:55:31[diff] [blame]91case DIR_GEN_TEST_DATA_ROOT:
Etienne Pierre-dorayf4dcbd6a2023-07-06 16:12:03[diff] [blame]92if(!PathService::Get(DIR_OUT_TEST_DATA_ROOT, result)){
Etienne Pierre-doraybd109b42023-06-15 15:55:31[diff] [blame]93returnfalse;
94}
95*result= result->Append(FILE_PATH_LITERAL("gen"));
96returntrue;
maniscalco6e147812015-12-11 18:23:13[diff] [blame]97case DIR_TEST_DATA:{
98FilePath test_data_path;
Etienne Pierre-dorayf4dcbd6a2023-07-06 16:12:03[diff] [blame]99if(!PathService::Get(DIR_SRC_TEST_DATA_ROOT,&test_data_path)){
tfarina@chromium.orgc4803e432013-03-28 00:40:04[diff] [blame]100returnfalse;
Etienne Pierre-dorayf4dcbd6a2023-07-06 16:12:03[diff] [blame]101}
maniscalco6e147812015-12-11 18:23:13[diff] [blame]102 test_data_path= test_data_path.Append(FILE_PATH_LITERAL("base"));
103 test_data_path= test_data_path.Append(FILE_PATH_LITERAL("test"));
104 test_data_path= test_data_path.Append(FILE_PATH_LITERAL("data"));
Peter Kasting134ef9af2024-12-28 02:30:09[diff] [blame]105if(!PathExists(test_data_path)){// We don't want to create this.
tfarina@chromium.orgc4803e432013-03-28 00:40:04[diff] [blame]106returnfalse;
Peter Kasting134ef9af2024-12-28 02:30:09[diff] [blame]107}
maniscalco6e147812015-12-11 18:23:13[diff] [blame]108*result= test_data_path;
brettw@chromium.orgffaee18e2014-02-19 20:34:23[diff] [blame]109returntrue;
maniscalco6e147812015-12-11 18:23:13[diff] [blame]110}
initial.commitd7cae122008-07-26 21:49:38[diff] [blame]111}
David Dorwinc694f722021-10-29 22:46:59[diff] [blame]112
113returnfalse;
initial.commitd7cae122008-07-26 21:49:38[diff] [blame]114}
115
116}// namespace base

[8]ページ先頭

©2009-2025 Movatter.jp